|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { readFileSync } from "node:fs"; |
| 4 | +import { test } from "node:test"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | +import { buildInputPatterns, isBuildAffected } from "./build-inputs.mjs"; |
| 7 | + |
| 8 | +const workflows = new Map([ |
| 9 | + ["desktop", "alpha-macos-aarch64.yml"], |
| 10 | + ["headless-runner", "celld-runner-deploy.yml"], |
| 11 | + ["review", "review-app-deploy.yml"], |
| 12 | +].map(([target, name]) => [target, readFileSync(new URL(`../workflows/${name}`, import.meta.url), "utf8")])); |
| 13 | + |
| 14 | +function job(workflow, name) { |
| 15 | + const body = workflow.split(`\n ${name}:\n`)[1]?.split(/\n [a-z][a-z0-9-]*:\n/)[0]; |
| 16 | + assert.ok(body, `Missing ${name} job`); |
| 17 | + return body; |
| 18 | +} |
| 19 | + |
| 20 | +for (const [target, workflow] of workflows) { |
| 21 | + test(`${target} classifies every dev push before requesting expensive runners or deployment approval`, () => { |
| 22 | + const triggers = workflow.split("\non:\n")[1]?.split("\npermissions:\n")[0]; |
| 23 | + assert.match(triggers, /push:[\s\S]*branches:[\s\S]*dev/); |
| 24 | + assert.match(triggers, /workflow_dispatch:/); |
| 25 | + // A copied workflow path list can filter a new graph edge out before the |
| 26 | + // dependency-aware classifier ever sees it. Only this cheap job is broad. |
| 27 | + assert.doesNotMatch(triggers, /^\s+paths(?:-ignore)?:/m); |
| 28 | + // Workflow-level locks would let an unrelated broad-trigger push cancel a |
| 29 | + // running build or replace a queued deployment before classification. |
| 30 | + assert.doesNotMatch(workflow.split("\njobs:\n")[0], /^concurrency:/m); |
| 31 | + |
| 32 | + const changes = job(workflow, "changes"); |
| 33 | + assert.match(changes, /runs-on: ubuntu-latest/); |
| 34 | + assert.match(changes, /affected: \$\{\{ steps\.classify\.outputs\.affected \}\}/); |
| 35 | + assert.match(changes, /persist-credentials: false/); |
| 36 | + assert.match(changes, /node-version: 24\.22\.1/); |
| 37 | + assert.match(changes, /BUILD_BASE: \$\{\{ github\.event\.before \}\}/); |
| 38 | + assert.match(changes, /BUILD_HEAD: \$\{\{ github\.sha \}\}/); |
| 39 | + assert.ok(changes.includes(`node .github/scripts/build-inputs.mjs --target ${target} --base "\${BUILD_BASE:-${"0".repeat(40)}}" --head "$BUILD_HEAD"`)); |
| 40 | + assert.doesNotMatch(changes, /\bpnpm\b|setup-bun|environment:|secrets\.|swift build|celld deploy|vercel@/); |
| 41 | + assert.equal(isBuildAffected(target, null), true, "Unknown comparisons must run, including dispatches without a push base"); |
| 42 | + assert.equal(isBuildAffected(target, []), false); |
| 43 | + assert.ok(buildInputPatterns(target).includes(".github/scripts/build-inputs.mjs")); |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +test("the workflow CLI commands force manual builds but skip a known empty push range", () => { |
| 48 | + for (const [target, workflow] of workflows) { |
| 49 | + const command = job(workflow, "changes").match(/^ run: (node .*)$/m)?.[1]; |
| 50 | + assert.ok(command, target); |
| 51 | + for (const [base, affected] of [["", true], ["HEAD", false]]) { |
| 52 | + const result = spawnSync("bash", ["-euc", command], { |
| 53 | + cwd: fileURLToPath(new URL("../../", import.meta.url)), |
| 54 | + env: { ...process.env, BUILD_BASE: base, BUILD_HEAD: "HEAD", GITHUB_OUTPUT: "", GITHUB_ACTIONS: "false" }, |
| 55 | + encoding: "utf8", |
| 56 | + timeout: 30_000, |
| 57 | + }); |
| 58 | + assert.equal(result.status, 0, `${target}: ${result.stderr}`); |
| 59 | + assert.ok(result.stdout.split("\n").includes(`affected=${affected}`), `${target}: ${result.stdout}`); |
| 60 | + assert.match(result.stdout, /fingerprint=[a-f0-9]{64}/); |
| 61 | + } |
| 62 | + } |
| 63 | +}); |
| 64 | + |
| 65 | +test("both alpha platforms depend on the desktop scope while retaining manual platform selection", () => { |
| 66 | + const workflow = workflows.get("desktop"); |
| 67 | + for (const [name, otherPlatform] of [ |
| 68 | + ["publish-alpha-macos-aarch64", "windows-x64"], |
| 69 | + ["publish-alpha-windows-x64", "macos-arm64"], |
| 70 | + ]) { |
| 71 | + const publish = job(workflow, name); |
| 72 | + assert.match(publish, /needs: changes/); |
| 73 | + assert.ok(publish.includes(`if: needs.changes.outputs.affected == 'true' && (github.event_name == 'push' || inputs.platform != '${otherPlatform}')`)); |
| 74 | + assert.match(publish, /pnpm --filter @openwork\/desktop\.\.\. --filter @openwork\/app\.\.\. --filter openwork-server\.\.\. install --frozen-lockfile --prefer-offline/); |
| 75 | + } |
| 76 | +}); |
| 77 | + |
| 78 | +test("deployment scope gates retain repository, environment and authentication checks", () => { |
| 79 | + const runner = job(workflows.get("headless-runner"), "deploy"); |
| 80 | + const review = job(workflows.get("review"), "deploy"); |
| 81 | + for (const deploy of [runner, review]) { |
| 82 | + assert.match(deploy, /needs: changes/); |
| 83 | + assert.match(deploy, /github\.repository == 'different-ai\/openwork'/); |
| 84 | + assert.match(deploy, /needs\.changes\.outputs\.affected == 'true'/); |
| 85 | + } |
| 86 | + assert.match(runner, /concurrency:\n group: celld-runner-deploy\n cancel-in-progress: false/); |
| 87 | + assert.match(review, /concurrency:\n group: review-app-deploy\n cancel-in-progress: false/); |
| 88 | + assert.match(runner, /environment: celld-production/); |
| 89 | + assert.match(runner, /name: Check the live runner and this one can serve each other/); |
| 90 | + assert.match(runner, /name: Preflight on a throwaway prefix/); |
| 91 | + assert.match(runner, /name: Wait for every node to adopt it/); |
| 92 | + assert.match(review, /name: review-app/); |
| 93 | + assert.match(review, /vars\.OPENWORK_REVIEW_URL != ''/); |
| 94 | + assert.match(review, /vars\.OPENWORK_REVIEW_VERCEL_ORG_ID != ''/); |
| 95 | + assert.match(review, /vars\.OPENWORK_REVIEW_VERCEL_PROJECT_ID != ''/); |
| 96 | + assert.match(review, /name: Verify the alias still requires Vercel Authentication/); |
| 97 | +}); |
| 98 | + |
| 99 | +test("Electron source selects desktop packaging, not backend builds or deployments", () => { |
| 100 | + const files = ["apps/desktop/electron/main.mjs"]; |
| 101 | + assert.equal(isBuildAffected("desktop", files), true); |
| 102 | + for (const target of ["den-api", "den-web", "inference", "client-web", "workbot", "headless-runner", "review", "swift"]) { |
| 103 | + assert.equal(isBuildAffected(target, files), false, target); |
| 104 | + } |
| 105 | +}); |
| 106 | + |
| 107 | +test("alpha includes transitive workspace packages and native/release inputs", () => { |
| 108 | + for (const path of [ |
| 109 | + "packages/browser-tabs/src/index.ts", |
| 110 | + "packages/remote-sessions/src/index.ts", |
| 111 | + "packages/sandbox-freestyle/src/index.ts", |
| 112 | + "packages/codemode/src/index.ts", |
| 113 | + "packages/free-auto/src/index.ts", |
| 114 | + "packages/headless-threads/src/index.ts", |
| 115 | + "packages/computer-use/native/Sources/ComputerUse/main.swift", |
| 116 | + ".github/actions/windows-signing/action.yml", |
| 117 | + "scripts/release/stamp-version.mjs", |
| 118 | + ".github/workflows/alpha-macos-aarch64.yml", |
| 119 | + ]) { |
| 120 | + assert.equal(isBuildAffected("desktop", [path]), true, path); |
| 121 | + } |
| 122 | +}); |
| 123 | + |
| 124 | +test("embedded docs include Markdown, MDX and navigation, not screenshots or website-only files", () => { |
| 125 | + for (const path of [ |
| 126 | + "packages/docs/start-here/overview.md", |
| 127 | + "packages/docs/cloud/run-in-the-cloud/cloud-mcp.mdx", |
| 128 | + "packages/docs/docs.json", |
| 129 | + ]) { |
| 130 | + assert.equal(isBuildAffected("desktop", [path]), true, path); |
| 131 | + } |
| 132 | + for (const path of [ |
| 133 | + "packages/docs/images/screenshot.png", |
| 134 | + "packages/docs/images/screenshot.svg", |
| 135 | + "packages/docs/openapi.json", |
| 136 | + "docs/codeql-results.md", |
| 137 | + "ee/apps/landing/app/page.tsx", |
| 138 | + ]) { |
| 139 | + assert.equal(isBuildAffected("desktop", [path]), false, path); |
| 140 | + } |
| 141 | +}); |
| 142 | + |
| 143 | +test("review follows all evidence dependencies and its external shared-color import", () => { |
| 144 | + for (const path of [ |
| 145 | + "apps/review/app/page.tsx", |
| 146 | + "packages/review/src/schema.ts", |
| 147 | + "packages/evidence-provider/src/provider.ts", |
| 148 | + "packages/daytona-evidence/src/review-provider.ts", |
| 149 | + "packages/freestyle/src/builder.ts", |
| 150 | + "apps/app/src/styles/colors.css", |
| 151 | + ".vercelignore", |
| 152 | + ".github/workflows/review-app-deploy.yml", |
| 153 | + ]) { |
| 154 | + assert.equal(isBuildAffected("review", [path]), true, path); |
| 155 | + } |
| 156 | + for (const path of ["apps/app/src/app.tsx", "apps/app/src/styles/base.css", "ee/apps/landing/app/page.tsx"]) { |
| 157 | + assert.equal(isBuildAffected("review", [path]), false, path); |
| 158 | + } |
| 159 | +}); |
| 160 | + |
| 161 | +test("celld includes the runner's transitive dependencies and desktop-image cross-file edge", () => { |
| 162 | + for (const path of [ |
| 163 | + "ee/apps/headless-runner/scripts/celld-bundle.ts", |
| 164 | + "ee/packages/headless-protocol/src/index.ts", |
| 165 | + "ee/packages/headless-computer/scripts/desktop-identity.mjs", |
| 166 | + "packages/workbook/src/index.ts", |
| 167 | + "packages/sandbox/src/index.ts", |
| 168 | + "packages/sandbox-freestyle/src/index.ts", |
| 169 | + "packages/sandbox-daytona/src/index.ts", |
| 170 | + "packages/sandbox-differently/src/index.ts", |
| 171 | + "packages/computer-use/computer-x11-driver.mjs", |
| 172 | + "packages/codemode/src/index.ts", |
| 173 | + "packages/types/src/browser-demonstration.ts", |
| 174 | + "ee/apps/den-worker-runtime/scripts/cloud-desktop.sh", |
| 175 | + ".github/workflows/celld-runner-deploy.yml", |
| 176 | + ]) { |
| 177 | + assert.equal(isBuildAffected("headless-runner", [path]), true, path); |
| 178 | + } |
| 179 | + for (const path of ["ee/apps/den-worker-runtime/src/index.ts", "ee/apps/workbot/src/index.ts", "apps/desktop/electron/main.mjs"]) { |
| 180 | + assert.equal(isBuildAffected("headless-runner", [path]), false, path); |
| 181 | + } |
| 182 | +}); |
| 183 | + |
| 184 | +test("every native deployment includes its dependency configuration and classifier", () => { |
| 185 | + for (const target of workflows.keys()) { |
| 186 | + for (const path of ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", ".npmrc", "patches/example.patch", ".github/scripts/build-inputs.mjs"]) { |
| 187 | + assert.equal(isBuildAffected(target, [path]), true, `${target}: ${path}`); |
| 188 | + } |
| 189 | + } |
| 190 | +}); |
0 commit comments