Public: anyone can read this; the crew can change it.
infra says lists in a stable order, and its test no longer races the clock #16934
Conflicts with main in 2 files
src/actions/infra.ts · test/talk-infra-says.test.ts
sold/says-order → main 1 commit 2 threads · 2 unresolved
This pull asks for more cpus. Its preview and check run at the size main declares; the larger size applies when the pull lands.
2 files
changed +20
−3
src/actions/infra.ts +6 −3
| @@ -242,7 +242,7 @@ function reckon(app: App, now: Date): { view: InfraView; rows: Map<string, Runni | ||
| 242 | 242 | const account = `${a.provider}/${a.name}`; |
| 243 | 243 | return [{ account, says: `At ${LABEL[a.provider]}, not in your infrastructure: ${what}`, href: accountHref(account) }]; |
| 244 | 244 | }); |
| 245 | ended.sort((a, b) => (retiredAt.get(b.name) ?? "").localeCompare(retiredAt.get(a.name) ?? "") || a.name.localeCompare(b.name)); | |
| 245 | ended.sort((a, b) => (retiredAt.get(b.name) ?? "").localeCompare(retiredAt.get(a.name) ?? "") || a.name.localeCompare(b.name, "en", { numeric: true })); | |
| 246 | 246 | return { view: { meters, drift, groups: ordered, ended, endedEarlier, experiments: x }, rows }; |
| 247 | 247 | } |
| 248 | 248 | |
| @@ -258,8 +258,11 @@ const named = (items: readonly string[]): string => | ||
| 258 | 258 | */ |
| 259 | 259 | export function infraSays(v: InfraView): string { |
| 260 | 260 | const machines = v.groups.flatMap((g) => g.machines); |
| 261 | const running = machines.filter((m) => m.clear === ""); | |
| 262 | const dead = machines.filter((m) => m.clear !== ""); | |
| 261 | // By name, so the paragraph reads the same however the rows were made; what ended keeps the | |
| 262 | // view's order: newest retired first, then by name. | |
| 263 | const byName = (a: Running, b: Running): number => a.name.localeCompare(b.name, "en", { numeric: true }); | |
| 264 | const running = machines.filter((m) => m.clear === "").sort(byName); | |
| 265 | const dead = machines.filter((m) => m.clear !== "").sort(byName); | |
| 263 | 266 | const total = [...machines, ...v.ended].reduce((s, m) => s + m.monthlyCents, 0); |
| 264 | 267 | return [ |
| 265 | 268 | `Running: ${running.length === 0 ? "none" : named(running.map((m) => `${m.name} (${m.billing})`))}.`, |
test/talk-infra-says.test.ts +14
| @@ -122,6 +122,8 @@ beforeAll(async () => { | ||
| 122 | 122 | machine(name, "retired"); |
| 123 | 123 | retired = app.bus.append({ kind: "pinned.retired", actorId: alice.id, payload: { name, withData: true } }).createdAt; |
| 124 | 124 | } |
| 125 | // Retired at the same instant, as production's two were: a tie, read by name (friend1 first). | |
| 126 | app.db.query("UPDATE event SET created_at = ?1 WHERE kind = 'pinned.retired'").run(retired); | |
| 125 | 127 | // A machine whose row was cleared: an event names it, no row does. |
| 126 | 128 | app.bus.append({ kind: "pinned.cleared", actorId: alice.id, payload: { name: "gone1" } }); |
| 127 | 129 | }); |
| @@ -149,6 +151,18 @@ describe("infra says it plainly", () => { | ||
| 149 | 151 | expect(Object.keys(said.value)[0]).toBe("says"); |
| 150 | 152 | }); |
| 151 | 153 | |
| 154 | test("what ended reads newest retired first, then by name; what runs and the dead rows by name", () => { | |
| 155 | const v = infraOf(app, alice); | |
| 156 | if (!v.ok) throw new Error(v.error); | |
| 157 | const at = (name: string) => v.value.ended.find((m) => m.name === name)!; | |
| 158 | // test1 retired a minute later than friend1: it reads first. | |
| 159 | const later = { ...v.value, ended: [at("test1"), at("friend1")] }; | |
| 160 | expect(infraSays(later)).toContain("Ended in the last 30 days: test1 ("); | |
| 161 | const dead = v.value.groups.flatMap((g) => g.machines).find((m) => m.name === "canary1")!; | |
| 162 | const shuffled = { ...v.value, groups: [{ kind: "app" as const, key: "", title: "", monthlyCents: 0, machines: [{ ...dead, name: "zed" }, { ...dead, name: "abe" }] }] }; | |
| 163 | expect(infraSays(shuffled)).toContain("Dead rows (nothing exists at the provider): abe, zed;"); | |
| 164 | }); | |
| 165 | ||
| 152 | 166 | test("each group names at most ten, then how many more", () => { |
| 153 | 167 | const v = infraOf(app, alice); |
| 154 | 168 | if (!v.ok) throw new Error(v.error); |
new above
offline
This comment is false: beforeAll now makes both retirements the same instant. Rewrite the test to exercise the view's real tie-break and recency order (see the review body).