Skip to content

Commit c2a2118

Browse files
committed
test(web): async-gen pairs E8 (birth seat) and E9 (latest in a derive)
E8 re-creates the tree's readers in the flush that applies each write and compares screens where nothing is in flight; E9 reads each latest(x) the tree makes through a memo of it. Both from the carve audit's seat pairs. First run (1,000 cases): #4377, #4378. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWKJDzwaZPgaGWE181b
1 parent 1a1c6a0 commit c2a2118

2 files changed

Lines changed: 83 additions & 11 deletions

File tree

‎packages/web/test/async-gen/campaign.spec.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ const out = (s: string) => process.stdout.write(s + "\n");
3232

3333
/** The equivalence pairs: two runs of one scenario that must show the same
3434
* screen at every settle point (or, `finalOnly`, once everything settled). */
35-
const PAIR_DEFS: Record<string, { a: Variant; b: Variant; finalOnly?: boolean }> = {
35+
const PAIR_DEFS: Record<
36+
string,
37+
{ a: Variant; b: Variant; finalOnly?: boolean; quietOnly?: boolean }
38+
> = {
3639
E1: { a: { grouped: true }, b: { split: true } },
3740
E2: { a: {}, b: { identity: true } },
3841
E2e: { a: {}, b: { inertErrored: true } },
3942
E3: { a: {}, b: { store: true } },
4043
E6: { a: {}, b: { autoFlush: true }, finalOnly: true },
41-
E7: { a: { owned: false }, b: { owned: true } }
44+
E7: { a: { owned: false }, b: { owned: true } },
45+
// The reader seat (carve audit): a reader born before a write vs one born
46+
// in the flush that applies it, compared where nothing is in flight (a
47+
// fresh reader of a pending node may show a fallback the old one holds);
48+
// `latest(x)` read in a derivation vs at the leaf.
49+
E8: { a: {}, b: { remount: true }, quietOnly: true },
50+
E9: { a: {}, b: { latestDerive: true } }
4251
};
4352

4453
/** What a screen shows, coarsely: an error, a fallback, or content. */
@@ -77,7 +86,13 @@ async function runWithPairs(sc: Scenario): Promise<{ base: Result; findings: Fin
7786
? a.final !== b.final
7887
? a.screens.length - 1
7988
: -1
80-
: a.screens.findIndex((x, i) => a.settled[i] && b.settled[i] && x !== b.screens[i]);
89+
: a.screens.findIndex(
90+
(x, i) =>
91+
a.settled[i] &&
92+
b.settled[i] &&
93+
(!def.quietOnly || (a.quiet[i] && b.quiet[i])) &&
94+
x !== b.screens[i]
95+
);
8196
const at = diff >= 0 ? diff : a.final !== b.final ? a.screens.length : -1;
8297
if (at >= 0) {
8398
const x = at < a.screens.length ? a.screens[at] : a.final;

‎packages/web/test/async-gen/run.ts‎

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export type Finding = {
4242
* wraps the tree in an Errored that shows what the root one would (E2);
4343
* `store` reads every memo through a derived store `{ v }` (E3);
4444
* `autoFlush` flushes after every step (E6, final screen only);
45-
* `owned` overrides where the memos are created.
45+
* `owned` overrides where the memos are created;
46+
* `remount` re-creates the tree's readers in the flush that applies each
47+
* write (E8, compared where nothing is in flight);
48+
* `latestDerive` reads every `latest(x)` through a memo of it (E9).
4649
*/
4750
export type Variant = {
4851
split?: boolean;
@@ -52,13 +55,17 @@ export type Variant = {
5255
store?: boolean;
5356
autoFlush?: boolean;
5457
owned?: boolean;
58+
remount?: boolean;
59+
latestDerive?: boolean;
5560
};
5661
export interface Result {
5762
findings: Finding[];
5863
screens: string[];
5964
/** Whether each screen is a settle point (after the first render, a task
6065
* step, the end): where equivalence pairs are compared. */
6166
settled: boolean[];
67+
/** Whether nothing was in flight at each screen. */
68+
quiet: boolean[];
6269
final: string;
6370
expected: string;
6471
description: string;
@@ -153,12 +160,44 @@ function buildApp(
153160
views.push(() => store.v);
154161
} else views.push(x);
155162
});
163+
// E9: `latest(x)` read in a derivation instead of at the leaf.
164+
const latestViews = new Map<string, () => any>();
165+
const makeLatestViews = () => {
166+
if (!variant.latestDerive) return;
167+
// Only the sources the tree reads with latest(): an extra observer of
168+
// anything else would be a different app.
169+
const srcs: SrcRef[] = [];
170+
const walk = (n: Node) => {
171+
if (n.t === "leaf")
172+
[...n.text, ...n.attrs].forEach(r => r.how === "latest" && srcs.push(r.src));
173+
else if (n.t === "group") n.kids.forEach(walk);
174+
else {
175+
if (n.t === "show" && n.when.how === "latest") srcs.push(n.when.src);
176+
walk(n.child);
177+
}
178+
};
179+
walk(sc.tree);
180+
for (const r of srcs) {
181+
if (latestViews.has(`${r.k}${r.i}`)) continue;
182+
const x = view(r);
183+
latestViews.set(
184+
`${r.k}${r.i}`,
185+
createMemo(() => latest(x))
186+
);
187+
}
188+
};
156189
const owned = variant.owned ?? !!sc.owned;
157-
if (!owned) makeMemos();
190+
if (!owned) {
191+
makeMemos();
192+
makeLatestViews();
193+
}
158194
const read = (r: Read) => {
159195
const x = view(r.src);
196+
if (r.how === "latest" && variant.latestDerive)
197+
return latestViews.get(`${r.src.k}${r.src.i}`)!();
160198
return r.how === "plain" ? x() : r.how === "latest" ? latest(x) : isPending(x);
161199
};
200+
const [epoch, setEpoch] = createSignal(1);
162201
const prefix = { plain: "v", latest: "l", pending: "p" } as const;
163202
const text = (r: Read) => `${prefix[r.how]}${r.src.k}${r.src.i}:${String(read(r))} `;
164203

@@ -230,11 +269,23 @@ function buildApp(
230269
createComponent(Loading, {
231270
fallback: "[ROOT-L]",
232271
get children() {
233-
if (owned) makeMemos();
234-
return renderNode(sc.tree);
272+
if (owned) {
273+
makeMemos();
274+
makeLatestViews();
275+
}
276+
if (!variant.remount) return renderNode(sc.tree);
277+
return createComponent(Show, {
278+
get when() {
279+
return epoch();
280+
},
281+
keyed: true,
282+
get children() {
283+
return renderNode(sc.tree);
284+
}
285+
} as any);
235286
}
236287
});
237-
return { sigs, app };
288+
return { sigs, app, remount: () => setEpoch(e => e + 1) };
238289
}
239290

240291
// ── driving ─────────────────────────────────────────────────────────────────
@@ -260,6 +311,7 @@ export async function runScenario(sc: Scenario, variant: Variant = {}): Promise<
260311
const findings: Finding[] = [];
261312
const screens: string[] = [];
262313
const settled: boolean[] = [];
314+
const quiet: boolean[] = [];
263315
const flights: Flight[] = [];
264316
const values = [...sc.signals];
265317
const errors: string[] = [];
@@ -303,7 +355,7 @@ export async function runScenario(sc: Scenario, variant: Variant = {}): Promise<
303355
let final = "";
304356
let expected = "";
305357
try {
306-
const { sigs, app } = buildApp(sc, values, false, flights, variant, errors);
358+
const { sigs, app, remount } = buildApp(sc, values, false, flights, variant, errors);
307359
const act = action(function* (s: number, v: number) {
308360
sigs[s][1](v);
309361
yield new Promise<number>(resolve => {
@@ -322,13 +374,17 @@ export async function runScenario(sc: Scenario, variant: Variant = {}): Promise<
322374
});
323375
screens.push(serialize(el));
324376
settled.push(true);
377+
quiet.push(flights.length === 0);
325378

326379
for (step = 0; step < sc.steps.length; step++) {
327380
const st = sc.steps[step];
328381
switch (st.t) {
329382
case "write":
330383
values[st.s] = st.v;
331-
guard("throw", () => sigs[st.s][1](st.v));
384+
guard("throw", () => {
385+
sigs[st.s][1](st.v);
386+
if (variant.remount) remount();
387+
});
332388
break;
333389
case "settle":
334390
if (flights.length) settleAt(flights, st.pick % flights.length);
@@ -362,6 +418,7 @@ export async function runScenario(sc: Scenario, variant: Variant = {}): Promise<
362418
const screen = serialize(el);
363419
screens.push(screen);
364420
settled.push(st.t === "task");
421+
quiet.push(flights.length === 0);
365422
// A read of an async value is its value or a throw (NotReady, the
366423
// error) — never undefined. NaN is undefined + 1 in a memo.
367424
if (/NaN|undefined/.test(screen) && !findings.some(f => f.law === "undefined-value"))
@@ -414,5 +471,5 @@ export async function runScenario(sc: Scenario, variant: Variant = {}): Promise<
414471
console.error = origError;
415472
console.warn = origWarn;
416473
}
417-
return { findings, screens, settled, final, expected, description: describeScenario(sc) };
474+
return { findings, screens, settled, quiet, final, expected, description: describeScenario(sc) };
418475
}

0 commit comments

Comments
 (0)