Public: anyone can read this; the crew can change it.
A hold's end always brings the games up, and a failed look at the hold cannot empty a sync's diagnosis #17761
Merged 10h 8m ago, live in production
sold/game-hold-end → main 0 commits
2 files
changed +73
−2
src/games/agent.sh +3 −2
| @@ -178,6 +178,8 @@ docker_needs_volume() { | ||
| 178 | 178 | HELD_READ="docs/features/game-box.md (Held) says how to choose, and both are kept until then" |
| 179 | 179 | vol_hold() { |
| 180 | 180 | printf '%s %s\n' "$1" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >"" |
| 181 | # No compose file counts as up, or as failed: whichever way the hold ends, the next sync brings the games up. | |
| 182 | rm -f "/.compose-sha" "/.up.failed" | |
| 181 | 183 | vol_step "refused: $2: nothing is started; " |
| 182 | 184 | } |
| 183 | 185 | # Mount the volume at the data directory. At a fresh boot the directory is empty; one that holds |
| @@ -823,7 +825,6 @@ job_tick() { | ||
| 823 | 825 | # Held: the volume may hold other worlds. An up is asked for again at each sync, so none is kept here. |
| 824 | 826 | if [ -f "" ] && [ "" != stop ] && [ "" != pull ]; then |
| 825 | 827 | [ -z "" ] || keep_result "" false "nothing is started: this box is held ($(cut -d' ' -f1 "")); " |
| 826 | rm -f "/.compose-sha" | |
| 827 | 828 | return |
| 828 | 829 | fi |
| 829 | 830 | printf '%s' "" >"/.job.id" |
| @@ -1287,7 +1288,7 @@ sync() { | ||
| 1287 | 1288 | logs "" | json_or '{}' >"/.sync.logs" |
| 1288 | 1289 | json_or '[]' <"/.results" >"/.sync.results" |
| 1289 | 1290 | host | json_or '{}' >"/.sync.host" |
| 1290 | bounded_diag | json_or '{}' | jq -c --argjson hold "$(held)" '. + {hold: $hold}' >"/.sync.diag" | |
| 1291 | bounded_diag | jq -c --argjson hold "$(held)" '. + {hold: $hold}' 2>/dev/null | json_or '{}' >"/.sync.diag" | |
| 1291 | 1292 | people | json_or '{}' >"/.sync.people" |
| 1292 | 1293 | metrics | json_or '{}' >"/.sync.metrics" |
| 1293 | 1294 | jq -c 'if type == "object" then . else {} end' "/snapshots.json" 2>/dev/null | json_or '{}' >"/.sync.snapshots" |
test/game-volume.test.ts +70
| @@ -415,6 +415,76 @@ describe.skipIf(BASH === null || lacks.length > 0)("agent.sh --mount-volume", () | ||
| 415 | 415 | } |
| 416 | 416 | }, 60_000); |
| 417 | 417 | |
| 418 | test.skipIf(Bun.which("jq") === null || Bun.which("curl") === null)("a stop and a pull queued while held do not cost the up that comes once the hold ends", async () => { | |
| 419 | const b = box({ data: { "level.dat": "new and empty" }, volume: { "level.dat": "the worlds" } }); | |
| 420 | const ask = [["c1", "stop"], ["c2", "pull"], ["c3", "start"]].map(([id, kind]) => ({ id, kind, service: "lobby", text: "" })); | |
| 421 | // The box had this very compose up before it was held, as a live one has. | |
| 422 | writeFileSync(join(b.game, ".compose-sha"), "def"); | |
| 423 | const { bodies, sync, server } = synced(b, (n) => { | |
| 424 | const has = String(bodies[n - 1]!["composeSha"]).trim(); | |
| 425 | return { commands: n === 2 ? ask : [], composeSha: "def", ...(has === "def" ? {} : { compose: "services: {}\n" }) }; | |
| 426 | }); | |
| 427 | const jobs = () => b.calls().flatMap((c) => / (up|start|stop|pull)( |$).*/.exec(c.startsWith("docker compose") ? c.replace(/^.* compose.yml/, "") : "")?.[0].trim() ?? []); | |
| 428 | const moved = () => b.log().includes("moved: "); | |
| 429 | try { | |
| 430 | for (let i = 0; i < 12 && bodies.flatMap((x) => x["results"] as unknown[]).length < 3; i++) await sync(); | |
| 431 | expect(bodies.flatMap((x) => x["results"] as unknown[])).toHaveLength(3); | |
| 432 | const results = bodies.flatMap((x) => x["results"] as { id: string; ok: boolean }[]); | |
| 433 | expect(results.map((x) => [x.id, x.ok])).toEqual([["c1", true], ["c2", true], ["c3", false]]); | |
| 434 | expect(jobs()).toEqual(["stop lobby", "pull lobby"]); | |
| 435 | // A held box says no compose file is up, so the forge sends it again. | |
| 436 | expect(String(bodies.at(-1)!["composeSha"])).toBe(""); | |
| 437 | renameSync(join(b.root, "st", "volume", "level.dat"), join(b.root, "level.dat.aside")); | |
| 438 | for (let i = 0; i < 12 && !jobs().some((c) => c.startsWith("up ")); i++) await sync(); | |
| 439 | expect(moved()).toBe(true); | |
| 440 | expect(jobs().filter((c) => c.startsWith("up "))).toEqual(["up -d --remove-orphans"]); | |
| 441 | await sync(); | |
| 442 | await sync(); | |
| 443 | expect(readFileSync(join(b.game, ".compose-sha"), "utf8")).toBe("def"); | |
| 444 | expect(b.held()).toBe(false); | |
| 445 | } finally { | |
| 446 | server.stop(true); | |
| 447 | } | |
| 448 | }, 60_000); | |
| 449 | ||
| 450 | test.skipIf(Bun.which("jq") === null || Bun.which("curl") === null)("a box that had its compose file up, held with only a stop asked, then given the volume's worlds, is brought up", async () => { | |
| 451 | const b = box({ data: { "level.dat": "new and empty" }, volume: { "level.dat": "the worlds" } }); | |
| 452 | writeFileSync(join(b.game, ".compose-sha"), "def"); | |
| 453 | writeFileSync(join(b.game, ".up.failed"), "def"); | |
| 454 | const { bodies, sync, server } = synced(b, (n) => { | |
| 455 | const has = String(bodies[n - 1]!["composeSha"]).trim(); | |
| 456 | return { commands: n === 1 ? [{ id: "c1", kind: "stop", service: "lobby", text: "" }] : [], composeSha: "def", ...(has === "def" ? {} : { compose: "services: {}\n" }) }; | |
| 457 | }); | |
| 458 | const ups = () => b.calls().filter((c) => / up -d /.test(c)); | |
| 459 | try { | |
| 460 | for (let i = 0; i < 3; i++) await sync(); | |
| 461 | expect(ups()).toEqual([]); | |
| 462 | // The how-to's way: the data directory's content aside, then the volume mounted. | |
| 463 | renameSync(b.data, `${b.data}.aside`); | |
| 464 | expect(b.run().code).toBe(0); | |
| 465 | for (let i = 0; i < 3 && ups().length === 0; i++) await sync(); | |
| 466 | expect(await waitFor(() => ups().length === 1, { within: 10_000, what: "the up" })).toBe(true); | |
| 467 | expect(b.file("level.dat")).toBe("the worlds"); | |
| 468 | } finally { | |
| 469 | server.stop(true); | |
| 470 | } | |
| 471 | }, 60_000); | |
| 472 | ||
| 473 | test("a hold file nobody can read still says held, with why unknown", async () => { | |
| 474 | for (const [text, since] of [["", ""], ["sideways 2026-12-03T00:00:00Z\n", "2026-12-03T00:00:00Z"]] as const) { | |
| 475 | const b = box({ data: { "level.dat": "w" } }); | |
| 476 | writeFileSync(join(b.game, ".volume.hold"), text); | |
| 477 | unlinkSync(b.dev); | |
| 478 | const { bodies, sync, server } = synced(b, () => ({ commands: [], composeSha: "abc" })); | |
| 479 | try { | |
| 480 | await sync(); | |
| 481 | expect(bodies.at(-1)!["diag"]).toEqual({ hold: { why: "unknown", since } }); | |
| 482 | } finally { | |
| 483 | server.stop(true); | |
| 484 | } | |
| 485 | } | |
| 486 | }, 60_000); | |
| 487 | ||
| 418 | 488 | // Box mc on 2026-12-03: ext4 on /dev/sda at the data directory, Docker's root on it, no mark and no hold. |
| 419 | 489 | test.skipIf(Bun.which("jq") === null || Bun.which("curl") === null)("a box whose volume is mounted is left alone at its next start: no hold, no copy, no mount, no restart, no up", async () => { |
| 420 | 490 | const b = box({ volume: {}, state: ["docker-active"] }); |
new above
offline