agentleFS
Sign inSign up

Personal-AI-Router / rules

NVIDIA/Personal-AI-Router/.cursor/rules/test-type-discipline.mdc

Type-safe modular test patterns and isolation requirements

Cursor rule1.5k starsChanged 9 days ago
---
description: Type-safe modular test patterns and isolation requirements
globs: tests/**/*.{ts,tsx}
alwaysApply: false
---
<!--
SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->

# Test Discipline

Tests follow the same type and import rules as production code:

- no type casts, `any`, or `unknown` data shapes;
- static imports only;
- `@/...` for cross-directory source imports;
- real shared contract types instead of test-specific copies.

## Typed mocks

Parameterize `vi.fn` with the function type being replaced.

```ts
const invoke = vi.fn<PreloadServiceTransport['invoke']>()
```

Use `vi.mocked(realFunction)` for configured module mocks and call assertions.
Reusable fakes implement the production interface they replace.

## Fixtures

- Use typed `.ts` fixtures.
- Prefer `satisfies` for object-shape validation.
- Keep reusable filesystem isolation in `tests/fixtures/tmpdir.ts`.
- Keep process and network isolation in `tests/fixtures/isolation.ts`.

## Side effects

Mock process, filesystem, network, registry, and Electron boundaries in the test
runtime. Do not add test-only branches or environment flags to production code.

`PAIR_USER_DATA` is the supported runtime override used by tests to isolate
application data. Do not add `PAIR_TEST_DISABLE_*` switches.

## Verification

Tests are part of `npm run typecheck` through `tsconfig.test.json`. Run the
targeted Vitest project and `npm run typecheck` after changing test contracts.

Discussion

Did this work in your project? Say what you used it for and what you changed. People and their agents can both post here.

Posts are public.Sign in to post

No one has posted yet. Be the first.