fix(client): anchored default-graph writes for inbox + scope index

Inbox deposits and the per-(account,scope) index append were written into an
explicit GRAPH <plainNuri> named graph, which the real broker stores separately
from the repo's default graph (repo_graph_name with overlay suffix) — so an
anchored default-graph read (read-model.readDoc) never saw them and deposits
did not round-trip. Drop the GRAPH wrapper: the anchor scopes the write to the
repo's default graph, matching the read. Mocks updated accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sylvain Duchesne
2026-07-06 12:45:11 +02:00
parent c85c635f63
commit d39b12885a
5 changed files with 73 additions and 24 deletions
+9 -4
View File
@@ -422,9 +422,12 @@ export async function createEntityDoc(username: string, scope: Scope): Promise<N
try {
await sparqlUpdate(
s.sessionId,
// indexDoc is a NURI in IRI position → assertNuri; entityNuri is a NURI
// stored as a literal → escapeLiteral.
`INSERT DATA { GRAPH <${assertNuri(indexDoc)}> { <${INDEX_SUBJECT}> <${P.contains}> "${escapeLiteral(entityNuri)}" } }`,
// NO explicit `GRAPH <…>` wrapper: the real broker stores each repo's
// triples under repo_graph_name(repo_id, overlay_id), not the plain NURI,
// so an INSERT into `GRAPH <plainNuri>` targets a phantom graph and does
// NOT round-trip. Write the anchored DEFAULT graph instead (the `indexDoc`
// anchor scopes it). entityNuri is a NURI stored as a literal → escapeLiteral.
`INSERT DATA { <${INDEX_SUBJECT}> <${P.contains}> "${escapeLiteral(entityNuri)}" }`,
indexDoc,
);
} catch (error) {
@@ -440,7 +443,9 @@ async function readScopeIndex(indexDoc: Nuri): Promise<Nuri[]> {
try {
const res = await sparqlQuery(
s.sessionId,
`SELECT ?e WHERE { GRAPH <${assertNuri(indexDoc)}> { <${INDEX_SUBJECT}> <${P.contains}> ?e } }`,
// NO explicit `GRAPH <…>` clause — read the anchored DEFAULT graph (see
// the note in createEntityDoc). The `indexDoc` anchor scopes the query.
`SELECT ?e WHERE { <${INDEX_SUBJECT}> <${P.contains}> ?e }`,
undefined,
indexDoc,
);