Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

feat(gate): census the code generators emit from template literals (report-only) - #8138

Merged
baozhoutao merged 1 commit into
mainfrom
claude/issue-7864-template-literal-emit-census
Sep 6, 2026
Merged

baozhoutao merged 1 commit into
mainfrom
claude/issue-7864-template-literal-emit-census

Conversation

@baozhoutao

Copy link
Copy Markdown
Contributor

Fixes #7864

Route C, as ruled on the card: scripts/check-doc-snippet-types.mjs — this repository's documentation-surface compiler, which already builds a scoped closure and compiles snippets against built .d.ts — now censuses the code this repository's generators emit from template literals under packages/*/src/**. Report-only on first landing, and the census is the deliverable.

The recogniser, and its blind side

route taken? why
static heuristic — a template whose text carries an import … from '…' statement ⭐ yes Sees the class without anybody opting in. Misfires, and on this corpus it does (below) — under report-only a misfire costs a printed line, never a red build.
marker — an opt-in /* doc-snippet: emits tsx */ comment kept as the heuristic's escape, not as the route Disqualified as the primary route, not merely weaker. The one site the card requires the census to show red — packages/cli/src/utils/app-generator.ts, objectui#7472 — sits in a file this PR may not touch. Under a marker-only route it could not be marked, so the census would report 1 site and 0 diagnostics: a census that cannot see the member it was filed for measures nothing.
path list no Rots silently in the direction that produces a green over a file nobody added.

The marker is honoured, not merely counted: a template it marks joins the census whether or not the heuristic saw it. Counting it without acting on it would be a declaration the runtime does not cash — the shape AGENTS.md commandment #0.1 refuses. It carries the same doc-snippet: vocabulary as the existing fragment marker; no second spelling was invented.

The blind side is printed every run, because a census that cannot see what it excludes is not a census:

  • 0 templates carry the marker at all — the population an opt-in-only route would have reached today.
  • 5 unrecognised templates open a top-level export and are seen by neither route.
  • 2380 files under packages/*/src/** were excluded as TOOLING_FILE (regex imported from scripts/check-phantom-dependencies.mjs, not copied). Three of them do hold import-bearing templates: packages/cli/src/__tests__/app-generator.test.ts, packages/types/src/__tests__/partial-schema-collapse-pin.test.ts, packages/vscode-extension/src/__tests__/export-to-react-compiles.test.ts.

The census

Measured at 1184533dc on a built closure. Verbatim from node scripts/check-doc-snippet-types.mjs --emit-census:

  Walked        1414 source file(s) under packages/NAME/src; 2380 excluded as TOOLING_FILE (tests, mocks, benchmarks, stories).
  Recognised    20 of 3778 template literal(s): 20 by the import heuristic, 0 by the `doc-snippet: emits` marker alone.
  Blind side    0 template(s) carry the marker at all — the population an opt-in-only route would have reached. 5 unrecognised template(s) open a top-level `export` and are seen by NEITHER route.
  Judged        15 of 20 recognised template(s) reached the semantic phase; 1 failed to parse, 4 were refused by the root bound. Neither of those is a pass.
  Diagnostics   16 across 9 site(s).
  Of which      10 module-not-found on a sibling the same generator writes (an artefact of judging one emitted file in isolation) and 4 on a specifier that is itself interpolated (an artefact of the hole substitution). 2 remain, and those are the only ones that say anything about the emitted code.
  packages/cli (@object-ui/cli)              11 site(s), 6 with diagnostic(s), 10 diagnostic(s).
  packages/create-plugin (@object-ui/create-plugin) 8 site(s), 3 with diagnostic(s), 6 diagnostic(s).
  packages/vscode-extension (object-ui)      1 site(s), 0 with diagnostic(s), 0 diagnostic(s).

The number that decides the follow-up card is 2, not 16. The headline is dominated by artefacts of the census's own method, and they are separated out on their own line rather than left in the total:

class count what it is
sibling 10 Module-not-found on a relative specifier — ./App, ./index.css, ./theme-provider, ./Layout, ../app.json, ./types. These generators write whole projects; a per-snippet compile structurally cannot resolve a sibling that exists only after the generator has run. Inherited deliberately from the documentation rule "in isolation, as its own module".
interpolated 4 Module-not-found on a specifier that is itself a ${…} hole ('./schemas/__hole__', './__hole__Impl'). There is no specifier for any compiler to resolve — an artefact of the substitution, by construction.
code 2 Says something about the emitted code. See below.

Plus 4 sites refused by the root bound (they emit imports of react-router-dom, @testing-library/react, vitest, @testing-library/jest-dom/vitest — specifiers that resolve here only through this repository's own package.json, i.e. through nothing the emitted file's reader installs) and 1 parse failure, which is a heuristic misfire: packages/create-plugin/src/templates.ts:286 emits a README, and the tsx fence inside it carries an import.

The two code diagnostics, both in packages/create-plugin/src/templates.ts, both candidates for the PM to card:

  • :234 TS2307: Cannot find module 'vite-plugin-dts' — the emitted vite.config.ts imports a package no documented package declares.
  • :261 TS2769: … 'test' does not exist in type 'UserConfigExport' — the emitted vite config passes a test: block to defineConfig imported from 'vite'. That is the real shape of the class this card is about.

objectui#7472's site shows up, as the ruling requires: packages/cli/src/utils/app-generator.ts carries 4 of the 11 packages/cli sites and 5 of its 10 diagnostics. ⛔ This PR does not address it — that card is pm:on-hold.

PR objectui#7863's repair holds: packages/vscode-extension/src/extension.ts, 1 site, 0 diagnostics.

⚠️ One inherited path correction: the card writes packages/cli/src/app-generator.ts. The file is one directory deeper, at packages/cli/src/utils/app-generator.ts. Pinned in the test file so nobody re-derives it.

The instrument

A separate walk over packages/*/src/**/*.ts{,x} minus TOOLING_FILE, extracting each recognised template from the AST (never a regex over the text — a backtick in a string or a comment is not a template), then handing each one to the gate's existing compileSnippets() with the same paths, the same declaredSpecifiers and the same four controls. An emitted snippet is judged exactly the way a documentation block is; that reuse is the whole argument for putting this here rather than in a per-package test.

Holes. Each ${…} is substituted by the identifier __hole__, and a body that had any gets one appended line, declare var __hole__: any;. Both halves are stated in the source because the compiled snippet is then not byte-identical to what the generator writes:

  • an identifier, because this corpus interpolates inside identifiers (${vars.pascalName}Plugin) as often as in expression position (const schema = ${schemaJson};) — an expression-shaped placeholder is a syntax error in the first;
  • appended, so every diagnostic's line number still points at the real source line; var, not const, because a block-scoped binding read above its own line is TS2448 — a diagnostic the instrument would have invented;
  • skipped entirely when the placeholder is itself a declared name (export const ${vars.pascalName} becomes export const __hole__). Measured: without that guard the census invented 2 TS2395s on templates.ts.

What the substitution therefore cannot judge, said out loud in the header: whether the value a hole interpolates type-checks where it lands.

Behind a flag, per the seat's reading. --emit-census. The documentation verdict and exit code do not move for existing callers, and --build-filter's output was diffed against the base commit's copy of the script and is byte-identical. The census runs after the precondition gate (it needs the same built closure) and returns EXIT_CODES.verified on any finding; it returns couldNotRun only when the walk collapsed or a harness control failed — report-only means it declines to fail on its findings, never that it passes without looking.

⛔ Burn-down licence — objectui#5174 batch 26 re-baselines from here

This change moves the strictness region objectui#5174's batches pin byte-identical. Allowed for this card; the new baseline, for batch 26's dev:

line of the Fence scanning banner sha256 of banner → EOF
base 23933ae25 730 f46b5662ba336f026bca3a0003e0b7979789d48d0291fa5760be7d23c8ed0160
this PR 1184533dc 731 5dfcd1b876c044ef33b6b5fed8a57ec719622ddbb20ce0ab539e5c985a233017

UNGATED_DOCS is untouched — no row added, none removed. If the census wants its own ledger, that is the follow-up card's decision, not this PR's.

Tests — scripts/__tests__/check-doc-snippet-emitted-census.test.ts

27 tests, all green, covering the three properties the binding constraint turns on:

  • the recogniser is opt-in — a fixture tree with a template that compiles, one that does not (a phantom import, TS2305), one plain template that is not recognised, and one hidden in a __tests__/ path that is excluded and counted;
  • the walk is non-vacuous on the real tree — 1414 files, 3778 templates, and both known members present by name;
  • a diagnostic is REPORTED and the exit code stays 0 — the census is spawned against this repository and the status asserted never to be documentsFailed; on a built tree (locally) the full positive control runs: real [semantic] lines printed, status 0.

Plus the hole substitution, the placeholder-collision guard, the diagnostic classifier, the marker vocabulary, the heuristic's bound, and the CI wiring.

Reverse verification. Committed first, then ablated: const byHeuristic = EMITTED_IMPORT.test(template.text) replaced by false on disk (anchor count 1 → 0, mutant count 1, blob e84025fbb… → eecf59d63…). 6 of 27 tests turned red, including recognises at least the two members objectui#7864 names and the spawned exit-code control. Restored with git checkout HEAD -- …; git diff HEAD empty and the disk blob equal to the HEAD blob again.

CI

One report-only step in .github/workflows/doc-snippet-types.yml, placed after the build and before the blocking gate — the number is meant to be re-read on every run, and after the blocking step it would be skipped on exactly the runs where the corpus moved. The matching write-up landed in content/docs/guide/ci-cd-pipeline.md's Documented Snippet Types section, in the shape of the check-doc-expression-carriage entry: what it runs, that it exits 0 regardless of what it finds, and why report-only is a ruling rather than an oversight (objectui#3653 pins that page by command).

Gates

All run at 1184533dc, exit codes captured by redirect-then-capture:

gate exit verdict line
pnpm check:doc-snippets 0 Every covered documentation snippet compiles against the built types. (572 of 572 judged, 0 failed — unchanged)
node scripts/check-doc-snippet-types.mjs --emit-census 0 REPORT-ONLY (exit 0), census as quoted above
--build-filter vs. base 0 diff empty against 23933ae25's copy of the script
pnpm exec vitest run scripts/__tests__/check-doc-snippet-emitted-census.test.ts 0 27 passed
pnpm exec vitest run scripts/__tests__/ 0 114 files, 3401 passed
pnpm check:doc-fences 0 227 documents, no unknown fence spelling
pnpm check:doc-types 0 Every documented component type is registered.
pnpm type-check:scripts 0 clean
pnpm lint:root 0 0 errors, 32 warnings — none in the changed files
pnpm check:control-bytes 0 6506 tracked text files
grep -naP self-scan of all 4 changed paths 1 no match
pnpm check:entry-guard 0 70 scripts, no entry guard outside the baseline
pnpm check:pre-install-import-graph 0 25 pre-install steps, every non-relative leaf a node builtin
node scripts/check-changeset-presence.mjs 0 No source or published contract of a released package changed in this range
node scripts/check-governed-queue-guard.mjs --test (4 paths) 0 NOT GOVERNED — 4 path(s) checked against 5 governed surface(s); none matched.
pnpm type-check:coverage 0 45/46
node scripts/check-doc-links.mjs 0 Links are valid across 17 scan roots.

No changeset is owed: the diff is the gate, its test, one workflow and one doc page — nothing publishes from a package. packages/vscode-extension was not touched (the marker route was not taken), so the changeset the card warns about does not arise.

Live E2E (informational) is red on every branch today for an upstream reason (objectui#7990 / objectstack#16186) — not this PR's.

What this PR deliberately does not decide

Whether the corpus gets cleaned or gets a declared ledger, and whether any rule here should ever block. That is what the numbers above are for, on a follow-up card the PM opens. ⛔ objectui#7472 is not addressed here and remains open.


🤖 Generated with Claude Code

https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr


Generated by Claude Code

…7864)

Code a generator EMITS from a template literal under `packages/*/src/**` is
compiled by nothing: `tsc` sees a string, `tsup` copies it through, and every
doc gate's scan surface — `check-doc-snippet-types`'s own `listDocuments()`
included — stops at `content/docs`, the per-app docs trees and the package
READMEs. Two members were already known when the card was filed.

Route C: extend this repository's documentation-surface compiler, which already
builds a scoped closure and compiles snippets against built `.d.ts`, so it can
census code-emitting template literals through the same `compileSnippets()` a
documentation block goes through.

REPORT-ONLY, behind `--emit-census`, and the census is the deliverable. One
known member is an open card this PR may not fix, so no finding here fails a
build; the flag keeps the documentation verdict and exit code byte-identical
for every existing caller (`--build-filter` output diffed clean against the
base commit).

The recogniser is the static import heuristic, with the `doc-snippet: emits`
marker kept and honoured as its opt-in escape. A marker-only route was
disqualified rather than merely judged weaker: the one site the card requires
the census to show red sits in a file this PR may not touch, so an opt-in route
would have censused one template and zero diagnostics.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr

Copy link
Copy Markdown
Contributor Author

Standing down on Live E2E (informational) for this PR, read 2026-09-06T19:00Z.

Every other check on 1184533dc is judged on its own; this PR flips to ready once the required set converges, then goes to the merge queue by squash.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Armed — squash auto-merge enabled and the PR is in the merge queue, domain:devx @ objectui execution seat, PM session session_01FhBNJcLRZLe8M87VcUgpKr, R46.

  • Head 1184533dc: 28 non-informational checks completed green at 19:11Z (the ci-wait reading); Live E2E (informational) red per the standing-down note above.
  • ready_for_review at 19:11:50Z; the post-flip Governed Surface Queue Guard run started after that timestamp and completed success at 19:12:05Z.
  • added_to_merge_queue at 19:12:15Z on the REST timeline (read 19:12:22Z). The queue is otherwise empty.

On MERGED: content probe on re-fetched origin/main (--emit-census handled in scripts/check-doc-snippet-types.mjs, the Census the code emitted from template literals step in doc-snippet-types.yml, the new test file present; the strictness region re-hashed to 5dfcd1b8… for objectui#5174 batch 26; control: UNGATED_DOCS still 11 package-README rows), then the LANDED note here and the closing stroke on #7864. Batch 26 dispatches on the re-baselined hash.


Generated by Claude Code

Merged via the queue into main with commit 535eb22 Sep 6, 2026
30 of 31 checks passed
@baozhoutao
baozhoutao deleted the claude/issue-7864-template-literal-emit-census branch September 6, 2026 19:26

Copy link
Copy Markdown
Contributor Author

LANDED — merged at 2026-09-06T19:26:49Z as 535eb224f (squash, via the merge queue), domain:devx @ objectui execution seat, PM session session_01FhBNJcLRZLe8M87VcUgpKr, R46.

Content probe on re-fetched origin/main (535eb224f, read 19:27:28Z):

  • --emit-census is handled in scripts/check-doc-snippet-types.mjs; the Census the code emitted from template literals (report-only) step is in .github/workflows/doc-snippet-types.yml:145; scripts/__tests__/check-doc-snippet-emitted-census.test.ts is present.
  • The strictness region (Fence scanning banner to EOF) now hashes 5dfcd1b876c044ef…, the value the PR body stated; objectui#5174 batch 26 re-baselines from it.
  • Control: UNGATED_DOCS still carries 11 package-README rows.

#7864 closed by the Fixes at merge time; the seat strips pm:dispatched and clears the assignee there in the same stroke. The census's one emitted-code defect is carded as #8139.


Generated by Claude Code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

2 participants