|
| 1 | +/** |
| 2 | + * #4427: D-28's verdict-seat reset (#4275, #4284) — a leaf seated as a |
| 3 | + * hold's verdict reader leaves the seat for a lane that is not that hold's |
| 4 | + * — compared verdict lanes by object identity. A transaction merged into |
| 5 | + * the hold keeps its own verdict lane (`verdictLane(t)` is per transaction |
| 6 | + * object; a node stamped before the merge stays in it), and that lane is |
| 7 | + * the same hold's (D-4: holds that merge are one). Read as another hold's, |
| 8 | + * the leaf left the seat and was served the derivation's staging as the |
| 9 | + * hold's own work (L7'): its run waited for the hold's landing while the |
| 10 | + * derivation it read was already on screen — the same value shown two ways |
| 11 | + * on one screen (F-1). |
| 12 | + * |
| 13 | + * Shape: action A holds `x`, `m = memo(latest(x) * 10)` is its verdict |
| 14 | + * lane's; action B holds `y`, and a pass reading both (`k`) merges A into |
| 15 | + * B. A leaf `[latest(y), m()]` mounted under B (born held) is seated as B's |
| 16 | + * verdict reader by `latest(y)`; A's next write re-derives `m`. |
| 17 | + */ |
| 18 | +import { expect, it } from "vitest"; |
| 19 | +import { |
| 20 | + action, |
| 21 | + createMemo, |
| 22 | + createRenderEffect, |
| 23 | + createRoot, |
| 24 | + createSignal, |
| 25 | + flush, |
| 26 | + latest |
| 27 | +} from "../src/index.js"; |
| 28 | + |
| 29 | +const tick = async () => { |
| 30 | + for (let i = 0; i < 6; i++) await Promise.resolve(); |
| 31 | + flush(); |
| 32 | +}; |
| 33 | + |
| 34 | +it("a verdict reader seated in a hold reads a merged transaction's verdict lane as that hold's", async () => { |
| 35 | + const [x, setX] = createSignal(0); |
| 36 | + const [y, setY] = createSignal(0); |
| 37 | + let a1!: () => void, a2!: () => void, b1!: () => void, b2!: () => void; |
| 38 | + const actA = action(function* () { |
| 39 | + setX(1); |
| 40 | + yield new Promise<void>(r => (a1 = r)); |
| 41 | + setX(2); |
| 42 | + yield new Promise<void>(r => (a2 = r)); |
| 43 | + }); |
| 44 | + const actB = action(function* () { |
| 45 | + setY(1); |
| 46 | + yield new Promise<void>(r => (b1 = r)); |
| 47 | + setY(2); |
| 48 | + yield new Promise<void>(r => (b2 = r)); |
| 49 | + }); |
| 50 | + let shownM: unknown, leaf: unknown; |
| 51 | + createRoot(() => { |
| 52 | + const m = createMemo(() => latest(x) * 10); |
| 53 | + const k = createMemo(() => x() + y()); |
| 54 | + createRenderEffect(x, () => {}); |
| 55 | + createRenderEffect(y, () => {}); |
| 56 | + createRenderEffect(m, v => { |
| 57 | + shownM = v; |
| 58 | + }); |
| 59 | + createRenderEffect(k, () => {}); |
| 60 | + // <Show when={y() > 0}>{[latest(y), m()]}</Show> |
| 61 | + const when = createMemo(() => y() > 0); |
| 62 | + const content = createMemo(() => { |
| 63 | + if (!when()) return "off"; |
| 64 | + createRenderEffect( |
| 65 | + () => `${latest(y)}/${m()}`, |
| 66 | + v => { |
| 67 | + leaf = v; |
| 68 | + } |
| 69 | + ); |
| 70 | + return "on"; |
| 71 | + }); |
| 72 | + createRenderEffect(content, () => {}); |
| 73 | + }); |
| 74 | + flush(); |
| 75 | + actA(); |
| 76 | + await tick(); |
| 77 | + expect(shownM).toBe(10); |
| 78 | + actB(); |
| 79 | + await tick(); |
| 80 | + expect(leaf).toBe("1/10"); |
| 81 | + |
| 82 | + // A's next step re-derives `m` in its (merged) verdict lane: the leaf |
| 83 | + // shows it with `m`, not at B's landing. |
| 84 | + a1(); |
| 85 | + await tick(); |
| 86 | + await tick(); |
| 87 | + expect(shownM).toBe(20); |
| 88 | + expect(leaf).toBe("1/20"); |
| 89 | + |
| 90 | + b1(); |
| 91 | + await tick(); |
| 92 | + await tick(); |
| 93 | + expect(leaf).toBe("2/20"); |
| 94 | + b2(); |
| 95 | + a2(); |
| 96 | + await tick(); |
| 97 | + await tick(); |
| 98 | + expect([shownM, leaf]).toEqual([20, "2/20"]); |
| 99 | +}); |
0 commit comments