From d6a6b132b32df63629cd99b430d5cb02974f9db5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 14 Jul 2026 18:31:00 -0700 Subject: [PATCH] test: speed live updater fixtures (#107892) --- test/scripts/openclaw-live-updater.test.ts | 36 ++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/test/scripts/openclaw-live-updater.test.ts b/test/scripts/openclaw-live-updater.test.ts index 1e3803888298..227b15c853d2 100644 --- a/test/scripts/openclaw-live-updater.test.ts +++ b/test/scripts/openclaw-live-updater.test.ts @@ -1,6 +1,7 @@ import { execFileSync, spawn, spawnSync } from "node:child_process"; import { chmodSync, + constants as fsConstants, cpSync, existsSync, mkdirSync, @@ -99,9 +100,11 @@ function initializeFixture(root: string) { const origin = path.join(root, "origin.git"); const seed = path.join(root, "seed"); const mirror = path.join(root, "mirror"); + const gitTemplate = path.join(root, "git-template"); + mkdirSync(gitTemplate); mkdirSync(seed); - git(root, "init", "--bare", origin); - git(seed, "init", "-b", "main"); + git(root, "init", "--bare", "-b", "main", `--template=${gitTemplate}`, origin); + git(seed, "init", "-b", "main", `--template=${gitTemplate}`); git(seed, "config", "user.name", "Test"); git(seed, "config", "user.email", "test@example.com"); writeFileSync(path.join(seed, "README.md"), "one\n"); @@ -110,14 +113,17 @@ function initializeFixture(root: string) { git(seed, "commit", "-m", "initial"); git(seed, "remote", "add", "origin", "../origin.git"); git(seed, "push", "-u", "origin", "main"); - git(root, "--git-dir", origin, "symbolic-ref", "HEAD", "refs/heads/main"); - git(root, "clone", origin, mirror); + git(root, "clone", `--template=${gitTemplate}`, origin, mirror); const canonicalOrigin = "https://github.com/openclaw/openclaw.git"; git(mirror, "remote", "set-url", "origin", canonicalOrigin); return { root, mirror, origin, seed }; } -function makeFixture() { +type Fixture = ReturnType; + +function makeFixture(): Omit; +function makeFixture(options: { includeSeed: true }): Fixture; +function makeFixture(options?: { includeSeed?: boolean }) { if (!fixtureTemplate) { throw new Error("fixture template is not initialized"); } @@ -127,12 +133,16 @@ function makeFixture() { const mirror = path.join(root, "mirror"); // Mutable refs and configs must stay isolated; copying one initialized repo // set avoids rebuilding identical Git history for every test. - cpSync(fixtureTemplate.origin, origin, { recursive: true }); - cpSync(fixtureTemplate.seed, seed, { recursive: true }); - cpSync(fixtureTemplate.mirror, mirror, { recursive: true }); + const copyOptions = { mode: fsConstants.COPYFILE_FICLONE, recursive: true }; + cpSync(fixtureTemplate.origin, origin, copyOptions); + cpSync(fixtureTemplate.mirror, mirror, copyOptions); + if (options?.includeSeed) { + cpSync(fixtureTemplate.seed, seed, copyOptions); + } fixtureOrigins.set(mirror, origin); fixtureOrigins.set(realpathSync(mirror), origin); - return { root, mirror, origin, seed }; + const fixture = { root, mirror, origin }; + return options?.includeSeed ? { ...fixture, seed } : fixture; } function writeBuild(mirror: string) { @@ -942,7 +952,7 @@ describe("openclaw live updater", () => { }); test("fast-forwards, builds exact SHA, restarts Gateway, then proves exact Mac target", () => { - const { root, mirror, seed } = makeFixture(); + const { root, mirror, seed } = makeFixture({ includeSeed: true }); mkdirSync(path.join(seed, "apps/macos/Sources/OpenClaw"), { recursive: true }); writeFileSync(path.join(seed, "apps/macos/Sources/OpenClaw/App.swift"), "// changed\n"); git(seed, "add", "."); @@ -1309,7 +1319,7 @@ describe("openclaw live updater", () => { }); test("repoints an ancestor snapshot across the next source update", () => { - const { root, mirror, seed } = makeFixture(); + const { root, mirror, seed } = makeFixture({ includeSeed: true }); mkdirSync(path.join(mirror, "node_modules")); writeBuild(mirror); writeFileSync(path.join(seed, "README.md"), "snapshot update\n"); @@ -1777,7 +1787,7 @@ describe("openclaw live updater", () => { }); test("retains failed exact-bundle Mac proof for the next heartbeat", () => { - const { root, mirror, seed } = makeFixture(); + const { root, mirror, seed } = makeFixture({ includeSeed: true }); mkdirSync(path.join(seed, "apps/macos/Sources/OpenClaw"), { recursive: true }); writeFileSync(path.join(seed, "apps/macos/Sources/OpenClaw/App.swift"), "// changed\n"); git(seed, "add", "."); @@ -1824,7 +1834,7 @@ describe("openclaw live updater", () => { }); test("records pending Mac work before Gateway maintenance can fail", () => { - const { root, mirror, seed } = makeFixture(); + const { root, mirror, seed } = makeFixture({ includeSeed: true }); mkdirSync(path.join(seed, "apps/macos/Sources/OpenClaw"), { recursive: true }); writeFileSync(path.join(seed, "apps/macos/Sources/OpenClaw/App.swift"), "// changed\n"); git(seed, "add", ".");