Skip to content

refactor(scripts): drive every generated region through one registry - #507

Merged
Vivswan merged 1 commit into
mainfrom
refactor/region-driver
Oct 6, 2026
Merged

Vivswan merged 1 commit into
mainfrom
refactor/region-driver

Conversation

@Vivswan

@Vivswan Vivswan commented Oct 6, 2026

Copy link
Copy Markdown
Owner

What this changes

before: gen-docs.ts         PAGE_REGIONS + renderPage() + renderCoverageFile() + a read/write loop in main
        gen-action-docs.ts  GENERATED_REGIONS + regenerateText() + regenerateAll() + its own loop in main
after:  gen-docs.ts         PAGES: GeneratedFiles   -> regenerateFiles("gen-docs", PAGES, ROOT)
        gen-action-docs.ts  FILES: GeneratedFiles   -> regenerateFiles("gen-action-docs", FILES, ROOT)
        lib/region-driver.ts  the one lookup, the two whole-file hooks, the one read/write loop

How

  • One registry shape: each path maps to { regions, shape?, rendered? }; the driver checks shape on the text as read, regenerates the regions, then checks rendered on the result.
  • gen-docs's two page rules become registry data: the coverage page's title-and-tail rule is its shape, the token-form label rule is every other page's rendered.
  • The coverage page joins the docs registry, so generated.ts derives the docs rows from one Object.keys().
  • Four wrappers go: renderPage, renderCoverageFile, regenerateText, regenerateAll; tests call the driver with the registry.

Proof

  • Regenerated output: every generator in generated.ts run, git status clean for every generated path.
  • Census: read, write, and regenerateRegions calls in gen-docs.ts 4 to 0, in gen-action-docs.ts 3 to 0, in the driver 3.
  • Tests: gen-docs, gen-action-docs, and generated test files: 121 pass, no new test.
Technical details
  • One message changed: the unregistered-path refusal reads "no generated regions are registered for " for both scripts; gen-docs used to prefix it with "gen-docs: ". No user reaches it, since paths come from the registry keys.
  • Write policy: gen-docs wrote every page on every run and logged each; both scripts now write only a page whose bytes changed and log one line, as gen-action-docs did.
  • Hook order: shape runs before the regions so a mis-titled coverage page reports its title, not its region's placement, which the existing coverage test pins; rendered runs after because fresh markers render the token-form definition the rule counts.
  • Library: none added; the driver wraps the repository's own lib/generated-regions.ts.
  • Review: two rubber-duck rounds with codex; round one asked for one wrapped line and shorter driver comments, round two clean.
  • Accounting (git diff --numstat): region-driver.ts +54, gen-docs.ts +40/-53, gen-action-docs.ts +72/-97, generated.ts +4/-4, gen-docs.test.ts +11/-6, gen-action-docs.test.ts +9/-9.

gen-docs.ts and gen-action-docs.ts each drove their generated regions by hand: a lookup in a path-to-regions record, a throw for an unregistered path, a call to regenerateRegions, a read/write loop in main, and a log line. lib/region-driver.ts is now the one driver both call. A registry maps each path to its regions and the two whole-file rules no region's placement can carry: a shape rule judged on the file as read, before any region, and a rendered rule judged over the regenerated text.

gen-docs's two page rules become registry data: the coverage page's title-and-tail rule is its shape, and the token-form label rule is every other page's rendered rule. The coverage page joins the docs registry, so generated.ts derives the docs rows from one Object.keys(). The four wrappers renderPage, renderCoverageFile, regenerateText, and regenerateAll go; tests call the driver with the registry.

Every generated page regenerates byte-identically. The one message change is the unregistered-path refusal, which no longer carries a "gen-docs: " prefix; no user reaches it, since paths come from the registry keys.
Copilot AI balanced review requested due to automatic review settings October 6, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The refactor preserves existing validation behavior while removing duplicated generation loops.

Review effort: Balanced
Findings: None

What changed in this PR

Centralizes generated-region processing in a shared registry-driven driver.

Changes:

  • Adds shared file regeneration and validation hooks.
  • Migrates documentation generators to unified registries.
  • Updates generated-output discovery and tests.
File Description
.github/​scripts/​lib/​region-driver.ts Adds the shared registry and regeneration loop.
.github/​scripts/​gen-docs.ts Migrates documentation pages to PAGES.
.github/​scripts/​gen-action-docs.ts Migrates action documentation to FILES.
.github/​scripts/​generated.ts Derives generated paths from both registries.
test/​scripts/​gen-docs.test.ts Updates documentation generator tests.
test/​scripts/​gen-action-docs.test.ts Updates action documentation generator tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Vivswan
Vivswan marked this pull request as ready for review October 6, 2026 10:52
@Vivswan
Vivswan merged commit 0971c6c into main Oct 6, 2026
30 checks passed
@Vivswan Vivswan added the merge-when-green Owner approved: merge once every gate is green label Oct 6, 2026
@Vivswan
Vivswan deleted the refactor/region-driver branch October 6, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-green Owner approved: merge once every gate is green

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants