fix: encode dal.Key parent chain into record path (per-parent scoping)#2
Merged
Conversation
The adapter mapped a dal.Key to an in-repo record path using only the leaf collection + record id, dropping the key's parent chain. Two keys sharing a leaf but living under different parents — e.g. spaces/family/contacts/c1 and spaces/work/contacts/c1 — resolved to the same path and clobbered each other (no per-space scoping). Add resolveScopedCollection, which walks key.Parent() and interleaves each ancestor record id with its subcollection name into the DirPath, mirroring Firestore-style nesting (spaces/<spaceID>/contacts/...). This matches the Option A layout already shipped in github.com/ingitdb/dalgo2ingitdb v0.1.0, so the write and read paths agree with the sibling adapters. Top-level (non-nested) keys are unchanged: a plain flat def.Collections lookup. Route both resolveCollection (Set/Insert/Delete, incl. the batching tx) and the previously-inlined Get through the scoped resolver so reads and writes agree. Regression tests: two keys with the same leaf id under different parents map to DISTINCT paths, plus an end-to-end round-trip proving a record written under one parent is not visible/overwritten under another. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FV3pbooAc9UPpNdiaJuKve
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
dalgo2ingitdb4github(used by sneat-co/sneat-go PR #712) mapped a dalgodal.Keyto an in-repo record path using only the leafcollection/{id},dropping the key's parent chain. Two records under different parents that share
a leaf id collided:
spaces/family/contacts/c1→spaces/contacts/$records/c1.yamlspaces/work/contacts/c1→spaces/contacts/$records/c1.yaml← same file!The second write clobbered the first — no per-space scoping.
Fix
Add
resolveScopedCollection, which walkskey.Parent()and interleaves eachancestor record id with its subcollection name into the collection
DirPath,mirroring Firestore-style nesting:
spaces/family/contacts/c1→spaces/family/contacts/$records/c1.yamlspaces/work/contacts/c1→spaces/work/contacts/$records/c1.yamlThis is the same Option A layout already shipped in
github.com/ingitdb/dalgo2ingitdb v0.1.0, so all three adapters agree on theon-repo layout (write path == read path). Top-level keys are unchanged (flat
def.Collectionslookup).Get(previously inlined) andresolveCollection(Set/Insert/Delete + thebatching tx) now both route through the scoped resolver.
Tests
TestResolveScopedCollection_DistinctPathsForSameLeaf— same leaf id underdifferent parents → distinct paths; top-level path unchanged.
TestResolveScopedCollection_DeepNesting/_Errors— grandchild path +error branches.
TestGitHubDB_NestedKeys_ScopedByParentRecord— end-to-end round-trip:write under two parents, read both back, no clobber.
go build ./...,go test ./...,go vet ./...all pass; coverage 99.5%.🤖 Generated with Claude Code