#16544: refactor(test): structural MockFn for harness exports
channel: imessage
channel: telegram
channel: whatsapp-web
maintainer
size: M
Context:
- Recent CI/tsgo failures (TS2742) were caused by exporting inferred vitest mock types from harness modules under `src/`.
Change:
- `src/test-utils/vitest-mock-fn.ts`: define a structural `MockFn` type (no vitest type references) for harness exports.
- Update harnesses to use `vi.fn<T>()` so mocks don't widen to `Constructable | Procedure`.
- Small test assertion tweak to satisfy oxlint (`no-base-to-string`).
Gate:
- pnpm check
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Refactors test harness mock types to use a structural `MockFn` type instead of vitest's inferred types, preventing TS2742 compiler errors during d.ts emit under pnpm.
**Key changes:**
- Introduced `src/test-utils/vitest-mock-fn.ts` with a structural `MockFn<T>` type that doesn't reference vitest internals
- Updated all test harness files to use `vi.fn<T>()` with explicit type parameters to avoid Vitest's default `Constructable | Procedure` widening
- Replaced `AnyMock` type aliases with `MockFn<(...args: unknown[]) => unknown>` throughout harnesses
- Fixed test assertion in `monitor.skips-group-messages-without-mention-by-default.test.ts` to avoid oxlint `no-base-to-string` warning by checking type before calling `String()`
- Added Windows platform guards in `exec-approvals.test.ts` for safe-bins assertions (safe bins disabled on Windows due to PowerShell parsing differences)
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The refactor addresses a real build issue (TS2742) with a well-documented structural typing solution. Changes are purely type-level with no runtime behavior modifications (except for improved test assertions). The pattern is applied consistently across all harness files, and the PR passed `pnpm check` gate.
- No files require special attention
<sub>Last reviewed commit: ec349c4</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16479: fix(test): annotate vitest mock return types to resolve TS2742 port...
by colddonkey · 2026-02-14
83.4%
#17393: fix(ci): resolve TS2742 type error blocking all PRs
by miloudbelarebia · 2026-02-15
79.5%
#21500: fix(test): resolve vi.mock hoisting failures on macOS runners
by irchelper · 2026-02-20
74.4%
#23594: test(tui): fix mock typing in command handler tests
by Sashamine · 2026-02-22
73.9%
#17900: refactor(security): extract shared normalizeAllowFromList into audi...
by iyoda · 2026-02-16
69.8%
#23772: fix(ci): unblock repo-wide check gate type regressions
by SmithLabsLLC · 2026-02-22
69.5%
#23669: refactor(logging): migrate node-host and tailscale console calls to...
by kevinWangSheng · 2026-02-22
68.0%
#19063: CI/macOS: disable Vitest vmForks for TS tests to stop mock-state le...
by agisilaos · 2026-02-17
67.7%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
67.6%
#9333: Tests: add test coverage for security/audit-fs.ts
by M00N7682 · 2026-02-05
67.5%