fix(caps): créer un document en donne le cap, + corriger 9 faits NextGraph
Le trou trouvé par l'e2e contre le broker en ligne : `docs.docCreate` ne
déposait aucun cap pour le créateur, donc un consommateur pouvait créer un
document par la primitive publique puis se voir refuser sa lecture et son
écriture. En amont c'est impossible — `doc_create` commite
`AddRepo { read_cap }` sur la branche Store du store, et le créateur le détient
dès le premier instant. Délibérément non répliqué dans `physical.ts` : les
documents du shim n'appartiennent à aucun utilisateur virtuel, et
`store-registry` classe leurs caps là où il sait à qui ils sont.
e2e : 22 passés / 8 échoués → 39 / 0. Les autres échecs venaient du harnais,
qui agissait comme une seconde identité sans l'établir, ou lisait un document
quelconque comme une inbox. Un run e2e contre un wallet persistant exige une
identité FRAÎCHE par run : `walletInbox(id)` rend l'inbox stable pour son
propriétaire — c'est son intérêt — donc un id fixe accumule les dépôts des runs
précédents (vert au 2e run, rouge au 3e, à code inchangé).
Revue adverse de la documentation, 9 défauts, tous vérifiés à la source avant
correction :
- « chaque document a une inbox native » est FAUX. Seuls les repos de store
public et protected en ont une (`site.rs:128,149`) ; `new_store_default` n'en
pose que `if !private` et `doc_create` laisse `inbox: None`. Le store privé
n'en a pas non plus. Ce que le code fait est donc une ANTICIPATION — assumée
et notée comme telle dans `documentInbox`, le brief et l'ADR discovery. Ce qui
est vérifié, c'est la FORME : `AddInboxCapV0` est clé par `repo_id`.
- `InboxMsgContent::Link` est une variante unit sans charge utile : l'inbox ne
transporte aucun ReadCap. `shareCap` était juste et le reste ; ses citations
sont complétées aux deux bouts (émetteur `unimplemented!()`, récepteur qui
ignore `details.read_cap`).
- les 3 stores appartiennent au user (`SiteV0`), pas au wallet ;
- le TODO `OpenRepo` ne concerne pas la lecture cross-wallet — il est dans
`open_branch_`, après `RepoNotFound` ; charger par cap, c'est
`load_repo_from_read_cap` ;
- la liste des méthodes JS était un sous-ensemble présenté comme la surface
(77 exportées) ;
- `outbox-log.ts` n'enregistre rien : il inspecte l'outbox du SDK ;
- l'ADR private-store-nuri-scope citait `orm_start_graph` au présent, remplacé
par `ensureRepoOpen` ;
- l'incident write-loss plaçait `disconnections_sender.send` dans `broker.rs` ;
- la section « Apps & services » n'a aucune citation et rien ne lui correspond
dans le moteur : marquée à re-confirmer, pas à citer comme vérifiée.
Aussi : `fileOwnCaps` n'existe plus (`holdOwnCap` / `readStoreCaps` /
`fileOwnStructure`) — pointeur mort corrigé dans `caps.ts`.
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
getCaps,
|
||||
resetCaps,
|
||||
shareCap,
|
||||
connectedUser,
|
||||
} from "@ng-eventually/client/polyfill";
|
||||
import {
|
||||
docs,
|
||||
@@ -368,10 +369,18 @@ const identity = new IdentityStore(
|
||||
},
|
||||
|
||||
// ── inbox ────────────────────────────────────────────────────────────────
|
||||
async inboxPostRead(payloadA: unknown, payloadB: unknown) {
|
||||
const s = await sessionReady;
|
||||
const target = await docs.docCreate(s.session_id, "Graph", "data:graph", "store", undefined);
|
||||
setCurrentUser("inbox-user");
|
||||
/**
|
||||
* `id` must be FRESH per run (run.ts stamps it). A user's inbox is stable over time —
|
||||
* that is the point of it — so re-running against a reused id accumulates the previous
|
||||
* runs' deposits on a persistent wallet, and the exact-count assertion drifts. The
|
||||
* thing to make disposable is the user, not the inbox.
|
||||
*/
|
||||
async inboxPostRead(id: string, payloadA: unknown, payloadB: unknown) {
|
||||
// The target must be that user's OWN inbox, not an arbitrary document: you may
|
||||
// deposit into anyone's, you may only read your own. Establishing the identity
|
||||
// FIRST is what makes `walletInbox` resolve (and file) that user's inbox.
|
||||
setCurrentUser(id);
|
||||
const target = await storeRegistry.walletInbox(id);
|
||||
await inbox.post(target, { payload: payloadA, from: null, ts: 1000 });
|
||||
await inbox.post(target, { payload: payloadB, from: null, ts: 2000 });
|
||||
const deposits = await inbox.read(target);
|
||||
@@ -380,9 +389,12 @@ const identity = new IdentityStore(
|
||||
},
|
||||
// watch (doc_subscribe-based) fires when a deposit lands.
|
||||
_inboxWatch: { fires: 0, lastLen: -1, unsub: () => {}, target: "" },
|
||||
async inboxWatchStart() {
|
||||
const s = await sessionReady;
|
||||
const target = await docs.docCreate(s.session_id, "Graph", "data:graph", "store", undefined);
|
||||
/** `id` fresh per run, for the same reason as {@link inboxPostRead}. */
|
||||
async inboxWatchStart(id: string) {
|
||||
// Watching an inbox is READING it continuously, so the watcher stays connected
|
||||
// for the whole probe — including across `inboxWatchDeposit`.
|
||||
setCurrentUser(id);
|
||||
const target = await storeRegistry.walletInbox(id);
|
||||
const rec = { fires: 0, lastLen: -1, unsub: () => {}, target };
|
||||
(window as any).__sdk._inboxWatch = rec;
|
||||
rec.unsub = inbox.watch(target, (deposits) => {
|
||||
@@ -393,9 +405,7 @@ const identity = new IdentityStore(
|
||||
},
|
||||
async inboxWatchDeposit(payload: unknown) {
|
||||
const rec = (window as any).__sdk._inboxWatch;
|
||||
setCurrentUser("watcher");
|
||||
await inbox.post(rec.target, { payload, from: null });
|
||||
setCurrentUser(null);
|
||||
},
|
||||
inboxWatchState() {
|
||||
const r = (window as any).__sdk._inboxWatch;
|
||||
@@ -403,6 +413,7 @@ const identity = new IdentityStore(
|
||||
},
|
||||
inboxWatchStop() {
|
||||
(window as any).__sdk._inboxWatch.unsub();
|
||||
setCurrentUser(null);
|
||||
},
|
||||
// spoof guard: depositing as another principal throws.
|
||||
async inboxSpoofGuard() {
|
||||
@@ -440,10 +451,16 @@ const identity = new IdentityStore(
|
||||
},
|
||||
async entityDocsBounded(idA: string, idB: string) {
|
||||
storeRegistry.resetRegistryCache();
|
||||
// Each user creates its OWN documents: you act as one virtual user at a time,
|
||||
// and the caps of what you create are filed under the identity you were acting
|
||||
// as. Creating B's document while connected as A is not a thing the model has.
|
||||
setCurrentUser(idA);
|
||||
const dA1 = await storeRegistry.createEntityDoc(idA, "public");
|
||||
const dA2 = await storeRegistry.createEntityDoc(idA, "public");
|
||||
setCurrentUser(idB);
|
||||
const dB1 = await storeRegistry.createEntityDoc(idB, "public");
|
||||
// listMyEntityDocs(A) → only A's docs (poll: the index append can lag).
|
||||
setCurrentUser(idA);
|
||||
let listA: string[] = [];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
storeRegistry.resetRegistryCache();
|
||||
@@ -451,6 +468,7 @@ const identity = new IdentityStore(
|
||||
if (listA.includes(dA1) && listA.includes(dA2)) break;
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
}
|
||||
setCurrentUser(null);
|
||||
return {
|
||||
dA1, dA2, dB1,
|
||||
listA,
|
||||
@@ -474,6 +492,10 @@ const identity = new IdentityStore(
|
||||
async reconnectSeed(id: string, scope: "public" | "protected" | "private") {
|
||||
storeRegistry.resetRegistryCache();
|
||||
const s = await sessionReady;
|
||||
// Seed AS the user whose document this is — otherwise the cap of the created
|
||||
// document is filed under nobody and the very session that created it is
|
||||
// refused the write below.
|
||||
setCurrentUser(id);
|
||||
const entityNuri = await storeRegistry.createEntityDoc(id, scope);
|
||||
const marker = "recon-" + Date.now();
|
||||
await docs.sparqlUpdate(
|
||||
@@ -505,11 +527,24 @@ const identity = new IdentityStore(
|
||||
* fail-without-the-fix proof (see run.ts's reconnection step comment).
|
||||
*/
|
||||
async reconnectRead(id: string, scope: "public" | "protected" | "private", entityNuri: string, marker: string) {
|
||||
// DIAGNOSTIC: a RAW anchored read of the entity doc with NO open at all, first
|
||||
// thing in the fresh session — reports how many rows the bare anchored query
|
||||
// resolves for a not-yet-opened repo (the premise: 0 until opened). Uses the
|
||||
// low-level docs primitive directly, bypassing readUnion's open step.
|
||||
const s = session ?? (await sessionReady);
|
||||
// A fresh session holds nothing in memory: connect AS the user so the caps are
|
||||
// restored from the durable registers (own documents from the Store branches,
|
||||
// received ones from the Links) before anything is read back.
|
||||
setCurrentUser(id);
|
||||
await connectedUser();
|
||||
|
||||
storeRegistry.resetRegistryCache();
|
||||
const listed = await storeRegistry.listMyEntityDocs(id, scope);
|
||||
// DIAGNOSTIC: a RAW anchored read of the entity doc with NO open — reports how
|
||||
// many rows the bare anchored query resolves for a not-yet-opened repo (the
|
||||
// premise: 0 until opened). Uses the low-level docs primitive directly, bypassing
|
||||
// readUnion's open step.
|
||||
//
|
||||
// Placed AFTER `listMyEntityDocs`, which is what restores the caps of the user's
|
||||
// own documents from the Store branch. Before it, the boundary refuses the read
|
||||
// and the probe would measure the guard rather than the open — a number that
|
||||
// looks like the premise holding while proving nothing about it.
|
||||
let rawRowCount = -1;
|
||||
try {
|
||||
const raw: any = await docs.sparqlQuery(s.session_id, "SELECT ?s ?p ?o WHERE { ?s ?p ?o }", undefined, asNuri(entityNuri));
|
||||
@@ -517,9 +552,6 @@ const identity = new IdentityStore(
|
||||
} catch (e: any) {
|
||||
rawRowCount = -2; // threw (e.g. RepoNotFound / InvalidNuri)
|
||||
}
|
||||
|
||||
storeRegistry.resetRegistryCache();
|
||||
const listed = await storeRegistry.listMyEntityDocs(id, scope);
|
||||
const subjects = await readModel.readUnion(listed.length ? listed : [asNuri(entityNuri)]);
|
||||
const markers: string[] = [];
|
||||
for (const subj of subjects) {
|
||||
@@ -770,24 +802,30 @@ const identity = new IdentityStore(
|
||||
* "receive" operation exists, and no principal is ever named to the registry.
|
||||
* Runs against the REAL broker inbox document, so it exercises the whole path.
|
||||
*/
|
||||
async capsShareCap() {
|
||||
async capsShareCap(friendId: string) {
|
||||
const s = await sessionReady;
|
||||
resetCaps();
|
||||
const doc = await docs.docCreate(s.session_id, "Graph", "data:graph", "store", undefined);
|
||||
const friendInbox = await docs.docCreate(s.session_id, "Graph", "data:graph", "store", undefined);
|
||||
injectedSetItems = [{ "@graph": doc, "@id": "1", v: "shared-item" }];
|
||||
// The recipient's OWN inbox — the address a cap is delivered to. Resolved while
|
||||
// connected as them, since that is who owns it and who may later read it.
|
||||
// `friendId` is fresh per run: this test's assertions survive accumulated caps, but
|
||||
// the recipient's durable Links would grow run after run on a persistent wallet,
|
||||
// making every later `connectedUser()` re-apply a longer and longer history.
|
||||
setCurrentUser(friendId);
|
||||
const friendInbox = await storeRegistry.walletInbox(friendId);
|
||||
|
||||
setCurrentUser("owner-O");
|
||||
const doc = await docs.docCreate(s.session_id, "Graph", "data:graph", "store", undefined);
|
||||
injectedSetItems = [{ "@graph": doc, "@id": "1", v: "shared-item" }];
|
||||
getCaps().open(doc, "protected");
|
||||
const cap = capFor(doc)!;
|
||||
|
||||
setCurrentUser("friend");
|
||||
setCurrentUser(friendId);
|
||||
const before = [...(libUseShape(null, null) as Iterable<any>)].length;
|
||||
|
||||
setCurrentUser("owner-O");
|
||||
await shareCap(cap, friendInbox);
|
||||
|
||||
setCurrentUser("friend");
|
||||
setCurrentUser(friendId);
|
||||
const absorbed = await inbox.read(friendInbox); // processing it applies the cap
|
||||
const after = [...(libUseShape(null, null) as Iterable<any>)].length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user