Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7404: ci: scope validation and remove duplicate lifecycle runs (#8451)
Jiayuan Zhangd7f8c3f2b667
diff --git a/.github/actions/frontend-quality/action.yml b/.github/actions/frontend-quality/action.ymlnew file mode 100644index 0000000000..ac36b44a9f--- /dev/null+++ b/.github/actions/frontend-quality/action.yml@@ -0,0 +1,22 @@+name: Frontend quality+description: Shared UI checks using the caller's installed dependencies+runs:+ using: composite+ steps:+ - name: Check packages/ui wildcard exports+ shell: bash+ run: |+ bash scripts/check-ui-wildcard-exports.test.sh+ node scripts/check-ui-wildcard-exports.mjs++ - name: Check UI radius tokens+ shell: bash+ run: |+ node --test scripts/check-ui-radius-tokens.test.mjs+ node scripts/check-ui-radius-tokens.mjs++ # Keep existing knip findings advisory in either caller.+ - name: Check for dead code and phantom dependencies (knip)+ continue-on-error: true+ shell: bash+ run: pnpm knipdiff --git a/.github/ci-paths.json b/.github/ci-paths.jsonnew file mode 100644index 0000000000..a67b6a9e29--- /dev/null+++ b/.github/ci-paths.json@@ -0,0 +1,138 @@+{+ "frontend": [+ ".github/actions/frontend-quality/**",+ "apps/web/**",+ "apps/desktop/**",+ "packages/**",+ "package.json",+ ".npmrc",+ "pnpm-lock.yaml",+ "pnpm-workspace.yaml",+ "patches/**",+ "turbo.json",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "backend": [+ "server/**",+ "packages/core/runtimes/cli-version.ts",+ "scripts/agent-cli-command-names.txt",+ "scripts/go-test-with-agent-cli-guard.sh",+ "scripts/test-go.sh",+ "scripts/test-go.test.sh",+ "Makefile",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "sqlc": [+ "server/pkg/db/queries/**",+ "server/pkg/db/generated/**",+ "server/migrations/**",+ "server/sqlc.yaml",+ "Makefile",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "runtime": [+ "packages/core/runtimes/cli-version.ts",+ "scripts/agent-cli-command-names.txt",+ "scripts/go-test-with-agent-cli-guard.sh",+ "scripts/test-go.sh",+ "scripts/test-go.test.sh",+ ".github/workflows/ci.yml",+ "server/internal/**",+ "server/pkg/**",+ "server/cmd/**",+ "server/go.mod",+ "server/go.sum",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "quality": [+ ".github/actions/frontend-quality/**",+ "apps/**",+ "packages/**",+ "package.json",+ ".npmrc",+ "pnpm-lock.yaml",+ "pnpm-workspace.yaml",+ "patches/**",+ "turbo.json",+ "knip.jsonc",+ "scripts/*.mjs",+ "scripts/check-ui-wildcard-exports.test.sh",+ ".github/workflows/mobile-verify.yml",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json"+ ],+ "scripts": [+ "scripts/generate-reserved-slugs.mjs",+ "scripts/selfhost-config.test.sh",+ "scripts/drop-database.sh",+ "scripts/remove-worktree.sh",+ "scripts/worktree-db.test.sh",+ "scripts/dev-env.sh",+ "scripts/dev-env.test.sh",+ "scripts/perf-compare.mjs",+ "scripts/perf-compare.test.sh",+ "scripts/selfhost-wait.sh",+ "scripts/install.sh",+ "scripts/install.ps1",+ "scripts/check.sh",+ "scripts/dev.sh",+ "scripts/local-env.sh",+ "scripts/init-worktree-env.sh",+ "scripts/local-env.test.sh",+ "scripts/helm-config.test.sh",+ "scripts/entrypoint.test.sh",+ "scripts/makefile-build.test.sh",+ "deploy/helm/**",+ "docker/entrypoint.sh",+ ".env.example",+ "docker-compose.selfhost.yml",+ "docker-compose.selfhost.build.yml",+ "Makefile",+ "server/internal/handler/reserved_slugs.json",+ "packages/core/paths/reserved-slugs.ts",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "installer": [+ "scripts/install.sh",+ "scripts/install.test.sh",+ "scripts/install.ps1",+ "scripts/install.ps1.test.ps1",+ ".env.example",+ "docker-compose.selfhost.yml",+ "docker-compose.selfhost.build.yml",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ],+ "images": [+ "**/*.png",+ "**/*.jpg",+ "**/*.jpeg",+ "**/*.gif",+ "**/*.bmp",+ "**/*.tif",+ "**/*.tiff",+ "**/*.webp",+ "**/*.avif",+ "scripts/check-image-budget.mjs",+ ".github/workflows/ci.yml",+ ".github/ci-paths.json",+ "scripts/ci-scope.mjs",+ "scripts/ci-scope.test.mjs"+ ]+}diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 1f9fae993b..af77976155 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -5,20 +5,24 @@ on:branches: [main]pull_request:branches: [main]+ schedule:+ - cron: "23 3 * * *"+ workflow_dispatch:concurrency:- group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}+ group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}cancel-in-progress: truejobs:+ # Linux is already covered by the two full backend race suites.cursor-background-lifecycle:needs: changes- if: ${{ needs.changes.outputs.backend == 'true' }}+ if: ${{ needs.changes.outputs.runtime == 'true' }}runs-on: ${{ matrix.os }}strategy:fail-fast: falsematrix:- os: [ubuntu-latest, macos-latest, windows-latest]+ os: [macos-latest, windows-latest]steps:- uses: actions/checkout@v6- uses: actions/setup-go@v5@@ -33,24 +37,26 @@ jobs:run: |go test -race ./pkg/agent -v -run 'TestCursorBackground|TestCaptureCursorBackground' -count=1go test -race ./internal/daemon -v -run 'Test.*Background.*Watchdog|Test.*IdleWatchdog' -count=1- - name: Repeat macOS finalization and verify cgo-free ownership- if: runner.os == 'macOS'+ - name: Verify macOS finalization without race instrumentation+ if: runner.os == 'macOS' && needs.changes.outputs.full != 'true'+ working-directory: server+ run: go test ./pkg/agent -run '^TestCursorBackgroundLifecycle/finish$' -count=1++ - name: Stress macOS finalization+ if: runner.os == 'macOS' && needs.changes.outputs.full == 'true'shell: bashworking-directory: serverrun: |go test ./pkg/agent -run '^TestCursorBackgroundLifecycle/finish$' -count=5go test -race ./pkg/agent -run '^TestCursorBackgroundLifecycle/finish$' -count=5- CGO_ENABLED=0 go test ./pkg/agent -run '^TestCaptureCursorBackground(KernelRejectsStaleIdentity|DetachedSession|LateDescendant)$' -count=1-- # Decides whether the heavy frontend validation jobs, the backend Go jobs- # and sqlc verification have anything to do.- # The frontend jobs validate the web/desktop apps, the shared packages,- # the install graph, and the selfhost / reserved-slugs scripts it runs;- # a pure backend-only or docs-only PR touches none of those and gains- # nothing from a full web build. Symmetrically, the backend jobs compile- # and test server/, so a frontend-only or docs-only PR gains nothing from- # a `go test -race` run. The outputs are consumed by the focused jobs- # below.+ - name: Verify cgo-free macOS ownership+ if: runner.os == 'macOS'+ shell: bash+ working-directory: server+ run: CGO_ENABLED=0 go test ./pkg/agent -run '^TestCaptureCursorBackground(KernelRejectsStaleIdentity|DetachedSession|LateDescendant)$' -count=1++ # PRs and main pushes use the same paths. Scheduled/manual runs validate all+ # scopes, including platform stress tests, without charging every merge for them.changes:runs-on: ubuntu-latestpermissions:@@ -60,155 +66,51 @@ jobs:frontend: ${{ steps.decide.outputs.frontend }}backend: ${{ steps.decide.outputs.backend }}sqlc: ${{ steps.decide.outputs.sqlc }}- images: ${{ steps.filter.outputs.images }}+ runtime: ${{ steps.decide.outputs.runtime }}+ quality_only: ${{ steps.decide.outputs.quality_only }}+ scripts: ${{ steps.decide.outputs.scripts }}+ installer: ${{ steps.decide.outputs.installer }}+ images: ${{ steps.decide.outputs.images }}+ full: ${{ steps.decide.outputs.full }}steps:- name: Checkoutuses: actions/checkout@v6+ - name: Setup Node.js+ uses: actions/setup-node@v6+ with:+ node-version: 22++ - name: Test CI selection and gates+ run: node --test scripts/ci-scope.test.mjs scripts/check-image-budget.test.mjs+- name: Filter pathsid: filter+ if: github.event_name == 'pull_request' || github.event_name == 'push'uses: dorny/paths-filter@v3with:- # apps/docs is excluded from the frontend turbo run, but knip does- # analyze it, so a docs-only change still needs this job.- # apps/mobile has its own mobile-verify workflow. Everything else- # the frontend job touches is listed here; bias toward- # over-matching since a missed path silently skips validation.- filters: |- frontend:- - 'apps/web/**'- - 'apps/desktop/**'- - 'apps/docs/**'- - 'packages/**'- - 'package.json'- - '.npmrc'- - 'pnpm-lock.yaml'- - 'pnpm-workspace.yaml'- - 'turbo.json'- - 'knip.jsonc'- - '.github/workflows/ci.yml'- - 'scripts/generate-reserved-slugs.mjs'- - 'server/internal/handler/reserved_slugs.json'- - 'scripts/check-ui-wildcard-exports.mjs'- - 'scripts/check-ui-wildcard-exports.test.sh'- - 'scripts/check-ui-radius-tokens.mjs'- - 'scripts/check-ui-radius-tokens.test.mjs'- - 'scripts/selfhost-config.test.sh'- - 'scripts/drop-database.sh'- - 'scripts/remove-worktree.sh'- - 'scripts/worktree-db.test.sh'- - 'scripts/dev-env.sh'- - 'scripts/dev-env.test.sh'- - 'scripts/perf-compare.mjs'- - 'scripts/perf-compare.test.sh'- - 'scripts/selfhost-wait.sh'- # selfhost-config.test.sh asserts on the installers' side of- # the port contract, so a change to either must run it.- - 'scripts/install.sh'- - 'scripts/install.ps1'- - 'scripts/check.sh'- - 'scripts/dev.sh'- - 'scripts/local-env.sh'- - '.env.example'- - 'docker-compose.selfhost.yml'- - 'docker-compose.selfhost.build.yml'- - 'Makefile'- # Everything the backend jobs (backend-tests, backend-agent-tests,- # go-vulnerability-scan, windows-execenv) read, which is NOT the- # same thing as server/**: four Go tests reach out of the module- # to pin a contract against a file the other side owns, across- # three cross-module file dependencies. Each of those files has- # to be listed here or the PR that breaks the contract is exactly- # the PR that skips the test. Same bias as the frontend filter:- # over-match rather than silently skip validation.- backend:- - 'server/**'- - 'deploy/helm/**'- # pkg/agent/worktree_capability_contract_test.go reads this file- # and compares LOCAL_WORKTREE_CAPABILITY against the daemon's- # protocol constant. A typo on either side disables worktree- # mode for everyone with no error anywhere, so a change to the- # frontend half must run the backend suite.- - 'packages/core/runtimes/cli-version.ts'- # internal/daemon/agent_command_names_test.go exercises the- # guard script; scripts/test-go.sh also uses it as the backend- # test entry point, and the script reads the command names file.- - 'scripts/agent-cli-command-names.txt'- - 'scripts/go-test-with-agent-cli-guard.sh'- - 'scripts/helm-config.test.sh'- - 'scripts/entrypoint.test.sh'- - 'docker/entrypoint.sh'- - 'scripts/test-go.sh'- - 'scripts/test-go.test.sh'- # makefile-build.test.sh asserts how `make build` names its- # output binaries, so a change to either side must run it.- - 'scripts/makefile-build.test.sh'- - 'Makefile'- - '.github/workflows/ci.yml'- sqlc:- - 'server/pkg/db/queries/**'- - 'server/pkg/db/generated/**'- - 'server/migrations/**'- - 'server/sqlc.yaml'- - 'Makefile'- - '.github/workflows/ci.yml'- # Gates the image-budget job so the full-history checkout it- # needs is only paid for on PRs that actually touch a bitmap.- images:- - '**/*.png'- - '**/*.jpg'- - '**/*.jpeg'- - '**/*.gif'- - '**/*.bmp'- - '**/*.tif'- - '**/*.tiff'- - '**/*.webp'- - '**/*.avif'- - 'scripts/check-image-budget.mjs'+ # Pushes compare before/head SHAs. PRs use the pull-request file API;+ # paths-filter ignores base/ref for pull_request events.+ base: ${{ github.event_name == 'push' && github.event.before || github.base_ref }}+ ref: ${{ github.sha }}+ filters: .github/ci-paths.json- name: Decideid: decide- # Always run everything on push to main (full validation); on- # pull_request, run only the areas whose paths changed.- # The gated jobs themselves always run and report success — their- # steps are gated on these outputs rather than the job being skipped- # — so the required "frontend" / "backend" status checks are- # satisfied with a genuine green instead of being left pending on- # filtered PRs. It also keeps the aggregate gates strict: a job that- # goes missing for any OTHER reason (a failed `changes`, a cancelled- # run) still reports non-success and fails the gate.env:EVENT_NAME: ${{ github.event_name }}- FRONTEND_CHANGED: ${{ steps.filter.outputs.frontend }}- BACKEND_CHANGED: ${{ steps.filter.outputs.backend }}- SQLC_CHANGED: ${{ steps.filter.outputs.sqlc }}- run: |- if [ "$EVENT_NAME" != "pull_request" ] || [ "$FRONTEND_CHANGED" = "true" ]; then- echo "frontend=true" >> "$GITHUB_OUTPUT"- else- echo "frontend=false" >> "$GITHUB_OUTPUT"- fi- if [ "$EVENT_NAME" != "pull_request" ] || [ "$BACKEND_CHANGED" = "true" ]; then- echo "backend=true" >> "$GITHUB_OUTPUT"- else- echo "backend=false" >> "$GITHUB_OUTPUT"- fi- if [ "$EVENT_NAME" != "pull_request" ] || [ "$SQLC_CHANGED" = "true" ]; then- echo "sqlc=true" >> "$GITHUB_OUTPUT"- else- echo "sqlc=false" >> "$GITHUB_OUTPUT"- fi+ FILTER_RESULTS: ${{ toJSON(steps.filter.outputs) }}+ run: node scripts/ci-scope.mjs decidesqlc-check:needs: changes+ if: ${{ needs.changes.outputs.sqlc == 'true' }}runs-on: ubuntu-lateststeps:- name: Checkout- if: ${{ needs.changes.outputs.sqlc == 'true' }}uses: actions/checkout@v6- name: Setup Go- if: ${{ needs.changes.outputs.sqlc == 'true' }}uses: actions/setup-go@v5with:go-version: "1.26.x"@@ -216,7 +118,6 @@ jobs:cache-dependency-path: server/go.sum- name: Verify generated SQL is up to date- if: ${{ needs.changes.outputs.sqlc == 'true' }}run: |make sqlcgit diff --exit-code -- server/pkg/db/generated@@ -236,28 +137,25 @@ jobs:# increases total runner-minutes but reduces wall-clock feedback time.frontend-build:needs: changes+ if: ${{ needs.changes.outputs.frontend == 'true' }}runs-on: ubuntu-latestenv:# Pin turbo's filesystem cache somewhere actions/cache can address.TURBO_CACHE_DIR: .turbo/cachesteps:- name: Checkout- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/checkout@v6- name: Setup pnpm- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: pnpm/action-setup@v4- name: Setup Node.js- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/setup-node@v6with:node-version: 22cache: pnpm- name: Install dependencies- if: ${{ needs.changes.outputs.frontend == 'true' }}run: pnpm install# `node-version: 22` above floats across patch releases, and turbo's@@ -267,7 +165,6 @@ jobs:# the old interpreter and report green without executing anything.- name: Resolve runtime for cache keyid: runtime- if: ${{ needs.changes.outputs.frontend == 'true' }}run: echo "node=$(node --version)" >> "$GITHUB_OUTPUT"# Cache entries are immutable, so the key carries the commit SHA to make@@ -277,7 +174,6 @@ jobs:# GitHub scopes caches by branch: a PR reads main's entries (so unchanged# tasks hit on the first push) and writes its own (so re-pushes hit too).- name: Restore turbo cache- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/cache@v6with:path: .turbo/cache@@ -285,37 +181,7 @@ jobs:restore-keys: |turbo-build-${{ runner.os }}-${{ runner.arch }}-${{ steps.runtime.outputs.node }}-- - name: Test self-host env derivation- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: bash scripts/selfhost-config.test.sh-- - name: Test worktree database cleanup- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: bash scripts/worktree-db.test.sh-- - name: Test development environment registry- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: bash scripts/dev-env.test.sh-- # The browser comparison runs only on demand, but its verdict and its- # cleanup are cheap to prove on every change: a fake pnpm, no build and- # no browser, a few seconds.- - name: Test UI performance comparison runner- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: bash scripts/perf-compare.test.sh-- - name: Verify reserved-slugs.ts is up to date- if: ${{ needs.changes.outputs.frontend == 'true' }}- # Re-runs the generator and fails on any drift from the- # checked-in TypeScript output. The Go side embeds the JSON- # source directly, so a passing diff here proves both sides- # share one source of truth.- run: |- pnpm generate:reserved-slugs- git diff --exit-code -- packages/core/paths/reserved-slugs.ts-- name: Build, type check, and lint- if: ${{ needs.changes.outputs.frontend == 'true' }}# Mobile lives in a parallel mobile-verify workflow (path-filtered# to apps/mobile/** + packages/core/**) so it doesn't add# ~50s of expo-lint + tsc to every web/desktop PR. Keep this@@ -323,69 +189,33 @@ jobs:# exclude @multica/mobile.run: pnpm exec turbo build typecheck lint --filter='!@multica/docs' --filter='!@multica/mobile'- # Blocking from the start: it reports nothing today, and it covers the- # one regression knip structurally cannot see. packages/ui exports four- # wildcards, which knip expands into entry-point globs over every file- # in those directories — so a newly stranded component there always- # reads as "used". See the script header for the options ruled out.- - name: Check packages/ui wildcard exports- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: |- bash scripts/check-ui-wildcard-exports.test.sh- node scripts/check-ui-wildcard-exports.mjs-- - name: Check UI radius tokens- if: ${{ needs.changes.outputs.frontend == 'true' }}- run: |- node --test scripts/check-ui-radius-tokens.test.mjs- node scripts/check-ui-radius-tokens.mjs-- # WARN PHASE — reports, never blocks. `shamefully-hoist=true` in .npmrc- # hides both halves of the drift this catches: an undeclared import still- # resolves, and an obsolete declaration still installs. Neither shows up- # in build, typecheck, or lint.- #- # `continue-on-error` alone, with no `|| true`: the real exit code has to- # reach Actions for the step to show as a warning rather than a silent- # pass, and it is what makes the promotion below a one-line change.- #- # TO PROMOTE TO BLOCKING: once this step has run clean for a full cycle- # on main, drop `continue-on-error`. The findings it reports today are- # pre-existing dead code left out of the cleanup that introduced it- # (MUL-6353) — clear those first, or the flip turns them into a red main.- - name: Check for dead code and phantom dependencies (knip)- if: ${{ needs.changes.outputs.frontend == 'true' }}- continue-on-error: true- run: pnpm knip+ - name: Check frontend quality+ uses: ./.github/actions/frontend-qualityfrontend-test:needs: changes+ if: ${{ needs.changes.outputs.frontend == 'true' }}runs-on: ubuntu-latestenv:TURBO_CACHE_DIR: .turbo/cachesteps:- name: Checkout- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/checkout@v6- name: Setup pnpm- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: pnpm/action-setup@v4- name: Setup Node.js- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/setup-node@v6with:node-version: 22cache: pnpm- name: Install dependencies- if: ${{ needs.changes.outputs.frontend == 'true' }}run: pnpm install- name: Resolve runtime for cache keyid: runtime- if: ${{ needs.changes.outputs.frontend == 'true' }}run: echo "node=$(node --version)" >> "$GITHUB_OUTPUT"# See frontend-build for the key strategy. These entries are tiny (~60KB@@ -393,7 +223,6 @@ jobs:# logs rather than artifacts -- yet a hit still skips the whole suite,# which is the single most expensive task in the graph.- name: Restore turbo cache- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/cache@v6with:path: .turbo/cache@@ -402,7 +231,6 @@ jobs:turbo-test-${{ runner.os }}-${{ runner.arch }}-${{ steps.runtime.outputs.node }}-- name: Test web, core, and desktop- if: ${{ needs.changes.outputs.frontend == 'true' }}# Same filter rationale as frontend-build. Type errors are not this# job's responsibility -- frontend-build owns the `typecheck` task.# `test` reaches dependency sources through the hash-only@@ -414,6 +242,7 @@ jobs:frontend-views-test:name: frontend-views-test (${{ matrix.index }}/${{ matrix.total }})needs: changes+ if: ${{ needs.changes.outputs.frontend == 'true' }}strategy:fail-fast: falsematrix:@@ -427,27 +256,22 @@ jobs:TURBO_CACHE_DIR: .turbo/cachesteps:- name: Checkout- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/checkout@v6- name: Setup pnpm- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: pnpm/action-setup@v4- name: Setup Node.js- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/setup-node@v6with:node-version: 22cache: pnpm- name: Install dependencies- if: ${{ needs.changes.outputs.frontend == 'true' }}run: pnpm install- name: Resolve runtime for cache keyid: runtime- if: ${{ needs.changes.outputs.frontend == 'true' }}run: echo "node=$(node --version)" >> "$GITHUB_OUTPUT"# Each shard has its own prefix so concurrent jobs never race to save the@@ -455,7 +279,6 @@ jobs:# argument in the task hash, while dependency sources still flow through# turbo.json's hash-only `^cache-inputs` edge.- name: Restore turbo cache- if: ${{ needs.changes.outputs.frontend == 'true' }}uses: actions/cache@v6with:path: .turbo/cache@@ -464,36 +287,20 @@ jobs:turbo-views-test-${{ matrix.index }}-of-${{ matrix.total }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.runtime.outputs.node }}-- name: Test views shard ${{ matrix.index }}/${{ matrix.total }}- if: ${{ needs.changes.outputs.frontend == 'true' }}run: pnpm exec turbo test --filter='@multica/views' -- --shard=${{ matrix.index }}/${{ matrix.total }}- # Aggregate gate. `frontend` is the status-check name the repository's- # branch rules refer to, so it has to survive the split above: this job- # keeps reporting under that name and simply fails when any worker fails.- # It also inherits the old contract that the check goes green (rather than- # staying pending) on PRs the path filter excluded — all workers succeed- # trivially in that case because every step is gated off.+ # Preserve the aggregate check names while validating intentional skips.frontend:- needs: [frontend-build, frontend-test, frontend-views-test]- # `!cancelled()` rather than `always()`: a run superseded by a newer push- # is cancelled by the concurrency group above, and there is no reason to- # spend a runner reporting a verdict nobody will read.+ needs: [changes, frontend-build, frontend-test, frontend-views-test, frontend-quality]if: ${{ !cancelled() }}runs-on: ubuntu-lateststeps:+ - uses: actions/checkout@v6- name: Check frontend job resultsenv:- BUILD_RESULT: ${{ needs.frontend-build.result }}- TEST_RESULT: ${{ needs.frontend-test.result }}- VIEWS_TEST_RESULT: ${{ needs.frontend-views-test.result }}- run: |- echo "frontend-build: $BUILD_RESULT"- echo "frontend-test: $TEST_RESULT"- echo "frontend-views-test: $VIEWS_TEST_RESULT"- if [ "$BUILD_RESULT" != "success" ] || [ "$TEST_RESULT" != "success" ] || [ "$VIEWS_TEST_RESULT" != "success" ]; then- echo "::error::frontend validation failed"- exit 1- fi+ NEEDS_JSON: ${{ toJSON(needs) }}+ JOB_SCOPES: '{"frontend-build":"frontend","frontend-test":"frontend","frontend-views-test":"frontend","frontend-quality":"quality_only"}'+ run: node scripts/ci-scope.mjs gate# The Go caches are handled explicitly here rather than through setup-go's# `cache: true`. setup-go keys its entry on go.sum alone and shares that key@@ -532,13 +339,9 @@ jobs:# a cached "ok" from an untouched package could mask a real failure.backend-tests:needs: changes+ if: ${{ needs.changes.outputs.backend == 'true' }}runs-on: ubuntu-latest- # `services` cannot be conditional, so the Postgres and Redis containers- # still start on a filtered PR. That is ~1 minute of runner time against- # the several minutes the gated steps below cost; job-level `if` would- # save it but report `skipped` to the aggregate gate, which then has to- # accept `skipped` as success and stops catching jobs that go missing for- # reasons other than the path filter.+ # Job-level filtering skips both services on unrelated changes.services:postgres:image: pgvector/pgvector:pg17@@ -572,12 +375,10 @@ jobs:GOFLAGS: -count=1steps:- name: Checkout- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/checkout@v6- name: Setup Goid: go- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/setup-go@v5with:# Deliberately independent from the minimum patch in server/go.mod:@@ -587,7 +388,6 @@ jobs:cache: false- name: Restore Go module cache- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/cache@v6with:path: ~/go/pkg/mod@@ -597,35 +397,16 @@ jobs:# shell step spells the build-cache key prefix once for restore and save.- name: Resolve Go build cache keyid: gocache- if: ${{ needs.changes.outputs.backend == 'true' }}run: echo "prefix=go-build-race-${{ runner.os }}-${{ runner.arch }}-$ImageOS-${{ steps.go.outputs.go-version }}-" >> "$GITHUB_OUTPUT"- name: Restore Go build cache- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/cache/restore@v6with:path: ~/.cache/go-buildkey: ${{ steps.gocache.outputs.prefix }}${{ github.sha }}restore-keys: ${{ steps.gocache.outputs.prefix }}- - name: Setup Helm- if: ${{ needs.changes.outputs.backend == 'true' }}- uses: azure/setup-helm@v4-- - name: Test Helm chart- if: ${{ needs.changes.outputs.backend == 'true' }}- run: bash scripts/helm-config.test.sh-- - name: Test backend entrypoint signals- if: ${{ needs.changes.outputs.backend == 'true' }}- run: bash scripts/entrypoint.test.sh-- - name: Test build output naming- if: ${{ needs.changes.outputs.backend == 'true' }}- run: bash scripts/makefile-build.test.sh-- name: Build- if: ${{ needs.changes.outputs.backend == 'true' }}run: cd server && go build -race ./...# The `agentintegration` files execute real agent CLIs, so no CI job runs@@ -635,19 +416,15 @@ jobs:# untagged job still green. vet type-checks test files, so this is the# cheapest gate that keeps them honest without needing an agent CLI.- name: Vet tag-gated agent integration tests- if: ${{ needs.changes.outputs.backend == 'true' }}run: cd server && go vet -race -tags agentintegration ./...- name: Run migrations- if: ${{ needs.changes.outputs.backend == 'true' }}run: cd server && go run ./cmd/migrate up- name: Verify Go test wrapper- if: ${{ needs.changes.outputs.backend == 'true' }}run: bash scripts/test-go.test.sh- name: Test- if: ${{ needs.changes.outputs.backend == 'true' }}# pkg/agent runs on its own runner: backend-agent-tests below.run: bash scripts/test-go.sh --race --only regular@@ -674,18 +451,17 @@ jobs:# to relink.backend-agent-tests:needs: changes+ if: ${{ needs.changes.outputs.backend == 'true' }}runs-on: ubuntu-latestenv:# Same policy as backend-tests: CI always executes the tests it reports.GOFLAGS: -count=1steps:- name: Checkout- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/checkout@v6- name: Setup Goid: go- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/setup-go@v5with:go-version: "1.26.x"@@ -693,7 +469,6 @@ jobs:cache: false- name: Restore Go module cache- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/cache/restore@v6with:path: ~/go/pkg/mod@@ -702,11 +477,9 @@ jobs:# Must match backend-tests' key step exactly.- name: Resolve Go build cache keyid: gocache- if: ${{ needs.changes.outputs.backend == 'true' }}run: echo "prefix=go-build-race-${{ runner.os }}-${{ runner.arch }}-$ImageOS-${{ steps.go.outputs.go-version }}-" >> "$GITHUB_OUTPUT"- name: Restore Go build cache- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/cache/restore@v6with:path: ~/.cache/go-build@@ -714,21 +487,19 @@ jobs:restore-keys: ${{ steps.gocache.outputs.prefix }}- name: Test agent package- if: ${{ needs.changes.outputs.backend == 'true' }}run: bash scripts/test-go.sh --race --only agent# Keep the live vulnerability database from hiding build and test results.# The aggregate backend job below still treats both jobs as one merge gate.go-vulnerability-scan:needs: changes+ if: ${{ needs.changes.outputs.backend == 'true' }}runs-on: ubuntu-lateststeps:- name: Checkout- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/checkout@v6- name: Setup Go- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/setup-go@v5with:# Deliberately independent from the minimum patch in server/go.mod:@@ -738,49 +509,36 @@ jobs:cache-dependency-path: server/go.sum- name: Scan Go vulnerabilities- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: serverrun: go tool govulncheck ./...# Preserve the existing required-check name while allowing tests, generated# SQL verification, and the vulnerability scan to run independently.backend:- needs: [backend-tests, backend-agent-tests, sqlc-check, go-vulnerability-scan]+ needs: [changes, backend-tests, backend-agent-tests, sqlc-check, go-vulnerability-scan, cursor-background-lifecycle, windows-execenv, script-checks, installer]if: ${{ !cancelled() }}runs-on: ubuntu-lateststeps:+ - uses: actions/checkout@v6- name: Check backend job resultsenv:- TEST_RESULT: ${{ needs.backend-tests.result }}- AGENT_TEST_RESULT: ${{ needs.backend-agent-tests.result }}- SQLC_RESULT: ${{ needs.sqlc-check.result }}- VULNERABILITY_RESULT: ${{ needs.go-vulnerability-scan.result }}- run: |- echo "backend-tests: $TEST_RESULT"- echo "backend-agent-tests: $AGENT_TEST_RESULT"- echo "sqlc-check: $SQLC_RESULT"- echo "go-vulnerability-scan: $VULNERABILITY_RESULT"- if [ "$TEST_RESULT" != "success" ] || [ "$AGENT_TEST_RESULT" != "success" ] || [ "$SQLC_RESULT" != "success" ] || [ "$VULNERABILITY_RESULT" != "success" ]; then- echo "::error::backend validation failed"- exit 1- fi+ NEEDS_JSON: ${{ toJSON(needs) }}+ JOB_SCOPES: '{"backend-tests":"backend","backend-agent-tests":"backend","sqlc-check":"sqlc","go-vulnerability-scan":"backend","cursor-background-lifecycle":"runtime","windows-execenv":"runtime","script-checks":"scripts","installer":"installer"}'+ run: node scripts/ci-scope.mjs gatewindows-execenv:# The environment-preparation deadline owns a process tree, not just a Go# process. This Windows runtime test verifies Job Object cancellation kills# a delayed descendant before an immediate retry can reuse the same root.- # Every step here is a Go test under server/, so it rides the same path- # filter as the backend jobs; steps are gated rather than the job so the- # check still reports green on a filtered PR.+ # The runtime scope includes daemon/agent sources and their Go dependencies.needs: changes+ if: ${{ needs.changes.outputs.runtime == 'true' }}runs-on: windows-lateststeps:- name: Checkout- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/checkout@v6- name: Setup Go- if: ${{ needs.changes.outputs.backend == 'true' }}uses: actions/setup-go@v5with:# Deliberately independent from the minimum patch in server/go.mod:@@ -790,7 +548,6 @@ jobs:cache-dependency-path: server/go.sum- name: Test Windows execution-environment isolation- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# Keep this job scoped to the runtime regression it exists to prove.# The package's legacy OpenClaw HOME tests are not Windows-safe and are@@ -798,7 +555,6 @@ jobs:run: go test ./internal/daemon/execenv -run '^TestPrepareIsolated_WindowsKillsDescendantBeforeRetry$' -count=1 -timeout=5m- name: Test Windows daemon local-skill discovery- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# These fixtures must redirect both the Windows user profile and the# platform-native Hermes home; otherwise discovery scans the runner's@@ -806,7 +562,6 @@ jobs:run: go test ./internal/daemon -v -run '^(TestListRuntimeLocalSkills_HermesFollowsTaskHome|TestLocalSkills_DiscoversACPProviderRoots)$' -count=1 -timeout=5m- name: Test Windows agent launcher argv/stdin handling- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# Agent prompts must never reach a Windows launcher through argv: the# official cursor-agent.ps1, pi.ps1, and qwen.ps1 launch native children with@@ -823,7 +578,6 @@ jobs:run: go test ./pkg/agent -v -run '^(TestCursorExecutePromptSurvivesPowerShellShim|TestPiExecutePromptSurvivesPowerShellShim|TestQwenExecutePromptSurvivesPowerShellShim|TestPlatformCursorInvocation|TestPlatformCopilotInvocation|TestPlatformPiInvocation|TestPlatformQwenInvocation)' -count=1 -timeout=5m- name: Test Windows OpenCode oversized prompt reaches stdin- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# #6538: the daemon inlined the whole task prompt as an argv element,# so every OpenCode task whose prompt cleared CreateProcess's 32,767@@ -840,7 +594,6 @@ jobs:run: go test ./pkg/agent -v -run '^TestOpencodeExecuteOversizedPromptStartsOnWindows$' -count=1 -timeout=5m- name: Test Windows agent process-tree ownership- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# A Job Object is the only way to prove whole-tree termination on# Windows, and only a real Windows runner can exercise it: that a@@ -851,7 +604,6 @@ jobs:run: go test ./pkg/agent -v -run '^(TestStartOwnedProcessTreeCapturesImmediateDescendants|TestStartOwnedProcessTreeLeavesNoSuspendedChild|TestWaitProcessGroupGoneWithoutOwnershipReportsUnconfirmed|TestCodexInitializeRetrySupportedWithOwnedProcessTree|TestCodexWindowsDescendantsDieWithTheOwnedProcessTree|TestCodeArtsWindowsCancellationTerminatesDescendants)$' -count=1 -timeout=5m- name: Test bounded CLI output collection on Windows- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# MUL-5467: RunCollect / RunCollectQuiet own the pipes as well as the# process tree on the OpenClaw CLI paths, which outputOwned cannot. A real@@ -866,7 +618,6 @@ jobs:run: go test ./pkg/agent -v -run '^TestWindowsRunCollect' -count=1 -timeout=5m- name: Test Windows Pi session lock leaves the transcript readable- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# #7840: the session lock claimed the transcript itself, and Windows# byte-range locks are mandatory. Pi's own read of the file we hand it@@ -879,7 +630,6 @@ jobs:run: go test ./pkg/agent -v -run '^TestPiSessionFileLock' -count=1 -timeout=5m- name: Test Windows OpenClaw npm shim interpreter resolution- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# #6061: every OpenClaw task failed execenv prep on a Windows host with# a bare `exit status 1` and no stderr. A batch shim resolves and runs@@ -901,7 +651,6 @@ jobs:run: go test ./internal/daemon/execenv -v -run '^TestWindowsOpenclawShim' -count=1 -timeout=5m- name: Test Windows isolated repo checkout is committable- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# #6449: on Windows the daemon now hands Codex tasks a checkout whose# .git lives inside the task workdir, because a linked worktree's@@ -923,7 +672,6 @@ jobs:run: go test ./internal/daemon/repocache -v -run '^(TestIsolatedCheckoutIsCommittableOnWindows|TestIsolatedCheckoutAcrossVolumesOnWindows)$' -count=1 -timeout=5m- name: Test Windows directory-junction link safety- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# MUL-6000: the per-task codex-home links the user's real skills into# the task directory instead of copying them. On Windows that link is a@@ -943,7 +691,6 @@ jobs:go test ./internal/daemon -v -run '^(TestCleanTaskArtifacts_DoesNotFollowDirectoryJunction|TestTaskSize_DoesNotCountDirectoryJunction)$' -count=1 -timeout=5m- name: Test Windows task temp dir sweep survives a sharing violation- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# The GC's task temp sweep has to cope with a file it cannot delete: a# leftover child process holding one open is what left 174 directories@@ -957,7 +704,6 @@ jobs:run: go test ./internal/daemon/execenv -v -run '^TestPruneTaskTempDirsSurvivesRealSharingViolation$' -count=1 -timeout=5m- name: Test Windows agent executable junction resolution- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: server# The standalone Codex installer exposes bin as a directory junction.# filepath.EvalSymlinks cannot traverse that reparse-point shape, so@@ -968,7 +714,6 @@ jobs:run: go test ./internal/daemon -v -run '^(TestCanonicalExecutablePath|TestTrimExtendedLengthPrefix|TestResolveAgentExecutablePathKeeps|TestResolveAgentEntry(FollowsRetargetedInstallerJunction|CanonicalizesRediscoveredJunction|ForLaunchKeepsCmdShimLaunchable|ForLaunchRejectsUnverifiedInitialJunctionTarget|ForLaunchRejectsRediscoveredJunctionWhenFinalPathResolutionFails|DoesNotSharePreRetargetSingleflightResult|ForLaunchFailsWhenJunctionKeepsRetargeting)|TestHandleTaskReportsWindowsCodexProcessStartFailure)' -count=1 -timeout=5m- name: Build Windows CLI helper entrypoint- if: ${{ needs.changes.outputs.backend == 'true' }}working-directory: serverrun: go build ./cmd/multica@@ -984,14 +729,18 @@ jobs:- name: Checkoutuses: actions/checkout@v6with:- # The check diffs against the base branch, which a shallow- # clone does not contain.- fetch-depth: 0+ fetch-depth: 1++ - name: Fetch comparison base+ env:+ BASE_SHA: ${{ github.event.pull_request.base.sha }}+ run: git fetch --no-tags --depth=1 origin "$BASE_SHA"- name: Check image budgetenv:PR_BODY: ${{ github.event.pull_request.body }}- run: node scripts/check-image-budget.mjs --base "origin/${{ github.base_ref }}"+ BASE_SHA: ${{ github.event.pull_request.base.sha }}+ run: node scripts/check-image-budget.mjs --base "$BASE_SHA"installer:# Stub-driven shell tests for scripts/install.sh and scripts/install.ps1.@@ -1001,6 +750,8 @@ jobs:# userlands. Windows runs the PowerShell installer's own suite: the two# installers share one port contract, and neither is covered by the# frontend job.+ needs: changes+ if: ${{ needs.changes.outputs.installer == 'true' }}strategy:fail-fast: falsematrix:@@ -1018,3 +769,63 @@ jobs:if: runner.os == 'Windows'shell: pwshrun: ./scripts/install.ps1.test.ps1++ script-checks:+ needs: changes+ if: ${{ needs.changes.outputs.scripts == 'true' }}+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v6+ - uses: actions/setup-node@v6+ with:+ node-version: 22++ - name: Test self-host env derivation+ run: bash scripts/selfhost-config.test.sh++ - name: Test worktree database cleanup+ run: bash scripts/worktree-db.test.sh++ - name: Test development environment registry+ run: bash scripts/dev-env.test.sh++ - name: Test UI performance comparison runner+ run: bash scripts/perf-compare.test.sh++ - name: Verify reserved-slugs.ts is up to date+ # Re-runs the generator and fails on any drift from the+ # checked-in TypeScript output. The Go side embeds the JSON+ # source directly, so a passing diff here proves both sides+ # share one source of truth.+ run: |+ node scripts/generate-reserved-slugs.mjs+ git diff --exit-code -- packages/core/paths/reserved-slugs.ts++ - name: Setup Helm+ uses: azure/setup-helm@v4++ - name: Test Helm chart+ run: bash scripts/helm-config.test.sh++ - name: Test backend entrypoint signals+ run: bash scripts/entrypoint.test.sh++ - name: Test build output naming+ run: bash scripts/makefile-build.test.sh++ frontend-quality:+ needs: changes+ if: ${{ needs.changes.outputs.quality_only == 'true' }}+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v6+ - uses: pnpm/action-setup@v4+ - uses: actions/setup-node@v6+ with:+ node-version: 22+ cache: pnpm+ - name: Install dependencies+ run: pnpm install --frozen-lockfile++ - name: Check frontend quality+ uses: ./.github/actions/frontend-qualitydiff --git a/.github/workflows/mobile-verify.yml b/.github/workflows/mobile-verify.ymlindex 22b9ef7cfc..e18bdd7619 100644--- a/.github/workflows/mobile-verify.yml+++ b/.github/workflows/mobile-verify.yml@@ -16,6 +16,8 @@ name: Mobile Verify# Mobile's vitest suite is intentionally narrow (Node env, pure-function# tests under apps/mobile/lib/*.test.ts — see apps/mobile/vitest.config.ts).# RN component-level rendering is not exercised here.+# Repository-wide radius checks run once in CI: frontend-build owns them when+# selected, otherwise frontend-quality handles docs/mobile-only changes.on:push:@@ -27,8 +29,6 @@ on:- "pnpm-lock.yaml"- "pnpm-workspace.yaml"- "turbo.json"- - "scripts/check-ui-radius-tokens.mjs"- - "scripts/check-ui-radius-tokens.test.mjs"- ".github/workflows/mobile-verify.yml"pull_request:branches: [main]@@ -39,8 +39,6 @@ on:- "pnpm-lock.yaml"- "pnpm-workspace.yaml"- "turbo.json"- - "scripts/check-ui-radius-tokens.mjs"- - "scripts/check-ui-radius-tokens.test.mjs"- ".github/workflows/mobile-verify.yml"concurrency:@@ -68,8 +66,3 @@ jobs:- name: Type check, lint, and testrun: pnpm exec turbo typecheck lint test --filter=@multica/mobile-- - name: Check UI radius tokens- run: |- node --test scripts/check-ui-radius-tokens.test.mjs- node scripts/check-ui-radius-tokens.mjsdiff --git a/scripts/check-image-budget.test.mjs b/scripts/check-image-budget.test.mjsnew file mode 100644index 0000000000..5b24eab15a--- /dev/null+++ b/scripts/check-image-budget.test.mjs@@ -0,0 +1,52 @@+import assert from "node:assert/strict";+import { execFileSync, spawnSync } from "node:child_process";+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath, pathToFileURL } from "node:url";+import test from "node:test";++test("image checks need only a shallow head and the exact base, not full history", (t) => {+ const dir = mkdtempSync(join(tmpdir(), "image-budget-"));+ t.after(() => rmSync(dir, { recursive: true, force: true }));+ const source = join(dir, "source");+ const checkout = join(dir, "checkout");+ mkdirSync(source);+ const env = {+ ...process.env,+ GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null",+ GIT_AUTHOR_NAME: "CI test", GIT_AUTHOR_EMAIL: "[email protected]",+ GIT_COMMITTER_NAME: "CI test", GIT_COMMITTER_EMAIL: "[email protected]",+ };+ const git = (cwd, ...args) => execFileSync("git", args, { cwd, env, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();+ git(source, "init", "-b", "main");+ writeFileSync(join(source, "existing.png"), Buffer.alloc(400 * 1024));+ git(source, "add", ".");+ git(source, "commit", "-m", "base");+ const base = git(source, "rev-parse", "HEAD");+ // Put an intermediate commit between base and head to prove no ancestry is needed.+ writeFileSync(join(source, "README.md"), "intermediate\n");+ git(source, "add", ".");+ git(source, "commit", "-m", "intermediate");+ const intermediate = git(source, "rev-parse", "HEAD");+ writeFileSync(join(source, "new.png"), Buffer.alloc(350 * 1024));+ git(source, "add", ".");+ git(source, "commit", "-m", "head");+ git(dir, "clone", "--depth=1", pathToFileURL(source).href, checkout);+ git(checkout, "fetch", "--no-tags", "--depth=1", "origin", base);+ assert.equal(git(checkout, "rev-parse", "--is-shallow-repository"), "true");+ assert.notEqual(spawnSync("git", ["cat-file", "-e", intermediate], { cwd: checkout, env }).status, 0);++ const script = fileURLToPath(new URL("./check-image-budget.mjs", import.meta.url));+ const check = (body = "") => spawnSync(process.execPath, [script, "--base", base], {+ cwd: checkout, env: { ...env, PR_BODY: body }, encoding: "utf8",+ });+ const oversized = check();+ assert.equal(oversized.status, 1, oversized.stderr);+ assert.match(oversized.stdout, /new\.png/);+ assert.doesNotMatch(oversized.stdout, /existing\.png/);+ assert.equal(check("Oversized image exemption: required test fixture").status, 0);+ writeFileSync(join(checkout, "new.png"), Buffer.alloc(100));+ writeFileSync(join(checkout, "existing.png"), Buffer.alloc(350 * 1024));+ assert.equal(check().status, 0, "unchanged or shrinking oversized files should pass");+});diff --git a/scripts/ci-scope.mjs b/scripts/ci-scope.mjsnew file mode 100644index 0000000000..3d8d0b8d0d--- /dev/null+++ b/scripts/ci-scope.mjs@@ -0,0 +1,70 @@+#!/usr/bin/env node+// Path filtering and aggregate gates share this fail-closed decision contract.+import { appendFileSync, readFileSync } from "node:fs";+import { pathToFileURL } from "node:url";++export const filters = JSON.parse(+ readFileSync(new URL("../.github/ci-paths.json", import.meta.url), "utf8"),+);++export function decideScopes(event, filtered) {+ const full = event === "schedule" || event === "workflow_dispatch";+ if (!full && event !== "push" && event !== "pull_request") {+ throw new Error(`Unsupported CI event: ${event}`);+ }+ const outputs = { full: String(full) };+ for (const scope of Object.keys(filters)) {+ if (!full && filtered[scope] !== "true" && filtered[scope] !== "false") {+ throw new Error(`Missing or invalid path-filter result: ${scope}`);+ }+ outputs[scope] = full ? "true" : filtered[scope];+ }+ // Product builds already install dependencies and run the shared checks.+ // Only allocate a separate runner when quality is the sole frontend work.+ outputs.quality_only = String(outputs.quality === "true" && outputs.frontend === "false");+ return outputs;+}++export function checkGate(needs, jobScopes) {+ if (needs.changes?.result !== "success") {+ throw new Error("Path filtering did not succeed");+ }+ for (const [job, scope] of Object.entries(jobScopes)) {+ const selected = needs.changes.outputs?.[scope];+ if (selected !== "true" && selected !== "false") {+ throw new Error(`Missing or invalid scope: ${scope}`);+ }+ const expected = selected === "true" ? "success" : "skipped";+ if (needs[job]?.result !== expected) {+ throw new Error(`${job}: expected ${expected}, got ${needs[job]?.result ?? "missing"}`);+ }+ }+ // A newly added dependency must have a declared scope before the gate can pass.+ for (const job of Object.keys(needs)) {+ if (job !== "changes" && !Object.hasOwn(jobScopes, job)) {+ throw new Error(`Unchecked dependency: ${job}`);+ }+ }+}++if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {+ try {+ switch (process.argv[2]) {+ case "decide": {+ const outputs = decideScopes(process.env.EVENT_NAME, JSON.parse(process.env.FILTER_RESULTS));+ appendFileSync(process.env.GITHUB_OUTPUT,+ Object.entries(outputs).map(([key, value]) => `${key}=${value}\n`).join(""));+ break;+ }+ case "gate":+ checkGate(JSON.parse(process.env.NEEDS_JSON), JSON.parse(process.env.JOB_SCOPES));+ console.log("All selected CI jobs succeeded; only unselected jobs were skipped.");+ break;+ default:+ throw new Error("Usage: node scripts/ci-scope.mjs decide|gate");+ }+ } catch (error) {+ console.error(error.message);+ process.exitCode = 1;+ }+}diff --git a/scripts/ci-scope.test.mjs b/scripts/ci-scope.test.mjsnew file mode 100644index 0000000000..a44336242f--- /dev/null+++ b/scripts/ci-scope.test.mjs@@ -0,0 +1,209 @@+import assert from "node:assert/strict";+import { mkdtempSync, readFileSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { join, matchesGlob } from "node:path";+import { spawnSync } from "node:child_process";+import { fileURLToPath } from "node:url";+import test from "node:test";+import { checkGate, decideScopes, filters } from "./ci-scope.mjs";++// The filters use only literal paths, * and **; Node's matcher exercises those+// against realistic changes, including files removed or renamed by a PR.+function filterFiles(files) {+ return Object.fromEntries(Object.entries(filters).map(([scope, patterns]) => [+ scope, String(files.some((file) => patterns.some((pattern) => matchesGlob(file, pattern)))),+ ]));+}++for (const [name, files, selected] of [+ ["readme only", ["README.md"], []],+ ["docs only", ["apps/docs/content/docs/guide.mdx"], ["quality"]],+ ["web changelog", ["apps/web/features/landing/i18n/en.ts"], ["frontend", "quality"]],+ ["mobile UI", ["apps/mobile/app/index.tsx"], ["quality"]],+ ["migration only", ["server/migrations/999_example.up.sql"], ["backend", "sqlc"]],+ ["agent process code", ["server/pkg/agent/cursor_background.go"], ["backend", "runtime"]],+ ["daemon dependency", ["server/internal/skill/service.go"], ["backend", "runtime"]],+ ["native test compilation dependency", ["server/pkg/db/generated/issues.sql.go"], ["backend", "sqlc", "runtime"]],+ ["Go dependencies", ["server/go.mod", "server/go.sum"], ["backend", "runtime"]],+ ["Helm only", ["deploy/helm/multica/templates/deployment.yaml"], ["scripts"]],+ ["container entrypoint", ["docker/entrypoint.sh"], ["scripts"]],+ ["selfhost config", [".env.example"], ["scripts", "installer"]],+ ["shell installer", ["scripts/install.sh"], ["scripts", "installer"]],+ ["PowerShell installer", ["scripts/install.ps1.test.ps1"], ["installer"]],+ ["cleanup script", ["scripts/drop-database.sh"], ["scripts"]],+ ["performance harness", ["scripts/perf-compare.test.sh"], ["scripts"]],+ ["reserved slug source", ["server/internal/handler/reserved_slugs.json"], ["backend", "runtime", "scripts"]],+ ["reserved slug output", ["packages/core/paths/reserved-slugs.ts"], ["frontend", "quality", "scripts"]],+ ["cross-module runtime contract", ["packages/core/runtimes/cli-version.ts"], ["frontend", "backend", "runtime", "quality"]],+ ["lockfile", ["pnpm-lock.yaml"], ["frontend", "quality"]],+ ["package patch", ["patches/example.patch"], ["frontend", "quality"]],+ ["radius policy", ["scripts/check-ui-radius-tokens.mjs"], ["quality"]],+ ["shared quality action", [".github/actions/frontend-quality/action.yml"], ["frontend", "quality"]],+ ["new bitmap", ["apps/web/public/hero.png"], ["frontend", "quality", "images"]],+ ["mixed docs and migration", ["apps/docs/content/guide.mdx", "server/migrations/999_example.up.sql"], ["quality", "backend", "sqlc"]],+ ["CI configuration", [".github/ci-paths.json"], Object.keys(filters)],+]) {+ test(`PR and main select only affected scopes: ${name}`, () => {+ for (const event of ["pull_request", "push"]) {+ const outputs = decideScopes(event, filterFiles(files));+ assert.equal(outputs.full, "false");+ assert.deepEqual(Object.keys(filters).filter((scope) => outputs[scope] === "true").sort(),+ [...selected].sort());+ assert.equal(outputs.quality_only, String(selected.includes("quality") && !selected.includes("frontend")));+ }+ });+}++test("scheduled and manual runs select every scope without a path-filter result", () => {+ for (const event of ["schedule", "workflow_dispatch"]) {+ const { quality_only, ...scopes } = decideScopes(event, {});+ assert.ok(Object.values(scopes).every((value) => value === "true"));+ assert.equal(quality_only, "false", "the full frontend build owns quality checks");+ }+});++test("missing, malformed and unsupported filter results fail closed", () => {+ for (const value of [undefined, "", "unknown", true]) {+ assert.throws(() => decideScopes("push", { ...filterFiles([]), backend: value }), /backend/);+ }+ assert.throws(() => decideScopes("unknown", filterFiles([])), /Unsupported/);+});++// Read the production wiring without installing workspace dependencies in the+// lightweight changes job. These fields deliberately use single-line syntax;+// unsupported formatting fails the assertions instead of being silently ignored.+const workflow = readFileSync(new URL("../.github/workflows/ci.yml", import.meta.url), "utf8");+const jobSource = workflow.slice(workflow.indexOf("\njobs:\n") + "\njobs:\n".length);+const headings = [...jobSource.matchAll(/^ ([\w-]+):$/gm)];+const jobs = Object.fromEntries(headings.map((match, index) => [+ match[1], jobSource.slice(match.index, headings[index + 1]?.index),+]));+function field(source, pattern) {+ const match = source.match(pattern);+ assert.ok(match, `Missing production field: ${pattern}`);+ return match[1];+}+function productionMapping(gate) {+ return JSON.parse(field(jobs[gate], /^ JOB_SCOPES: '(.+)'$/m));+}+function productionNeeds(gate, outputs) {+ const dependencies = field(jobs[gate], /^ needs: \[(.+)\]$/m).split(", ");+ return Object.fromEntries(dependencies.map((job) => {+ if (job === "changes") return [job, { result: "success", outputs }];+ const scope = field(jobs[job], /^ if: \$\{\{ needs\.changes\.outputs\.(\w+) == 'true' \}\}$/m);+ return [job, { result: outputs[scope] === "true" ? "success" : "skipped" }];+ }));+}++for (const gate of ["frontend", "backend"]) {+ test(`production ${gate} gate matches every dependency, condition and scope output`, () => {+ const mapping = productionMapping(gate);+ assert.match(jobs[gate], /^ if: \$\{\{ !cancelled\(\) \}\}$/m);+ assert.match(jobs[gate], /^ NEEDS_JSON: \$\{\{ toJSON\(needs\) \}\}$/m);+ assert.match(jobs[gate], /^ run: node scripts\/ci-scope\.mjs gate$/m);+ for (const scope of Object.values(mapping)) {+ assert.ok(jobs.changes.includes(` ${scope}: \${{ steps.decide.outputs.${scope} }}`));+ }+ const scopes = Object.keys(filters);+ // Exercise mixed scopes too: installers and quality may run without the+ // corresponding product backend/frontend suite being selected.+ for (let mask = 0; mask < 2 ** scopes.length; mask++) {+ const filtered = Object.fromEntries(scopes.map((scope, bit) => [scope, String(Boolean(mask & (1 << bit)))]));+ const outputs = decideScopes("pull_request", filtered);+ checkGate(productionNeeds(gate, outputs), mapping);+ }+ for (const event of ["schedule", "workflow_dispatch"]) {+ checkGate(productionNeeds(gate, decideScopes(event, {})), mapping);+ }+ });++ test(`production ${gate} gate rejects unsuccessful or missing selected jobs`, () => {+ const mapping = productionMapping(gate);+ for (const job of Object.keys(mapping)) {+ // A docs-only run selects the standalone quality runner; a full run+ // selects every other dependency, including the installer matrix.+ const outputs = job === "frontend-quality"+ ? decideScopes("pull_request", filterFiles(["apps/docs/content/guide.mdx"]))+ : decideScopes("workflow_dispatch", {});+ for (const result of ["failure", "cancelled", "skipped", undefined]) {+ const input = productionNeeds(gate, outputs);+ assert.equal(input[job].result, "success");+ input[job].result = result;+ assert.throws(() => checkGate(input, mapping), new RegExp(job));+ }+ const missing = productionNeeds(gate, outputs);+ delete missing[job];+ assert.throws(() => checkGate(missing, mapping), new RegExp(job));+ }+ });++ test(`production ${gate} gate rejects invalid filtering and unchecked dependencies`, () => {+ const mapping = productionMapping(gate);+ const unselected = () => productionNeeds(gate, decideScopes("pull_request", filterFiles([])));+ for (const result of ["failure", "cancelled", "skipped", undefined]) {+ const input = unselected();+ input.changes.result = result;+ assert.throws(() => checkGate(input, mapping), /Path filtering/);+ }+ for (const [job, scope] of Object.entries(mapping)) {+ const failed = unselected();+ failed[job].result = "failure";+ assert.throws(() => checkGate(failed, mapping), new RegExp(job));+ for (const value of [undefined, "", "unknown"]) {+ const invalid = unselected();+ invalid.changes.outputs[scope] = value;+ assert.throws(() => checkGate(invalid, mapping), /scope/);+ }+ }+ const extra = unselected();+ extra.extra = { result: "failure" };+ assert.throws(() => checkGate(extra, mapping), /Unchecked dependency/);+ });+}++test("the backend gate owns the three-platform installer matrix", () => {+ assert.equal(productionMapping("backend").installer, "installer");+ assert.match(jobs.installer, /^ os: \[ubuntu-latest, macos-latest, windows-latest\]$/m);+ assert.doesNotMatch(jobs.installer, /continue-on-error:/);+});++test("quality checks have exactly one runner and reuse the product build install", () => {+ const invocation = "uses: ./.github/actions/frontend-quality";+ const owners = Object.entries(jobs).filter(([, source]) => source.includes(invocation)).map(([job]) => job);+ assert.deepEqual(owners.sort(), ["frontend-build", "frontend-quality"]);+ assert.equal(productionMapping("frontend")["frontend-quality"], "quality_only");+ assert.match(jobs["frontend-build"], / - name: Check frontend quality\n uses: \.\/\.github\/actions\/frontend-quality\n/);+ for (const frontend of ["true", "false"]) {+ for (const quality of ["true", "false"]) {+ const outputs = decideScopes("pull_request", { ...filterFiles([]), frontend, quality });+ const results = productionNeeds("frontend", outputs);+ const runners = owners.filter((job) => results[job].result === "success");+ assert.equal(runners.length, frontend === "true" || quality === "true" ? 1 : 0);+ }+ }+ const action = readFileSync(new URL("../.github/actions/frontend-quality/action.yml", import.meta.url), "utf8");+ assert.match(action, /run: pnpm knip/);+ assert.match(action, /continue-on-error: true/);+ assert.doesNotMatch(action, /pnpm install/);+});++test("the CLI writes real Actions outputs and exits nonzero on a failed gate", (t) => {+ const dir = mkdtempSync(join(tmpdir(), "ci-scope-"));+ t.after(() => rmSync(dir, { recursive: true, force: true }));+ const output = join(dir, "output");+ const script = fileURLToPath(new URL("./ci-scope.mjs", import.meta.url));+ const run = spawnSync(process.execPath, [script, "decide"], {+ env: { ...process.env, EVENT_NAME: "push", FILTER_RESULTS: JSON.stringify(filterFiles(["README.md"])), GITHUB_OUTPUT: output },+ encoding: "utf8",+ });+ assert.equal(run.status, 0, run.stderr);+ assert.match(readFileSync(output, "utf8"), /^backend=false$/m);+ const failed = productionNeeds("backend", decideScopes("workflow_dispatch", {}));+ failed["backend-tests"].result = "failure";+ const gate = spawnSync(process.execPath, [script, "gate"], {+ env: { ...process.env, NEEDS_JSON: JSON.stringify(failed), JOB_SCOPES: JSON.stringify(productionMapping("backend")) },+ encoding: "utf8",+ });+ assert.equal(gate.status, 1);+ assert.match(gate.stderr, /backend-tests/);+});