diff --git a/.agents/lessons/README.md b/.agents/lessons/README.md index e5764cd..5799f73 100644 --- a/.agents/lessons/README.md +++ b/.agents/lessons/README.md @@ -12,7 +12,7 @@ and **how to apply it**. | [`art.md`](art.md) | 2 | The image pipeline. | | [`code.md`](code.md) | 2 | TypeScript, Svelte, async ordering, Rust. | | [`technical.md`](technical.md) | 5 | The browser and the build as platforms. | -| [`testing.md`](testing.md) | 4 | What makes a test worth having, and how a passing test lies. | +| [`testing.md`](testing.md) | 5 | What makes a test worth having, and how a passing test lies. | | `privacy.md` | none yet | What could leave the device or make a person findable. (The geocell finding is in the review, not here: it was caught before it cost anything.) | | [`process.md`](process.md) | 2 | Workflow, commits, credentials, honesty about what shipped. | diff --git a/.agents/lessons/testing.md b/.agents/lessons/testing.md index 608f059..ce2c3d1 100644 --- a/.agents/lessons/testing.md +++ b/.agents/lessons/testing.md @@ -58,3 +58,18 @@ arrives. Then it fails for the first time on the author's machine, with the auth **How to apply it.** When a test branches on content that does not exist yet, fill the content temporarily, run the suite, restore it, and record the run in the review. + +## A one-time cold start is charged to the first case + +**What happened.** On 2026-11-01, with the machine at 80% CPU, `pnpm test` failed one engine +case: `purity-lint.test.ts` › *reports Date.now()*, timed out at 5 s. The snippet was fine. +The first `eslint.lintText` call loads the whole config and typescript-eslint, and vitest +charged that load to whichever case ran first. The fix is a `beforeAll` that lints an +empty file once, with its own 60 s timeout. + +**Why it bit.** A suite that passes on a quiet machine can still hide a fixed cost inside one +case. It fails only under load, and then it looks like a bug in the code that case tests. + +**How to apply it.** When the first case of a file loads something heavy (a linter, a +compiler, a browser), load it in `beforeAll` with an explicit timeout. If only the first case +of a file times out, suspect a cold start before suspecting the code. diff --git a/packages/engine/test/purity-lint.test.ts b/packages/engine/test/purity-lint.test.ts index 9e94c94..0832623 100644 --- a/packages/engine/test/purity-lint.test.ts +++ b/packages/engine/test/purity-lint.test.ts @@ -8,7 +8,7 @@ */ import { ESLint } from 'eslint'; import { fileURLToPath } from 'node:url'; -import { describe, expect, it } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; const repoRoot = fileURLToPath(new URL('../../..', import.meta.url)); const eslint = new ESLint({ cwd: repoRoot }); @@ -42,6 +42,12 @@ const IMPURE: readonly [what: string, code: string][] = [ ]; describe('engine purity lint rule', () => { + // The first lint loads the config and typescript-eslint. On a busy machine that + // alone took over vitest's 5 s, failing whichever case ran first. Pay it here. + beforeAll(async () => { + await messages('export {};', ENGINE_FILE); + }, 60_000); + it.each(IMPURE)('reports %s inside packages/engine/src', async (_what, code) => { const found = await messages(code, ENGINE_FILE); expect(found.filter((m) => m.startsWith('fatal')), 'snippet must parse').toEqual([]);