Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/core/src/evaluation/results-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4124,7 +4124,19 @@ export async function deleteWipBranch(params: {
}): Promise<void> {
const normalized = normalizeResultsConfig(params.config);
const cloneDir = await ensureResultsRepoClone(normalized);
await runGit(['push', normalized.remote, '--delete', params.wipBranch], { cwd: cloneDir });
const result = await runGit(['push', normalized.remote, '--delete', params.wipBranch], {
cwd: cloneDir,
check: false,
});
if (result.exitCode === 0 || isMissingRemoteRefDelete(result)) {
return;
}
throw new Error(result.stderr.trim() || result.stdout.trim() || 'Failed to delete WIP branch');
}

function isMissingRemoteRefDelete(result: { stdout: string; stderr: string }): boolean {
const text = `${result.stderr}\n${result.stdout}`.toLowerCase();
return text.includes('remote ref does not exist');
}

// git exits non-zero with one of these messages when the requested ref/object
Expand Down
42 changes: 42 additions & 0 deletions packages/core/test/evaluation/results-repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2808,4 +2808,46 @@ describe('WIP branch helpers', () => {
const branchesAfter = git('git branch -r', cloneDir);
expect(branchesAfter).not.toContain(`origin/${wipBranch}`);
}, 30000);

it('deleteWipBranch ignores a missing remote WIP branch', async () => {
await expect(
deleteWipBranch({ config, wipBranch: 'agentv/wip/test-host/missing-run' }),
).resolves.toBeUndefined();
}, 30000);

it('deleteWipBranch surfaces non-missing remote delete failures', async () => {
const wipBranch = 'agentv/wip/test-host/rejected-delete';
const handle = await setupWipWorktree({ config, wipBranch });
const runDir = path.join(rootDir, 'run-rejected-delete-test');
writeRunArtifacts(runDir, 'default', '2026-01-15T13-00-00');

try {
await pushWipCheckpoint({
handle,
sourceDir: runDir,
destinationPath: 'default/2026-01-15T13-00-00',
});
} finally {
await handle.cleanup();
}

const hookPath = path.join(remoteDir, 'hooks', 'update');
writeFileSync(
hookPath,
[
'#!/usr/bin/env sh',
'if [ "$3" = "0000000000000000000000000000000000000000" ]; then',
' echo "unable to delete protected WIP branch" >&2',
' exit 1',
'fi',
'exit 0',
'',
].join('\n'),
);
chmodSync(hookPath, 0o755);

await expect(deleteWipBranch({ config, wipBranch })).rejects.toThrow(
/unable to delete protected WIP branch|hook declined/,
);
}, 30000);
});
Loading