Public: anyone can read this; the crew can change it.
Games: a server the box no longer runs leaves its list #18029
Merged 12h 18m ago, live in production
sold/stale-services → main 0 commits
2 files
changed +18
−1
src/games/store.ts +4
| @@ -743,6 +743,10 @@ export function recordSync( | ||
| 743 | 743 | up_since = excluded.up_since, mem_limit_mib = excluded.mem_limit_mib, cpu_limit = excluded.cpu_limit`, |
| 744 | 744 | ).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)); |
| 745 | 745 | } |
| 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)); | |
| 746 | 750 | for (const [service, lines] of Object.entries(body.logs ?? {}).slice(0, 64)) { |
| 747 | 751 | if (!SERVICE_NAME.test(service) || !Array.isArray(lines)) continue; |
| 748 | 752 | 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"; | ||
| 18 | 18 | import { createToken } from "../src/core/tokens.ts"; |
| 19 | 19 | import { createUser, type User } from "../src/core/users.ts"; |
| 20 | 20 | 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"; | |
| 22 | 22 | import { serve, type Servers } from "../src/http/server.ts"; |
| 23 | 23 | import { cloudLines, cloudTreeScreen } from "../src/tui/screens/cloudtree.ts"; |
| 24 | 24 | 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, | ||
| 356 | 356 | expect(bobs.status).toBeGreaterThanOrEqual(403); |
| 357 | 357 | expect(await bobs.text()).not.toContain("Server] Done"); |
| 358 | 358 | }); |
| 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 | }); |
new above
offline