From 5cf94c296e8aa1c374a8a12838ae2f679f088c50 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sat, 2 May 2026 04:47:41 +0200 Subject: [PATCH] test: complete vitest mock API fixes for callCount and calls access --- packages/daemon/src/event-bridge.test.ts | 36 +++++++++---------- .../src/core/compaction/compaction.test.ts | 6 ++-- .../sf/tests/claude-import-tui.test.ts | 4 +-- .../sf/tests/post-exec-retry-bypass.test.ts | 8 ++--- .../tests/pre-execution-fail-closed.test.ts | 4 +-- .../tests/pre-execution-pause-wiring.test.ts | 10 +++--- .../validate-milestone-stuck-guard.test.ts | 12 +++---- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/packages/daemon/src/event-bridge.test.ts b/packages/daemon/src/event-bridge.test.ts index 155683813..a461f9456 100644 --- a/packages/daemon/src/event-bridge.test.ts +++ b/packages/daemon/src/event-bridge.test.ts @@ -179,7 +179,7 @@ describe('EventBridge', () => { sessionId: 'sess-1', projectDir: '/test/project', projectName: 'my-project', }); await tick(); - assert.equal(mockFn(channelManager.createProjectChannel).mock.callCount, 1); + assert.equal(mockFn(channelManager.createProjectChannel).mock.calls.length, 1); }); it('logs error and skips when channel creation fails', async () => { @@ -194,7 +194,7 @@ describe('EventBridge', () => { sessionId: 'sess-1', projectDir: '/test/project', projectName: 'my-project', }); await tick(); - assert.ok(mockFn(logger.error).mock.callCount > 0); + assert.ok(mockFn(logger.error).mock.calls.length > 0); }); }); @@ -213,7 +213,7 @@ describe('EventBridge', () => { }); await tick(); // No errors - assert.equal(mockFn(logger.error).mock.callCount, 0); + assert.equal(mockFn(logger.error).mock.calls.length, 0); }); it('filters events based on verbosity', async () => { @@ -239,7 +239,7 @@ describe('EventBridge', () => { event: { type: 'tool_execution_start', name: 'read' } as SdkAgentEvent, }); await tick(); - assert.equal(mockFn(logger.error).mock.callCount, 0); + assert.equal(mockFn(logger.error).mock.calls.length, 0); }); }); @@ -260,7 +260,7 @@ describe('EventBridge', () => { sessionId: 'sess-1', projectDir: '/test/project', projectName: 'my-project', blocker, }); await tick(); - assert.ok(mockFn(channelManager._channel.createMessageComponentCollector).mock.callCount > 0); + assert.ok(mockFn(channelManager._channel.createMessageComponentCollector).mock.calls.length > 0); }); it('sends DM when dm_on_blocker is configured', async () => { @@ -287,7 +287,7 @@ describe('EventBridge', () => { await tick(); const usersFetch = (client as unknown as Record).users.fetch; - assert.equal(mockFn(usersFetch).mock.callCount, 1); + assert.equal(mockFn(usersFetch).mock.calls.length, 1); }); it('does not send DM when dm_on_blocker is false', async () => { @@ -310,7 +310,7 @@ describe('EventBridge', () => { await tick(); const usersFetch = (client as unknown as Record).users.fetch; - assert.equal(mockFn(usersFetch).mock.callCount, 0); + assert.equal(mockFn(usersFetch).mock.calls.length, 0); }); }); @@ -346,7 +346,7 @@ describe('EventBridge', () => { collector.emit('collect', mockInteraction); await tick(); - assert.equal(mockFn(sessionManager.resolveBlocker).mock.callCount, 1); + assert.equal(mockFn(sessionManager.resolveBlocker).mock.calls.length, 1); const args = mockFn(sessionManager.resolveBlocker).mock.calls[0]!; assert.equal(args[0], 'sess-1'); assert.equal(args[1], 'true'); @@ -382,8 +382,8 @@ describe('EventBridge', () => { collector.emit('collect', mockInteraction); await tick(); - assert.equal(mockFn(sessionManager.resolveBlocker).mock.callCount, 0); - assert.equal(mockFn(mockInteraction.reply).mock.callCount, 1); + assert.equal(mockFn(sessionManager.resolveBlocker).mock.calls.length, 0); + assert.equal(mockFn(mockInteraction.reply).mock.calls.length, 1); }); it('posts error when resolveBlocker throws', async () => { @@ -417,7 +417,7 @@ describe('EventBridge', () => { collector.emit('collect', mockInteraction); await tick(); - assert.equal(mockFn(mockInteraction.reply).mock.callCount, 1); + assert.equal(mockFn(mockInteraction.reply).mock.calls.length, 1); const replyArg = mockFn(mockInteraction.reply).mock.calls[0]![0] as Record; assert.ok(String(replyArg.content).includes('Failed to resolve')); }); @@ -445,7 +445,7 @@ describe('EventBridge', () => { client.emit('messageCreate', msg); await tick(); - assert.equal(mockFn(session.client.steer).mock.callCount, 1); + assert.equal(mockFn(session.client.steer).mock.calls.length, 1); assert.equal(mockFn(session.client.steer).mock.calls[0]![0], 'check the test results'); }); @@ -474,7 +474,7 @@ describe('EventBridge', () => { client.emit('messageCreate', msg); await tick(); - assert.equal(mockFn(sessionManager.resolveBlocker).mock.callCount, 1); + assert.equal(mockFn(sessionManager.resolveBlocker).mock.calls.length, 1); assert.equal(mockFn(sessionManager.resolveBlocker).mock.calls[0]![1], 'my-api-key-value'); }); @@ -498,7 +498,7 @@ describe('EventBridge', () => { }); await tick(); - assert.equal(mockFn(session.client.steer).mock.callCount, 0); + assert.equal(mockFn(session.client.steer).mock.calls.length, 0); }); it('ignores messages in non-project channels', async () => { @@ -516,7 +516,7 @@ describe('EventBridge', () => { }); await tick(); - assert.equal(mockFn(session.client.steer).mock.callCount, 0); + assert.equal(mockFn(session.client.steer).mock.calls.length, 0); }); it('ignores messages from unauthorized users', async () => { @@ -539,7 +539,7 @@ describe('EventBridge', () => { }); await tick(); - assert.equal(mockFn(session.client.steer).mock.callCount, 0); + assert.equal(mockFn(session.client.steer).mock.calls.length, 0); }); it('posts error when steer fails', async () => { @@ -566,7 +566,7 @@ describe('EventBridge', () => { client.emit('messageCreate', msg); await tick(); - assert.equal(mockFn(msg.reply).mock.callCount, 1); + assert.equal(mockFn(msg.reply).mock.calls.length, 1); }); }); @@ -591,7 +591,7 @@ describe('EventBridge', () => { event: { type: 'tool_execution_start', name: 'read' } as SdkAgentEvent, }); await tick(); - assert.equal(mockFn(logger.error).mock.callCount, 0); + assert.equal(mockFn(logger.error).mock.calls.length, 0); }); }); diff --git a/packages/pi-coding-agent/src/core/compaction/compaction.test.ts b/packages/pi-coding-agent/src/core/compaction/compaction.test.ts index 8dcf38360..fc6362b58 100644 --- a/packages/pi-coding-agent/src/core/compaction/compaction.test.ts +++ b/packages/pi-coding-agent/src/core/compaction/compaction.test.ts @@ -154,8 +154,8 @@ describe("generateSummary — chunked fallback (#2932)", () => { // Assert: should have called completeSimple more than once (chunked) assert.ok( - mockComplete.mock.callCount > 1, - `Expected multiple calls for chunked summarization, got ${mockComplete.mock.callCount}`, + mockComplete.mock.calls.length > 1, + `Expected multiple calls for chunked summarization, got ${mockComplete.mock.calls.length}`, ); // First call should be an initial summary, subsequent should be updates @@ -189,7 +189,7 @@ describe("generateSummary — chunked fallback (#2932)", () => { await generateSummary(messages, model, reserveTokens, undefined, undefined, undefined, undefined, mockComplete); assert.equal( - mockComplete.mock.callCount, + mockComplete.mock.calls.length, 1, "Should use single-pass summarization when messages fit in context window", ); diff --git a/src/resources/extensions/sf/tests/claude-import-tui.test.ts b/src/resources/extensions/sf/tests/claude-import-tui.test.ts index 51c3a02b5..9f261dfb3 100644 --- a/src/resources/extensions/sf/tests/claude-import-tui.test.ts +++ b/src/resources/extensions/sf/tests/claude-import-tui.test.ts @@ -317,8 +317,8 @@ describe("TUI Command Flow Tests", { skip: skipReason }, () => { console.log("\nNotifications shown:"); notifyCalls.forEach((call, i) => { - const msg = call.arguments[0]; - const level = call.arguments[1]; + const msg = call[0]; + const level = call[1]; console.log(` ${i + 1}. [${level}]: ${String(msg).split("\n")[0]}`); }); }); diff --git a/src/resources/extensions/sf/tests/post-exec-retry-bypass.test.ts b/src/resources/extensions/sf/tests/post-exec-retry-bypass.test.ts index 10255b7f4..1b3cdc697 100644 --- a/src/resources/extensions/sf/tests/post-exec-retry-bypass.test.ts +++ b/src/resources/extensions/sf/tests/post-exec-retry-bypass.test.ts @@ -231,7 +231,7 @@ describe("Post-execution blocking failure retry bypass", () => { // Non-execute-task units should return "continue" immediately assert.equal(result, "continue"); - assert.equal(pauseAutoMock.mock.callCount, 0); + assert.equal(pauseAutoMock.mock.calls.length, 0); }); test("returns continue when verification passes", async () => { @@ -256,7 +256,7 @@ describe("Post-execution blocking failure retry bypass", () => { // When verification passes, should return "continue" and not call pauseAuto assert.equal(result, "continue"); - assert.equal(pauseAutoMock.mock.callCount, 0); + assert.equal(pauseAutoMock.mock.calls.length, 0); // Retry state should be cleared assert.equal(s.pendingVerificationRetry, null); @@ -345,7 +345,7 @@ describe("Post-execution blocking failure retry bypass", () => { const result = await runPostUnitVerification(vctx, pauseAutoMock); assert.equal(result, "pause"); - assert.equal(pauseAutoMock.mock.callCount, 1); + assert.equal(pauseAutoMock.mock.calls.length, 1); const adapter = _getAdapter(); const row = adapter @@ -426,7 +426,7 @@ describe("Post-execution retry behavior", () => { // When autofix is disabled and verification fails, should pause assert.equal(result, "pause"); - assert.equal(pauseAutoMock.mock.callCount, 1); + assert.equal(pauseAutoMock.mock.calls.length, 1); // Should NOT set up a retry assert.equal(s.pendingVerificationRetry, null); diff --git a/src/resources/extensions/sf/tests/pre-execution-fail-closed.test.ts b/src/resources/extensions/sf/tests/pre-execution-fail-closed.test.ts index 52488390f..b769a9cbc 100644 --- a/src/resources/extensions/sf/tests/pre-execution-fail-closed.test.ts +++ b/src/resources/extensions/sf/tests/pre-execution-fail-closed.test.ts @@ -210,7 +210,7 @@ describe("Pre-execution fail-closed behavior", () => { // With valid tasks, pre-exec should pass and not pause assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 0, "pauseAuto should NOT be called when pre-execution checks pass", ); @@ -267,7 +267,7 @@ describe("Pre-execution fail-closed behavior", () => { // With a blocking failure, pauseAuto should be called assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 1, "pauseAuto should be called when pre-execution checks fail", ); diff --git a/src/resources/extensions/sf/tests/pre-execution-pause-wiring.test.ts b/src/resources/extensions/sf/tests/pre-execution-pause-wiring.test.ts index cb9e6332c..04742d4be 100644 --- a/src/resources/extensions/sf/tests/pre-execution-pause-wiring.test.ts +++ b/src/resources/extensions/sf/tests/pre-execution-pause-wiring.test.ts @@ -312,7 +312,7 @@ describe("Pre-execution checks → pauseAuto wiring", () => { // Verify pauseAuto was called assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 1, "pauseAuto should be called exactly once when pre-execution checks fail with blocking issues", ); @@ -360,7 +360,7 @@ describe("Pre-execution checks → pauseAuto wiring", () => { // Verify pauseAuto was called (strict mode promotes warnings to blocking) assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 1, "pauseAuto should be called when strict mode is enabled and pre-execution returns warn", ); @@ -410,7 +410,7 @@ describe("Pre-execution checks → pauseAuto wiring", () => { // Verify pauseAuto was NOT called (warnings don't block in non-strict mode) assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 0, "pauseAuto should NOT be called when strict mode is disabled and only warnings exist", ); @@ -442,7 +442,7 @@ describe("Pre-execution checks → pauseAuto wiring", () => { // Verify pauseAuto was NOT called (pre-execution checks only run for plan-slice) assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 0, "pauseAuto should NOT be called for non-plan-slice unit types", ); @@ -477,7 +477,7 @@ describe("Pre-execution checks → pauseAuto wiring", () => { // Verify pauseAuto was NOT called (pre-execution checks disabled) assert.equal( - pauseAutoMock.mock.callCount, + pauseAutoMock.mock.calls.length, 0, "pauseAuto should NOT be called when enhanced_verification_pre is disabled", ); diff --git a/src/resources/extensions/sf/tests/validate-milestone-stuck-guard.test.ts b/src/resources/extensions/sf/tests/validate-milestone-stuck-guard.test.ts index 63cfb2c35..e712b3f55 100644 --- a/src/resources/extensions/sf/tests/validate-milestone-stuck-guard.test.ts +++ b/src/resources/extensions/sf/tests/validate-milestone-stuck-guard.test.ts @@ -139,8 +139,8 @@ describe("validate-milestone stuck-loop guard (#4094)", () => { ); assert.equal(result, "pause"); - assert.equal(pauseAutoMock.mock.callCount, 1); - assert.equal(ctx.ui.notify.mock.callCount, 1); + assert.equal(pauseAutoMock.mock.calls.length, 1); + assert.equal(ctx.ui.notify.mock.calls.length, 1); const notifyArgs = ctx.ui.notify.mock.calls[0]; assert.match(notifyArgs[0], /needs-remediation/); assert.equal(notifyArgs[1], "error"); @@ -173,7 +173,7 @@ describe("validate-milestone stuck-loop guard (#4094)", () => { ); assert.equal(result, "pause"); - assert.equal(pauseAutoMock.mock.callCount, 1); + assert.equal(pauseAutoMock.mock.calls.length, 1); }); test("continues when verdict=needs-remediation but a queued remediation slice exists", async () => { @@ -203,7 +203,7 @@ describe("validate-milestone stuck-loop guard (#4094)", () => { ); assert.equal(result, "continue"); - assert.equal(pauseAutoMock.mock.callCount, 0); + assert.equal(pauseAutoMock.mock.calls.length, 0); }); test("continues when verdict is pass", async () => { @@ -227,7 +227,7 @@ describe("validate-milestone stuck-loop guard (#4094)", () => { ); assert.equal(result, "continue"); - assert.equal(pauseAutoMock.mock.callCount, 0); + assert.equal(pauseAutoMock.mock.calls.length, 0); }); test("continues when no VALIDATION file exists yet", async () => { @@ -250,6 +250,6 @@ describe("validate-milestone stuck-loop guard (#4094)", () => { ); assert.equal(result, "continue"); - assert.equal(pauseAutoMock.mock.callCount, 0); + assert.equal(pauseAutoMock.mock.calls.length, 0); }); });