chore: final cleanup of offload configuration paths and test assertions

This commit is contained in:
mkorwel
2026-03-13 19:47:02 -07:00
parent 7113c5093d
commit d4a386c4ed
7 changed files with 47 additions and 42 deletions
+9 -29
View File
@@ -65,37 +65,17 @@ describe('Offload Tooling Matrix', () => {
});
});
describe('Fix Loop', () => {
it('should iterate until CI passes', async () => {
let checkAttempts = 0;
vi.mocked(spawnSync).mockImplementation((cmd: any, args: any) => {
// Correctly check command AND args
const isCheck = (typeof cmd === 'string' && cmd.includes('pr checks')) ||
(Array.isArray(args) && args.includes('checks'));
if (isCheck) {
checkAttempts++;
return { status: 0, stdout: Buffer.from(checkAttempts === 1 ? 'fail' : 'success') } as any;
}
return { status: 0, stdout: Buffer.from('test-branch\n') } as any;
});
vi.useFakeTimers();
describe('Fix Playbook', () => {
it('should launch the agentic fix-pr skill', async () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
const workerPromise = runWorker(['123', 'test-branch', '/path/policy', 'fix']);
await runWorker(['123', 'test-branch', '/path/policy', 'fix']);
// Multi-stage timer flush to get through TaskRunner cycles and the polling loop
for(let i=0; i<10; i++) {
await vi.advanceTimersByTimeAsync(2000);
}
await vi.advanceTimersByTimeAsync(40000); // 1st fail
for(let i=0; i<10; i++) { await vi.advanceTimersByTimeAsync(2000); }
await vi.advanceTimersByTimeAsync(40000); // 2nd pass
await workerPromise;
expect(checkAttempts).toBe(2);
vi.useRealTimers();
const spawnSyncCalls = vi.mocked(spawnSync).mock.calls;
const fixCall = spawnSyncCalls.find(call =>
JSON.stringify(call).includes("activate the 'fix-pr' skill")
);
expect(fixCall).toBeDefined();
});
});
});
@@ -78,9 +78,32 @@ describe('Offload Orchestration', () => {
await runOrchestrator(['123'], {});
const spawnCalls = vi.mocked(spawnSync).mock.calls;
const sshCall = spawnCalls.find(call => typeof call[0] === 'string' && call[0].includes('tmux new-session'));
// Match the new 'offload-123-test-branch' format
expect(sshCall![0]).toContain('offload-123-test-branch');
});
it('should use isolated config path when geminiSetup is isolated', async () => {
const isolatedSettings = {
...mockSettings,
maintainer: {
...mockSettings.maintainer,
deepReview: {
...mockSettings.maintainer.deepReview,
geminiSetup: 'isolated'
}
}
};
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(isolatedSettings));
await runOrchestrator(['123'], {});
const spawnCalls = vi.mocked(spawnSync).mock.calls;
const sshCall = spawnCalls.find(call => {
const cmdStr = typeof call[0] === 'string' ? call[0] : '';
return cmdStr.includes('GEMINI_CLI_HOME=~/.offload/gemini-cli-config');
});
expect(sshCall).toBeDefined();
});
});
describe('setup.ts', () => {
@@ -99,6 +122,8 @@ describe('Offload Orchestration', () => {
const remoteCmd = args[1];
if (remoteCmd.includes('[ -d ~/test-dir/.git ]')) return { status: 0 } as any;
if (remoteCmd.includes('command -v')) return { status: 0 } as any;
if (remoteCmd.includes('gh auth status')) return { status: 0 } as any;
if (remoteCmd.includes('google_accounts.json')) return { status: 0 } as any;
}
return { status: 0, stdout: Buffer.from(''), stderr: Buffer.from('') } as any;
});
@@ -122,15 +147,15 @@ describe('Offload Orchestration', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
await runWorker(['123', 'test-branch', '/test-policy.toml', 'review']);
const spawnCalls = vi.mocked(spawn).mock.calls;
expect(spawnCalls.some(c => c[0].includes('/review-frontend'))).toBe(true);
expect(spawnCalls.some(c => c[0].includes("activate the 'review-pr' skill"))).toBe(true);
});
it('should launch the fix playbook when requested', async () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
await runWorker(['123', 'test-branch', '/test-policy.toml', 'fix']);
const spawnCalls = vi.mocked(spawn).mock.calls;
// Match the updated prompt string in fix.ts
expect(spawnCalls.some(c => c[0].toLowerCase().includes('analyze current failures'))).toBe(true);
// runFixPlaybook uses spawnSync
const spawnSyncCalls = vi.mocked(spawnSync).mock.calls;
expect(spawnSyncCalls.some(c => JSON.stringify(c).includes("activate the 'fix-pr' skill"))).toBe(true);
});
});