Repository navigation
fix(render): match TypeScript dotted-name lookup, list length and zero truthiness in C# and Rust - #688
Merged
Conversation
… 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.
…ut mustache-ng still pinned
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
Rendererresolves a dotted name whole against each context, innermost outward, so a context holding only the first segment no longer hides an outer match. Therender-shadowed-dotted-prefixdrift entry is removed fromRenderConformanceTests.metaobjects-renderdropsmustache-ngfor its own Mustache engine (src/mustache.rs). It gives whole-path lookup, a list'slengthas a number, and0falsy for sections while it still prints as0. Lists and objects print as JavaScript does (1,2/[object Object]), and U+FDD0 / U+FDD1 are no longer refused.render-list-lengthandrender-zero-falsinesspass without a ledger.docs/CONFORMANCE.md,CHANGELOG.md(Unreleased),docs/ports/rust.md,docs/features/templates-and-payloads.mdand ADR-0065 are updated to match.Validation
Risk Assessment
objectgetter 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,01refusal, NEL). No source files changed and the worktree is clean.cargo test -p metaobjects-renderrender_conformance ok;dotnet test MetaObjects.Render.Tests376 passed; KNOWN_DRIFT is empty in both runners{{#items.0}},{{items.0.name}}, non-canonical{{ys.01}}throws ERR_VAR_NOT_ON_PAYLOAD, and a NEL-only standalone line is keptEvidence: Shared adversarial cases
Evidence: TS oracle output
Evidence: Rust output
Evidence: C# output
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{"items":[{"name":"x"}]}. 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'slength, 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 ("0", not"01"). 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 rendersx. (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 ownlookup/resolve/property/is_truthy(lines 96-150). The new engine'smustache::lookup(mustache.rs,pub(crate)) has no caller outside mustache.rs. The two lookups disagree, so the publicrendergives wrong results. (1){{ys.01}}withys:["a","b"]: presence.rs:128 accepts"01"throughparse::<usize>. The engine's canonicalarray_indexmisses, 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 renders5/hand the engine supports it. (3){{#s.length}}{{missing}}{{/s.length}}: presence skips the body, and the engine rendersmissingas empty where TS throws. The unit testlength_and_index_read_as_javascript_propertiescallsmustache::renderdirectly, which hides the split. Remedy: make presence resolve throughmustache::lookupand the engine'sis_truthyon one Cow stack. Then drop presence'sproperty,LENGTH_ZERO/LENGTH_NONZEROand its ownis_truthy.server/rust/metaobjects-render/src/mustache.rs:138- Recorded round-1 decision (fix), still unfixed.is_js_whitespacesays it is JavaScript's\s, butchar::is_whitespacealso matches U+0085 (NEL), and JS\sdoes 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() && c != '\u{0085}') || c == '\u{FEFF}'.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{{=<% %>=}}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{"items":[{"name":"x"}]}. 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'slength, 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 ("0", not"01"). 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 rendersx. (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{{=<% %>=}}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 thetypeof(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 toPayloadAccessors.ViewLookup, which now receives the joined keyownernick. ViewLookup reads that as a member literally named that, returns null, and Stubble moves outward and finds nothing. Concrete case: payloadPlainPayload(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 walkedownerthennickthrough 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 inRenderer.csby 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.
cargo test -p metaobjects-renderrender_conformance ok;dotnet test MetaObjects.Render.Tests376 passed; KNOWN_DRIFT is empty in both runners{{#items.0}},{{items.0.name}}, non-canonical{{ys.01}}throws ERR_VAR_NOT_ON_PAYLOAD, and a NEL-only standalone line is keptscripts/ci-local.sh --affected --strict-toolchainsBaseline: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) - greendotnet test MetaObjects.Render.Tests(376 tests including render-conformance with KnownDrift empty, plus new list-index, dynamic-object, present-null and delimiter tests) - greenCross-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.spec/decisions/ADR-0065-rust-is-the-sixth-port.md:39- Layout decision still says metaobjects-render is built 'over themustache-ngcrate'. 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.