Public: anyone can read this; the crew can change it.
A test pins that a fleet operation is undone at most once: `claimUndo` and `releaseUndo` #6765
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6762-a-test-pins-that-a-fleet-operation-is-un → main 1 commit fork
1 file
changed +69
−0
test/fleet-undo-claim.test.ts added +69
| @@ -0,0 +1,69 @@ | ||
| 1 | /** | |
| 2 | * An undo is claimed once (#6762): `claimUndo` takes a recorded operation, | |
| 3 | * `releaseUndo` gives it back when the undo came to nothing, and a finished | |
| 4 | * undo stays finished. | |
| 5 | */ | |
| 6 | import { expect, test } from "bun:test"; | |
| 7 | import { | |
| 8 | claimUndo, | |
| 9 | getOperation, | |
| 10 | recordOperation, | |
| 11 | releaseUndo, | |
| 12 | settleUndo, | |
| 13 | } from "../src/core/fleet_ops.ts"; | |
| 14 | import { migrations } from "../src/core/schema.ts"; | |
| 15 | import { openDb } from "../src/kernel/db.ts"; | |
| 16 | ||
| 17 | function recorded() { | |
| 18 | const db = openDb(":memory:", migrations); | |
| 19 | db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u1','u','u@x','x')"); | |
| 20 | const op = recordOperation(db, { | |
| 21 | actorId: "u1", | |
| 22 | query: "is:repo", | |
| 23 | kind: "repo", | |
| 24 | verb: "set", | |
| 25 | value: "x", | |
| 26 | reversible: true, | |
| 27 | undoOf: null, | |
| 28 | rows: [], | |
| 29 | }); | |
| 30 | return { db, op }; | |
| 31 | } | |
| 32 | ||
| 33 | test("the first claim wins and a second is refused", () => { | |
| 34 | const { db, op } = recorded(); | |
| 35 | expect(claimUndo(db, op.id)).toBe(true); | |
| 36 | expect(claimUndo(db, op.id)).toBe(false); | |
| 37 | }); | |
| 38 | ||
| 39 | test("a released claim can be taken again", () => { | |
| 40 | const { db, op } = recorded(); | |
| 41 | expect(claimUndo(db, op.id)).toBe(true); | |
| 42 | releaseUndo(db, op.id); | |
| 43 | expect(getOperation(db, op.id)!.undoneBy).toBeNull(); | |
| 44 | expect(claimUndo(db, op.id)).toBe(true); | |
| 45 | }); | |
| 46 | ||
| 47 | test("a finished undo is not released or claimed again", () => { | |
| 48 | const { db, op } = recorded(); | |
| 49 | const undo = recordOperation(db, { | |
| 50 | actorId: "u1", | |
| 51 | query: "is:repo", | |
| 52 | kind: "repo", | |
| 53 | verb: "set", | |
| 54 | value: "y", | |
| 55 | reversible: false, | |
| 56 | undoOf: op.id, | |
| 57 | rows: [], | |
| 58 | }); | |
| 59 | expect(claimUndo(db, op.id)).toBe(true); | |
| 60 | settleUndo(db, op.id, undo.id); | |
| 61 | releaseUndo(db, op.id); | |
| 62 | expect(getOperation(db, op.id)!.undoneBy).toBe(undo.id); | |
| 63 | expect(claimUndo(db, op.id)).toBe(false); | |
| 64 | }); | |
| 65 | ||
| 66 | test("an unknown operation cannot be claimed", () => { | |
| 67 | const { db } = recorded(); | |
| 68 | expect(claimUndo(db, "nope")).toBe(false); | |
| 69 | }); |
new above
offline