fix(bindx): echo nested create IDs from MockAdapter - #87
Merged
Conversation
`PersistResult.data` is documented as "the entity node data after mutation ... contains nested entity IDs for inline creates", and since "reconcile immutable persistence executions" the persister enforces it: a create whose response does not carry the server IDs of its nested creates now fails with "Missing or ambiguous server ID for nested create ..." instead of quietly succeeding with leaked temp IDs (#70). MockAdapter never honoured that contract. `persist` returned a bare `{ ok: true }` with no node at all, and `create` echoed the raw payload back with relation operations left unmaterialised, so a nested `{ create: ... }` reached the persister as an operation object rather than a row with an ID. Any consumer testing a nested create against the shipped test double therefore started failing. Materialize relation operations recursively when creating a related entity, build the created node the same way, and echo the mutated node from `persist`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EmqgPtZvAfpvWKymfFZCEX
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
PersistResult.datais documented as "the entity node data after mutation (when ok is true). Contains nested entity IDs for inline creates", and since #85's73ce285 fix(bindx): reconcile immutable persistence executionsthe persister enforces it. A create whose response does not carry the server IDs of its nested creates now fails withinstead of quietly succeeding and leaving the temp IDs in the store (#70). That fail-safe is the right call — but
MockAdapter, the test double this repo ships, never honoured the contract it now has to satisfy:persistreturned a bare{ ok: true }with no node at all.createechoed the raw create payload back as the node, with relation operations left unmaterialised — a nested{ create: … }reached the persister as an operation object rather than a row with an ID.So every consumer whose test creates an entity with nested creates against
MockAdapterstarted failing on 0.1.47, with no way to tell it apart from a real persistence bug.Found while upgrading a production admin app: one of its component tests (an upload dialog that creates a file, its format rows, and the stored asset behind each of them in one scoped persist) went red on the version bump. Bisecting the 101 commits between
v0.1.46andv0.1.47landed on73ce285.Fix
createRelatedEntitymaterializes its own relation operations recursively instead of spreading the raw payload, so a nested create becomes a row with an ID.createbuilds the stored/echoed node the same way.persistechoes the mutated node.Real adapters are unaffected —
ContemberAdapteralready returns the node, which is why the existing node-echo coverage intests/unit/persistence/nestedCreateTempIdLeak.test.tspasses throughout.Verification
tests/unit/adapter/mockAdapterNestedCreates.test.ts— File → variants (hasMany) → asset (hasOne), scoped persist of the root. Fails 3/3 onmain, passes here.bun run test— 1,972 passed across 202 filesbun run typecheckclean,bun run lint0 errors / 17 warnings🤖 Generated with Claude Code
https://claude.ai/code/session_01EmqgPtZvAfpvWKymfFZCEX