Skip to content

fix(cli): hash linked generator packages in the gen skip key - #651

Merged
dmealing merged 8 commits into
mainfrom
fm/mo-gen-fingerprint-pack-imports
Nov 25, 2026
Merged

dmealing merged 8 commits into
mainfrom
fm/mo-gen-fingerprint-pack-imports

Conversation

@dmealing

@dmealing dmealing commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • TypeScript meta gen skip key (gen-fingerprint.ts) now hashes any config-imported @metaobjectsdev/* package that is not in the new CLI_ALIASED_PACKAGES set (exported from load-metaobjects-config.ts). Such packages, for example @metaobjectsdev/pack-config, are hashed like third-party generator packages: by content when linked, by version when installed. Previously every @metaobjectsdev/* import was skipped, so editing a linked pack's generator code left the key unchanged and gen skipped stale output. FINGERPRINT_FORMAT bumps to 4, so the first gen after upgrading renders once.
  • packageNameOf moves to its own module (lib/package-name.ts) and is shared by gen-fingerprint.ts, load-metaobjects-config.ts and runtime-eject.ts.
  • Rust cargo meta gen skip key (metaobjects-codegen): a path dependency of the owned codegen/ crate (in a build table or [patch]) is now hashed, following its own path dependencies and inherited workspace. The metaobjects and metaobjects-codegen engine crates are excluded by directory, since build.rs already hashes them into the engine source hash. FINGERPRINT_FORMAT bumps to 2.
  • Docs: ADR-0064, docs/features/cli.md and docs/ports/rust.md describe the new skip-key inputs; adds changelog fragment changelog.d/gen-skip-key-linked-generator-packages.md.

Why Rust is in this change, and the other ports

The task was to fix the TypeScript blind spot and to check every other port's skip key for the same one, fixing any that had it in the same PR.

  • Rust: had it, fixed here. The equivalent of a linked pack in Rust is a crate the owned codegen/ crate reaches by path. Nothing hashed it, so editing its generator code left the key unchanged and cargo meta gen skipped over stale output. The Cargo.toml reader handles multi-line inline tables, [dependencies.<name>], target.*, [patch]/[replace] and workspace inheritance, and adds no dependency (toml is not in the workspace tree).
  • Java, C#, Python: no prefix blind spot. None of them drops imports by package prefix. Python has a broader, unrelated gap: a package imported only transitively from an owned generator module is not hashed. It is not pack-specific and is not changed here.

Known follow-up (safe direction, output never stale): the review round cap left one Rust note open. A path dependency whose directory contains the project's .metaobjects/ (an owned crate depending on ..) makes the key change on every run, so cargo meta gen never skips in that layout.

This took one no-mistakes run (four review fixes and one documentation fix folded into it).

Validation

Risk Assessment

⚠️ Medium: The TypeScript fix meets the intent: a non-engine @metaobjectsdev/* config import is now hashed, and the round-3 narrowing is correct. The Rust path-dependency scan can defeat the skip key when a dependency covers the project root, but that fails safe: it re-renders and never leaves output stale.

Testing

Intent is that a linked @metaobjectsdev/* pack's generator code counts toward the ADR-0064 skip key. Two scenarios ran live through the real meta gen CLI on a disposable project. Editing only the pack's generator made the next gen overwrite its output. Running gen with nothing changed skipped and wrote nothing. Both pass. The focused test file passes 4/4, covering the engine-alias guard and a pack's own dependency on an aliased package. Both are unit-level only, not live, and the alias-guard boundary is not required by the intent. The base-code failure was not reproduced live, so the pre-fix regression claim rests on the test's own reasoning. The Rust path-dependency part of the change is outside the TypeScript intent and was not driven live. Overall: the two live scenarios pass; the alias-guard boundary is untested live.

  • Live validation: ✅ go - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Editing a linked @metaobjectsdev/* generator pack's source makes the next meta gen re-render (local CLI, synthetic disposable project) ✅ pass live linked-pack-gen-skip-key.log run3: generated/linked.txt overwrite, content first -> second
meta gen with nothing changed skips rendering and writes nothing (no spurious re-render from the new pack hashing) ✅ pass live linked-pack-gen-skip-key.log run2 and run4: 'nothing changed since the last meta gen, so nothing was rendered or written'
Config import of an engine-aliased package does not hash the project's copy; a pack's own dependency on an aliased package does (boundary of the alias guard) ⏸️ untested no Prior payload established only unit-level coverage: focused test file tests 3 and 4 (4/4 pass) on computeGenInputs/keyFor. Not driven through the CLI, so no live result. The intent does not require th…
Evidence: Live meta gen transcript: linked pack edit re-renders, unchanged project skips
# meta gen skip key with a linked @metaobjectsdev/* generator pack (disposable project; real CLI packages/cli/bin/meta.ts; fresh project per run)
## run1: first gen (fresh project)
gen[1]{file,status}:
  generated/linked.txt,new
exit=0
generated/linked.txt: first
## run2: no change
gen: []
summary: "nothing changed since the last meta gen, so nothing was rendered or written"
## edit pack generator only: content first -> second
1
## run3: after editing linked pack generator
gen[1]{file,status}:
  generated/linked.txt,overwrite
generated/linked.txt: second
## run4: no change again
gen: []
summary: "nothing changed since the last meta gen, so nothing was rendered or written"
generated/linked.txt: second

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

📌 **Review** - 1 warning left as notes at the round cap
  • ⚠️ server/rust/metaobjects-codegen/src/engine.rs:299 - Scope exceeds the stated intent. The intent is TypeScript-only: stop configGraphEntries from dropping non-engine @metaobjectsdev/* imports. The change also adds a Rust-port feature that no intent requirement needs: ~190 lines in engine.rs (path_dependency_entries, a hand-rolled line-scan TOML reader with manifest_dependencies, toml_key_value, toml_key_string, unquoted, strip_toml_comment, workspace_root_manifest), a new METAOBJECTS_ENGINE_CRATE_DIRS env emitted by build.rs, a FINGERPRINT_FORMAT bump to 2 in fingerprint.rs, new tests in run_engine.rs, and the docs/ports/rust.md paragraph. The Rust port has no @metaobjectsdev/*-import-dropping path to fix, so this is a separate defect class (path dependencies of the owned crate) plus a new parser to maintain. Smallest honest remedy: remove the Rust part from this change and land it separately if wanted. Confirm with the author whether Rust parity was deliberately in scope. If it stays, a line scan will miss multi-line inline tables (dep = {\n path = ... }), which cargo accepts. The doc says the forms 'one-line' are supported, so that limit is known.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ server/rust/metaobjects-codegen/src/engine.rs:299 - Scope exceeds the stated intent. The intent is TypeScript-only: stop configGraphEntries from dropping non-engine @metaobjectsdev/* imports. The change also adds a Rust-port feature that no intent requirement needs: ~190 lines in engine.rs (path_dependency_entries, a hand-rolled line-scan TOML reader with manifest_dependencies, toml_key_value, toml_key_string, unquoted, strip_toml_comment, workspace_root_manifest), a new METAOBJECTS_ENGINE_CRATE_DIRS env emitted by build.rs, a FINGERPRINT_FORMAT bump to 2 in fingerprint.rs, new tests in run_engine.rs, and the docs/ports/rust.md paragraph. The Rust port has no @metaobjectsdev/*-import-dropping path to fix, so this is a separate defect class (path dependencies of the owned crate) plus a new parser to maintain. Smallest honest remedy: remove the Rust part from this change and land it separately if wanted. Confirm with the author whether Rust parity was deliberately in scope. If it stays, a line scan will miss multi-line inline tables (dep = {\n path = ... }), which cargo accepts. The doc says the forms 'one-line' are supported, so that limit is known.
  • ⚠️ server/rust/metaobjects-codegen/src/engine.rs:345 - Path dependency silently goes unhashed when its manifest was already queued as a workspace root. enqueue dedupes by manifest path and means both "scanned this manifest" and "hashed this crate". At line 337 a workspace = true dependency queues the workspace root manifest before the paths loop runs. If a path dependency then points at that same root directory, line 345 gets None from enqueue and continues, so no path-dependency: entry is pushed. Example: the project root is a workspace with its own [package], codegen/Cargo.toml has serde.workspace = true and myapp = { path = &#34;..&#34; }. The root crate's src/ is then hashed by nothing, and editing it regenerates nothing, which is the stale-output failure this change exists to fix. Fix: track hashed crate directories in a separate set from scanned manifests, and push the entry whenever the crate dir is not yet hashed. The engine and queued dedupe then only guard re-scanning. Add a run_engine.rs case with a workspace-inheriting owned crate that path-depends on its workspace root. This is new code from the original change, not from the fix round. The fix round's logical_lines rewrite does not touch it.

🔧 Fix applied.
2 issues (1 warning, 1 info) still open:

  • ⚠️ server/typescript/packages/cli/src/lib/gen-fingerprint.ts:190 - The new skip parameter of packageClosureEntries (if (skip.has(dep)) continue;, passed CLI_ALIASED_PACKAGES from configGraphEntries) is not required by the intent and drops coverage. The intent only requires that a non-engine @metaobjectsdev/* config import be hashed like any other generator package. The closure walk already deduped engine copies through the shared seen set. The skip also changes what is hashed under a linked pack: any dependency in CLI_ALIASED_PACKAGES (@metaobjectsdev/codegen-ts, metadata, migrate-ts, cli, and bare ts-poet) is now left out of the closure. Before this change a third-party generator package's ts-poet dependency, and a linked pack's @metaobjectsdev/codegen-ts dependency, were hashed. The rationale 'never runs, so only the engine copy counts' holds only for the config file, which loadMetaobjectsConfig rewrites onto the CLI's copies. load-metaobjects-config.ts states that under Bun jiti's alias map is not applied and 'only the config file is pre-processed'. A module inside the pack that imports @metaobjectsdev/codegen-ts therefore resolves through the project's node_modules. In that case a different physical copy runs from the CLI's own, and nothing hashes it now. Smallest honest remedy: remove the skip parameter and the CLI_ALIASED_PACKAGES argument at the packageClosureEntries call site, keeping CLI_ALIASED_PACKAGES only for the top-level config-import skip. The extra entries then only over-approximate, which at worst causes a spurious regen. The third test (an import the CLI aliases onto its engine is not hashed) pins this narrower behaviour for the linked pack's dependency. It would need its fixture's expectation reconsidered if the skip goes.
  • ℹ️ changelog.d/gen-skip-key-linked-generator-packages.md:9 - Changelog line 9 runs far past the wrapped width. 'Both ports bump their fingerprint format, so the first gen after upgrading renders once. Before this change, ...' sits on one overlong line after 'bump'. Rewrap for consistency with the surrounding lines.

🔧 Fix applied.
📌 Review round cap reached: 1 warning left unresolved as notes (no further fix round):

  • ⚠️ server/rust/metaobjects-codegen/src/engine.rs:333 - A path dependency that contains the project's own .metaobjects/.gen-state makes the Rust skip key unstable, so cargo meta gen never skips. The round-2 fix explicitly supports the case where the owned crate path-depends on the project or workspace root (app = { path = &#34;..&#34; }, the second unit test). hash_tree_except(&amp;dir, PATH_DEPENDENCY_NOT_INPUTS) skips only the top-level names target and .git (see fingerprint.rs hash_tree_except: the skip list applies only to the root's direct entries). .metaobjects/.gen-state/fingerprint lives under project_root (engine.rs gen_state) and holds the previous key. Trace: run 1 computes K1 and stores it. Run 2 hashes a tree containing the file holding K1, so the key is K2 != K1; it regenerates and stores K2. Run 3 hashes a tree containing K2, so the key is K3 != K2, and so on. The .hashes/ manifest, which is rewritten on each gen, is also hashed. Output is never stale. The cost is that the skip optimisation is permanently defeated for exactly the layout the round-2 fix targets. Round 2 added the case but left this sibling behind. The unit test only compares hashes before and after an edit and never runs gen twice, so it cannot see it. When the dependency is a strict ancestor (monorepo root), .metaobjects is not a top-level entry, so a top-level skip would not catch it either. Smallest fix: exclude any .metaobjects directory (and the owned codegen/ dir, already hashed on its own) from the path-dependency tree walk, then add a run_engine.rs case where the owned crate path-depends on .. and a second gen is Outcome::Skipped.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Editing a linked @metaobjectsdev/* generator pack's source makes the next meta gen re-render (local CLI, synthetic disposable project) ✅ pass live linked-pack-gen-skip-key.log run3: generated/linked.txt overwrite, content first -> second
meta gen with nothing changed skips rendering and writes nothing (no spurious re-render from the new pack hashing) ✅ pass live linked-pack-gen-skip-key.log run2 and run4: 'nothing changed since the last meta gen, so nothing was rendered or written'
Config import of an engine-aliased package does not hash the project's copy; a pack's own dependency on an aliased package does (boundary of the alias guard) ⏸️ untested no Prior payload established only unit-level coverage: focused test file tests 3 and 4 (4/4 pass) on computeGenInputs/keyFor. Not driven through the CLI, so no live result. The intent does not require th…
  • scripts/ci-local.sh --affected --strict-toolchains
  • cd server/typescript &amp;&amp; bun test packages/cli/test/gen-fingerprint-linked-package.test.ts (4 pass, 0 fail; unit level)
  • Live: disposable project under $DEV_SCRATCH with metaobjects.config.ts importing @metaobjectsdev/pack-fixture, a source-checkout pack symlinked into node_modules; driven with bun server/typescript/packages/cli/bin/meta.ts gen four times (first gen, no change, pack generator edited, no change again)
  • Evidence log kept in the local pipeline evidence store; disposable project removed afterwards
  • Baseline configured command scripts/ci-local.sh --affected --strict-toolchains already passed at target commit; no source or test files changed in this turn, so not re-run
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ℹ️ spec/decisions/ADR-0064-skip-codegen-when-nothing-changed.md:42 - ADR-0064 §3 lists generator identity 'in practice' as the engine package and its MetaObjects dependencies, plus codegen config, owned generators and template roots. It does not name third-party or pack generator packages the config imports. The change now hashes a non-engine @metaobjectsdev/* pack like any other generator package. I left the ADR unchanged: the decision already says a generator's identity is the hash of its built code, and the pack case falls under that rule. Judgment call: add a short Amendment if the ADR's list is meant to be exhaustive.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…Script, Rust)

TypeScript: the ADR-0064 key dropped every @metaobjectsdev/* import of the
config on the assumption that the CLI aliases it onto its engine, while the
engine half hashes only the CLI's own dependencies. A package the CLI does
not depend on (an independent pack) was then hashed by nothing. Only the
packages the CLI actually aliases (CLI_ALIASED_PACKAGES) are left out now.

Rust: a crate the owned codegen crate depends on by path is now an input,
followed through its own path dependencies; the engine crates its source
hash covers are left out.

Java (plugin and project classpath content), C# (project references by
content, packages by version) and Python (every named module's package by
content) had no such gap.
Rust: follow workspace-inherited path dependencies, [patch]/[replace]
tables, single-quoted paths and trailing comments. TypeScript: leave the
CLI-aliased packages out of a generator package's closure too. Both ports
bump their fingerprint format. The linked-package test runs in scratch.
One packageNameOf for the CLI; one quote-aware TOML line scanner in Rust;
each manifest read once; engine crates matched by the directories build.rs
hashed rather than by name, so another checkout named like one is hashed.
@dmealing
dmealing merged commit 67f4a0c into main Nov 25, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-gen-fingerprint-pack-imports branch November 25, 2026 09:15
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