Files
adolf/test/scripts/check-workflows.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

256 lines
9.5 KiB
TypeScript

// Check Workflows tests cover check workflows script behavior.
import { spawnSync } from "node:child_process";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
const scriptPath = path.resolve("scripts/check-workflows.mjs");
const tempDirs: string[] = [];
afterEach(() => {
cleanupTempDirs(tempDirs);
});
describe("check-workflows", () => {
it("prints an actionable diagnostic when actionlint and go are unavailable", () => {
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: {
...process.env,
PATH: "",
},
});
expect(result.status).toBe(1);
expect(result.stderr).toContain("missing workflow linter");
expect(result.stderr).toContain("install actionlint, Go");
});
it("uses the pinned go fallback and audits all workflows with zizmor", () => {
const tempDir = makeTempDir(tempDirs, "check-workflows-");
const binDir = path.join(tempDir, "bin");
const markerPath = path.join(tempDir, "go-run.txt");
const preCommitMarkerPath = path.join(tempDir, "pre-commit.txt");
mkdirSync(binDir);
writeFileSync(
path.join(binDir, "go"),
[
"#!/bin/sh",
'if [ "$1" = "version" ]; then exit 0; fi',
'if [ "$1" = "run" ]; then printf "%s\\n" "$*" > "$GO_FALLBACK_MARKER"; exit 0; fi',
"exit 1",
"",
].join("\n"),
{ mode: 0o755 },
);
writeFileSync(
path.join(binDir, "pre-commit"),
[
"#!/bin/sh",
'if [ "$1" = "--version" ]; then exit 0; fi',
'printf "%s\\n" "$*" >> "$PRE_COMMIT_MARKER"',
"exit 0",
"",
].join("\n"),
{ mode: 0o755 },
);
for (const command of ["python3", "node"]) {
writeFileSync(path.join(binDir, command), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
}
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: {
...process.env,
GO_FALLBACK_MARKER: markerPath,
PRE_COMMIT_MARKER: preCommitMarkerPath,
PATH: binDir,
},
});
expect(result.status).toBe(0);
expect(readFileSync(markerPath, "utf8")).toContain(
"github.com/rhysd/actionlint/cmd/actionlint@v1.7.11",
);
const preCommitArgs = readFileSync(preCommitMarkerPath, "utf8");
expect(preCommitArgs).toContain("run --config .pre-commit-config.yaml zizmor --files");
expect(preCommitArgs).toContain(".github/workflows/ci.yml");
expect(preCommitArgs).toContain(".github/workflows/windows-testbox-probe.yml");
});
it("bootstraps pinned pre-commit in a temporary Python venv when needed", () => {
const tempDir = makeTempDir(tempDirs, "check-workflows-");
const binDir = path.join(tempDir, "bin");
const markerPath = path.join(tempDir, "python.txt");
mkdirSync(binDir);
writeFileSync(path.join(binDir, "node"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
writeFileSync(
path.join(binDir, "python3"),
[
"#!/bin/sh",
'if [ "$1" = "--version" ]; then exit 0; fi',
'if [ "$1" = "-m" ] && [ "$2" = "pre_commit" ] && [ "$3" = "--version" ]; then exit 1; fi',
'if [ "$1" = "-m" ] && [ "$2" = "pip" ]; then',
' printf "%s\\n" "$*" >> "$PRE_COMMIT_BOOTSTRAP_MARKER"',
" exit 0",
"fi",
'if [ "$1" = "-m" ] && [ "$2" = "pre_commit" ]; then',
' printf "%s\\n" "$*" >> "$PRE_COMMIT_BOOTSTRAP_MARKER"',
" exit 0",
"fi",
'if [ "$1" = "-m" ] && [ "$2" = "venv" ]; then',
' /bin/mkdir -p "$3/bin"',
' /bin/cp "$0" "$3/bin/python"',
' /bin/chmod +x "$3/bin/python"',
" exit 0",
"fi",
"exit 0",
"",
].join("\n"),
{ mode: 0o755 },
);
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: {
...process.env,
PATH: binDir,
PRE_COMMIT_BOOTSTRAP_MARKER: markerPath,
},
});
expect(result.status).toBe(0);
const pythonArgs = readFileSync(markerPath, "utf8");
expect(pythonArgs).toContain("-m pip install --disable-pip-version-check pre-commit==4.2.0");
expect(pythonArgs).toContain(
"-m pre_commit run --config .pre-commit-config.yaml actionlint --files",
);
expect(pythonArgs).toContain(
"-m pre_commit run --config .pre-commit-config.yaml zizmor --files",
);
});
it("prints the missing runtime diagnostic when Python venv support is unavailable", () => {
const tempDir = makeTempDir(tempDirs, "check-workflows-");
const binDir = path.join(tempDir, "bin");
mkdirSync(binDir);
writeFileSync(path.join(binDir, "node"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
writeFileSync(
path.join(binDir, "python3"),
[
"#!/bin/sh",
'if [ "$1" = "--version" ]; then exit 0; fi',
'if [ "$1" = "-m" ] && [ "$2" = "pre_commit" ] && [ "$3" = "--version" ]; then exit 1; fi',
'if [ "$1" = "-m" ] && [ "$2" = "venv" ]; then',
' printf "%s\\n" "python venv unavailable" >&2',
" exit 1",
"fi",
"exit 1",
"",
].join("\n"),
{ mode: 0o755 },
);
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: {
...process.env,
PATH: binDir,
},
});
expect(result.status).toBe(1);
expect(result.stderr).toContain("python venv unavailable");
expect(result.stderr).toContain("missing pre-commit runtime for actionlint");
expect(result.stderr).toContain("Python venv support for pre-commit 4.2.0");
});
it("cleans the temporary Python venv before exiting on hook failure", () => {
const tempDir = makeTempDir(tempDirs, "check-workflows-");
const binDir = path.join(tempDir, "bin");
const markerPath = path.join(tempDir, "venv-path.txt");
mkdirSync(binDir);
writeFileSync(path.join(binDir, "node"), "#!/bin/sh\nexit 0\n", { mode: 0o755 });
writeFileSync(
path.join(binDir, "python3"),
[
"#!/bin/sh",
'if [ "$1" = "--version" ]; then exit 0; fi',
'if [ "$1" = "-m" ] && [ "$2" = "pre_commit" ] && [ "$3" = "--version" ]; then exit 1; fi',
'if [ "$1" = "-m" ] && [ "$2" = "venv" ]; then',
' /bin/mkdir -p "$3/bin"',
' /bin/cp "$0" "$3/bin/python"',
' /bin/chmod +x "$3/bin/python"',
' printf "%s\\n" "$3" > "$PRE_COMMIT_VENV_MARKER"',
" exit 0",
"fi",
'if [ "$1" = "-m" ] && [ "$2" = "pip" ]; then exit 0; fi',
'if [ "$1" = "-m" ] && [ "$2" = "pre_commit" ]; then',
' printf "%s\\n" "hook failed" >&2',
" exit 13",
"fi",
"exit 1",
"",
].join("\n"),
{ mode: 0o755 },
);
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
env: {
...process.env,
PATH: binDir,
PRE_COMMIT_VENV_MARKER: markerPath,
},
});
expect(result.status).toBe(13);
expect(result.stderr).toContain("hook failed");
expect(existsSync(readFileSync(markerPath, "utf8").trim())).toBe(false);
});
it("keeps Windows WSL2 probe output normalized through the shared wrapper", () => {
const workflow = readFileSync(".github/workflows/windows-testbox-probe.yml", "utf8");
expect(workflow).toContain(
'$import = Invoke-WslText -Arguments @("--import", "UbuntuProbe", $wslRoot, $rootfs, "--version", "2")',
);
expect(workflow).toContain("function Resolve-UbuntuWslRootfsUrl");
expect(workflow).toContain('"x64" { $wslArch = "amd64" }');
expect(workflow).toContain('"arm64" { $wslArch = "arm64" }');
expect(workflow).toContain("ubuntu-noble-wsl-$wslArch-wsl.rootfs.tar.gz");
expect(workflow).toContain("ubuntu_wsl_rootfs_arch=$wslArch");
expect(workflow).toContain('Write-Host "wsl_import_exit=$($import.Code)"');
expect(workflow).toContain("wsl2_restart_required=true");
expect(workflow).toContain("import_ubuntu_wsl2=skipped_restart_required");
expect(workflow).toContain("wsl_exec_skipped=restart_required");
expect(workflow).toContain(
'"wsl2_restart_required=$($restartRequired.ToString().ToLowerInvariant())"',
);
expect(workflow).toContain(
'$exec = Invoke-WslText -Arguments @("-d", $distro, "--exec", "bash", "-lc"',
);
expect(workflow).toContain('Write-Host "wsl_exec_exit=$($exec.Code)"');
expect(workflow).not.toContain("wsl.exe --import UbuntuProbe");
expect(workflow).not.toContain("Microsoft-Hyper-V-All");
});
it("keeps the Windows probe CI shard opt-in and dependency-backed", () => {
const workflow = readFileSync(".github/workflows/windows-testbox-probe.yml", "utf8");
expect(workflow).toContain("run_windows_ci:");
expect(workflow).toContain(
'description: "Run the focused Windows-native CI test shard after probing"',
);
expect(workflow).toContain("default: false");
expect(workflow).toContain("if: ${{ inputs.run_windows_ci }}");
expect(workflow).toContain("source .github/actions/setup-pnpm-store-cache/ensure-node.sh");
expect(workflow).toContain("uses: ./.github/actions/setup-pnpm-store-cache");
expect(workflow).toContain("pnpm install --frozen-lockfile --prefer-offline");
expect(workflow).toContain("pnpm test:windows:ci");
expect(workflow).toContain("if: ${{ always() && !cancelled() }}");
expect(workflow).toContain("if: ${{ always() && !cancelled() && inputs.require_wsl2 }}");
});
});