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

opened this

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.

Review

Sign in to review this change.
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
242242 const account = `${a.provider}/${a.name}`;
243243 return [{ account, says: `At ${LABEL[a.provider]}, not in your infrastructure: ${what}`, href: accountHref(account) }];
244244 });
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 }));
246246 return { view: { meters, drift, groups: ordered, ended, endedEarlier, experiments: x }, rows };
247247 }
248248
@@ -258,8 +258,11 @@ const named = (items: readonly string[]): string =>
258258 */
259259 export function infraSays(v: InfraView): string {
260260 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);
263266 const total = [...machines, ...v.ended].reduce((s, m) => s + m.monthlyCents, 0);
264267 return [
265268 `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 () => {
122122 machine(name, "retired");
123123 retired = app.bus.append({ kind: "pinned.retired", actorId: alice.id, payload: { name, withData: true } }).createdAt;
124124 }
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);
125127 // A machine whose row was cleared: an event names it, no row does.
126128 app.bus.append({ kind: "pinned.cleared", actorId: alice.id, payload: { name: "gone1" } });
127129 });
@@ -149,6 +151,18 @@ describe("infra says it plainly", () => {
149151 expect(Object.keys(said.value)[0]).toBe("says");
150152 });
151153
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.

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).

159 const later = { ...v.value, ended: [at("test1"), at("friend1")] };
160 expect(infraSays(later)).toContain("Ended in the last 30 days: test1 (");

This passes on the old code too, because infraSays just preserves the ended it is given. Assert on v.value.ended from infraOf (friend1 before test1 on the tie), and give one machine a later retire time to prove newest-first.

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
152166 test("each group names at most ten, then how many more", () => {
153167 const v = infraOf(app, alice);
154168 if (!v.ok) throw new Error(v.error);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs