Skip to content

fix(render): match TypeScript dotted-name lookup, list length and zero truthiness in C# and Rust - #688

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-mustache-dotted-lookup-parity
Dec 2, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-mustache-dotted-lookup-parity

Conversation

@dmealing

@dmealing dmealing commented Dec 2, 2026

Copy link
Copy Markdown
Member

What Changed

  • C# Renderer resolves a dotted name whole against each context, innermost outward, so a context holding only the first segment no longer hides an outer match. The render-shadowed-dotted-prefix drift entry is removed from RenderConformanceTests.
  • Rust metaobjects-render drops mustache-ng for its own Mustache engine (src/mustache.rs). It gives whole-path lookup, a list's length as a number, and 0 falsy for sections while it still prints as 0. Lists and objects print as JavaScript does (1,2 / [object Object]), and U+FDD0 / U+FDD1 are no longer refused. render-list-length and render-zero-falsiness pass without a ledger.
  • Both render-conformance drift ledgers are now empty. docs/CONFORMANCE.md, CHANGELOG.md (Unreleased), docs/ports/rust.md, docs/features/templates-and-payloads.md and ADR-0065 are updated to match.
Validation

Risk Assessment

⚠️ Medium: The Rust engine and the C# shadowed-prefix fix meet the intent, the ledgers are empty, and the fix-round changes look sound. One C# regression remains: a dotted name inside a typed-POCO context renders empty with no error, because only the object getter handles the joined key.

Testing

Broad regression came from the configured scripts/ci-local.sh --affected --strict-toolchains, which passed at this commit. Both ports' render-conformance corpora ran green with empty drift ledgers, covering the three target fixtures. I then drove 8 adversarial templates through the real TS, Rust and C# renderers and the outputs were byte-identical on all 8, including the three review-fix cases (list index, 01 refusal, NEL). No source files changed and the worktree is clean.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Rust and C# render-conformance corpora pass, including render-shadowed-dotted-prefix, render-list-length and render-zero-falsiness, with empty drift ledgers ✅ pass live cargo test -p metaobjects-render render_conformance ok; dotnet test MetaObjects.Render.Tests 376 passed; KNOWN_DRIFT is empty in both runners
Differential: shadowed dotted prefix, list length, zero falsiness render the same in TS, Rust and C# ✅ pass live cases.json ids shadow, list-length, zero-falsy, nested-missing-section-body; ts-out.json, rust-out.json and cs-out.json are identical for each
Adversarial: list index {{#items.0}}, {{items.0.name}}, non-canonical {{ys.01}} throws ERR_VAR_NOT_ON_PAYLOAD, and a NEL-only standalone line is kept ✅ pass live idx-section, idx-interp, idx-noncanon, nel-standalone in ts-out.json, rust-out.json and cs-out.json are all identical
Evidence: Shared adversarial cases
[
 {"id":"idx-section","t":"{{#items.0}}First: {{name}}{{/items.0}}","p":{"items":[{"name":"x"}]}},
 {"id":"idx-interp","t":"{{items.0.name}}","p":{"items":[{"name":"x"}]}},
 {"id":"idx-noncanon","t":"{{ys.01}}","p":{"ys":["a","b"]}},
 {"id":"list-length","t":"{{ys.length}}|{{#ys.length}}n{{/ys.length}}{{^zs.length}}empty{{/zs.length}}","p":{"ys":["a","b"],"zs":[]}},
 {"id":"zero-falsy","t":"{{#n}}yes{{/n}}{{^n}}no{{/n}}|{{#f}}yes{{/f}}{{^f}}no{{/f}}","p":{"n":0,"f":0.0}},
 {"id":"shadow","t":"{{#items}}[{{a.b}}]{{/items}}","p":{"a":{"b":"1"},"items":[{"a":{"c":2}}]}},
 {"id":"nel-standalone","t":"a\n{{#x}}\u{0085}\nb\n{{/x}}\n","p":{"x":true}},
 {"id":"nested-missing-section-body","t":"{{#zs.length}}{{missing}}{{/zs.length}}ok","p":{"zs":[]}}
]
Evidence: TS oracle output
{
 "idx-section": "First: x",
 "idx-interp": "x",
 "idx-noncanon": "ERR:render verify failed: ERR_VAR_NOT_ON_PAYLOAD (ys.01)",
 "list-length": "2|nempty",
 "zero-falsy": "no|no",
 "shadow": "[1]",
 "nel-standalone": "a\n�\nb\n",
 "nested-missing-section-body": "ok"
}
Evidence: Rust output
{
  "idx-section": "First: x",
  "idx-interp": "x",
  "idx-noncanon": "ERR:render verify failed: ERR_VAR_NOT_ON_PAYLOAD (ys.01)",
  "list-length": "2|nempty",
  "zero-falsy": "no|no",
  "shadow": "[1]",
  "nel-standalone": "a\n�\nb\n",
  "nested-missing-section-body": "ok"
}
Evidence: C# output
{
  "idx-section": "First: x",
  "idx-interp": "x",
  "idx-noncanon": "ERR:render verify failed: ERR_VAR_NOT_ON_PAYLOAD (ys.01)",
  "list-length": "2|nempty",
  "zero-falsy": "no|no",
  "shadow": "[1]",
  "nel-standalone": "a\n\u{0085}\nb\n",
  "nested-missing-section-body": "ok"
}

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

📌 **Review** - 3 issues (2 warnings, 1 info) left as notes at the round cap
  • ⚠️ server/csharp/MetaObjects.Render/Renderer.cs:229 - Recorded round-1 decision (fix), still unfixed in current code. A dotted section with a list index renders nothing in C#. Example: {{#items.0}}First: {{name}}{{/items.0}} over {&#34;items&#34;:[{&#34;name&#34;:&#34;x&#34;}]}. JoinDottedNames (Renderer.cs:253) joins the name into one key. WholePathGetter (Renderer.cs:274) then calls TryWalk. TryProperty (Renderer.cs:229-238) knows only payload members and a list's length, with no list index. Every context misses, Stubble gets null, and the section is skipped without an error. mustache.js and the new Rust engine both render it. Before this change, Stubble's List<object?> getter (elementAt) handled it. Fix in TryProperty: read a list element for a canonical non-negative integer key (&#34;0&#34;, not &#34;01&#34;). Sibling sites with the same invariant: (a) FailOnMissingVariable/TryResolve (Renderer.cs:153, 205) uses the same TryProperty, so {{items.0}} throws ERR_VAR_NOT_ON_PAYLOAD where TS renders x. (b) PayloadAccessors.cs:224 TryLookup reports every key on a Delegate or IDynamicMetaObjectProvider as present with value null. Through WholePathGetter, {{obj.dyn.x}} now resolves to ResolvedNull and prints empty, where Stubble's getter used to read the real member. Add regression tests for {{#items.0}}…{{/items.0}} and {{items.0.name}}, with mustache.js as the oracle.
  • ⚠️ server/rust/metaobjects-render/src/presence.rs:96 - Recorded round-1 decision (fix), still unfixed. presence.rs keeps its own lookup/resolve/property/is_truthy (lines 96-150). The new engine's mustache::lookup (mustache.rs, pub(crate)) has no caller outside mustache.rs. The two lookups disagree, so the public render gives wrong results. (1) {{ys.01}} with ys:[&#34;a&#34;,&#34;b&#34;]: presence.rs:128 accepts &#34;01&#34; through parse::&lt;usize&gt;. The engine's canonical array_index misses, so the output is empty, where TS throws ERR_VAR_NOT_ON_PAYLOAD. (2) {{s.length}} / {{s.0}} on a string: presence refuses with ERR_VAR_NOT_ON_PAYLOAD, where TS renders 5 / h and the engine supports it. (3) {{#s.length}}{{missing}}{{/s.length}}: presence skips the body, and the engine renders missing as empty where TS throws. The unit test length_and_index_read_as_javascript_properties calls mustache::render directly, which hides the split. Remedy: make presence resolve through mustache::lookup and the engine's is_truthy on one Cow stack. Then drop presence's property, LENGTH_ZERO/LENGTH_NONZERO and its own is_truthy.
  • ℹ️ server/rust/metaobjects-render/src/mustache.rs:138 - Recorded round-1 decision (fix), still unfixed. is_js_whitespace says it is JavaScript's \s, but char::is_whitespace also matches U+0085 (NEL), and JS \s does not. Take a line that holds only {{#x}}, a U+0085 and a newline. mustache.js keeps that line, and this engine strips it, so the bytes differ without an error. Fix: (c.is_whitespace() &amp;&amp; c != &#39;\u{0085}&#39;) || c == &#39;\u{FEFF}&#39;.
  • ℹ️ server/rust/metaobjects-render/src/render.rs:10 - Applied inline. The module doc said set-delimiter tags are refused 'as the Python and C# renderers refuse them'. The C# renderer refuses them only in a template that also uses partials (Renderer.cs:62), and this change's own C# test renders a {{=&lt;% %&gt;=}} template. The comment now says so.

🔧 Fix applied.
📌 Review round cap reached: 3 issues (2 warnings, 1 info) left unresolved as notes (no further fix round):

  • ⚠️ server/csharp/MetaObjects.Render/Renderer.cs:229 - Recorded round-1 decision (fix), still unfixed in current code. A dotted section with a list index renders nothing in C#. Example: {{#items.0}}First: {{name}}{{/items.0}} over {&#34;items&#34;:[{&#34;name&#34;:&#34;x&#34;}]}. JoinDottedNames (Renderer.cs:253) joins the name into one key. WholePathGetter (Renderer.cs:274) then calls TryWalk. TryProperty (Renderer.cs:229-238) knows only payload members and a list's length, with no list index. Every context misses, Stubble gets null, and the section is skipped without an error. mustache.js and the new Rust engine both render it. Before this change, Stubble's List<object?> getter (elementAt) handled it. Fix in TryProperty: read a list element for a canonical non-negative integer key (&#34;0&#34;, not &#34;01&#34;). Sibling sites with the same invariant: (a) FailOnMissingVariable/TryResolve (Renderer.cs:153, 205) uses the same TryProperty, so {{items.0}} throws ERR_VAR_NOT_ON_PAYLOAD where TS renders x. (b) PayloadAccessors.cs:224 TryLookup reports every key on a Delegate or IDynamicMetaObjectProvider as present with value null. Through WholePathGetter, {{obj.dyn.x}} now resolves to ResolvedNull and prints empty, where Stubble's getter used to read the real member. Add regression tests for {{#items.0}}…{{/items.0}} and {{items.0.name}}, with mustache.js as the oracle.
  • ℹ️ server/rust/metaobjects-render/src/render.rs:10 - Applied inline. The module doc said set-delimiter tags are refused 'as the Python and C# renderers refuse them'. The C# renderer refuses them only in a template that also uses partials (Renderer.cs:62), and this change's own C# test renders a {{=&lt;% %&gt;=}} template. The comment now says so.
  • ⚠️ server/csharp/MetaObjects.Render/Renderer.cs:115 - C# regression: a dotted name asked of a typed-object (TypedView) context now silently renders empty. The whole-path rule is installed only as the typeof(object) getter (WholePathGetter, line 118), but Stubble dispatches by the context's type. A TypedView context is a POCO with no [JsonPropertyName]. It still goes to PayloadAccessors.ViewLookup, which now receives the joined key ownernick. ViewLookup reads that as a member literally named that, returns null, and Stubble moves outward and finds nothing. Concrete case: payload PlainPayload (a record with no wire names, as in TypedPayloadTests) with template {{#entries}}{{owner.nick}}{{/entries}}. FailOnMissingVariable passes, because TryWalk -> TryProperty -> TryLookup(TypedView) walks segment by segment. The render then emits an empty string with no error. Before JoinDottedNames, Stubble walked owner then nick through ViewLookup and printed the nick. The existing test only covers {{Total.Cents}} where the dotted name starts on a Dictionary (wire-named) root, so the typed-context path is untested. This defect comes from the original change. Fix round 1 (cs-dotted-list-index) closed the dynamic-object sibling only through TryProperty and did not cover other context types. Fix in Renderer.cs by registering the joined-key check on every getter that can receive a context: wrap the ViewType getter so a key containing PathSeparator delegates to WholePathGetter, and do the same for the List<object?> getter (line 116) and the IDynamicMetaObjectProvider default getter, e.g. a {{#dyn}}{{a.b}}{{/dyn}} section whose context is a DynamicObject. Add a TypedPayloadTests case that renders a dotted name inside a section over a plain record, with the output taken from the TS renderer / mustache.js as the oracle.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Rust and C# render-conformance corpora pass, including render-shadowed-dotted-prefix, render-list-length and render-zero-falsiness, with empty drift ledgers ✅ pass live cargo test -p metaobjects-render render_conformance ok; dotnet test MetaObjects.Render.Tests 376 passed; KNOWN_DRIFT is empty in both runners
Differential: shadowed dotted prefix, list length, zero falsiness render the same in TS, Rust and C# ✅ pass live cases.json ids shadow, list-length, zero-falsy, nested-missing-section-body; ts-out.json, rust-out.json and cs-out.json are identical for each
Adversarial: list index {{#items.0}}, {{items.0.name}}, non-canonical {{ys.01}} throws ERR_VAR_NOT_ON_PAYLOAD, and a NEL-only standalone line is kept ✅ pass live idx-section, idx-interp, idx-noncanon, nel-standalone in ts-out.json, rust-out.json and cs-out.json are all identical
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains (already passed at target commit)
  • cargo test -p metaobjects-render --offline (41 unit tests plus render/extract/verify conformance corpora, KNOWN_DRIFT empty) - green
  • dotnet test MetaObjects.Render.Tests (376 tests including render-conformance with KnownDrift empty, plus new list-index, dynamic-object, present-null and delimiter tests) - green
  • Cross-port differential: 8 templates rendered through the TS renderer (bun, oracle), Rust render() via a temporary example, and C# Renderer.Render via a temporary xunit test. Temporary files deleted afterwards.
⚠️ **Document** - 1 warning
  • ⚠️ spec/decisions/ADR-0065-rust-is-the-sixth-port.md:39 - Layout decision still says metaobjects-render is built 'over the mustache-ng crate'. The crate no longer depends on it; it renders with its own engine (server/rust/metaobjects-render/src/mustache.rs). Accepted ADRs are decision records, so the fix is an amendment or an accepted rewording, not a silent edit.
  • ℹ️ server/rust/metaobjects-codegen/tests/gen-check.lock:1213 - Cargo-generated lockfile still pins the mustache-ng package, which the render crate dropped. The gate that reads it (tests/common/mod.rs:233, 359) checks that resolved packages are pinned. The file should be regenerated by cargo, not hand-edited, so the regeneration needs a cargo run.

🔧 Fix applied.
1 info still open:

  • ℹ️ server/rust/metaobjects-codegen/tests/gen-check.lock:1213 - Partly resolved. Regenerated with the gate's own command (UPDATE_GEN_LOCK=1 cargo test -p metaobjects-codegen --test compile generated_crates); it passes. The regen drops stale entries for tokio-macros, indexmap and foldhash 0.2.0 and dedupes foldhash. mustache-ng is still pinned (line 1213): assert_pinned merges by union with the committed file, so cargo cannot remove a pin it no longer resolves. Removing it needs either a hand edit (refused by the ruling) or a change to the merge in tests/common/mod.rs to replace rather than union. Left for a decision.

🔧 No changes applied.
1 warning still open:

  • ⚠️ server/rust/metaobjects-codegen/tests/gen-check.lock:1212 - server/rust/metaobjects-codegen/tests/gen-check.lock still pins mustache-ng 0.10.0 (line ~1212). Recorded round-2 ruling says to hand-delete that package block and rerun the gate test. This docs-only phase may not edit non-doc files, so the edit was not made. Conflict left for a decision: either the outer executor runs the ruled hand edit, or the merge in tests/common/mod.rs is changed in a later PR.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

… TypeScript does

C# resolves a dotted name whole against each context, innermost outward,
through Stubble's value getters (Stubble's Context is sealed): a context that
holds only the first segment no longer hides an outer match, and a path that
resolves to a present null stops there, as mustache.js does.

The Rust metaobjects-render crate renders with its own Mustache engine over
its tag scanner in place of mustache-ng, following the reference renderer's
whole-path lookup, JavaScript properties (a list's length and index),
truthiness (0 is falsy and still prints 0) and standalone-line rule.

Closes the render-conformance drift entries render-shadowed-dotted-prefix
(C#, Rust), render-list-length and render-zero-falsiness (Rust); both ledgers
are now empty.
@dmealing
dmealing merged commit 71e1576 into main Dec 2, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-mustache-dotted-lookup-parity branch December 2, 2026 13:43
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