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
30 changes: 30 additions & 0 deletions packages/engine/src/review-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ describe('runReviewJob', () => {
expect(results.events.some((e) => e.type === 'review.posted')).toBe(true);
});

test('writes the trace while the review runs, so the Console can follow it live', async () => {
let seenWhileRunning: string[] = [];
const { github, results, context } = setup();
const model = new MockLanguageModelV4({
doGenerate: async () => {
seenWhileRunning = results.events.map((e) => e.type);
return toolCall('submit_review', {
summary: 'Divides for real.',
findings: [],
tier: 'A',
walkthrough: []
});
}
});
context.models = { review: { model, provider: 'mock', modelId: 'mock-1' } };
github.patches = [
{
path: 'src/math.ts',
patch:
'@@ -1,3 +1,3 @@\n export function divide(a, b) {\n- return 0;\n+ return a / b;\n }'
}
];
results.queue({ id: 'review1' });

await runReviewJob(job(), context, first);

expect(seenWhileRunning).toContain('review.mode');
expect(results.review('review1')?.status).toBe('completed');
});

test('a push that changes nothing after the blocking finding settled stops blocking the PR', async () => {
const model = new MockLanguageModelV4({
doGenerate: [
Expand Down
13 changes: 13 additions & 0 deletions packages/engine/src/review-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,21 @@ async function executeReview(
.catch((error: unknown) => log.warn('could not record review usage', { err: error }));
return pendingWrites;
};
// Steps are written as they happen, so the Console can follow a running review. Steps
// recorded while a write is out wait for the next one, so a busy review sends batches,
// not a request per step.
let writeQueued = false;
const flushSoon = () => {
if (writeQueued) return;
writeQueued = true;
pendingWrites = pendingWrites.then(() => {
writeQueued = false;
});
void flush();
};
const record = (event: TraceStep) => {
events.push({ type: event.type, at: new Date(), data: event.data ?? {} });
flushSoon();
progress.onEvent(event);
if (event.type !== 'anchoring.suspicious') return;
log.warn('most findings could not be attached to a changed line', {
Expand Down