#16479: fix(test): annotate vitest mock return types to resolve TS2742 portability errors
channel: imessage
stale
size: S
## Summary
- Several shared test harnesses (`monitor.test-harness.ts`, `agent-runner.heartbeat-typing.test-harness.ts`, `agent-runner.memory-flush.test-harness.ts`, `reply.triggers.trigger-handling.test-harness.ts`) export getter functions that return `vi.fn()` mocks without explicit type annotations.
- TypeScript infers the return type via the internal `@vitest/spy` path, producing `TS2742: The inferred type cannot be named without a reference to .pnpm/@vitest+spy@...`. This is non-portable and breaks strict type-checking in some environments.
- Fix: import `type Mock` from `vitest` and explicitly annotate all affected return types.
## Test plan
- [x] `pnpm tsgo` passes cleanly - all TS2742 errors resolved.
- [x] No behavioral changes - annotations only.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds explicit `Mock` type annotations (imported from `vitest`) to exported getter functions across four shared test harness files. This resolves TS2742 portability errors where TypeScript inferred return types via the internal `@vitest/spy` path, which is non-portable across different `node_modules` layouts.
- All four harness files (`reply.triggers.trigger-handling.test-harness.ts`, `agent-runner.heartbeat-typing.test-harness.ts`, `agent-runner.memory-flush.test-harness.ts`, `monitor.test-harness.ts`) receive the same treatment: `import { type Mock } from "vitest"` and explicit `: Mock` return type annotations on exported getter functions.
- For getters returning objects with multiple mock properties, inline object types with `Mock`-typed fields are used.
- No behavioral or runtime changes — annotations only.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it contains only type annotations with zero runtime impact.
- All changes are type-only annotations on test harness files. No logic, runtime behavior, or test assertions are modified. The `Mock` type from vitest correctly matches the return type of `vi.fn()`. The PR resolves legitimate TS2742 errors as confirmed by the test plan.
- No files require special attention.
<sub>Last reviewed commit: 80aca37</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17393: fix(ci): resolve TS2742 type error blocking all PRs
by miloudbelarebia · 2026-02-15
85.1%
#16544: refactor(test): structural MockFn for harness exports
by steipete · 2026-02-14
83.4%
#21500: fix(test): resolve vi.mock hoisting failures on macOS runners
by irchelper · 2026-02-20
78.8%
#23594: test(tui): fix mock typing in command handler tests
by Sashamine · 2026-02-22
77.5%
#23772: fix(ci): unblock repo-wide check gate type regressions
by SmithLabsLLC · 2026-02-22
73.8%
#21027: fix(tests): resolve TypeScript type errors in CLI test files
by kittipond2365 · 2026-02-19
72.1%
#15569: test: comprehensive test coverage expansion (57 new test files)
by tangcruz · 2026-02-13
71.8%
#22990: test: fix readonly typing regressions in CI check baseline
by bmendonca3 · 2026-02-21
71.4%
#8964: test(msteams): add comprehensive tests for graph-upload module
by RajdeepKushwaha5 · 2026-02-04
70.9%
#9333: Tests: add test coverage for security/audit-fs.ts
by M00N7682 · 2026-02-05
70.1%