From d806cf41716a157af040c82c4da7722fb509827c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 16 Jul 2026 09:03:15 -0700 Subject: [PATCH] test: reuse resolver git fixture (#109154) --- test/scripts/resolve-openclaw-ref.test.ts | 35 ++++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/test/scripts/resolve-openclaw-ref.test.ts b/test/scripts/resolve-openclaw-ref.test.ts index 80ab0bc7b6b1..8807405ef843 100644 --- a/test/scripts/resolve-openclaw-ref.test.ts +++ b/test/scripts/resolve-openclaw-ref.test.ts @@ -1,13 +1,15 @@ // Resolve OpenClaw ref tests cover the release workflow ref resolver script. import { execFileSync, spawnSync } from "node:child_process"; import { join } from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { createTempDirTracker } from "../helpers/temp-dir.js"; const SCRIPT_PATH = "scripts/github/resolve-openclaw-ref.sh"; const tempDirs = createTempDirTracker(); +let remoteRepo: string; +let remoteSha: string; -afterEach(() => { +afterAll(() => { tempDirs.cleanup(); }); @@ -35,6 +37,10 @@ function createRemoteRepo() { return { repo, sha }; } +beforeAll(() => { + ({ repo: remoteRepo, sha: remoteSha } = createRemoteRepo()); +}); + function runResolver(remote: string, args: string[]) { return spawnSync("bash", [SCRIPT_PATH, ...args], { cwd: process.cwd(), @@ -68,42 +74,38 @@ function expectSuccessfulOutput(result: ReturnType): Record< describe("scripts/github/resolve-openclaw-ref.sh", () => { it("resolves branch and tag refs with git ls-remote", () => { - const { repo, sha } = createRemoteRepo(); - - expect(expectSuccessfulOutput(runResolver(repo, ["--ref", "release/test"]))).toEqual({ + expect(expectSuccessfulOutput(runResolver(remoteRepo, ["--ref", "release/test"]))).toEqual({ fallback: "false", fast: "true", ref_kind: "branch", - sha, + sha: remoteSha, }); - expect(expectSuccessfulOutput(runResolver(repo, ["--ref", "v2026.6.21"]))).toEqual({ + expect(expectSuccessfulOutput(runResolver(remoteRepo, ["--ref", "v2026.6.21"]))).toEqual({ fallback: "false", fast: "true", ref_kind: "tag", - sha, + sha: remoteSha, }); }); it("accepts full commit SHA refs without remote lookup", () => { - const { repo, sha } = createRemoteRepo(); - const result = runResolver(repo, ["--ref", sha.toUpperCase()]); + const result = runResolver(remoteRepo, ["--ref", remoteSha.toUpperCase()]); expect(expectSuccessfulOutput(result)).toEqual({ fallback: "true", fast: "false", ref_kind: "sha", - sha, + sha: remoteSha, }); }); it("writes fallback outputs for unresolved refs when a caller supplies an expected SHA", () => { - const { repo, sha } = createRemoteRepo(); const outputPath = join(tempDirs.make("openclaw-ref-output-"), "github-output.txt"); - const result = runResolver(repo, [ + const result = runResolver(remoteRepo, [ "--ref", "missing-ref", "--expected-sha", - sha, + remoteSha, "--fallback-ok", "--github-output", outputPath, @@ -115,7 +117,7 @@ describe("scripts/github/resolve-openclaw-ref.sh", () => { fallback: "true", fast: "false", ref_kind: "unknown", - sha, + sha: remoteSha, }); }); @@ -135,8 +137,7 @@ describe("scripts/github/resolve-openclaw-ref.sh", () => { }); it("rejects ambiguous branch and tag names before emitting outputs", () => { - const { repo } = createRemoteRepo(); - const result = runResolver(repo, ["--ref", "ambiguous"]); + const result = runResolver(remoteRepo, ["--ref", "ambiguous"]); expect(result.status).toBe(1); expect(result.stderr).toContain("Ref resolved ambiguously as both branch and tag: ambiguous");