Skip to content

feat(csharp): writer seams for DbContext hooks, framework names at emit, quiet regen - #683

Merged
dmealing merged 5 commits into
mainfrom
fm/mo-130-csharp-post
Dec 1, 2026
Merged

dmealing merged 5 commits into
mainfrom
fm/mo-130-csharp-post

Conversation

@dmealing

@dmealing dmealing commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Generators spell framework references (System.…, Microsoft.…) through CSharpNaming.Framework / FrameworkPrefix at emit. The runner no longer rewrites output with global::. It now warns on a bare reference that a generated namespace shadows, and the output of a run stays byte-identical.
  • DbContextGenerator text hooks (OwnedTypeConfig, FieldTypeConfig, DbSetLine, ContextPreambleLines, EntityConfigTrailer and others) gain CsWriter overloads. Each defaults to its string hook, so existing overrides keep working. Fr019SharedEnum.ProvidedEnumNamespace(SharedEnum, GenConfig) is public, and SharedEnumTypeReference calls it.
  • The per-regen warning for an object-typed field on a projection or write-through read model is gone from gen. verify now reports each such field once, with a fix hint.
Validation

Risk Assessment

✅ Low: Changes are additive writer seams, emit-time framework qualification (output is byte-identical through the runner, backed by a shadow-check warning), and a verify-only advisory. Both fix-round changes (unwrapping HandEditsGenerator and honouring Include; body-only hook fragments) are correct and covered by tests that execute the real code.

Testing

Drove three scenarios live against the built C# codegen on a disposable model. Verify prints the object-typed projection advisory once with its fix hint; gen (first, unchanged, and forced) prints nothing; the wrapped-generator verify still warns. All pass. The C# conformance gate lane was not re-run in this step; the baseline affected run passed at this commit. Scratch files removed; worktree clean.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Live: dotnet meta verify on a projection with an object-typed field prints the advisory once, with its fix hint (local C# codegen, synthetic model) ✅ pass live cs-live-object-projection.log: verify --codegen prints one warning for OrderSummary.shipTo with the fix hint, exit 0
Live: dotnet meta gen on the same model prints no advisory (first run, unchanged regen, --force) ✅ pass live cs-live-object-projection.log (first gen and unchanged regen) and cs-live-wrapped-generator.log (gen --force), no advisory line
Live adversarial: advisory still reported when the entity generator is wrapped in WithHandEdits (round-2 fix) ✅ pass live cs-live-wrapped-generator.log: WRAPPED=1 verify --codegen prints the advisory
C# conformance gate lane (eject-alone compile, engine-surface contract) passes at this commit ⏸️ untested no A test-suite run, not a live product scenario; it was not re-driven in this step, so it is not marked pass.
Evidence: Live gen/verify transcript, object-typed projection
== gen (first) ==
  written: Order.g.cs
  written: OrderSummary.g.cs
  written: Address.g.cs
dotnet meta gen: 3 file(s) written
exit=0
== gen (regen, unchanged) ==
dotnet meta gen: nothing changed since the last run; skipped (use --force to regenerate)
exit=0
== verify --codegen ==
  warning: entity-generator: object-typed field "OrderSummary.shipTo" is not emitted on projection OrderSummary: a view-mapped class carries no value object here. Remove the field from the projection, or read the value through its entity: a write-through entity's <Entity>View read model carries a value object stored as jsonb.
dotnet meta verify --codegen: OK (nothing changed since the last gen; --full renders and compares)
exit=0
Evidence: Live verify/gen transcript, wrapped EntityGenerator
== WRAPPED=1 gen --force ==
  unchanged: Order.g.cs
  unchanged: OrderSummary.g.cs
  unchanged: Address.g.cs
dotnet meta gen: 0 file(s) written
exit=0
== WRAPPED=1 verify --codegen ==
  warning: entity-generator: object-typed field "OrderSummary.shipTo" is not emitted on projection OrderSummary: a view-mapped class carries no value object here. Remove the field from the projection, or read the value through its entity: a write-through entity's <Entity>View read model carries a value object stored as jsonb.
dotnet meta verify --codegen: OK (nothing changed since the last gen; --full renders and compares)
exit=0
== plain gen --force ==
  unchanged: Order.g.cs
  unchanged: OrderSummary.g.cs
  unchanged: Address.g.cs
dotnet meta gen: 0 file(s) written
exit=0
  • Outcome: 🔧 3 issues found → no changes applied ✅ across 2 runs (53m7s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ⚠️ server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs:316 - UnemittedObjectFields checks for the entity generator with generators.Any(g =&gt; g is EntityGenerator). An entry wrapped by the documented new EntityGenerator().WithHandEdits(HandEdits.Overwrite) is an internal HandEditsGenerator, so the check fails. Generation still drops the field from the view class, but verify then reports nothing. This change also removed the per-regen ctx.Warn, so for those projects the skip becomes completely silent, which defeats finding 13's 'report it once with a fix hint'. The function also ignores each entity generator's Include, so verify can report projections that generator never emits. Fix: unwrap with g is HandEditsGenerator h ? h.Inner : g (as CodegenCli.Unwrapped does), take the EntityGenerator instances, and report an object only when one of them has a null Include or one that accepts the object. Both call sites use this one function: server/csharp/MetaObjects.Cli/VerifyCommand.cs:516 and server/csharp/MetaObjects.Codegen/CodegenCli.cs:1102.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/DbContextGenerator.cs:110 - HookEntries (around line 133) renders a writer-hook fragment with fragment.ToString(). CsWriter.Body() puts the writer's header and using block in front of the body. An override that calls w.Using(...), or a NewWriter() override whose writer prints a header, therefore puts using X; (or the header) inside OnModelCreating or the class body, and the using line does not compile. The comment at line 110 says the opposite ('a fragment writer's own using block is not carried over'). Either render only the base body (a protected or internal body-only accessor on CsWriter, or a plain CodeWriter for fragments), or reject a fragment that has usings and name ContextUsings. At minimum, correct the comment.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/NamesGenerator.cs:42 - The new Fx property was inserted between Generate's XML doc (Pass 1 / Pass 2) and the method. Fx then had two &lt;summary&gt; blocks and Generate had none. I moved the Fx property and its doc above Generate's doc.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/FilterAllowlistGenerator.cs:75 - The 'FR-044 — a served report joins the set…' comment that belongs to Generate sat above the new Fx property's doc. I moved it back to just above Generate.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs:98 - The 'FR-044 — a served report joins the set as its ROW MODEL…' comment that describes Generate sat above the new Fx property's doc. I moved it back to just above Generate.

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

  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/NamesGenerator.cs:42 - The new Fx property was inserted between Generate's XML doc (Pass 1 / Pass 2) and the method. Fx then had two &lt;summary&gt; blocks and Generate had none. I moved the Fx property and its doc above Generate's doc.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/FilterAllowlistGenerator.cs:75 - The 'FR-044 — a served report joins the set…' comment that belongs to Generate sat above the new Fx property's doc. I moved it back to just above Generate.
  • ℹ️ server/csharp/MetaObjects.Codegen/Generators/RoutesGenerator.cs:98 - The 'FR-044 — a served report joins the set as its ROW MODEL…' comment that describes Generate sat above the new Fx property's doc. I moved it back to just above Generate.
🔧 **Test** - 3 issues found → no changes applied ✅
  • 🚨 configured test command failed with exit code 1
  • ⚠️ server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs:314 - Live scenario not driven: the intent's item 13 (object-typed projection advisory prints once on dotnet meta verify, nothing on gen) and item 8/9/10/11 CLI output were only covered by in-process focused tests, which are not live. Needs a disposable fixture run of dotnet meta verify and dotnet meta gen to confirm the once-per-verify behaviour.
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Gate lane: C# conformance (eject-alone compiles against public API, engine-surface contract) passes after fix, Live: dotnet meta verify on a projection with an object-typed field prints the advisory once with its fix hint, Live: dotnet meta gen on the same model prints no advisory on regen
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Gate lane: C# conformance (eject-alone compiles against public API, engine-surface contract) passes after fix ⏸️ untested no Ran scripts/ci-local.sh --only csharp, which executes the dotnet test suites in-process. Not a live product run, so no pass is recorded.
Live: dotnet meta verify on a projection with an object-typed field prints the advisory once with its fix hint ⏸️ untested no Not driven. Building a disposable C# fixture project and running the CLI was not attempted within the time budget. Covered only by UnemittedObjectFieldsTests in-process.
Live: dotnet meta gen on the same model prints no advisory on regen ⏸️ untested no Not driven for the same reason as the verify scenario above.
  • scripts/ci-local.sh --affected --strict-toolchains
  • scripts/ci-local.sh --affected --strict-toolchains (baseline failure: conformance: csharp; other lanes green)
  • scripts/ci-local.sh --only csharp before fix (eject contract tests failed: CS0122 inaccessible HandEditsGenerator, CsWriter.BodyOnly not found)
  • dotnet test EjectContractTests and EjectedGeneratorsAloneTests (engine-surface check failed on GeneratorExtensions reference; fixed by moving unwrap to callers)
  • scripts/ci-local.sh --only csharp after fix: LOCAL CI PASSED (Conformance 2946, Render 372, Codegen 2076 pass/1 skipped, Cli 504, IntegrationTests 549). In-process test run, not live.
  • Not run: live dotnet meta verify/gen on a fixture (advisory once-per-verify, no-output-on-gen for item 13). Not run: full repo-wide regression suite (only C# lane and affected lanes from the gate).

🔧 No changes applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 3 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Live: dotnet meta verify on a projection with an object-typed field prints the advisory once, with its fix hint (local C# codegen, synthetic model) ✅ pass live cs-live-object-projection.log: verify --codegen prints one warning for OrderSummary.shipTo with the fix hint, exit 0
Live: dotnet meta gen on the same model prints no advisory (first run, unchanged regen, --force) ✅ pass live cs-live-object-projection.log (first gen and unchanged regen) and cs-live-wrapped-generator.log (gen --force), no advisory line
Live adversarial: advisory still reported when the entity generator is wrapped in WithHandEdits (round-2 fix) ✅ pass live cs-live-wrapped-generator.log: WRAPPED=1 verify --codegen prints the advisory
C# conformance gate lane (eject-alone compile, engine-surface contract) passes at this commit ⏸️ untested no A test-suite run, not a live product scenario; it was not re-driven in this step, so it is not marked pass.
  • scripts/ci-local.sh --affected --strict-toolchains
  • Scratch C# project outside the repository (removed afterwards) referencing server/csharp/MetaObjects.Codegen, generator list [EntityGenerator], model acme::shop: object.value Address, object.entity Order (table, shipTo field.object @objectRef Address @storage jsonb), object.projection OrderSummary (view, shipTo extends Order.shipTo)
  • dotnet run --project codegen -- gen --out generated (first run and unchanged regen)
  • dotnet run --project codegen -- gen --force --out generated
  • dotnet run --project codegen -- verify --codegen --out generated
  • Same gen/verify with generator wrapped in WithHandEdits(HandEdits.Overwrite) (env WRAPPED=1)
  • Transcripts: evidence cs-live-object-projection.log and cs-live-wrapped-generator.log
  • Baseline configured command scripts/ci-local.sh --affected --strict-toolchains already passed at this commit (not re-run here)
⚠️ **Document** - 1 info
  • ℹ️ docs/ports/csharp.md - Docs for the C# change checked against diff: CHANGELOG 1.3.0 entries, docs/ports/csharp.md framework-name, CsWriter-overload and UseIdentityStartMigrations sections, CONFORMANCE global:: note, agent-context reference. All still accurate. Added one sentence to docs/ports/csharp.md (verify advisory for skipped object-typed fields on projections/read models). Remaining: agent-context csharp.md (and its shipped and fixture copies) does not mention the new CsWriter overloads; the text still holds, so left unchanged to avoid regenerating shipped copies.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.


Validated in one no-mistakes run.

…it, quiet regen

- Generators write framework references through CSharpNaming.Framework /
  FrameworkPrefix (or the generator's Fx prefix), so output is right as
  emitted. The runner no longer rewrites System./Microsoft. to global::
  in every .cs file; it keeps a check that names a file still writing a
  bare reference a generated namespace shadows.
- DbContextGenerator: a CsWriter overload for every statement hook
  (OwnedTypeConfig, FieldTypeConfig, DbColumnTypeConfig, DefaultValueConfig,
  ReferenceConfig, TphSubtypeFieldConfig, EntityConfigTrailer,
  EmitCheckConfig, DbSetLine, ContextMemberLines, ContextPreambleLines,
  ContextTrailerLines). Each defaults to its text hook; output and
  ConfigureModelNN splits are unchanged unless one is overridden, and a
  writer entry is never split.
- Fr019SharedEnum.ProvidedEnumNamespace(SharedEnum, GenConfig) is public and
  is what SharedEnumTypeReference uses.
- An object-typed field left off a view class is no longer warned on every
  gen; dotnet meta verify lists each once with its fix.
@dmealing
dmealing merged commit 94e4475 into main Dec 1, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-csharp-post branch December 1, 2026 05:01
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