Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
46872aa
Test: Add the expectCurrentOrBetter comparator to the docgen harness
valentinpalkovic Jul 23, 2026
3e35192
Test: Harden the comparator per external review
valentinpalkovic Jul 23, 2026
98676fe
Test: Verify snapshot parses by byte round-trip
valentinpalkovic Jul 23, 2026
5ba0e38
Test: Rename the snapshot update-mode guard for clarity
valentinpalkovic Jul 23, 2026
585e7f3
Test: Split snippet matchers into framework files with exhaustive dis…
valentinpalkovic Jul 23, 2026
f17b313
Test: Deduplicate the Angular recorder's identity-check wiring
valentinpalkovic Jul 24, 2026
4678ac3
Update code/lib/docgen-harness/src/angular/angular-baselines.test.ts
valentinpalkovic Jul 24, 2026
1cd408b
Update code/lib/docgen-harness/src/vue3/vue3-baselines.test.ts
valentinpalkovic Jul 24, 2026
fb18b89
Update code/lib/docgen-harness/src/compare/parse-snapshot.ts
valentinpalkovic Jul 24, 2026
ead79cf
Update code/lib/docgen-harness/src/compare/parse-snapshot.ts
valentinpalkovic Jul 24, 2026
5b8263e
Update code/lib/docgen-harness/src/compare/snippets-vue3.ts
valentinpalkovic Jul 24, 2026
997d502
Update code/lib/docgen-harness/src/compare/argtypes.ts
valentinpalkovic Jul 24, 2026
3af39a3
Update code/lib/docgen-harness/src/compare/argtypes.ts
valentinpalkovic Jul 24, 2026
0011c0b
Update code/lib/docgen-harness/src/compare/argtypes.ts
valentinpalkovic Jul 24, 2026
1b4619c
Update code/lib/docgen-harness/src/compare/argtypes.ts
valentinpalkovic Jul 24, 2026
754a84c
Update code/lib/docgen-harness/src/compare/argtypes.ts
valentinpalkovic Jul 24, 2026
287c99b
Update code/lib/docgen-harness/src/angular/angular-baselines.test.ts
valentinpalkovic Jul 24, 2026
efa7fb5
Test: Replace hand-rolled scanners with regex forms
valentinpalkovic Jul 24, 2026
24e0df9
Docs: Rewrite the harness README for humans
valentinpalkovic Jul 24, 2026
52f0cfd
Test: Address CodeRabbit review findings
valentinpalkovic Jul 24, 2026
fa06006
Test: Close the type-fidelity hole in the docgen comparator
valentinpalkovic Jul 24, 2026
849a346
Merge branch 'next' into valentin/sb11-story-1-8-expect-current-or-be…
valentinpalkovic Jul 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion code/lib/docgen-harness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ Nothing here ships to npm (`private: true`).

```text
code/lib/docgen-harness/src/
├── index.ts # package entry (the expectCurrentOrBetter comparator lands here)
├── index.ts # package entry: the comparator's public surface
├── compare/
│ ├── parse-snapshot.ts # tokenizer for committed argtypes*.snapshot text (pretty-format, not JSON)
│ ├── argtypes.ts # per-key argTypes floor rules
│ ├── snippets.ts # representation-set snippet rules + exhaustive framework dispatch
│ ├── snippets-vue3.ts # Vue matcher (template block, v-model, slots, default content)
│ ├── snippets-angular.ts # Angular matcher ([input] / (output) attributes)
│ ├── parse-element.ts # framework-neutral root-element and attribute scanning
│ ├── expect-current-or-better.ts # the throwing wrapper
│ ├── is-snapshot-update-run.ts # -u detection shared by both recorders
│ └── types.ts # Violation model
├── vue3/
│ ├── vue3-baselines.test.ts # legacy baseline recorder (argTypes + snippets)
│ ├── vue3-legacy-gaps.test.ts # test.fails red markers for the closeable legacy gaps
Expand Down Expand Up @@ -73,6 +83,19 @@ Editing a fixture component or its supporting sources therefore always requires
The signal fixtures' `aot-cmp.ts` maps follow the same rule: they are captured once from real `ngc` output (`@angular/compiler-cli` 21.2.17) by compiling the staged component and reading the emitted class's `ɵcmp.inputs`/`ɵcmp.outputs`, and re-capturing with another Angular version is a reviewed baseline change.
The production reader consumes only each input tuple's first slot and the plain output strings; the remaining tuple slots are carried for shape fidelity only.

## The expectCurrentOrBetter comparator

`src/compare/` enforces "current or better" mechanically: nothing a committed baseline records may be lost, and improvements pass.
For argTypes it is a per-key floor: a baseline key, description presence, default-value presence, or type must survive into the candidate; types may change only by normalized deep equality or an enumerated improvement (an `other` catch-all becoming structured, enum/union member supersets, recursive object/array widening).
`required`, `table.category`, `table.jsDocTags`, `control`/`action`, `table.type.summary`, and description/default contents are deliberately not compared - each would entrench a recorded lie (#28706's `required: true`) or lateral engine vocabulary.
For snippets it is a representation floor: represented names (bindings, slots, default content) are compared as sets, so attribute order, whitespace, and quote style cannot fail; a name the baseline represents must stay represented, a candidate-only representation is an improvement, and a declared arg absent from both sides is a baseline-encoded accepted delta.
Committed `argtypes*.snapshot` files are pretty-format output, not JSON: `parseArgTypesSnapshot` tokenizes them (literal raw newlines and unescaped inner quotes in strings, bare `undefined`/`NaN`) and throws on anything outside that grammar - a silently dropped entry would loosen the floor invisibly.
Both recorders run the checks per fixture on every baseline file, reading the committed text BEFORE its `toMatchFileSnapshot` call: under `-u` the match call rewrites the file, so the comparator judges the fresh output against the last committed text exactly when a flip re-record needs regressions surfaced.
A parser round-trip (`parsed toEqual live`) guards the tokenizer on every normal and CI run; it skips files a `-u` run rewrites and re-arms on the next normal run.
Acceptance is the reviewed snapshot update: there is no allowlist file, the committed baseline IS the allowlist, and a wanted deviation lands by re-recording under `-u` and reviewing the diff.
Red markers and the comparator divide the work: markers pin specific closeable gaps and harden on the `BASELINE_PATH` flip, while the comparator is the general floor with no gap knowledge - a marker closing shows up as a passing improvement, and any unrelated loss still fails.
Each framework's snippet matcher lives in its own `snippets-<framework>.ts`; the dispatch in `snippets.ts` is an exhaustive switch, so adding a member to the `Framework` union fails compilation there until the new framework's matcher exists.

## Known legacy gaps (vue3)

Thin or empty output is recorded as-is - never "fix" a fixture to make legacy output richer.
Expand Down
65 changes: 45 additions & 20 deletions code/lib/docgen-harness/src/angular/angular-baselines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
} from '../../../../frameworks/angular-vite/src/client/compodoc.ts';
import { computesTemplateSourceFromComponent } from '../../../../frameworks/angular-vite/src/client/renderer/ComputesTemplateFromComponent.ts';
import { getComponentInputsOutputs } from '../../../../frameworks/angular-vite/src/client/renderer/utils/NgComponentAnalyzer.ts';
import { expectCurrentOrBetter } from '../compare/expect-current-or-better.ts';
import { isSnapshotUpdateRun } from '../compare/is-snapshot-update-run.ts';
import { parseArgTypesSnapshot } from '../compare/parse-snapshot.ts';
import { BASELINE_PATH } from './baseline-path.ts';

if (BASELINE_PATH !== 'legacy') {
Expand All @@ -40,6 +43,9 @@ const fixtureCases = readdirSync(fixturesDir, { withFileTypes: true })
.map((entry) => entry.name)
.sort();

const readCommitted = (path: string): string | undefined =>
existsSync(path) ? readFileSync(path, 'utf8') : undefined;

type AotCmp = {
inputs: Record<string, [string, number, null]>;
outputs: Record<string, string>;
Expand All @@ -48,8 +54,7 @@ type AotCmp = {
describe('angular legacy baselines', () => {
it.each(fixtureCases)('%s', async (fixtureCase) => {
const testDir = join(fixturesDir, fixtureCase);
const dirFiles = readdirSync(testDir);
expect(dirFiles.filter((file) => file === `${fixtureCase}.component.ts`)).toHaveLength(1);
expect(existsSync(join(testDir, `${fixtureCase}.component.ts`))).toBe(true);

setCompodocJson(JSON.parse(readFileSync(join(testDir, 'compodoc-input.json'), 'utf8')));

Expand Down Expand Up @@ -83,33 +88,53 @@ describe('angular legacy baselines', () => {
// call (Type<unknown> accepts it structurally).
const asCompodocRef = component as unknown as Parameters<typeof extractArgTypes>[0];

flags.angularFilterNonInputControls = false;
const argTypes = extractArgTypes(asCompodocRef);
await expect(argTypes).toMatchFileSnapshot(join(testDir, 'argtypes.snapshot'));
const recordArgTypes = async (filterNonInputControls: boolean, fileName: string) => {
flags.angularFilterNonInputControls = filterNonInputControls;
const path = join(testDir, fileName);
const committed = readCommitted(path);
const extracted = extractArgTypes(asCompodocRef);
await expect(extracted).toMatchFileSnapshot(path);
flags.angularFilterNonInputControls = false;
if (committed !== undefined) {
const parsed = parseArgTypesSnapshot(committed, `${fixtureCase}/${fileName}`);
if (!isSnapshotUpdateRun()) {
// Round-trip proof: the tokenizer must reconstruct exactly what pretty-format wrote.
expect(parsed).toEqual(extracted);
}
expectCurrentOrBetter({ kind: 'argTypes', baseline: parsed, candidate: extracted! });
}
return extracted;
};

flags.angularFilterNonInputControls = true;
await expect(extractArgTypes(asCompodocRef)).toMatchFileSnapshot(
join(testDir, 'argtypes-filtered.snapshot')
);
flags.angularFilterNonInputControls = false;
const argTypes = await recordArgTypes(false, 'argtypes.snapshot');
await recordArgTypes(true, 'argtypes-filtered.snapshot');

expect(Object.keys(stories).length).toBeGreaterThan(0);

const actionArgNames = Object.entries(argTypes ?? {})
.filter(([, argType]) => argType.action)
.map(([name]) => name);

for (const [exportName, story] of Object.entries<{ args?: Record<string, unknown> }>(stories)) {
// Production runs the actions addon's addActionsFromArgTypes args enhancer before
// the source decorator: every output argType carries `action`, so outputs a story
// does not set still receive an auto-injected handler arg and the legacy snippet
// binds every declared output. Only key presence reaches the snippet text, so a
// plain stub stands in for the injected action.
const props: Record<string, unknown> = { ...meta.args, ...story.args };
for (const [name, argType] of Object.entries(argTypes ?? {})) {
if (argType.action && !(name in props)) {
for (const name of actionArgNames) {
if (!(name in props)) {
props[name] = () => {};
}
}
await expect(
computesTemplateSourceFromComponent(component, props, argTypes)
).toMatchFileSnapshot(join(testDir, `snippet-${exportName}.snapshot`));
const snippetPath = join(testDir, `snippet-${exportName}.snapshot`);
const committedSnippet = readCommitted(snippetPath);
const snippet = computesTemplateSourceFromComponent(component, props, argTypes!);
await expect(snippet).toMatchFileSnapshot(snippetPath);
if (committedSnippet !== undefined) {
expectCurrentOrBetter({
kind: 'snippet',
framework: 'angular',
args: props,
baseline: committedSnippet,
candidate: snippet,
});
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

// toMatchFileSnapshot files sit outside vitest's obsolete-snapshot detection, so a
Expand Down
Loading