Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(ubicloud): run the teardown probe from a fixture repo, not the live checkout

garrytan3ad5c112a18e
diff --git a/test/scripts/ci-ubicloud-teardown.slow.test.ts b/test/scripts/ci-ubicloud-teardown.slow.test.ts
index 4f5b345769..8d7f19e9da 100644
--- a/test/scripts/ci-ubicloud-teardown.slow.test.ts
+++ b/test/scripts/ci-ubicloud-teardown.slow.test.ts
@@ -2,32 +2,44 @@
// a cancelled background operation) to scripts/ci-ubicloud.ts while
// its VMs are still provisioning (one created, two creates in flight) against
// a mock Ubicloud API. Every name is recorded before its create, and teardown
-// returns only after each VM that came to exist is destroyed and gone. Slow
-// because the orchestrator packs the whole checkout before provisioning.
+// returns only after each VM that came to exist is destroyed and gone.
+//
+// The orchestrator packs its whole checkout (.git and untracked files
+// included) before it provisions anything, so it runs from a fixture repo
+// holding only scripts/ and docker-compose.ci.yml. Run from the real
+// checkout, the time to the first create grew with the operator's checkout:
+// a 4.6 GB one never reached it within 120 s.
import { afterEach, describe, expect, it } from "bun:test";
-import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
+import { makeGitFixture } from "../helpers/git-fixture.ts";
import { startMockUbicloud, waitForEvent, type MockUbicloud } from "../helpers/mock-ubicloud-api.ts";
const ROOT = resolve(import.meta.dir, "..", "..");
let dir = "";
-let runDir = "";
let mock: MockUbicloud | null = null;
+let proc: ReturnType<typeof Bun.spawn> | null = null;
afterEach(() => {
+ proc?.kill("SIGKILL");
+ proc = null;
mock?.stop();
rmSync(dir, { recursive: true, force: true });
- if (runDir) rmSync(runDir, { recursive: true, force: true });
});
describe("ci:ubicloud teardown", () => {
for (const signal of ["SIGTERM", "SIGHUP"] as const) it(`${signal} mid-provision destroys every VM it asked for, including creates still in flight`, async () => {
dir = mkdtempSync(join(tmpdir(), "ci-ubicloud-teardown-"));
+ 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"));
const api = (mock = startMockUbicloud({ createDelayMs: (name) => (/-ci01/.test(name) ? 0 : 4000) }));
- const proc = Bun.spawn(["bun", "run", "scripts/ci-ubicloud.ts", "--vms", "3", "--lanes", "gitleaks"], {
- cwd: ROOT,
+ const child = (proc = Bun.spawn(["bun", "run", "scripts/ci-ubicloud.ts", "--vms", "3", "--lanes", "gitleaks"], {
+ cwd: repo,
env: {
PATH: process.env.PATH ?? "/usr/bin:/bin",
HOME: dir,
@@ -39,16 +51,22 @@ describe("ci:ubicloud teardown", () => {
},
stdout: "pipe",
stderr: "pipe",
+ }));
+ const stdout = new Response(child.stdout).text();
+ const stderr = new Response(child.stderr).text();
+ // An orchestrator that exits before provisioning fails here with its output, not after a blind timeout.
+ const exitedEarly = child.exited.then(async (code) => {
+ throw new Error(`ci-ubicloud exited ${code} before the probe signal\n${await stdout}\n${await stderr}`);
});
- const stdout = new Response(proc.stdout).text();
- const stderr = new Response(proc.stderr).text();
- await waitForEvent(api, /^created \S+-ci01/, 120_000);
- await waitForEvent(api, /^create-start \S+-ci03/, 10_000);
+ await Promise.race([waitForEvent(api, /^created \S+-ci01/, 120_000), exitedEarly]);
+ await Promise.race([waitForEvent(api, /^create-start \S+-ci03/, 10_000), exitedEarly]);
+ exitedEarly.catch(() => {});
expect(api.events.some((e) => /^created \S+-ci0[23]/.test(e))).toBe(false);
- proc.kill(signal);
- expect(await proc.exited).toBe(130);
+ child.kill(signal);
+ expect(await child.exited).toBe(130);
const out = await stdout;
- runDir = /logs in (\S+)/.exec(out)?.[1] ?? "";
+ const runDir = /logs in (\S+)/.exec(out)?.[1] ?? "";
+ expect(runDir.startsWith(repo)).toBe(true);
const requested = readFileSync(join(runDir, "vms.txt"), "utf8").trim().split("\n").map((l) => l.split(" ")[0]!);
expect(requested).toHaveLength(3);