Skip to content

fix(bindx): echo nested create IDs from MockAdapter - #87

Merged
matej21 merged 1 commit into
mainfrom
fix/mock-adapter-nested-create-ids
Aug 25, 2026
Merged

fix(bindx): echo nested create IDs from MockAdapter#87
matej21 merged 1 commit into
mainfrom
fix/mock-adapter-nested-create-ids

Conversation

@matej21

@matej21 matej21 commented Aug 25, 2026

Copy link
Copy Markdown
Member

Problem

PersistResult.data is documented as "the entity node data after mutation (when ok is true). Contains nested entity IDs for inline creates", and since #85's 73ce285 fix(bindx): 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 Variant:__temp_…, Asset:__temp_…

instead 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:

  • persist returned a bare { ok: true } with no node at all.
  • create echoed 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 MockAdapter started 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.46 and v0.1.47 landed on 73ce285.

Fix

  • createRelatedEntity materializes its own relation operations recursively instead of spreading the raw payload, so a nested create becomes a row with an ID.
  • create builds the stored/echoed node the same way.
  • persist echoes the mutated node.

Real adapters are unaffected — ContemberAdapter already returns the node, which is why the existing node-echo coverage in tests/unit/persistence/nestedCreateTempIdLeak.test.ts passes throughout.

Verification

  • New tests/unit/adapter/mockAdapterNestedCreates.test.ts — File → variants (hasMany) → asset (hasOne), scoped persist of the root. Fails 3/3 on main, passes here.
  • bun run test — 1,972 passed across 202 files
  • bun run typecheck clean, bun run lint 0 errors / 17 warnings
  • Re-ran the downstream app's failing test against this branch: green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EmqgPtZvAfpvWKymfFZCEX

`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
@matej21
matej21 merged commit 6d6ea5c into main Aug 25, 2026
4 checks passed
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