The Atlas MikeAzureDev's documentation, bound to its code
140 documents
.claude/skills/mike-test-maintenance/SKILL.md

name: mike-test-maintenance description: Maintain and extend the MikeAzureDev vitest suites (backend node+supertest, frontend jsdom+RTL+MSW) - how to run them, the mock/fake patterns the suites are built on, drift-adaptation rules, and the catalog of known gotchas. Use when writing tests for new features, fixing failing tests, adapting tests after upstream syncs or Tier B mirror deliveries, or when a test failure looks environmental.

Mike test maintenance

Two vitest suites, both run with pnpm test (test:watch, test:coverage) in their package dir:

  • backend/ — node env, supertest route tests mount buildApp() from src/app.ts (never index.ts — entrypoint side effects live there).
  • frontend/ — jsdom + Testing Library + MSW. Harness in frontend/src/test/: renderWithProviders (render.tsx) injects Config/Auth contexts; msw-server.ts fails tests on unhandled requests.

vitest does NOT type-check. Always finish with npx tsc --noEmit in the touched package — type drift in test files only surfaces there, and it breaks the Docker build later if ignored.

Prime directive: tests encode INTENDED behaviour

When a test fails against changed source, do not silently re-shape the assertion. First determine which side is right: read the source's comments and git log on the module. This suite has caught real product bugs — e.g. a route test timing out at exactly its 5s limit means the handler hung (escaped async rejection, the issue-041 class): that is a PRODUCT bug — fix the route (try/catch → 500), don't extend the timeout.

When source legitimately moved on, adapt the test and leave a one-line comment naming the change (see the drift comments in the ported suite).

Writing new tests — follow the house patterns

  1. Route test: copy the shape of src/routes/caseLaw.test.ts (small) or user.test.ts (large). vi.hoisted() for mock fns → vi.mock() per collaborator module → import { makeApp } LAST. Auth is mocked at the provider layer (validateSupabaseToken etc.), not middleware.
  2. Multi-table DB logic: use src/test/helpers/fakeDb.ts (makeFakeDb(respond)) — respond-per-call + recorded ops. Don't grow new one-off thenable fakes.
  3. Env-reading code: snapshot/restore touched env vars in beforeEach/afterEach (see any existing suite's TOUCHED_ENV block). buildApp() reads env per call, so per-test env mutation works.
  4. Frontend component: RTL + userEvent; query by role/label. Contexts consumed via the harness require the context OBJECT exported from the context module (ConfigContext/AuthContext already are).
  5. Never touch the network: mock dns/promises, fetch collaborators, or add MSW handlers. Azure SDK dynamic imports (@azure/keyvault- secrets, @azure/identity) are mockable with plain vi.mock — it intercepts dynamic import() too.

Every new backend/frontend feature lands with its tests in the same commit (small commits, per working style). New route chain methods on the supabase client (e.g. .is() was added for soft-deletes) must be added to the fakes that the route's tests use, or every test in the file fails with ...is not a function.

Known gotchas

The catalog of concrete failures we have already debugged once is in GOTCHAS.md. Scan it BEFORE debugging any weird test failure — mock-specifier collisions, tsx CJS interop, supertest laziness, pnpm allowBuilds, and friends are all in there. Add new entries when you burn time on something novel; that file is the institutional memory.

Suite lifecycle

  • Provenance: the base suite was backported from the OSS mirror (MikeOssAzure ddcfbdc, PRs #1–#2) and adapted to dev — commits 6846189 / ac5cf08; extension for 1.0.10 features in later test(...) commits.
  • Tier B deliveries snapshot dev → mirror, so tests travel with them automatically; never hand-edit tests mirror-side.
  • After an upstream sync batch, run both suites; failures are your drift-report — triage with the prime directive above.