import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { parseArgs, releaseEvidenceVerificationArgs, releaseEvidenceVerifierPath, } from "../../scripts/full-release-validation-at-sha.mjs"; describe("full-release-validation-at-sha", () => { it("parses release validation dispatch args", () => { expect( parseArgs([ "--sha", "abc123", "--workflow-sha", "origin/main", "--keep-branch", "--dry-run", "-f", "provider=anthropic", "--", "mode=linux", ]), ).toMatchObject({ dryRun: true, keepBranch: true, inputs: { mode: "linux", provider: "anthropic", reuse_evidence: "true", }, sha: "abc123", workflowSha: "origin/main", }); }); it("rejects missing option values", () => { expect(() => parseArgs(["--sha", "--dry-run"])).toThrow("--sha requires a value"); expect(() => parseArgs(["--sha", "-h"])).toThrow("--sha requires a value"); expect(() => parseArgs(["--workflow-sha", "--dry-run"])).toThrow( "--workflow-sha requires a value", ); expect(() => parseArgs(["--workflow-sha", "-h"])).toThrow("--workflow-sha requires a value"); expect(() => parseArgs(["-f", "--dry-run"])).toThrow("-f requires a value"); expect(() => parseArgs(["-f", "-h"])).toThrow("-f requires a value"); }); it("allows exact-target reuse to be disabled for a forced fresh run", () => { expect(parseArgs(["-f", "reuse_evidence=false"]).inputs.reuse_evidence).toBe("false"); expect(() => parseArgs(["-f", "reuse_evidence=maybe"])).toThrow( "reuse_evidence must be true or false", ); }); it("reserves the candidate ref for the resolved --sha", () => { expect(() => parseArgs(["-f", "ref=other"])).toThrow("reserves the ref input"); expect(() => parseArgs(["--", "ref=other"])).toThrow("reserves the ref input"); }); it("validates direct and reused runs through the strict evidence verifier", () => { expect(releaseEvidenceVerificationArgs("123")).toEqual([ "--validate-run", "123", "--trusted-workflow-ref", "main", "--json", ]); expect(() => releaseEvidenceVerificationArgs("")).toThrow("positive decimal"); }); it("supports current and legacy verifier locations in trusted workflow checkouts", () => { const root = mkdtempSync(join(tmpdir(), "openclaw-release-verifier-path-")); try { const legacy = join( root, ".agents", "skills", "release-openclaw-ci", "scripts", "release-ci-summary.mjs", ); mkdirSync(join(legacy, ".."), { recursive: true }); writeFileSync(legacy, ""); expect(releaseEvidenceVerifierPath(root)).toBe(legacy); const current = join(root, "scripts", "release-ci-summary.mjs"); mkdirSync(join(current, ".."), { recursive: true }); writeFileSync(current, ""); expect(releaseEvidenceVerifierPath(root)).toBe(current); } finally { rmSync(root, { force: true, recursive: true }); } }); });