Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
67 changes: 67 additions & 0 deletions packages/cli/src/commands/review/agent-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,73 @@ describe('--round — the CLI bakes the round into the identity line and the key
}
});

it('reads the same clock on the --chunk build gate (#9256)', () => {
// The clock argument is passed at every cap call site, but only the
// sibling paths were exercised: a mutation confined to the `--chunk`
// gate's call site survived. Same sized huge plan and both clock arms as
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
// the test above, driven through the per-chunk gate instead.
const dir = mkdtempSync(join(tmpdir(), 'ap-clock-chunk-'));
try {
const findings = join(dir, 'f.md');
writeFileSync(findings, '- x');
const handler = agentPromptCommand.handler as (a: unknown) => void;
const before = process.env[DEADLINE_ENV];
const stderr = () =>
(writeStderrLine as unknown as Mock).mock.calls
.map((c) => c[0])
.join('\n');
// Separate plans per arm: a successful --chunk build stamps the round's
// admission, and a stamped round's --chunk rebuilds are exempt from the
// gate — the second arm must gate against an unstamped plan of its own.
const noClockPlan = join(dir, 'huge-noclock.json');
const withClockPlan = join(dir, 'huge-withclock.json');
const sizedPlan = JSON.stringify({
...PLAN,
srcDiffLines: 5000,
diffLines: 5000,
});
writeFileSync(noClockPlan, sizedPlan);
writeFileSync(withClockPlan, sizedPlan);
try {
// No clock: the 3B tier stands and round 4 builds chunk 13.
delete process.env[DEADLINE_ENV];
process.exitCode = undefined;
(writeStderrLine as unknown as Mock).mockClear();
handler({
plan: noClockPlan,
role: 'reverse-audit',
findings,
round: 4,
chunk: 13,
});
expect(process.exitCode).toBeUndefined();
expect(readRecordedPrompts(noClockPlan).size).toBe(1);

// A clock: the same round refused at the reduced tier.
process.env[DEADLINE_ENV] = String(
Math.floor(Date.now() / 1000) + 7200,
);
process.exitCode = undefined;
(writeStderrLine as unknown as Mock).mockClear();
handler({
plan: withClockPlan,
role: 'reverse-audit',
findings,
round: 4,
chunk: 13,
});
expect(process.exitCode).toBe(4);
expect(stderr()).toContain('round cap is 3');
} finally {
if (before === undefined) delete process.env[DEADLINE_ENV];
else process.env[DEADLINE_ENV] = before;
}
} finally {
process.exitCode = undefined;
rmSync(dir, { recursive: true, force: true });
}
});

it('takes the round cap from the plan’s topology on the chunkless path', () => {
// 3A is the topology that actually runs this path — one auditor a round,
// the whole diff — and it is the one the tier raises. Both arms use the
Expand Down
56 changes: 56 additions & 0 deletions packages/cli/src/commands/review/fetch-pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isCollapsedFromUpstream,
} from './fetch-pr.js';
import { classifyHeavy } from './lib/heavy.js';
import { DEADLINE_ENV } from './lib/deadline.js';
import { PARSE_ARGS_REPORT } from './lib/paths.js';

describe('classifyHeavy', () => {
Expand Down Expand Up @@ -338,6 +339,61 @@ describe('fetch-pr report assembly', () => {
expect(report.host).toBe('ghe.example.com');
});

it('records the round cap its capture wiring writes — huge tier only with a clock (#9256)', async () => {
// plan-diff and capture-local pin this wiring in their own handlers; the
// fetch-pr side had no assertion because this harness steers the lightest
// real path (no merge base → no diff). Override the two mocks that steer
// it into a real diff instead: a resolvable merge base and a raw diff
// buffer. A handler that forgot the deadline read — or the capture-time
// tier call — would keep every budget unit test green and this one red.
const mergeBase = vi.mocked(
(await import('./lib/merge-base.js')).resolveMergeBase,
);
const gitRawMock = vi.mocked((await import('./lib/git.js')).gitRaw);
mergeBase.mockReturnValue({ sha: 'beef0000', baseFetchFailed: false });
gitRawMock.mockReturnValue(Buffer.from(makeHugeDiff()));
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

const before = process.env[DEADLINE_ENV];
try {
delete process.env[DEADLINE_ENV];
producerMocks.writeFileSync.mockClear();
const noClock = await reportFor({});
expect(noClock.srcDiffLines).toBeGreaterThanOrEqual(3000);
expect(noClock.budget.reverseAuditRounds).toBe(5);

process.env[DEADLINE_ENV] = String(Math.floor(Date.now() / 1000) + 7200);
producerMocks.writeFileSync.mockClear();
const withClock = await reportFor({});
expect(withClock.budget.reverseAuditRounds).toBe(3);
} finally {
if (before === undefined) delete process.env[DEADLINE_ENV];
else process.env[DEADLINE_ENV] = before;
}
});

// A 9,000-line single-file addition — effective size well past the huge
// floor, in the same shape plan-diff's harness uses.
function makeHugeDiff(): string {
const n = 9000;
const body: string[] = [];
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
while (body.length < n) {
body.push(`+function f${body.length}() {`);
for (let k = 0; k < 8 && body.length < n; k++)
body.push(`+ const x = ${k};`);
body.push('+}');
body.push('+');
}
body.length = n;
return [
'diff --git a/src/huge.ts b/src/huge.ts',
'--- /dev/null',
'+++ b/src/huge.ts',
`@@ -0,0 +1,${n} @@`,
...body,
'',
].join('\n');
}

it('preserves the earliest window opening across drift restarts of the same PR', async () => {
// A drift restart reruns fetch-pr and overwrites this report; the audit
// boundary must keep reaching back to the abandoned attempt's opening.
Expand Down
Loading
Loading