-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: hoist scenario-template registry out of materializer orchestrator #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Scenario-template registry (#333). | ||
| // | ||
| // Single source of truth for the materializer's knowledge of which | ||
| // scenario templates exist and where their emitted Playwright suites | ||
| // live. Consumed by: | ||
| // | ||
| // - `materializer/src/index.ts` — the template emission loop reads | ||
| // this registry to wire `emitTemplateSuites` per template, instead | ||
| // of open-coding one block per template. | ||
| // - `materializer/src/coverage.ts` — `buildCoverage` reads this | ||
| // registry to map template-name → emitted output directory when | ||
| // computing the per-endpoint feature-spec suppression set (#331). | ||
| // | ||
| // Adding a new ScenarioTemplate normally requires two coordinated edits: | ||
| // | ||
| // 1. Add an ABox row in `configs/<config>/ontology/scenario-templates.json`. | ||
| // 2. Add one entry here. | ||
| // | ||
| // The TBox in `path-analyser/src/ontology/scenarioTemplateSchema.ts` | ||
| // is name-agnostic (template names are just strings), so it only needs | ||
| // updating when the ABox row *shape* changes (a new step kind, a new | ||
| // `appliesTo` kind, etc.). Likewise, `emitTemplateSuites` only needs | ||
| // extending when the new template's rendered shape genuinely differs | ||
| // from the lifecycle templates it already handles. | ||
| // | ||
| // No other site in the orchestrator needs to know about the new | ||
| // template. The guard in `tests/codegen/template-registry.test.ts` | ||
| // asserts symmetric equality between the active config's ABox and | ||
| // this registry so an ABox row without a registry entry (or vice | ||
| // versa) fails red. | ||
| // | ||
| // Step 2 of #333 (deriving the registry directly from the ABox) is | ||
| // deferred; that requires teaching the materializer to dispatch | ||
| // emitters by name when future templates need shapes beyond the | ||
| // universal `emitTemplateSuites` renderer. | ||
|
|
||
| export interface TemplateBinding { | ||
| /** Template name as declared in `scenarioTemplateSchema.ts` and as | ||
| * the subdirectory name under `generated/<config>/scenarios/templates/`. */ | ||
| name: string; | ||
| /** Output subdirectory relative to the Playwright suite root, | ||
| * i.e. `generated/<config>/playwright/<outputDir>/`. */ | ||
| outputDir: string; | ||
| } | ||
|
|
||
| export const TEMPLATE_REGISTRY: readonly TemplateBinding[] = [ | ||
| { name: 'EdgeLifecycle', outputDir: 'edges' }, | ||
| { name: 'EntityLifecycle', outputDir: 'entities' }, | ||
| { name: 'UpdatedFieldVisibleOnReadBack', outputDir: 'runtime-entities' }, | ||
| { name: 'StateTransitionVisibleAfterAction', outputDir: 'state-transitions' }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import path from 'node:path'; | ||
| import { describe, expect, test } from 'vitest'; | ||
| import { TEMPLATE_REGISTRY } from '../../materializer/src/templateRegistry.ts'; | ||
| import { loadScenarioTemplatesAbox } from '../../path-analyser/src/ontology/loader.ts'; | ||
|
|
||
| const REPO_ROOT = path.resolve(import.meta.dirname, '..', '..'); | ||
|
|
||
| /** | ||
| * Registry / ABox symmetry guard (#333). | ||
| * | ||
| * Locks in the invariant that the active config's scenario-templates | ||
| * ABox and the materializer's `TEMPLATE_REGISTRY` agree on which | ||
| * templates exist. Drift in either direction is a real defect: | ||
| * | ||
| * - Template in ABox but not in registry → planner emits scenario | ||
| * JSONs that the orchestrator never renders to a spec, and | ||
| * `buildCoverage` silently skips them. Adding a template would | ||
| * appear to do nothing. | ||
| * - Template in registry but not in ABox → orchestrator wipes and | ||
| * re-creates an output dir for a template whose scenarios the | ||
| * planner never produced; the dir stays empty and `buildCoverage` | ||
| * sees no scenarios. Effectively dead wiring. | ||
| * | ||
| * The single registry file (`materializer/src/templateRegistry.ts`) | ||
| * is the only place to wire a new template into the orchestrator. | ||
| */ | ||
| describe('TEMPLATE_REGISTRY ↔ scenario-templates ABox symmetry (#333)', () => { | ||
| test('every ABox template has a registry entry, and vice versa', () => { | ||
| const abox = loadScenarioTemplatesAbox(REPO_ROOT); | ||
| if (!abox) { | ||
| throw new Error( | ||
| 'scenario-templates ABox missing for the active config — cannot verify registry symmetry', | ||
| ); | ||
| } | ||
| const aboxNames = abox.templates.map((t) => t.name).sort(); | ||
| const registryNames = TEMPLATE_REGISTRY.map((t) => t.name).sort(); | ||
| expect(registryNames).toEqual(aboxNames); | ||
| }); | ||
|
|
||
| test('registry outputDirs are distinct (no two templates clobber the same subdir)', () => { | ||
| const outputDirs = TEMPLATE_REGISTRY.map((t) => t.outputDir); | ||
| const unique = new Set(outputDirs); | ||
| expect(unique.size).toBe(outputDirs.length); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.