Skip to content

Commit ca2302a

Browse files
authored
test: sequence the advisor mock with ordered handlers (#64)
## Summary `packages/agent-core/test/session/session-advisor.test.ts` emitted two `vitest(no-conditional-in-test)` warnings from a call-counter mock that branched on which `rawGenerate` call it was handling. A reviewer raised this on #59 and I declined it incorrectly, citing an `oxlint --quiet` run as evidence the rule did not fire. That flag suppresses warnings, so the evidence was an artifact of the command rather than a fact about the code. This is the follow-up. ## Approach The three-call sequence is now expressed with ordered `mockImplementationOnce` handlers plus a trailing default, so an unexpected fourth call falls through to the real implementation instead of returning `undefined`. No production code and no assertions changed. ## Test plan - `pnpm --filter @pythoughts/agent-core exec vitest run test/session/session-advisor.test.ts` — all pass. - `npx oxlint packages/agent-core/test/session/session-advisor.test.ts` (no `--quiet`) — 2 warnings before, 0 after. - Red proof that the test still catches its bug: restoring the mid-turn `#deliverPending()` call in `session-advisor.ts` fails the test with `expected 1 to be +0` on `callsWhileActive`. [skip changeset] — tests-only change under `packages/agent-core/test/`. No production source is touched and nothing enters the CLI bundle, so per the repo's changeset rules there is no user-visible change to record. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Updated mid-turn advisor coverage to validate review and active-turn behavior using explicit response sequencing. * Improved test reliability by removing dependence on call-count state. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 7fc36fd commit ca2302a

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

packages/agent-core/test/session/session-advisor.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ describe('SessionAdvisor', () => {
7777
const reviewGate = createDeferred<void>();
7878
const activeTurnGate = createDeferred<void>();
7979
const generate = fixture.main.rawGenerate;
80-
let generateCall = 0;
81-
vi.spyOn(fixture.main, 'rawGenerate').mockImplementation(async (...args) => {
82-
generateCall += 1;
83-
const currentCall = generateCall;
84-
const result = await generate(...args);
85-
if (currentCall === 2) await reviewGate.promise;
86-
if (currentCall === 3) await activeTurnGate.promise;
87-
return result;
88-
});
80+
vi.spyOn(fixture.main, 'rawGenerate')
81+
.mockImplementationOnce(generate)
82+
.mockImplementationOnce(async (...args) => {
83+
const result = await generate(...args);
84+
await reviewGate.promise;
85+
return result;
86+
})
87+
.mockImplementationOnce(async (...args) => {
88+
const result = await generate(...args);
89+
await activeTurnGate.promise;
90+
return result;
91+
})
92+
.mockImplementation(generate);
8993
const steer = vi.spyOn(fixture.main.turn, 'steer').mockReturnValue(null);
9094
queueReview(fixture.scripted, 'Check the active turn.', 'concern');
9195

0 commit comments

Comments
 (0)