Files
adolf/test/scripts/mobile-release-ref.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

232 lines
6.7 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { copyFileSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
mobileReleaseRefFor,
parseArgs,
preflightMobileReleaseRef,
recordMobileReleaseRef,
resolveMobileReleaseRef,
} from "../../scripts/mobile-release-ref.ts";
const SCRIPT_PATH = path.join(process.cwd(), "scripts", "mobile-release-ref.ts");
function run(command: string, args: string[], cwd: string): string {
return execFileSync(command, args, {
cwd,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
});
}
function git(cwd: string, args: string[]): string {
return run("git", args, cwd);
}
function createFixtureRepo(): { cleanup: () => void; remote: string; root: string; sha: string } {
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-mobile-release-ref-"));
const remote = path.join(root, "remote.git");
const checkout = path.join(root, "checkout");
git(root, ["init", "--bare", remote]);
git(root, ["clone", remote, checkout]);
git(checkout, ["config", "user.email", "release@example.com"]);
git(checkout, ["config", "user.name", "Release Test"]);
writeFileSync(path.join(checkout, "README.md"), "release\n", "utf8");
git(checkout, ["add", "README.md"]);
git(checkout, ["commit", "-m", "initial"]);
const sha = git(checkout, ["rev-parse", "HEAD"]).trim();
git(checkout, ["push", "origin", "HEAD:main"]);
return {
cleanup: () => rmSync(root, { force: true, recursive: true }),
remote: "origin",
root: checkout,
sha,
};
}
describe("mobile-release-ref", () => {
it("renders platform release refs from store identities", () => {
expect(mobileReleaseRefFor({ platform: "ios", version: "2026.6.10", build: "8" })).toBe(
"refs/openclaw/mobile-releases/ios/2026.6.10-8",
);
expect(
mobileReleaseRefFor({
platform: "android",
version: "2026.6.10",
versionCode: "2026061008",
}),
).toBe("refs/openclaw/mobile-releases/android/2026.6.10-2026061008");
});
it("validates platform-specific numeric identities", () => {
expect(() =>
mobileReleaseRefFor({ platform: "ios", version: "2026.6.10", build: "0" }),
).toThrow("Invalid iOS build");
expect(() =>
mobileReleaseRefFor({
platform: "android",
version: "2026.6.10",
versionCode: "not-a-code",
}),
).toThrow("Invalid Android versionCode");
expect(() =>
mobileReleaseRefFor({
platform: "android",
version: "2026.6.10",
versionCode: "2026061101",
}),
).toThrow("Expected 2026061001 through 2026061099");
expect(() =>
mobileReleaseRefFor({ platform: "ios", version: "2026.06.10", build: "8" }),
).toThrow("Invalid mobile release version");
});
it("parses CLI commands and rejects missing platform-specific fields", () => {
expect(
parseArgs([
"record",
"--",
"--platform",
"android",
"--version",
"2026.6.10",
"--version-code",
"2026061008",
"--sha",
"HEAD",
]),
).toMatchObject({
command: "record",
platform: "android",
version: "2026.6.10",
versionCode: "2026061008",
});
expect(() =>
mobileReleaseRefFor({
platform: "android",
version: "2026.6.10",
}),
).toThrow("Invalid Android versionCode");
});
it("creates, resolves, and idempotently accepts an existing same-SHA ref", () => {
const fixture = createFixtureRepo();
try {
const options = {
build: "8",
command: "record" as const,
platform: "ios" as const,
remote: fixture.remote,
rootDir: fixture.root,
sha: "HEAD",
version: "2026.6.10",
versionCode: null,
};
expect(preflightMobileReleaseRef(options).status).toBe("available");
expect(recordMobileReleaseRef(options)).toMatchObject({
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
sha: fixture.sha,
status: "created",
});
expect(recordMobileReleaseRef(options).status).toBe("already-recorded");
expect(resolveMobileReleaseRef(options)).toMatchObject({
ref: "refs/openclaw/mobile-releases/ios/2026.6.10-8",
sha: fixture.sha,
});
} finally {
fixture.cleanup();
}
});
it("rejects an existing ref at a different SHA", () => {
const fixture = createFixtureRepo();
try {
const first = {
build: null,
command: "record" as const,
platform: "android" as const,
remote: fixture.remote,
rootDir: fixture.root,
sha: "HEAD",
version: "2026.6.10",
versionCode: "2026061008",
};
recordMobileReleaseRef(first);
writeFileSync(path.join(fixture.root, "README.md"), "next\n", "utf8");
git(fixture.root, ["add", "README.md"]);
git(fixture.root, ["commit", "-m", "next"]);
expect(() => recordMobileReleaseRef(first)).toThrow("already points at");
} finally {
fixture.cleanup();
}
});
it("prints the resolved SHA from the CLI", () => {
const fixture = createFixtureRepo();
try {
recordMobileReleaseRef({
build: "9",
command: "record",
platform: "ios",
remote: fixture.remote,
rootDir: fixture.root,
sha: "HEAD",
version: "2026.6.10",
versionCode: null,
});
const stdout = run(
process.execPath,
[
"--import",
"tsx",
SCRIPT_PATH,
"resolve",
"--platform",
"ios",
"--version",
"2026.6.10",
"--build",
"9",
"--root",
fixture.root,
],
process.cwd(),
);
expect(stdout).toBe(`${fixture.sha}\trefs/openclaw/mobile-releases/ios/2026.6.10-9\n`);
} finally {
fixture.cleanup();
}
});
it("runs the CLI entrypoint from a path containing spaces", () => {
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw mobile release ref-"));
try {
const scriptDir = path.join(root, "script dir");
const scriptPath = path.join(scriptDir, "mobile-release-ref.ts");
mkdirSync(scriptDir, { recursive: true });
writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n', "utf8");
copyFileSync(SCRIPT_PATH, scriptPath);
const stdout = run(
process.execPath,
["--import", "tsx", realpathSync(scriptPath), "--help"],
process.cwd(),
);
expect(stdout).toContain("scripts/mobile-release-ref.ts preflight");
} finally {
rmSync(root, { force: true, recursive: true });
}
});
});