diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2fe60f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Golden files are compared byte for byte (test/README.md): never converted to CRLF on checkout. +test/goldens/** -text diff --git a/README.md b/README.md index 9ee629c..8db99de 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,8 @@ editor. ```sh npm ci -npm test # unit tests +npm test # unit tests, golden tests included (test/README.md) +npm run test:goldens # only the golden tests; UPDATE_GOLDENS=1 rewrites them npm run test:integration # the extension in a real VS Code (needs a display, or xvfb) npm run package # code-notes-.vsix ``` diff --git a/package.json b/package.json index 08f3d9f..85611a8 100644 --- a/package.json +++ b/package.json @@ -1656,6 +1656,7 @@ "test:scenes": "node test/journey-scene/check.mjs test/journey-scene/sample.json", "test:panel": "node test/journey-map/shoot.mjs", "test:cli": "node --test test/cli/*.test.mjs", + "test:goldens": "tsc -p . && node --import ./test/hermetic.mjs --test out/test/golden-*.test.js test/cli/golden-*.test.mjs", "test:checkpanel": "node test/check-panel/shoot.mjs", "test:checktour": "node test/check-tour/shoot.mjs", "test:journeylist": "node test/journey-list/shoot.mjs", diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..abd1825 --- /dev/null +++ b/test/README.md @@ -0,0 +1,60 @@ +# Tests + +| Command | What runs | +| --- | --- | +| `npm test` | the TypeScript unit tests (`test/*.test.ts`, compiled to `out/test/`) and the CLI's (`test/cli/*.test.mjs`), golden tests included | +| `npm run test:goldens` | only the golden tests (a few seconds) | +| `npm run test:integration` | the extension in a real VS Code | +| `npm run test:panel`, `test:scenes`, `test:checkpanel`, `test:journeylist`, `test:podcast` | the webviews in a headless browser | + +Every unit test runs with `test/hermetic.mjs` loaded first: the CI job's own variables never reach the code under test. + +## Golden tests + +A golden test pins what pure code returns today, byte for byte: its output is written to a file under +`test/goldens//` and every run compares against that file. They are a regression net for refactors: any byte +that changes in any output fails the test and shows a diff. + +What is pinned: + +| File | Area (`test/goldens/…`) | What | +| --- | --- | --- | +| `test/golden-journey.test.ts` | `journey/` | Every fixture journey as `parseJourney` reads it (and the old-format files it refuses), crafted journeys that break the rules (the refusal or the problems), anchors, code links, value hints and marks as read, marks found in code and their problems, code-link markup, paths in step text, each step card's text (as written, moved, stale, renamed and gone files), the shop journey's steps placed in its code after edits, search words and scores, the Journeys list model (sorts, searches, chips, the active file), and the pure parts of the map's layout (`media/journey-layout.js`) | +| `test/golden-podcast.test.ts` | `podcast/` | The full check of every case in `test/fixtures/podcast/cases.json` (problems, messages, paths, places in the file, the episode), the sample podcast's episode (what the panel is sent), its timing (views, chapters, jumps, calm views, resume) and its marks | +| `test/golden-notes.test.ts` | `notes/` | Real and crafted note files read and written back (the JSON the extension writes), notes that are refused and why, the three-way merge, the agents' README, v2 anchors and v3 compact anchors found again after edits, the stale diff | +| `test/golden-check.test.ts` | `check-model/` | The prompts that write a check and its tour, failures in plain words, TODO comments, the Check view's names and the requests its page may send | +| `test/cli/golden-understanding.test.mjs` | `check/` | The understanding check end to end on the refunds change of `test/fixtures/grader-cases`: the skill's script output and the check file it writes, every CLI command's output and `status --json`, the Check view (`checkView`, what the view is sent) at each stage, each question's thread, grading replies (and refused ones), the CI job and its merge request comment, broken check files and what `validate` says, drift / conflicts / the default branch, and the CLI's pure helpers | + +Not pinned (not pure enough): the messages built inside vscode-dependent classes — the journey panel's `tour` / +`journey` message (`mapState`, `TourInfo`), the step card (`tour/card.ts`), the podcast player's messages +(`podcast/player.ts`, `listenView.ts`) and `media/journey-layout.js`'s `layout()` (it measures the DOM). Their +payloads that are pure are pinned: the parsed journey, the list model, the podcast episode, the Check view. The quiz +is not on `main` yet, so it has no goldens. + +### How it works + +`test/golden.ts` has one function, `expectGolden(area, name, value)`. A string is written as it is +(`.txt`); anything else as `JSON.stringify(value, null, 2)` in its real key order (the order is part of what is +pinned), with what JSON can't say spelled out: `"[undefined]"`, `{ "[Map]": [...] }`, `{ "[Set]": [...] }`, +`"[NaN]"`. A missing golden fails the test. The CLI's goldens replace what changes from run to run before comparing: +temporary paths (``, ``), ISO times (`