Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ci-ubicloud): a cancelled gate reports an interrupt instead of retiring every VM for infrastructure errors
garrytan506d7d798bc4
diff --git a/scripts/ci-ubicloud.ts b/scripts/ci-ubicloud.tsindex 275ab080ac..373768057e 100755--- a/scripts/ci-ubicloud.ts+++ b/scripts/ci-ubicloud.ts@@ -422,7 +422,8 @@ async function main() {const done = new Set(parsed.map((r) => r.file));for (const result of parsed) record(vm, slot, result);const lost = batch.filter((item) => !done.has(item.file));- if (lost.length) {+ // The teardown killed this batch: its lost items say nothing about the VM.+ if (lost.length && !interrupted) {vm.infraErrors++;log(`batch on ${vm.name} slot ${slot} ended (exit ${code}) with ${lost.length} unfinished item(s); log ${logPath}`);for (const item of lost) {@@ -529,6 +530,7 @@ async function main() {try {await Promise.race([Promise.all(vms.map((vm, i) => vmLifecycle(vm, i))), recorded]);if (control.length && !controlDone) throw new Error("no VM became ready to run gitleaks/verify/exclusive items");+ if (interrupted) throw new Error(`interrupted: ${totalItems - results.size} item(s) did not run`);if (queue.length) throw new Error(`${queue.length} items never ran: every VM failed`);} catch (error) {console.error(`ci-ubicloud: ${error instanceof Error ? error.message : String(error)}`);diff --git a/test/scripts/ci-ubicloud-teardown.slow.test.ts b/test/scripts/ci-ubicloud-teardown.slow.test.tsindex 6745a7dbde..868da49ca8 100644--- a/test/scripts/ci-ubicloud-teardown.slow.test.ts+++ b/test/scripts/ci-ubicloud-teardown.slow.test.ts@@ -13,7 +13,7 @@// a 4.6 GB one never reached it within 120 s.import { afterEach, describe, expect, it } from "bun:test";-import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";+import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { makeGitFixture } from "../helpers/git-fixture.ts";@@ -84,3 +84,56 @@ describe("ci:ubicloud teardown", () => {expect(await stderr).not.toContain("WARNING");}, 180_000);});++// A SIGTERM while batches run (a cancelled gate) kills those batches. They+// are the teardown's doing, so the run reports an interrupt: no VM is+// retired for "infrastructure errors" and nothing claims every VM failed.+// scripts/ubicloud/ubi-runner.sh is replaced in the fixture by a stub whose+// batches block until killed.+const STUB_RUNNER = [+ "#!/usr/bin/env bash",+ "sub=$1; shift",+ "case \"$sub\" in",+ " owner) echo probe;;",+ " pack) tar -C \"$1\" -cf - scripts 2>/dev/null;;",+ " unpack) cat >/dev/null;;",+ " down) sleep 2;;",+ " ssh) name=$1; shift; case \"$*\" in *ci-item.sh*) echo \"$name\" >> \"$UBI_RUNNER_STATE/batches\"; exec sleep 60;; *\"bash -s\"*) cat >/dev/null;; esac;;",+ "esac",+ "exit 0",+].join("\n");++describe("ci:ubicloud interrupt", () => {+ it("SIGTERM while batches run reports an interrupt, not VM infrastructure errors", async () => {+ dir = mkdtempSync(join(tmpdir(), "ci-ubicloud-interrupt-"));+ const repo = join(dir, "repo");+ mkdirSync(repo);+ await makeGitFixture(repo);+ cpSync(join(ROOT, "scripts"), join(repo, "scripts"), { recursive: true });+ cpSync(join(ROOT, "docker-compose.ci.yml"), join(repo, "docker-compose.ci.yml"));+ writeFileSync(join(repo, "scripts/ubicloud/ubi-runner.sh"), STUB_RUNNER, { mode: 0o755 });+ mkdirSync(join(repo, "test"));+ for (let i = 0; i < 12; i++) writeFileSync(join(repo, "test", `t${i}.test.ts`), "import { test } from 'bun:test';\ntest('x', () => {});\n");+ const state = join(dir, "state");+ mkdirSync(state);+ const child = (proc = Bun.spawn(["bun", "run", "scripts/ci-ubicloud.ts", "--vms", "1", "--lanes", "unit"], {+ cwd: repo,+ env: { PATH: process.env.PATH ?? "/usr/bin:/bin", HOME: dir, UBICLOUD_API_KEY: "test-token", UBI_RUNNER_STATE: state, UBI_OWNER: "probe" },+ stdout: "pipe",+ stderr: "pipe",+ }));+ const stdout = new Response(child.stdout).text();+ const stderr = new Response(child.stderr).text();+ for (let i = 0; i < 300 && !existsSync(join(state, "batches")); i++) await Bun.sleep(100);+ expect(existsSync(join(state, "batches"))).toBe(true);+ await Bun.sleep(500);+ child.kill("SIGTERM");+ expect(await child.exited).toBe(130);+ const out = await stdout;+ const err = await stderr;+ expect(out).toContain("SIGTERM: tearing down");+ expect(out).not.toContain("infrastructure errors");+ expect(err).not.toContain("every VM failed");+ expect(err).toMatch(/interrupted: \d+ item\(s\) did not run/);+ }, 120_000);+});