mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
test(home): pin the idempotency contract bd143e2's eager-apply relies on
bd143e2 closed a /api/dispatch race by eagerly applying the
freshly-appended event to state, then tailLog re-applies the same
event when fs.watch fires — so each event flows through
state.applyEvent twice in production. The fix's correctness depends
on those two applications producing the same state. No test asserted
that, so a future change to the bridge.dispatch or bridge.cancel
projection that accidentally broke idempotency would slip through.
Two new state.ts regression cases:
• bridge.dispatch applied twice → currentRun unchanged (runId,
intent, adapter, reason, confidence all match the single-apply
snapshot).
• bridge.cancel applied twice → cancelledRunIds contains exactly
one copy of the runId (the existing filter() in the projection
dedupes — verify it stays that way).
home/state 17/17 (was 15/15). Total: 78/78 across the eight home/
suites. tsc clean.
This commit is contained in:
1 file changed
+29
@@ -221,6 +221,35 @@ function selfTest() {
|
||||
return ps.currentRun?.runId === "a" && ps.currentRun.adapter === "codex";
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "applying the SAME bridge.dispatch twice is idempotent (server.ts eager-apply contract)",
|
||||
check: () => {
|
||||
// /api/dispatch eagerly applies the freshly-appended event to close
|
||||
// a race with fs.watch (bd143e2). tailLog then re-applies the same
|
||||
// event when the watcher catches up. Both states must be identical.
|
||||
const evt = dispatch("a");
|
||||
const s1 = applyAll([evt]);
|
||||
const s2 = applyAll([evt, evt]);
|
||||
const a = s1.get("T")!.currentRun;
|
||||
const b = s2.get("T")!.currentRun;
|
||||
return a?.runId === b?.runId
|
||||
&& a?.intent === b?.intent
|
||||
&& a?.adapter === b?.adapter
|
||||
&& a?.reason === b?.reason
|
||||
&& a?.confidence === b?.confidence;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "applying the SAME bridge.cancel twice doesn't duplicate the runId in cancelledRunIds",
|
||||
check: () => {
|
||||
// Same eager-apply path for /api/cancel. cancelledRunIds.filter()
|
||||
// in the projection dedupes — verify with an explicit twice-apply.
|
||||
const c = cancel("a");
|
||||
const s = applyAll([dispatch("a"), c, c]);
|
||||
const ids = s.get("T")?.cancelledRunIds ?? [];
|
||||
return ids.length === 1 && ids[0] === "a";
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "worker.started overwrites currentRun (idempotent same-shape)",
|
||||
check: () => {
|
||||
|
||||
Reference in new issue
Block a user