fix(csharp): payload-generator resolves bare @payloadRef in a named package#221
Open
dmealing wants to merge 1 commit into
Open
fix(csharp): payload-generator resolves bare @payloadRef in a named package#221dmealing wants to merge 1 commit into
dmealing wants to merge 1 commit into
Conversation
…ackage PayloadGenerator/PayloadCodegen.EmitRecord silently emitted an empty payload file for any template.output declared in a named (non-default) package with a bare @payloadRef. MetaData.Attr() resolves a bare template attr to its fully-qualified form per ADR-0042, but PayloadCodegen.FindObject's bare short-name match compared against the raw (possibly FQN) voName without stripping it first — nested @objectref fields already got this treatment via FieldType's CSharpNaming.StripPkg call, but the top-level payloadRef never did. PayloadGenerator.EmitPayload's output filename had the same leak (literal "::" in the file name). Strip the package qualifier once, at the top of EmitRecord, before it's used for the FindObject lookup, the emitted set key, and the record's own type name; strip it in EmitPayload's file name too. Added PayloadGeneratorTests.cs covering the generator end-to-end (the existing PayloadCodegenTests only exercised GeneratePayloadRecords directly with a hardcoded bare voName, never through the template.output -> Attr() -> FQN path that actually triggers this).
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.
Problem
PayloadGenerator/PayloadCodegen.EmitRecordsilently emitted an empty payloadfile (header comment, no record) for any
template.outputdeclared in a named(non-default) package with a bare
@payloadRef.MetaData.Attr()resolves abare template attr to its fully-qualified form per ADR-0042, but
PayloadCodegen.FindObject's bare short-name match compared against the raw(possibly FQN)
voNamewithout stripping it first — nested@objectReffieldsalready got this treatment via
FieldType'sCSharpNaming.StripPkgcall, butthe top-level
payloadRefnever did.PayloadGenerator.EmitPayload's outputfilename had the same leak (literal
"::"in the file name).Fix
Strip the package qualifier once, at the top of
EmitRecord, before it's usedfor the
FindObjectlookup, the emitted-set key, and the record's own typename; strip it in
EmitPayload's file name too. This bringsPayloadCodegenin line with the same
StripPkg-before-lookup convention already used byRoutesGenerator,EntityGenerator,M2MNavigation,OutputParserGenerator,DbContextGenerator,ReverseFinders, andPackageBindingResolver.Why the existing test suite didn't catch this
The old
PayloadCodegenTests.cscalledGeneratePayloadRecords(root, "AuthorBrief")directly with a hardcoded bare name — it never went through the
template.output → Attr() → FQNresolution step that actually produces thepackage-qualified string, so it never exercised the path that broke. The new
PayloadGeneratorTests.csdrives the real end-to-end path (load metadata witha named package →
PayloadGenerator.Generate→EmitPayload→PayloadCodegen.GeneratePayloadRecords) and asserts the generated fileactually contains the record body, not just a header.
Cross-port impact: none
Audited TS, Java, Kotlin, and Python — none have this bug:
resolveObjectRefis FQN-exact when the ref contains::.resolveObjectByShortOrFqnmatches either bare or FQNform, and all three name the emitted class after the declaring
template, not the raw
payloadRefstring, so an FQN could never leak intoa generated identifier there in the first place.
package as their default test fixture (
acme::ai/acme::demo), sothey've been exercising this exact scenario all along.
Follow-ups filed (not blocking, out of scope for this PR)
PayloadCodegen.FindObject's bare-name match can still pick thewrong
object.valueon a genuine cross-package short-name collision (apre-existing, documented, port-wide limitation shared by ~7 other C#
generators — not introduced by this fix).
xpkg-collision(ADR-0041) sub-corpus at all, unlike the other 4 ports.Test plan
PayloadGeneratorTests.cs— new regression test drives the realtemplate.output → Attr() → FQN → EmitRecordpath in a named package andasserts a full record body (was empty before the fix)
PayloadCodegenTests.cs(default-package + cross-package@objectRefcollision cases) still passper this repo's CI policy; not gated on PRs