feat(offload): implement WorkerProvider abstraction and robust IAP fallback

This commit is contained in:
mkorwel
2026-03-16 15:33:40 -07:00
parent 5786dc675d
commit cc7b7e2fbc
14 changed files with 554 additions and 375 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { spawnSync, spawn } from 'child_process';
import { spawnSync } from 'child_process';
import fs from 'fs';
import { runFixPlaybook } from '../../scripts/playbooks/fix.ts';
@@ -9,26 +9,15 @@ vi.mock('fs');
describe('Fix Playbook', () => {
beforeEach(() => {
vi.resetAllMocks();
vi.mocked(fs.mkdirSync).mockReturnValue(undefined as any);
vi.mocked(fs.writeFileSync).mockReturnValue(undefined as any);
vi.mocked(fs.createWriteStream).mockReturnValue({ pipe: vi.fn() } as any);
vi.mocked(spawn).mockImplementation(() => {
return {
stdout: { pipe: vi.fn(), on: vi.fn() },
stderr: { pipe: vi.fn(), on: vi.fn() },
on: vi.fn((event, cb) => { if (event === 'close') cb(0); })
} as any;
});
vi.mocked(spawnSync).mockReturnValue({ status: 0 } as any);
});
it('should register and run initial build, failure analysis, and fixer', async () => {
runFixPlaybook('123', '/tmp/target', '/path/policy', '/path/gemini');
it('should launch the agentic fix-pr skill via spawnSync', async () => {
const status = await runFixPlaybook('123', '/tmp/target', '/path/policy', '/path/gemini');
const spawnCalls = vi.mocked(spawn).mock.calls;
expect(status).toBe(0);
const spawnCalls = vi.mocked(spawnSync).mock.calls;
expect(spawnCalls.some(c => c[0].includes('npm ci'))).toBe(true);
expect(spawnCalls.some(c => c[0].includes('gh run view --log-failed'))).toBe(true);
expect(spawnCalls.some(c => c[0].includes('Gemini Fixer'))).toBe(false); // Should wait for build
expect(spawnCalls.some(c => JSON.stringify(c).includes("activate the 'fix-pr' skill"))).toBe(true);
});
});
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { spawnSync, spawn } from 'child_process';
import { spawn } from 'child_process';
import fs from 'fs';
import { runReviewPlaybook } from '../../scripts/playbooks/review.ts';
@@ -22,16 +22,15 @@ describe('Review Playbook', () => {
});
});
it('should register and run build, ci, analysis, and verification', async () => {
const promise = runReviewPlaybook('123', '/tmp/target', '/path/policy', '/path/gemini');
it('should register and run build, ci, and review tasks', async () => {
// We don't await because TaskRunner uses setInterval and we'd need to mock timers
// but we can check if spawn was called with the right commands.
runReviewPlaybook('123', '/tmp/target', '/path/policy', '/path/gemini');
// The worker uses setInterval(1500) to check for completion, so we need to wait
// or mock the timer. For simplicity in this POC, we'll just verify spawn calls.
const spawnCalls = vi.mocked(spawn).mock.calls;
// These should start immediately (no deps)
expect(spawnCalls.some(c => c[0].includes('npm ci'))).toBe(true);
expect(spawnCalls.some(c => c[0].includes('gh pr checks'))).toBe(true);
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);
});
});