← Back to PRs

#16544: refactor(test): structural MockFn for harness exports

by steipete open 2026-02-14 21:06 View on GitHub →
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