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
170 changes: 169 additions & 1 deletion packages/cli/src/commands/review/agent-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3778,6 +3778,10 @@ describe('per-chunk retirement — cold territories stop costing a round', () =>
beforeEach(() => {
(writeStdoutLine as unknown as Mock).mockClear();
(writeStderrLine as unknown as Mock).mockClear();
// Cleared beside its throwing siblings (#9259): uncleared, every
// assertion below read the ACCUMULATED output of earlier tests — an
// order-dependent oracle that passed on residue alone.
(writeStderrLineSafe as unknown as Mock).mockClear();
Comment thread
wenshao marked this conversation as resolved.
Resolved
dir = mkdtempSync(join(tmpdir(), 'ap-retire-'));
dirs.push(dir);
plan = join(dir, 'plan.json');
Expand All @@ -3788,11 +3792,25 @@ describe('per-chunk retirement — cold territories stop costing a round', () =>
utimesSync(plan, old, old);
findings = join(dir, 'findings.md');
writeFileSync(findings, '');
for (const k of ['QWEN_CODE_PROJECT_DIR', 'QWEN_CODE_SESSION_ID']) {
for (const k of [
'QWEN_CODE_PROJECT_DIR',
'QWEN_CODE_SESSION_ID',
// The budget gate reads these three straight from process.env on
// every admission the tests below drive (#9272): an ambient value
// inherited from a concurrent review makes admission
// environment-dependent — the same isolation the repro harness
// carries (#9259), on the describe that actually needs it.
DEADLINE_ENV,
RESERVE_ENV,
TOOL_CONCURRENCY_ENV,
]) {
SAVED[k] = process.env[k];
}
process.env['QWEN_CODE_PROJECT_DIR'] = dir;
process.env['QWEN_CODE_SESSION_ID'] = 'S1';
delete process.env[DEADLINE_ENV];
delete process.env[RESERVE_ENV];
delete process.env[TOOL_CONCURRENCY_ENV];
mkdirSync(join(dir, 'subagents', 'S1'), { recursive: true });
});
afterEach(() => {
Expand Down Expand Up @@ -4836,6 +4854,12 @@ describe('per-chunk retirement — cold territories stop costing a round', () =>
expect(err).toContain(
'chunk 13 \u2014 round 1: no matching transcript; round 2: no matching transcript',
);
// The narrowing's absence half (#9259): chunk 14's failures exist in
// the same schedule but must NOT ride chunk 13's build — an
// unfiltered `schedule.diagnostics` here prints every chunk's note on
// every build, and the count lies about the coverage.
expect(err).not.toContain('chunk 14 \u2014');
expect(err).toContain('1 twice-audited chunk(s)');
// The first build admitted the round — its stamp is what used to gate
// the second build's diagnostic out.
expect(readRoundStamps(plan).some((s) => s.round === 3)).toBe(true);
Expand Down Expand Up @@ -4969,6 +4993,150 @@ describe('per-chunk retirement — cold territories stop costing a round', () =>
}
});

it('a refused round prints no audit NOTE — the round builder defers the catch note past the gate (#9259)', () => {
// Cap-3 plan, rounds 1-3 non-converging, transcripts unreadable: the
// schedule read dies AND round 4 is refused. The stderr must carry
// the ROUND CAP refusal only — a `auditing every chunk.` NOTE here
// promises an audit that never happens.
writeFileSync(
plan,
JSON.stringify({ ...PLAN, budget: { reverseAuditRounds: 3 } }),
);
const old = new Date(2020, 0, 1);
utimesSync(plan, old, old);
answerRound(1, { 13: YIELD, 14: YIELD, 15: YIELD });
answerRound(2, { 13: YIELD, 14: YIELD, 15: YIELD });
answerRound(3, { 13: YIELD, 14: YIELD, 15: YIELD });
delete process.env['QWEN_CODE_SESSION_ID'];
(writeStderrLineSafe as unknown as Mock).mockClear();

const out = runRound(4);

expect(process.exitCode).toBe(4);
expect(out).toBe('');
expect(keysOf(4)).toHaveLength(0);
const msg = (writeStderrLine as unknown as Mock).mock.calls
.map((c) => c[0])
.join('\n');
expect(msg).toContain('ROUND CAP');
const safe = (writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n');
expect(safe).not.toContain('reverse-audit retirement unavailable');
});

it('a refused per-chunk build prints no audit NOTE either (#9259)', () => {
// The --chunk twin of the gate-side truthfulness: an unadmitted round
// 4 at cap 3 with an unreadable history is refused, and the refusal
// is the only thing stderr says about the round.
writeFileSync(
plan,
JSON.stringify({ ...PLAN, budget: { reverseAuditRounds: 3 } }),
);
const old = new Date(2020, 0, 1);
utimesSync(plan, old, old);
answerRound(1, { 13: YIELD, 14: YIELD, 15: YIELD });
answerRound(2, { 13: YIELD, 14: YIELD, 15: YIELD });
answerRound(3, { 13: YIELD, 14: YIELD, 15: YIELD });
delete process.env['QWEN_CODE_SESSION_ID'];
(writeStderrLineSafe as unknown as Mock).mockClear();

(agentPromptCommand.handler as (a: unknown) => void)({
plan,
role: 'reverse-audit',
findings,
chunk: 13,
round: 4,
});

expect(process.exitCode).toBe(4);
const msg = (writeStderrLine as unknown as Mock).mock.calls
.map((c) => c[0])
.join('\n');
expect(msg).toContain('ROUND CAP');
const safe = (writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n');
expect(safe).not.toContain('reverse-audit retirement unavailable');
});

it('a repair build whose schedule begins to throw still names the degradation — once per round (#9259)', () => {
// Round 3's admission build (chunk 13) reads cleanly: stamp lands,
// nothing said. Then the history dies, and chunk 14's repair build
// must still print the NOTE — the stamp-keyed suppression this
// replaces silenced exactly this shape. Chunk 15's build repeats the
// failure and stays silent: the note earns its place once per round
// per process.
answerRound(1, { 13: DRY, 14: DRY, 15: YIELD });
answerRound(2, { 13: DRY, 14: DRY, 15: YIELD });
(writeStderrLineSafe as unknown as Mock).mockClear();
(agentPromptCommand.handler as (a: unknown) => void)({
plan,
role: 'reverse-audit',
findings,
chunk: 13,
round: 3,
});
expect(readRoundStamps(plan).some((s) => s.round === 3)).toBe(true);
expect(
(writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n'),
).not.toContain('reverse-audit retirement unavailable');

delete process.env['QWEN_CODE_SESSION_ID'];
(writeStderrLineSafe as unknown as Mock).mockClear();
(agentPromptCommand.handler as (a: unknown) => void)({
plan,
role: 'reverse-audit',
findings,
chunk: 14,
round: 3,
});
let safe = (writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n');
expect(safe).toContain('reverse-audit retirement unavailable');
expect(safe).toContain('auditing the chunk');
// The NOTE's middle carries the WHY — the underlying failure's own
// message, not an empty dash (#9272): the constant prefix and suffix
// alone would print `unavailable this round — — auditing the chunk.`
// and name nothing.
expect(safe).toMatch(/unavailable this round — .+ — auditing the chunk\./);

(writeStderrLineSafe as unknown as Mock).mockClear();
(agentPromptCommand.handler as (a: unknown) => void)({
plan,
role: 'reverse-audit',
findings,
chunk: 15,
round: 3,
});
safe = (writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n');
expect(safe).not.toContain('reverse-audit retirement unavailable');
// Every repair still builds its chunk — the safe direction stands.
expect(keysOf(3)).toHaveLength(3);

// The claim is per ROUND (#9272): the same failure beginning in a
// LATER round of the same run earns its own NOTE — a plan-only key
// would silence it forever. Round 4 is under the default cap, and
// the history is still unreadable.
(writeStderrLineSafe as unknown as Mock).mockClear();
(agentPromptCommand.handler as (a: unknown) => void)({
plan,
role: 'reverse-audit',
findings,
chunk: 13,
round: 4,
});
safe = (writeStderrLineSafe as unknown as Mock).mock.calls
.map((c) => String(c[0]))
.join('\n');
expect(safe).toContain('reverse-audit retirement unavailable');
});

it('the #9242 note stays below the convergence gate — a converged round notes nothing', () => {
// A plan whose own numbers say Step 3A: rounds 1 and 2 note the
// mismatch as they build, but round 3 converges and builds nothing —
Expand Down
Loading
Loading