[engine] PurityLint: Load ESLint once in beforeAll so a cold start under load cannot time out the first case

This commit is contained in:
2026-11-01 21:31:34 +01:00
parent 23e950c372
commit e0cbfc466a
3 changed files with 23 additions and 2 deletions
+1 -1
View File
@@ -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. |
+15
View File
@@ -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.
+7 -1
View File
@@ -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([]);