Skip to content

Commit ddf3c4f

Browse files
ryansolidclaude
andauthored
test(signals): pin #4402 and #4398 as fixed by #4393; #4399 as a carve row (#4411)
* test(signals): pin #4402 and #4398 as fixed by #4393; #4399 as a carve row Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * test(signals): drive the hold pins on fake timers The change-during-hold pin raced the flights under coverage on CI ([7, 10] for [5, 8, 10]); the script's order now decides it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent 822fa01 commit ddf3c4f

2 files changed

Lines changed: 143 additions & 1 deletion

File tree

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
146146
| CS-R2a | live | `docs/INTERNALS-STORE-STATE.md:107` | — | — | Corollary R2a (Ryan, 2026-08-17): **take no responsibility for mutation |
147147
| CS-R3 | live | `docs/rules-mining/core-store.md:18` | — | — | A store proxy ingested into another store (deep or shallow) is re-wrapped in the ingesting store's own proxy family — never identity-passed, never raw-marked.** |
148148
| CS-R4 | live | `docs/rules-mining/core-store.md:22` | — | — | Write isolation across a store chain: writing through the last store in a derived chain is visible only there; upstream stores and base objects untouched (shallow or deep middle).** |
149-
| CS-R5 | live | `docs/rules-mining/core-store.md:26` | — | latest-two-readers-one-ask-4393.test.ts×2 verdict-memo-flight-no-reask.test.ts×9 visibility-oracle-store.states.ts×4 visibility-oracle.states.ts×4 | Upstream writes propagate downstream through the chain without re-running structural machinery.** |
149+
| CS-R5 | live | `docs/rules-mining/core-store.md:26` | — | latest-first-one-pass-4402.test.ts×1 latest-two-readers-one-ask-4393.test.ts×2 verdict-memo-flight-no-reask.test.ts×9 visibility-oracle-store.states.ts×4 visibility-oracle.states.ts×4 | Upstream writes propagate downstream through the chain without re-running structural machinery.** |
150150
| CS-R6 | live | `docs/rules-mining/core-store.md:30` | — | — | No store write path ever mutates a user-provided source object.** Aligned with 2026-08-16b. |
151151
| CS-R7 | live | `docs/rules-mining/core-store.md:34` | — | — | Circular references wrap without infinite recursion; cycle consistent through proxy (`state.b.a === state.a`).** |
152152
| CS-R8 | live | `docs/rules-mining/core-store.md:38` | — | — | `snapshot` returns fully unwrapped values (no proxy anywhere, `$TARGET` undefined), incl. frozen objects/arrays; reflects committed written values incl. writes over inherited prototype props.** |
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Pins for what #4393 (R5, D-22) fixed beyond #4365, and one row it leaves
2+
// for the reader-seat carve.
3+
//
4+
// - #4402: a pass that reads `latest(s)` before `s()` computes once per
5+
// plain write, as `[s(), latest(s)]` does (D-22: one pass; it re-derives
6+
// only if the flush parks).
7+
// - #4398: `[isPending(m1), m1()]` in one effect, split across two, or
8+
// `m1()` alone show the same values when the write changes during the hold
9+
// (D-26, F-6: a grouped read holds as a lone read; #4284).
10+
// - #4399 (it.fails, carve row): two actions, each holding a verdict
11+
// memo's write, ask `m1:15` twice: once in A's verdict lane, once in B's
12+
// transaction over the same inputs (F-9).
13+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14+
import {
15+
action,
16+
createEffect,
17+
createLoadingBoundary,
18+
createMemo,
19+
createRenderEffect,
20+
createRoot,
21+
createSignal,
22+
flush,
23+
isPending,
24+
latest
25+
} from "../src/index.js";
26+
27+
// Fake timers: the flights' order is the script's, not the runner's speed.
28+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
29+
const wait = (ms: number) => vi.advanceTimersByTimeAsync(ms);
30+
async function settle(n = 4) {
31+
for (let i = 0; i < n; i++) {
32+
await wait(15);
33+
flush();
34+
}
35+
}
36+
37+
describe("#4402: latest(s) before s() computes once on a plain write", () => {
38+
for (const order of ["latest first", "plain first"] as const)
39+
for (const reader of ["render effect", "memo", "user effect"] as const)
40+
it(`${order}, ${reader}`, () => {
41+
const [s, set] = createSignal(0);
42+
let runs = 0;
43+
const f = () => (runs++, order === "latest first" ? [latest(s), s()] : [s(), latest(s)]);
44+
const dispose = createRoot(dispose => {
45+
if (reader === "render effect") createRenderEffect(f, () => {});
46+
else if (reader === "user effect") createEffect(f, () => {});
47+
else createRenderEffect(createMemo(f), () => {});
48+
return dispose;
49+
});
50+
flush();
51+
runs = 0;
52+
set(1);
53+
flush();
54+
expect(runs).toBe(1);
55+
dispose();
56+
});
57+
});
58+
59+
type Reader = "pair" | "split" | "value";
60+
61+
beforeEach(() => void vi.useFakeTimers());
62+
afterEach(() => void vi.useRealTimers());
63+
64+
async function run(reader: Reader, script: "change" | "two-actions") {
65+
const [s, setS] = createSignal(1);
66+
const [t, setT] = createSignal(0);
67+
const asks: string[] = [];
68+
const out: string[] = [];
69+
const ask = (n: string, v: number) => {
70+
asks.push(`${n}:${v}`);
71+
return sleep(10).then(() => v);
72+
};
73+
const show = (v: string) => void out.push(v);
74+
const dispose = createRoot(dispose => {
75+
const m0 = createMemo(() => ask("m0", 1 + latest(s) + s()));
76+
const m0b = createMemo(() => ask("m0b", 10 * (latest(t) + t())));
77+
const m1 = createMemo(() => ask("m1", 1 + m0() + (script === "two-actions" ? m0b() : 0)));
78+
const h = createMemo(() => (s() === 1 ? 1 : sleep(80).then(() => 1)));
79+
createLoadingBoundary(
80+
() => {
81+
const pre = () => (script === "two-actions" ? h() : 0);
82+
if (reader === "pair") createRenderEffect(() => (pre(), `${isPending(m1)},v${m1()}`), show);
83+
else if (reader === "split") {
84+
createRenderEffect(() => (pre(), `p${isPending(m1)}`), show);
85+
createRenderEffect(() => (pre(), `v${m1()}`), show);
86+
} else createRenderEffect(() => (pre(), `v${m1()}`), show);
87+
return null;
88+
},
89+
() => "L"
90+
);
91+
return dispose;
92+
});
93+
flush();
94+
await settle();
95+
asks.length = 0;
96+
out.length = 0;
97+
if (script === "change") {
98+
setS(2);
99+
await wait(25);
100+
flush();
101+
setS(4);
102+
} else {
103+
action(function* () {
104+
setS(2);
105+
yield sleep(30);
106+
})();
107+
await wait(5);
108+
action(function* () {
109+
setT(1);
110+
yield sleep(50);
111+
})();
112+
flush();
113+
}
114+
await settle();
115+
await settle();
116+
await settle();
117+
dispose();
118+
const values = out.map(v => v.match(/v(\d+)/)?.[1]).filter(v => v !== undefined);
119+
return { asks, values: values.filter((v, i) => v !== values[i - 1]) };
120+
}
121+
122+
describe("#4398: grouping isPending(m1) with m1() shows the same values", () => {
123+
it.each(["pair", "split", "value"] as const)("a change during the hold (%s)", async reader => {
124+
// The screen before the write (`4`) shows again only in the pair, where
125+
// `isPending` turns true beside it.
126+
const { values } = await run(reader, "change");
127+
expect(values.filter(v => v !== "4")).toEqual(["5", "8", "10"]);
128+
});
129+
});
130+
131+
describe("#4399: two actions, each holding a verdict memo's write", () => {
132+
// F-9: a re-ask of the same question is no new question. A row for the
133+
// reader-seat carve: telling B's pass apart from A's lane pass over the
134+
// same inputs needs a per-pass check.
135+
const once = async (reader: Reader) => {
136+
const { asks, values } = await run(reader, "two-actions");
137+
expect(new Set(asks).size, asks.join(" ")).toBe(asks.length);
138+
expect(values.at(-1)).toBe("26");
139+
};
140+
it("each question asked once (pair)", () => once("pair"));
141+
it.fails.each(["split", "value"] as const)("each question asked once (%s)", once);
142+
});

0 commit comments

Comments
 (0)