Repository navigation
fix(csharp): leave unchanged generated and ejected files unwritten - #631
Merged
Merged
Conversation
…nder eject --force An unchanged file is never rewritten: CodegenRunner.WriteOne's no-manifest path, every eject copy (generator, emitter companions, helper runtime) and the gen fingerprint now read the file first and leave identical bytes alone.
…overridable pieces (ADR-0063 item 7) W-CS-4 polish. RoutesGenerator works out a file's plan once (PlanStandardRoutes, PlanTphRoutes) and writes it from one protected virtual method per piece: the header, the list, item, create, update and delete routes, the M:N traversals, the TPH polymorphic list and item routes and the sort dispatch. Its Append* helpers become protected virtual Write*, and its other helpers and records are protected. Expression-indexes, report-export, requirement-tests, shared-model and api-docs get the same shape; ApiDocsGenerator is no longer sealed. Output is byte-identical: every registered generator over the 394 loadable fixture models in four layouts hashes the same before and after.
…entries) # Conflicts: # CHANGELOG.md
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What Changed
CodegenRunner.WriteOnenow compares content before writing on the no-manifest path too. A file already holding identical bytes returnsunchangedinstead ofwritten.dotnet meta gen --fingerprint(GenFingerprint) rewrites its file only when the text changes.dotnet meta eject --forceroutes every owned copy (generators, companion emitters, helper runtime) through a sharedWriteOwnedCopycheck. An identical copy is left alone and reported[unchanged].RoutesGeneratorplans each file once (PlanStandardRoutes,PlanTphRoutes) and writes it throughprotected virtualWrite*methods. Expression-indexes, report-export, requirement-tests, shared-model and api-docs follow the same shape, andApiDocsGeneratoris no longer sealed. Generated output is byte-identical to before.Also updates
CHANGELOG.md,docs/ports/csharp.mdanddocs/features/own-your-codegen.mdto describe the unchanged-file status and the overridable generator pieces. Only the C# port changes.Gate runs: this PR took 1 no-mistakes run.
The full sweep the gate left untested (every registered generator over the 394 loadable fixture models in four layouts, hashed before and after) was run locally before the gate, on the pre-change and post-change trees, and every hash matched.
Validation
Risk Assessment
✅ Low: Commit 1 adds compare-before-write on three paths with behavioral tests. Commit 2 is a mechanical split of RoutesGenerator into plan and Write* pieces, which I checked by a rename-normalized diff against the pre-change file: same emission order, same warning order, no logic change. The Codegen project builds with 0 warnings and 0 errors, and all newly protected signatures use public types. I did not run tests, so the byte-identical claim over the 394 fixtures is unverified by me.
Testing
Baseline
scripts/ci-local.sh --affected --strict-toolchainsalready passed at the target commit; not re-run, no source edits here. I built the realdotnet metaCLI from base and target trees (git archive into scratch) and drove it end-to-end. Scenario 1:genover persistence-conformance/canonical through a scaffolded codegen project wired to each tree. Base and target both wrote 287 files (227 generated, 60 docs); sha256 manifests match. Inheritance fixture also identical. Scenario 2: forcedgentwice outside the project root (no-manifest path): base rewrote 227 files on run 2, target wrote 0. Scenario 3: forcedejecttwice over unedited copies: base replaced 17 copies (mtimes moved), target reported [unchanged] for all and left copy mtimes alone. Scenario 4 (adversarial): a hand-edited eject copy and a tampered generated file were both restored under --force; a follow-up forced run wrote 0. Ejected RoutesGenerator.cs source differs base vs target as expected from the refactor (source copy, not generated output). Scratch trees and outputs deleted. Worktree git status clean. Left running: some dotnet MSBuild/VBCSCompiler node-reuse processes from my builds; not killed (could not separate them from other sessions without name matching); they idle out on their own.dotnet meta gen(built from base 9578cff and target 0e80885) over fixtures/persistence-conformance/canonical writes 287 files inc…diff -rand sha256 manifest match; see evidence file S1gen --forcerun outside the project root reports 0 written on target, while base rewrites all 227 fileseject --forceover unedited owned copies leaves them and their timestamps alone: target reports [unchanged] for all 17 copy lines and changes no copy mtime; base replaces 17 and rewrites themeject routes --force-> [replaced] with reference bytes restored (cmp);gen --force-> 'written: ReportExportWriter.g.cs' with base bytes restored; following forced run 0 written; evidence file S3Evidence: C# bundle 1 live validation summary (base vs target CLI transcripts and counts)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
dotnet meta gen(built from base 9578cff and target 0e80885) over fixtures/persistence-conformance/canonical writes 287 files inc…diff -rand sha256 manifest match; see evidence file S1gen --forcerun outside the project root reports 0 written on target, while base rewrites all 227 fileseject --forceover unedited owned copies leaves them and their timestamps alone: target reports [unchanged] for all 17 copy lines and changes no copy mtime; base replaces 17 and rewrites themeject routes --force-> [replaced] with reference bytes restored (cmp);gen --force-> 'written: ReportExportWriter.g.cs' with base bytes restored; following forced run 0 written; evidence file S3scripts/ci-local.sh --affected --strict-toolchainsgit archive 9578cff1a7 and 0e80885293 server/csharp into $DEV_SCRATCH;dotnet build -c Release -othe MetaObjects.Cli project in each (both 0 warnings, 0 errors)dotnet <cli>/MetaObjects.Cli.dll init --root <proj>to scaffold a codegen project; rewrote codegen/Generators.cs with the 12 generator entries and Codegen.csproj ProjectReference to each tree's MetaObjects.Codegendotnet <cli>/MetaObjects.Cli.dll gen meta --out <dir> --namespace Mo.Fxon fixtures/persistence-conformance/canonical (base and target): 287 files written,diff -rand sha256 manifest identical including docs/csharpSame gen on fixtures/codegen-conformance/inheritance input: 10 files each, trees identicalTwo forcedgen --forceruns outside the project root (no-manifest path) on base and target; per-run 'written' counts and mtime capturedotnet <cli>/MetaObjects.Cli.dll eject routes filter-allowlist --root <dir>then--forcere-eject on base and target; status lines and mtime diffAdversarial: hand-edited codegen/generators/RoutesGenerator.cs re-ejected with --force (target) -> [replaced], bytes restored; tampered ReportExportWriter.g.cs regenerated with --force -> rewritten, then follow-up forced run 0 written🔧 Fix applied.
1 info still open:
docs/ports/csharp.md:332- docs/ports/csharp.md said every generator is written on CsWriter. JSON, Markdown and template generators do not use it. Tightened the sentence to say every generator that emits C# source is written on CsWriter, and that the JSON, Markdown and template generators are not.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.