Public: anyone can read this; the crew can change it.

Games: a server the box no longer runs leaves its list #18029

opened this

Merged 12h 18m ago, live in production

sold/stale-services → main 0 commits

  • Merged. sold/stale-services was merged into main as 492f6df.

Review

Sign in to review this change.
2 files changed +18 −1
src/games/store.ts +4
@@ -743,6 +743,10 @@ export function recordSync(
743743 up_since = excluded.up_since, mem_limit_mib = excluded.mem_limit_mib, cpu_limit = excluded.cpu_limit`,
744744 ).run(box.id, name, str(s.state, 20), str(s.health, 20), str(s.startedAt, 40), num(s.cpuPct), num(s.memMiB), at, startOf(s.upSince, at), wholeMiB(s.memLimitMiB), limit(s.cpuLimit, 0.001, 4_096));
745745 }
746 // A server the box no longer runs leaves the list, so the page never shows one that is gone. An
747 // empty list says nothing (Docker may not have answered), so it clears nothing.
748 const seen = (body.services ?? []).slice(0, 64).map((s) => str(s.name, 64)).filter((n) => SERVICE_NAME.test(n));
749 if (seen.length > 0) db.query("DELETE FROM game_service WHERE box_id = ?1 AND name NOT IN (SELECT value FROM json_each(?2))").run(box.id, JSON.stringify(seen));
746750 for (const [service, lines] of Object.entries(body.logs ?? {}).slice(0, 64)) {
747751 if (!SERVICE_NAME.test(service) || !Array.isArray(lines)) continue;
748752 const insert = db.query("INSERT INTO game_log (box_id, service, line, at) VALUES (?1, ?2, ?3, ?4)");
test/cloud-containers.test.ts +14 −1
@@ -18,7 +18,7 @@ import { aboutContext, aboutLine } from "../src/core/talk_about.ts";
1818 import { createToken } from "../src/core/tokens.ts";
1919 import { createUser, type User } from "../src/core/users.ts";
2020 import { synced } from "../src/games/notify.ts";
21 import { boxNamed, createGameBox, grant, recordSync, type SyncBody } from "../src/games/store.ts";
21 import { boxNamed, createGameBox, grant, recordSync, servicesOf, type SyncBody } from "../src/games/store.ts";
2222 import { serve, type Servers } from "../src/http/server.ts";
2323 import { cloudLines, cloudTreeScreen } from "../src/tui/screens/cloudtree.ts";
2424 import { gameServiceScreen, gamesScreen } from "../src/tui/screens/games.ts";
@@ -356,3 +356,16 @@ test("a container's Logs tab shows its lines as text, live for its box's owner,
356356 expect(bobs.status).toBeGreaterThanOrEqual(403);
357357 expect(await bobs.text()).not.toContain("Server] Done");
358358 });
359
360 test("a server the box stops naming leaves its list; a sync that names none clears nothing", () => {
361 const names = () => servicesOf(app.db, boxNamed(app.db, "mc")!.id).map((s) => s.name);
362 sync();
363 const all = names();
364 expect(all.length).toBeGreaterThan(1);
365 sync({ ...SYNC, services: SYNC.services!.slice(0, 1) });
366 expect(names()).toEqual(["hub"]);
367 sync({ ...SYNC, services: [] });
368 expect(names()).toEqual(["hub"]);
369 sync();
370 expect(names()).toEqual(all);
371 });

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

Keyboard shortcuts

Docs