Skip to content

Commit 1e195ca

Browse files
test(cli): reset the prune mock explicitly instead of relying on restoreAllMocks
The converge test's toHaveBeenCalledTimes(1) held only because vitest 3's vi.restoreAllMocks() clears vi.fn() call state; vitest 4 restores spies only, so the count would accumulate across tests and fail. Reset pruneOrphanedLockEntries in beforeEach like the other manifest mocks — passes under both vitest 3.2.4 (pinned) and vitest 4. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent 9901b8f commit 1e195ca

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎packages/cli/src/commands/skills.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,19 @@ describe("hyperframes skills", () => {
184184
vi.resetModules();
185185
// vi.resetModules re-imports skills.js but the manifest mock's vi.fn
186186
// instances persist — restore their default behavior for each test.
187-
const { checkSkills, presentSkills } = await import("../utils/skillsManifest.js");
187+
// pruneOrphanedLockEntries is reset explicitly too: relying on afterEach's
188+
// vi.restoreAllMocks() to clear vi.fn() call state is vitest-3-specific
189+
// (vitest 4 restores spies only), and call-count assertions like the
190+
// twice-in-a-row convergence test would then see counts accumulated from
191+
// earlier tests.
192+
const { checkSkills, presentSkills, pruneOrphanedLockEntries } =
193+
await import("../utils/skillsManifest.js");
188194
vi.mocked(checkSkills).mockReset();
189195
vi.mocked(checkSkills).mockImplementation(async () => DEFAULT_CHECK as never);
190196
vi.mocked(presentSkills).mockReset();
191197
vi.mocked(presentSkills).mockImplementation((names: readonly string[]) => [...names]);
198+
vi.mocked(pruneOrphanedLockEntries).mockReset();
199+
vi.mocked(pruneOrphanedLockEntries).mockImplementation(() => []);
192200
// Each test asserts on process.exitCode; isolate it from the runner's own.
193201
prevExitCode = process.exitCode;
194202
process.exitCode = 0;
@@ -653,11 +661,16 @@ describe("hyperframes skills update <names>", () => {
653661
state.spawnExitCode = 0;
654662
state.gitMissing = false;
655663
vi.resetModules();
656-
const { checkSkills, presentSkills } = await import("../utils/skillsManifest.js");
664+
// Same explicit resets as the describe above (incl. the vitest-4-proofing
665+
// note on pruneOrphanedLockEntries).
666+
const { checkSkills, presentSkills, pruneOrphanedLockEntries } =
667+
await import("../utils/skillsManifest.js");
657668
vi.mocked(checkSkills).mockReset();
658669
vi.mocked(checkSkills).mockImplementation(async () => DEFAULT_CHECK as never);
659670
vi.mocked(presentSkills).mockReset();
660671
vi.mocked(presentSkills).mockImplementation((names: readonly string[]) => [...names]);
672+
vi.mocked(pruneOrphanedLockEntries).mockReset();
673+
vi.mocked(pruneOrphanedLockEntries).mockImplementation(() => []);
661674
prevExitCode = process.exitCode;
662675
process.exitCode = 0;
663676
});

0 commit comments

Comments
 (0)