fix: une mutation ne rend ni n-atteint ce que la vue cache

`Set.prototype.add` rend THIS pour permettre le chainage - EXECUTE, pas deduit,
sur le `Set` nu et sur le vrai `DeepSignalSet`, qui rendent tous deux la
collection. Les trois mutations etaient transmises liees a la cible sur le motif
ecrit juste au-dessus : "elles prennent un objet et rendent void ou un booleen,
donc elles ne laissent rien fuir". Faux pour `add`, et `add` est le PREMIER
membre que l-exemple de documentation du SDK emploie. Toutes les entrees etaient
filtrees et la sortie rendait la collection entiere.

Les deux autres rendaient bien ce que le motif disait, et AGISSAIENT au-dela de
la vue : `delete` retirait un objet dont `has` refuse meme de confirmer
l-existence - les deux se contredisaient - et `clear` vidait la collection que
toutes les identites partagent.

Une seule regle : une mutation atteint la collection dessous, mais ne rend ni
n-atteint ce que la vue cache. `add` rend la VUE, `delete` n-agit que sur ce que
la vue montre, `clear` vide la vue. L-ecriture atteint toujours le document.

Le motif commun aux cinq fuites de cette famille est une JUSTIFICATION ECRITE
SUR UNE VALEUR DE RETOUR JAMAIS EXECUTEE. Chacune etait raisonnable, aucune
n-avait ete jouee.

Aussi : la forme ordonnee rend des index la ou un Set rend des objets
(`keys`/`entries`/`forEach`), et le faux partage reproduit desormais le
`isLoading` LIVRE - inverse de sa propre declaration. L-inversion est amont ;
un faux plus correct que la cible recree l-aveuglement que cette tache enleve.
This commit is contained in:
Sylvain Duchesne
2026-09-24 19:00:19 +02:00
parent 0e2b8ba394
commit c5de1cea35
6 changed files with 221 additions and 24 deletions
+61 -2
View File
@@ -159,8 +159,12 @@ test("useShape: the holder reads their own items through every member the SDK of
expect([...(result.data as Iterable<BaseType>)].map((o) => o["@graph"])).toEqual([hers, hers]);
expect((result.data as { size: number }).size).toBe(2);
expect([...((await result.promise) as Iterable<BaseType>)]).toHaveLength(2);
// The load state is a boolean and passes on its own, with no entry naming it.
expect(result.isLoading).toBe(false);
// The load state is a boolean and passes on its own, with no entry naming it. It reads
// `true` on a payload that HAS arrived, because the shipped hook computes it as
// `ormSubscription.isReady` while the declaration beside it says the opposite. That
// inversion is upstream's; the fake reproduces it rather than correcting it, and this
// assertion is what stops anyone here quietly making the target nicer than it is.
expect(result.isLoading).toBe(true);
// The page commands forward: they return `void`, and what they load lands in a
// collection only ever read back through the filter.
result.nextPage?.();
@@ -198,6 +202,61 @@ test("useShape: an undefined config answers undefined rather than refusing", asy
expect(result.isLoading).toBe(false);
});
// -- A MUTATION MAY NOT REACH PAST WHAT THE VIEW SHOWS ---------------------
// THE RIGHTS CASE, second kind, and it is the member the SDK's own example reaches for
// first (`expenses.add({...})`). `Set.prototype.add` RETURNS THE COLLECTION so calls can
// be chained - measured, not assumed - so a mutation forwarded bound to the target handed
// the unfiltered collection back as its return value. The view filtered every way IN and
// gave the whole set away on the way OUT.
test("useShape: adding an item does not hand back the unfiltered collection", async () => {
const hook = makeUseShapeHook();
inject(hook);
const hers = await documentOf("alice");
const his = await documentOf("bob");
hook.items.push(noteIn(hers, "a1"), noteIn(his, "b1"));
setCurrentUser("bob");
const data = useShape(NoteShape, EVERYTHING).data as {
add(item: BaseType): unknown;
[Symbol.iterator](): Iterator<BaseType>;
};
expect([...data].map((o) => o["@graph"])).toEqual([his]); // the way in is filtered
const handedBack = data.add(noteIn(his, "b2"));
expect(handedBack).not.toBe(hook.raw());
// Chaining still works, and what it chains onto is the VIEW: still bob's documents only.
expect([...(handedBack as Iterable<BaseType>)].map((o) => o["@graph"])).toEqual([his, his]);
// and the write really did reach the collection underneath.
expect([...(hook.raw() as Iterable<BaseType>)]).toHaveLength(3);
});
// `has(item)` has always refused to answer about an item the holder may not read. Acting
// on one is the same question with a worse consequence, and the two disagreed: `has` said
// no while `delete` removed it.
test("useShape: deleting reaches only what the view shows", async () => {
const hook = makeUseShapeHook();
inject(hook);
const hers = await documentOf("alice");
const his = await documentOf("bob");
const hersItem = noteIn(hers, "a1");
hook.items.push(hersItem, noteIn(his, "b1"));
setCurrentUser("bob");
const data = useShape(NoteShape, EVERYTHING).data as {
delete(item: BaseType): boolean;
has(item: BaseType): boolean;
clear(): void;
};
expect(data.has(hersItem)).toBe(false);
expect(data.delete(hersItem)).toBe(false);
expect([...(hook.raw() as Iterable<BaseType>)]).toHaveLength(2); // hers survives
// and emptying the view empties the view, not the collection every identity shares.
data.clear();
expect([...(hook.raw() as Iterable<BaseType>)].map((o) => o["@graph"])).toEqual([hers]);
});
// -- SAFE FOR A SHAPE NOBODY HAS SEEN --------------------------------------
/** What a later `@ng-org/orm` might hand back: the six members of `alpha.21` plus two