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

opened this

Merged 10h 8m ago, live in production

sold/game-hold-end → main 0 commits

  • Merged. sold/game-hold-end was merged into main as b19b3da.

Review

Sign in to review this change.
2 files changed +73 −2
src/games/agent.sh +3 −2
@@ -178,6 +178,8 @@ docker_needs_volume() {
178178 HELD_READ="docs/features/game-box.md (Held) says how to choose, and both are kept until then"
179179 vol_hold() {
180180 printf '%s %s\n' "$1" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >"$VOLUME_HOLD"
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 "$DIR/.compose-sha" "$DIR/.up.failed"
181183 vol_step "refused: $2: nothing is started; $HELD_READ"
182184 }
183185 # Mount the volume at the data directory. At a fresh boot the directory is empty; one that holds
@@ -823,7 +825,6 @@ job_tick() {
823825 # Held: the volume may hold other worlds. An up is asked for again at each sync, so none is kept here.
824826 if [ -f "$VOLUME_HOLD" ] && [ "${args%% *}" != stop ] && [ "${args%% *}" != pull ]; then
825827 [ -z "$id" ] || keep_result "$id" false "nothing is started: this box is held ($(cut -d' ' -f1 "$VOLUME_HOLD")); $HELD_READ"
826 rm -f "$DIR/.compose-sha"
827828 return
828829 fi
829830 printf '%s' "$id" >"$DIR/.job.id"
@@ -1287,7 +1288,7 @@ sync() {
12871288 logs "$since" | json_or '{}' >"$DIR/.sync.logs"
12881289 json_or '[]' <"$DIR/.results" >"$DIR/.sync.results"
12891290 host | json_or '{}' >"$DIR/.sync.host"
1290 bounded_diag | json_or '{}' | jq -c --argjson hold "$(held)" '. + {hold: $hold}' >"$DIR/.sync.diag"
1291 bounded_diag | jq -c --argjson hold "$(held)" '. + {hold: $hold}' 2>/dev/null | json_or '{}' >"$DIR/.sync.diag"
12911292 people | json_or '{}' >"$DIR/.sync.people"
12921293 metrics | json_or '{}' >"$DIR/.sync.metrics"
12931294 jq -c 'if type == "object" then . else {} end' "$WORLDS/snapshots.json" 2>/dev/null | json_or '{}' >"$DIR/.sync.snapshots"
test/game-volume.test.ts +70
@@ -415,6 +415,76 @@ describe.skipIf(BASH === null || lacks.length > 0)("agent.sh --mount-volume", ()
415415 }
416416 }, 60_000);
417417
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
418488 // Box mc on 2026-12-03: ext4 on /dev/sda at the data directory, Docker's root on it, no mark and no hold.
419489 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 () => {
420490 const b = box({ volume: {}, state: ["docker-active"] });

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

Keyboard shortcuts

Docs