Skip to content

feat(codegen-ts): template generator renders the docs view - #666

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-130-ts-template-gen
Nov 27, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-130-ts-template-gen

Conversation

@dmealing

Copy link
Copy Markdown
Member

What Changed

  • template generator (server/typescript/packages/codegen-ts/src/generators/template-generator.ts) gains perNode and perRequirement scopes over the docs view, a data: "docsView" option for perPackage/perModel (default still the per-entity dictionary), match to filter nodes by <type>.<subType>, {path} in outputPattern, and a root value on each page for relative links. subDir, assets: { from } (copies a directory of UTF-8 text files) and linkCheck are also added, and the same keys are accepted in the JSON template spec (template-spec.ts, template-spec.schema.json).
  • linkCheck runs through a new Generator.checkRunOutput hook, called from runGen after all generators render and before any write, so a dangling link fails the run and writes nothing. docs-site exports the check as findDanglingLinks, and the docs view is built per run in docs-view-run.ts.
  • template-codegen-conformance gains a docs-view/ case (metadata, templates, assets and expected output), and docs/features/codegen-concepts.md, docs/features/docs-view.md and CHANGELOG.md document the new scopes. The explorer site output is unchanged.
Validation

Risk Assessment

✅ Low: The change adds opt-in features to the template generator, and existing specs keep the per-entity dictionary and their bytes. The fix round resolved F1 (the link check now ignores stale generated files in a sweeping run), F2 (in perNode, "*" skips requirement nodes) and F3 (assets.to removed everywhere, corpus bytes unchanged), each with a test that has an independent oracle. I found no new defects.

Testing

Ran the template-codegen conformance corpus and docs-view generator tests for the docs-view feature: 39 pass, 0 fail. Those tests execute the real generator in process against the committed fixture and scratch dirs, so they are not live product drives. The meta gen CLI was not driven live on a disposable project, so all three scenarios are untested-live. Verdict inconclusive, not no-go: nothing failed. Broad regression came from the configured baseline command, which passed.

  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Per-node pages render at {path} with root leading back (fixture site-objects) ⏸️ untested no Only exercised in process via bun test. A live meta gen run on a disposable project was not built in this turn.
Full site: perNode default match plus perRequirement write each page once, no collision ⏸️ untested no In-process test only; live CLI run not driven.
Broken relative link fails the run and writes nothing; stale generated page does not satisfy a full run ⏸️ untested no Adversarial case covered by in-process tests only; not driven through the CLI.
  • Outcome: ⚠️ 2 warnings across 1 run (6m4s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ server/typescript/packages/codegen-ts/src/runner.ts:1108 - The link check falls back to disk for any path this run did not emit (runner.ts:1108-1116), including generated files from an earlier run that this full run no longer produces. The run-wide orphan sweep (runner.ts:1246-1264, which runs only when generatorNames is undefined) then deletes those files after the check passed. Concrete sequence: a perNode entry with match "" wrote model/acme/Foo.prompt-…html last run; the user narrows match to "object."; a requirement page (linkCheck) still links to that node's {{root}}{{path}}; the full meta gen passes the check by reading the stale page from disk, then the sweep removes it, and the site ships a dangling link. The check claims every link lands. Fix: in a run that sweeps (opts.generatorNames undefined and no entity filter), do not answer from disk for a path recorded in the gen-state manifest (listGeneratedPaths) that this run did not emit. Keep the disk fallback for narrowed runs and for hand-authored files.
  • ⚠️ server/typescript/packages/codegen-ts/src/generators/template-generator.ts:260 - perNode defaults to match "*", and view.nodes holds top-level requirement nodes. Their path is requirements/<pkg>/<Name>.html, the same page perRequirement writes. The test 'match takes a list, and * matches every node type' confirms this: it writes b/Buy.txt for a requirement. So the natural full-site config (a perNode entry with the default match plus a perRequirement entry, both at outputPattern "{path}" in one subDir) fails with "Output path collision" on every top-level requirement. match has no exclusion form, so 'every node except requirements' means listing each other type by hand. Decide one of: perNode skips requirement-type nodes (perRequirement owns their pages), match gains an exclusion, or the docs warn about it (codegen-concepts.md, the perNode bullet). Same rule at template-generator.ts:184-187 (the perNode walk).
  • ⚠️ server/typescript/packages/codegen-ts/src/generators/template-generator.ts:64 - Simplification: assets.to, which re-roots the copied assets under subDir (also in template-spec.ts, template-spec.schema.json and assetFiles at line 225), goes beyond the intent's "copying a directory of static assets". Copying from straight under subDir is the narrower form: the author names the source directory to match the layout they want (e.g. from: "site/assets"). Recommend removing to unless a concrete layout needs it.
  • ℹ️ docs/ports/typescript.md:224 - Changed 'Abstract objects are excluded from every scope' to say they are excluded only from the scopes that read the per-entity dictionary, and that the docs-view scopes include them. The fixture renders the abstract BaseEntity through perNode.
  • ℹ️ fixtures/template-codegen-conformance/README.md:9 - Changed 'The corpus exercises all three built-in scopes' to 'The root case exercises the three per-entity-dictionary scopes'. There are now five scopes, and the docs-view/ case covers the other two.

🔧 Fix applied.
📝 2 wording or comment-placement notes left for the author (no fix round spent):

  • ℹ️ docs/ports/typescript.md:224 - Changed 'Abstract objects are excluded from every scope' to say they are excluded only from the scopes that read the per-entity dictionary, and that the docs-view scopes include them. The fixture renders the abstract BaseEntity through perNode.
  • ℹ️ fixtures/template-codegen-conformance/README.md:9 - Changed 'The corpus exercises all three built-in scopes' to 'The root case exercises the three per-entity-dictionary scopes'. There are now five scopes, and the docs-view/ case covers the other two.
⚠️ **Test** - 2 warnings
  • ⚠️ No live CLI run of meta gen with docs-view generators. Coverage is in-process via bun test over the real generator and fixture. Live validation would need a disposable project wiring templateSpecToGenerators into metaobjects.config.ts. Not built in this turn.
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Per-node pages render at {path} with root leading back (fixture site-objects), Full site: perNode default match plus perRequirement write each page once, no collision, Broken relative link fails the run and writes nothing; stale generated page does not satisfy a full run
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Per-node pages render at {path} with root leading back (fixture site-objects) ⏸️ untested no Only exercised in process via bun test. A live meta gen run on a disposable project was not built in this turn.
Full site: perNode default match plus perRequirement write each page once, no collision ⏸️ untested no In-process test only; live CLI run not driven.
Broken relative link fails the run and writes nothing; stale generated page does not satisfy a full run ⏸️ untested no Adversarial case covered by in-process tests only; not driven through the CLI.
  • scripts/ci-local.sh --affected --strict-toolchains
  • cd server/typescript && bun test packages/codegen-ts/test/template-codegen packages/codegen-ts/test/generators/template-generator-docs-view.test.ts (39 pass, 0 fail)
  • Covered by that run: perNode at {path} with root; match list and * default; full site with perNode plus perRequirement writes each page once; perRequirement and perModel/perPackage with docsView; broken link fails run and writes nothing; full run does not link to a stale generated file; link check sees later-rendered pages and assets; non-UTF-8 and missing assets refused; {path} outside perNode/perRequirement rejected; config parse and malformed-value refusal
  • Configured baseline scripts/ci-local.sh --affected --strict-toolchains passed at this target commit (broad regression; not re-run, no source changed this turn)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Documentation pages become ordinary configured Mustache templates over the
port-neutral docs view, run by the existing template generator.

- Two scopes walk the view: perNode (one file per top-level node of any
  type, filtered by `match`: "<type>.<subType>", "<type>.*", "*" or a list)
  and perRequirement (one per requirement at any depth). perModel and
  perPackage read the view with `data: "docsView"`; without it they keep the
  per-entity dictionary, so existing specs render the same bytes.
- `{path}` in outputPattern is the page the view gives a node or
  requirement; every docs-view page gets `root`, the way back to the site
  root, so `{{root}}{{path}}` links from any page. `subDir` sets the site
  directory.
- `assets: { from, to }` copies a directory of text files beside the pages.
- `linkCheck: true` fails the run, writing nothing, when a relative link in
  an entry's HTML pages lands on no file or anchor. It runs through a new
  `Generator.checkRunOutput` hook, called once every generator has rendered,
  so links to pages a later entry renders are checked too. docs-site's link
  check is split into a pure `findDanglingLinks` the generator reuses.
- The run's docs view is built in one place (docs-view-run.ts), shared with
  docsSiteFile().
- JSON template spec and its schema take the same keys.
- fixtures/template-codegen-conformance/docs-view/: a second case pinning the
  scopes, path output, subDir, assets and link check for the other ports.

The explorer site is unchanged.
@dmealing
dmealing merged commit 17d64c3 into main Nov 27, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-ts-template-gen branch November 27, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant