Skip to content

Commit 33029a1

Browse files
authored
test(tooling): reuse mobile release ref lifecycle fixtures (#134367)
1 parent efc9491 commit 33029a1

1 file changed

Lines changed: 81 additions & 113 deletions

File tree

Lines changed: 81 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { execFileSync } from "node:child_process";
2-
import { copyFileSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3-
import os from "node:os";
2+
import { copyFileSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
43
import path from "node:path";
5-
import { describe, expect, it } from "vitest";
4+
import { afterEach, describe, expect, it } from "vitest";
65
import {
76
mobileReleaseRefFor,
87
parseArgs,
98
preflightMobileReleaseRef,
109
recordMobileReleaseRef,
1110
resolveMobileReleaseRef,
1211
} from "../../scripts/mobile-release-ref.ts";
12+
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
1313

1414
const SCRIPT_PATH = path.join(process.cwd(), "scripts", "mobile-release-ref.ts");
15+
const tempRoots = useAutoCleanupTempDirTracker(afterEach);
1516

1617
function run(command: string, args: string[], cwd: string): string {
1718
return execFileSync(command, args, {
@@ -25,8 +26,8 @@ function git(cwd: string, args: string[]): string {
2526
return run("git", args, cwd);
2627
}
2728

28-
function createFixtureRepo(): { cleanup: () => void; remote: string; root: string; sha: string } {
29-
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-mobile-release-ref-"));
29+
function createFixtureRepo(): { remote: string; root: string; sha: string } {
30+
const root = tempRoots.make("openclaw-mobile-release-ref-");
3031
const remote = path.join(root, "remote.git");
3132
const checkout = path.join(root, "checkout");
3233

@@ -41,7 +42,6 @@ function createFixtureRepo(): { cleanup: () => void; remote: string; root: strin
4142
git(checkout, ["push", "origin", "HEAD:main"]);
4243

4344
return {
44-
cleanup: () => rmSync(root, { force: true, recursive: true }),
4545
remote: "origin",
4646
root: checkout,
4747
sha,
@@ -114,118 +114,86 @@ describe("mobile-release-ref", () => {
114114
).toThrow("Invalid Android versionCode");
115115
});
116116

117-
it("creates, resolves, and idempotently accepts an existing same-SHA ref", () => {
117+
it("records immutable platform refs and resolves the recorded SHA through the CLI", () => {
118118
const fixture = createFixtureRepo();
119-
try {
120-
const options = {
121-
build: "8",
122-
command: "record" as const,
123-
platform: "ios" as const,
124-
remote: fixture.remote,
125-
rootDir: fixture.root,
126-
sha: "HEAD",
127-
version: "2026.6.10",
128-
versionCode: null,
129-
};
130-
131-
expect(preflightMobileReleaseRef(options).status).toBe("available");
132-
expect(recordMobileReleaseRef(options)).toMatchObject({
133-
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
134-
sha: fixture.sha,
135-
status: "created",
136-
});
137-
expect(recordMobileReleaseRef(options).status).toBe("already-recorded");
138-
expect(resolveMobileReleaseRef(options)).toMatchObject({
139-
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
140-
sha: fixture.sha,
141-
});
142-
} finally {
143-
fixture.cleanup();
144-
}
145-
});
146-
147-
it("rejects an existing ref at a different SHA", () => {
148-
const fixture = createFixtureRepo();
149-
try {
150-
const first = {
151-
build: null,
152-
command: "record" as const,
153-
platform: "android" as const,
154-
remote: fixture.remote,
155-
rootDir: fixture.root,
156-
sha: "HEAD",
157-
version: "2026.6.10",
158-
versionCode: "2026061008",
159-
};
160-
recordMobileReleaseRef(first);
161-
162-
writeFileSync(path.join(fixture.root, "README.md"), "next\n", "utf8");
163-
git(fixture.root, ["add", "README.md"]);
164-
git(fixture.root, ["commit", "-m", "next"]);
119+
const iosOptions = {
120+
build: "8",
121+
command: "record" as const,
122+
platform: "ios" as const,
123+
remote: fixture.remote,
124+
rootDir: fixture.root,
125+
sha: "HEAD",
126+
version: "2026.6.10",
127+
versionCode: null,
128+
};
129+
130+
expect(preflightMobileReleaseRef(iosOptions).status).toBe("available");
131+
expect(recordMobileReleaseRef(iosOptions)).toMatchObject({
132+
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
133+
sha: fixture.sha,
134+
status: "created",
135+
});
136+
expect(recordMobileReleaseRef(iosOptions).status).toBe("already-recorded");
137+
expect(resolveMobileReleaseRef(iosOptions)).toMatchObject({
138+
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
139+
sha: fixture.sha,
140+
});
165141

166-
expect(() => recordMobileReleaseRef(first)).toThrow("already points at");
167-
} finally {
168-
fixture.cleanup();
169-
}
170-
});
142+
const androidOptions = {
143+
build: null,
144+
command: "record" as const,
145+
platform: "android" as const,
146+
remote: fixture.remote,
147+
rootDir: fixture.root,
148+
sha: "HEAD",
149+
version: "2026.6.10",
150+
versionCode: "2026061008",
151+
};
152+
recordMobileReleaseRef(androidOptions);
153+
154+
writeFileSync(path.join(fixture.root, "README.md"), "next\n", "utf8");
155+
git(fixture.root, ["add", "README.md"]);
156+
git(fixture.root, ["commit", "-m", "next"]);
157+
158+
expect(() => recordMobileReleaseRef(androidOptions)).toThrow("already points at");
159+
160+
// CLI resolution must return the recorded build even after checkout HEAD advances.
161+
const stdout = run(
162+
process.execPath,
163+
[
164+
"--import",
165+
"tsx",
166+
SCRIPT_PATH,
167+
"resolve",
168+
"--platform",
169+
"ios",
170+
"--version",
171+
"2026.6.10",
172+
"--build",
173+
"8",
174+
"--root",
175+
fixture.root,
176+
],
177+
process.cwd(),
178+
);
171179

172-
it("prints the resolved SHA from the CLI", () => {
173-
const fixture = createFixtureRepo();
174-
try {
175-
recordMobileReleaseRef({
176-
build: "9",
177-
command: "record",
178-
platform: "ios",
179-
remote: fixture.remote,
180-
rootDir: fixture.root,
181-
sha: "HEAD",
182-
version: "2026.6.10",
183-
versionCode: null,
184-
});
185-
186-
const stdout = run(
187-
process.execPath,
188-
[
189-
"--import",
190-
"tsx",
191-
SCRIPT_PATH,
192-
"resolve",
193-
"--platform",
194-
"ios",
195-
"--version",
196-
"2026.6.10",
197-
"--build",
198-
"9",
199-
"--root",
200-
fixture.root,
201-
],
202-
process.cwd(),
203-
);
204-
205-
expect(stdout).toBe(`${fixture.sha}\trefs/openclaw/mobile-releases/ios/2026.6.10-9\n`);
206-
} finally {
207-
fixture.cleanup();
208-
}
180+
expect(stdout).toBe(`${fixture.sha}\trefs/openclaw/mobile-releases/ios/2026.6.10-8\n`);
209181
});
210182

211183
it("runs the CLI entrypoint from a path containing spaces", () => {
212-
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw mobile release ref-"));
213-
try {
214-
const scriptDir = path.join(root, "script dir");
215-
const scriptPath = path.join(scriptDir, "mobile-release-ref.ts");
216-
mkdirSync(scriptDir, { recursive: true });
217-
writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n', "utf8");
218-
copyFileSync(SCRIPT_PATH, scriptPath);
219-
220-
const stdout = run(
221-
process.execPath,
222-
["--import", "tsx", realpathSync(scriptPath), "--help"],
223-
process.cwd(),
224-
);
225-
226-
expect(stdout).toContain("scripts/mobile-release-ref.ts preflight");
227-
} finally {
228-
rmSync(root, { force: true, recursive: true });
229-
}
184+
const root = tempRoots.make("openclaw mobile release ref-");
185+
const scriptDir = path.join(root, "script dir");
186+
const scriptPath = path.join(scriptDir, "mobile-release-ref.ts");
187+
mkdirSync(scriptDir, { recursive: true });
188+
writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n', "utf8");
189+
copyFileSync(SCRIPT_PATH, scriptPath);
190+
191+
const stdout = run(
192+
process.execPath,
193+
["--import", "tsx", realpathSync(scriptPath), "--help"],
194+
process.cwd(),
195+
);
196+
197+
expect(stdout).toContain("scripts/mobile-release-ref.ts preflight");
230198
});
231199
});

0 commit comments

Comments
 (0)