Public: anyone can read this; the crew can change it.
A child forge cannot bring back an ask the owner put aside by flooding new ones #15058
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15042-a-child-forge-cannot-bring-back-an-ask-t → main 1 commit fork
2 files
changed +36
−3
src/core/child_reach.ts +10 −3
| @@ -123,7 +123,8 @@ export const RAISE_AGAIN_MS = 24 * 3_600_000; | ||
| 123 | 123 | /** |
| 124 | 124 | * Keep one ask per forge and name. A repeat refreshes the one row (its time, |
| 125 | 125 | * its reason, who asked) and never adds another; one an admin put aside |
| 126 | * stays aside for a day. Past `ASKS_PER_FORGE` waiting, the oldest gives way. | |
| 126 | * stays aside for a day. Past `ASKS_PER_FORGE` waiting, the oldest waiting | |
| 127 | * ask gives way; a put-aside inside its day never does. | |
| 127 | 128 | */ |
| 128 | 129 | export function keepAsk( |
| 129 | 130 | db: Database, |
| @@ -155,10 +156,16 @@ export function keepAsk( | ||
| 155 | 156 | at, |
| 156 | 157 | again, |
| 157 | 158 | ); |
| 159 | // Only waiting asks give way. A put-aside still inside its day is the | |
| 160 | // admin's answer: evicting it would let a flood of new names wipe it, | |
| 161 | // and the next repeat would come back as a fresh ask. Its number is | |
| 162 | // bounded by the admin's own clicks, one per name. | |
| 158 | 163 | db.query( |
| 159 | 164 | `DELETE FROM child_reach_ask WHERE body_id = ?1 AND rowid IN ( |
| 160 | SELECT rowid FROM child_reach_ask WHERE body_id = ?1 ORDER BY last_at DESC, rowid DESC LIMIT -1 OFFSET ?2)`, | |
| 161 | ).run(input.bodyId, ASKS_PER_FORGE); | |
| 165 | SELECT rowid FROM child_reach_ask | |
| 166 | WHERE body_id = ?1 AND NOT (state = 'later' AND answered_at > ?3) | |
| 167 | ORDER BY last_at DESC, rowid DESC LIMIT -1 OFFSET ?2)`, | |
| 168 | ).run(input.bodyId, ASKS_PER_FORGE, again); | |
| 162 | 169 | })(); |
| 163 | 170 | return askFor(db, input.bodyId, input.host)!; |
| 164 | 171 | } |
test/ask-to-reach.test.ts +26
| @@ -32,10 +32,13 @@ import { hostAllowed, startEgress, type Egress } from "../src/apps/egress.ts"; | ||
| 32 | 32 | import { |
| 33 | 33 | addGrant, |
| 34 | 34 | askableHost, |
| 35 | askFor, | |
| 35 | 36 | ASKS_PER_FORGE, |
| 36 | 37 | keepAsk, |
| 37 | 38 | listAsks, |
| 38 | 39 | listGrants, |
| 40 | putAsideAsk, | |
| 41 | RAISE_AGAIN_MS, | |
| 39 | 42 | } from "../src/core/child_reach.ts"; |
| 40 | 43 | import { asksOfUser } from "../src/core/reach_ask.ts"; |
| 41 | 44 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -804,6 +807,29 @@ describe("for every hosted forge, not now, and across restarts", () => { | ||
| 804 | 807 | expect(kept).not.toContain("h0.many.invalid"); |
| 805 | 808 | parent.db.query("DELETE FROM child_reach_ask").run(); |
| 806 | 809 | }); |
| 810 | ||
| 811 | test("a flood of new asks cannot push out one an admin put aside: re-sent, it is still held", () => { | |
| 812 | const t0 = Date.now(); | |
| 813 | const ask = (host: string, at: number) => | |
| 814 | keepAsk( | |
| 815 | parent.db, | |
| 816 | { bodyId: maria.bodyId, child: "maria", host, why: "", askedBy: "ana" }, | |
| 817 | at, | |
| 818 | ); | |
| 819 | ask("aside.many.invalid", t0); | |
| 820 | expect(putAsideAsk(parent.db, maria.bodyId, "aside.many.invalid", "alice", t0)).toBe(true); | |
| 821 | for (let i = 0; i < ASKS_PER_FORGE + 5; i++) | |
| 822 | ask(`f${i}.many.invalid`, t0 + 1 + i); | |
| 823 | expect(askFor(parent.db, maria.bodyId, "aside.many.invalid")?.state).toBe("later"); | |
| 824 | const waiting = listAsks(parent.db).filter( | |
| 825 | (a) => a.bodyId === maria.bodyId && a.state === "asked", | |
| 826 | ); | |
| 827 | expect(waiting).toHaveLength(ASKS_PER_FORGE); | |
| 828 | expect(ask("aside.many.invalid", t0 + 100).state).toBe("later"); | |
| 829 | // Past its day it is an ordinary ask again, and may give way like one. | |
| 830 | expect(ask("aside.many.invalid", t0 + RAISE_AGAIN_MS + 1).state).toBe("asked"); | |
| 831 | parent.db.query("DELETE FROM child_reach_ask").run(); | |
| 832 | }); | |
| 807 | 833 | }); |
| 808 | 834 | |
| 809 | 835 | describe("the terminal's door", () => { |
new above
offline