From 86792056b21f9ac8e8a52522fb0e05254bb7fa5f Mon Sep 17 00:00:00 2001 From: luisleo526 Date: Tue, 10 Nov 2026 09:54:18 +0800 Subject: [PATCH 1/4] test(ci): cover advisory macOS compile policy Pin the independent compile workflow and exercise input, authorization, cache, build-only and gate-independence controls. --- .github/workflows/macos-compile.yml | 248 +++++++++++++++++++++ scripts/test_ci_preflight.py | 329 +++++++++++++++++++++++++++- 2 files changed, 573 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/macos-compile.yml diff --git a/.github/workflows/macos-compile.yml b/.github/workflows/macos-compile.yml new file mode 100644 index 000000000..863a48af6 --- /dev/null +++ b/.github/workflows/macos-compile.yml @@ -0,0 +1,248 @@ +name: macOS compile + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review, converted_to_draft] + push: + branches: [main] + workflow_dispatch: + inputs: + source_ref: + description: Existing repository commit to compile (full lowercase 40-hex SHA; empty uses dispatch SHA) + required: false + type: string + default: '' + +permissions: + contents: read + +env: + HOMEBREW_NO_AUTO_UPDATE: '1' + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPILERCHECK: content + +defaults: + run: + shell: bash + +jobs: + compile-macos: + name: macOS compile + runs-on: macos-latest + steps: + - name: Only our own pull requests and our own events run CI + env: + EVENT: ${{ github.event_name }} + REPO: ${{ github.repository }} + HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} + HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }} + ASSOCIATION: ${{ github.event.pull_request.author_association }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + WR_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} + WR_ACTOR: ${{ github.event.workflow_run.triggering_actor.login }} + GH_TOKEN: ${{ github.token }} # read-only use: one permission lookup for workflow_run + # Bot logins whose same-repository pull requests count as ours: dependabot[bot] (CI-DEPBOT A) + # and the org's own GitHub App bot logins by name (space-separated), nothing else. + ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]" + run: | + set -eu + fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; } + case "$EVENT" in + push|workflow_dispatch|schedule|merge_group|release|workflow_call|repository_dispatch) + # Only someone with write access to this repository (or our App's token) can cause these + # events; none of them runs pull-request code. + ;; + workflow_run) + # LB-437: bind identity to the triggering run and its re-runner. + # These two App bots are fixed canon policy; ALLOWED_BOTS is PR-only. + [ -n "${WR_HEAD_REPO:-}" ] || fail "workflow_run head repository is missing" + [ -n "${WR_ACTOR:-}" ] || fail "workflow_run triggering actor is missing" + [ "$WR_HEAD_REPO" = "$REPO" ] || fail "workflow_run head repository does not match this repository" + case "$WR_ACTOR" in + "pineforge-app[bot]"|"pineforge-ci-dispatcher[bot]") ;; + *"[bot]") fail "workflow_run bot is not on the canon allowlist" ;; + *) + perm=$(gh api "repos/$REPO/collaborators/$WR_ACTOR/permission" --jq .permission 2>/dev/null) || fail "workflow_run permission lookup failed" + case "$perm" in admin|maintain|write) ;; *) fail "workflow_run triggering actor does not have write permission" ;; esac ;; + esac ;; + pull_request) + [ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})" + [ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork" + case "$ASSOCIATION" in + OWNER|MEMBER|COLLABORATOR) ;; + *) + case " $ALLOWED_BOTS " in + *" $PR_AUTHOR "*) ;; + *) + # A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the + # author's permission on this repository; anything but admin/maintain/write (or a + # failed call) refuses. + perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none) + case "$perm" in admin|maintain|write) ;; *) fail "author ${PR_AUTHOR:-unknown} (${ASSOCIATION:-NONE}) has permission '$perm', not write, and is not an allowlisted bot" ;; esac ;; + esac ;; + esac ;; + *) fail "event $EVENT does not run CI (pull_request_target and other events are not allowed)" ;; + esac + echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY" + + - name: Require Darwin + env: + ACTUAL_OS: ${{ runner.os }} + run: | + set -euo pipefail + test "$ACTUAL_OS" = macOS + test "$(uname -s)" = Darwin + + - name: Select exact source + id: source + env: + EVENT: ${{ github.event_name }} + REPO: ${{ github.repository }} + REF: ${{ github.ref }} + EVENT_SHA: ${{ github.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_BASE_REF: ${{ github.event.pull_request.base.ref }} + PR_DRAFT: ${{ github.event.pull_request.draft }} + INPUT_SOURCE_REF: ${{ inputs.source_ref }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + fail() { echo "::error title=macOS compile::$1" >&2; exit 1; } + test "$REPO" = pineforge-4pass/pineforge-engine || fail "unexpected repository" + case "$EVENT" in + pull_request) + test "$PR_BASE_REF" = main || fail "pull request base is not main" + test "$PR_DRAFT" = false || fail "pull request is a draft" + test -z "$INPUT_SOURCE_REF" || fail "source_ref is dispatch-only" + source_sha="$PR_HEAD_SHA" + ;; + push) + test "$REF" = refs/heads/main || fail "push is not main" + test -z "$INPUT_SOURCE_REF" || fail "source_ref is dispatch-only" + source_sha="$EVENT_SHA" + ;; + workflow_dispatch) + source_sha="${INPUT_SOURCE_REF:-$EVENT_SHA}" + ;; + *) fail "event is not admitted by macOS compile" ;; + esac + [[ "$source_sha" =~ ^[0-9a-f]{40}$ ]] || fail "source_ref must be a full lowercase 40-hex commit SHA" + resolved_sha=$(gh api "repos/$REPO/commits/$source_sha" --jq .sha) || fail "source commit is unknown or unreadable" + test "$resolved_sha" = "$source_sha" || fail "repository commit does not match the requested SHA" + printf 'sha=%s\n' "$source_sha" >> "$GITHUB_OUTPUT" + + - name: Checkout exact source + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + repository: ${{ github.repository }} + ref: ${{ steps.source.outputs.sha }} + fetch-depth: 1 + persist-credentials: false + + - name: Verify and print source identity + env: + SOURCE_SHA: ${{ steps.source.outputs.sha }} + run: | + set -euo pipefail + actual_sha=$(git rev-parse --verify HEAD) + test "$actual_sha" = "$SOURCE_SHA" + test "$(git rev-parse --verify "${SOURCE_SHA}^{commit}")" = "$SOURCE_SHA" + actual_tree=$(git rev-parse --verify 'HEAD^{tree}') + printf 'source HEAD=%s\nsource tree=%s\n' "$actual_sha" "$actual_tree" + + - name: Identify compiler and cache paths + id: host + run: | + set -euo pipefail + sw_vers + uname -m + xcodebuild -version + c_compiler=$(xcrun --find clang) + cxx_compiler=$(xcrun --find clang++) + "$c_compiler" --version + "$cxx_compiler" --version + cmake --version + compiler_digest=$(shasum -a 256 "$cxx_compiler") + compiler_digest=${compiler_digest%% *} + [[ "$compiler_digest" =~ ^[0-9a-f]{64}$ ]] + brew_cache=$(brew --cache) + test -n "$brew_cache" + { + printf 'c-compiler=%s\ncxx-compiler=%s\n' "$c_compiler" "$cxx_compiler" + printf 'compiler=%s\nbrew-cache=%s\n' "$compiler_digest" "$brew_cache" + } >> "$GITHUB_OUTPUT" + + - name: Restore downloaded Homebrew dependencies + id: brew-restore + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ steps.host.outputs.brew-cache }} + key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache-${{ steps.source.outputs.sha }} + restore-keys: | + macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache- + + - name: Install dependencies + run: | + set -euo pipefail + brew install eigen ccache + eigen_prefix=$(brew --prefix eigen) + test -f "$eigen_prefix/share/eigen3/cmake/Eigen3Config.cmake" + echo "CMAKE_PREFIX_PATH=$eigen_prefix${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" >> "$GITHUB_ENV" + ccache --version + + - name: Restore ccache + id: ccache-restore + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ env.CCACHE_DIR }} + key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-${{ steps.host.outputs.compiler }}-ccache-${{ steps.source.outputs.sha }} + restore-keys: | + macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-${{ steps.host.outputs.compiler }}-ccache- + + - name: Configure Debug library and test binaries + env: + C_COMPILER: ${{ steps.host.outputs.c-compiler }} + CXX_COMPILER: ${{ steps.host.outputs.cxx-compiler }} + run: | + set -euo pipefail + cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_COMPILER:FILEPATH="$C_COMPILER" \ + -DCMAKE_CXX_COMPILER:FILEPATH="$CXX_COMPILER" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DEigen3_DIR:PATH="$(brew --prefix eigen)/share/eigen3/cmake" \ + -DFETCHCONTENT_FULLY_DISCONNECTED=ON \ + -DPINEFORGE_BUILD_TESTS=ON \ + -DPINEFORGE_BUILD_SOURCE_LAYER=ON \ + -DPINEFORGE_BUILD_TUTORIAL=ON \ + -DPINEFORGE_BUILD_LIVE_RUNNER=OFF \ + -DPINEFORGE_BUILD_CORPUS_STRATEGIES=OFF \ + -DPINEFORGE_BUILD_EXAMPLES=OFF \ + -DPINEFORGE_REQUIRE_ABI_RECEIPTS=OFF + sed -n '/^CMAKE_.*COMPILER/p; /^CMAKE_BUILD_TYPE:/p; /^PINEFORGE_BUILD_/p; /^PINEFORGE_REQUIRE_ABI_RECEIPTS:/p; /^Eigen3_DIR:/p' build/CMakeCache.txt + + - name: Build library and test binaries + run: | + set -euo pipefail + cmake --build build --parallel "$(sysctl -n hw.ncpu)" + test -s build/lib/libpineforge.a + test -x build/bin/test_ta + test -x build/bin/test_integration + + - name: Save downloaded Homebrew dependencies on successful main push + if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.brew-restore.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ steps.host.outputs.brew-cache }} + key: ${{ steps.brew-restore.outputs.cache-primary-key }} + + - name: Save ccache on successful main push + if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.ccache-restore.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ env.CCACHE_DIR }} + key: ${{ steps.ccache-restore.outputs.cache-primary-key }} diff --git a/scripts/test_ci_preflight.py b/scripts/test_ci_preflight.py index 6092a4379..6d5cc46ec 100644 --- a/scripts/test_ci_preflight.py +++ b/scripts/test_ci_preflight.py @@ -2318,6 +2318,15 @@ def test_post_events_require_post_fleet_except_the_fixed_hosted_job(self): continue if not events & post_events: continue + if name == 'macos-compile.yml': + # This sole mixed-event exception is a complete source contract, + # including authorization and compile-only steps, not an OS exemption. + self.assertEqual(set(_jobs(workflow)), {'compile-macos'}) + self.assertEqual(ci_preflight._job_values(_jobs(workflow)['compile-macos'], + 'runs-on'), ['macos-latest']) + self.assertEqual(ci_preflight.runner_findings({name: workflow}), []) + checked += 1 + continue self.assertNotIn('pull_request', events, name) for job, body in _jobs(workflow).items(): if ci_preflight._job_values(body, 'uses'): @@ -2368,7 +2377,11 @@ def test_pull_request_workflows_never_name_post_fleet(self): if 'pull_request' not in events: continue checked += 1 - self.assertFalse(events & {'push', 'schedule', 'workflow_dispatch'}, name) + if name == 'macos-compile.yml': + self.assertEqual(events, {'pull_request', 'push', 'workflow_dispatch'}) + self.assertEqual(ci_preflight.runner_findings({name: workflow}), []) + else: + self.assertFalse(events & {'push', 'schedule', 'workflow_dispatch'}, name) self.assertNotIn('gkp-', workflow, name) self.assertIsNone(ci_preflight._RETIRED_VM_LABEL.search(workflow), name) self.assertGreater(checked, 0) @@ -3721,6 +3734,286 @@ def test_shards_build_cold_and_keep_unique_diagnostics(self): changed, 'ci-post.yml', pr=False)) +class MacosCompilePolicy(unittest.TestCase): + """Read the real advisory workflow and exercise its policy and shell inputs.""" + + NAME = 'macos-compile.yml' + JOB = 'compile-macos' + REPO = 'pineforge-4pass/pineforge-engine' + + def workflow(self): + return (ROOT / '.github/workflows' / self.NAME).read_text() + + def assert_refused(self, changed, *, name=NAME): + if name == self.NAME: + self.assertNotEqual(changed, self.workflow(), 'the mutation must change the input') + self.assertTrue(ci_preflight.workflow_fleet_findings({name: changed})) + self.assertTrue(ci_preflight.runner_findings({name: changed})) + + def shell_tree(self, tools): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + root = Path(directory.name) + (root / 'tools').mkdir() + for name, script in tools.items(): + path = root / 'tools' / name + path.write_text('#!/bin/bash\nset -eu\n' + script) + path.chmod(0o755) + return root, {'PATH': str(root / 'tools') + os.pathsep + os.environ.get('PATH', '')} + + def run_script(self, root, env, step): + script = job_script(self.workflow(), self.JOB, step) + return subprocess.run(['bash', '-euo', 'pipefail', '-c', script], cwd=root, + env=env, text=True, capture_output=True) + + def test_real_compile_workflow_is_independent_and_admitted(self): + workflow = self.workflow() + workflows = {path.name: path.read_text() + for path in (ROOT / '.github/workflows').iterdir() + if path.suffix in ('.yml', '.yaml')} + self.assertEqual(ci_preflight.runner_findings(workflows), []) + sources = [(ROOT / path).read_text() for path in CI_SOURCES] + named = {Path(path).name for path in CI_SOURCES} + others = {name: text for name, text in workflows.items() if name not in named} + self.assertEqual(ci_workflow_findings(*sources, others=others), []) + job, = _jobs(workflow) + self.assertEqual(job, self.JOB) + self.assertEqual(ci_preflight._job_values(_jobs(workflow)[job], 'name'), ['macOS compile']) + steps = ci_preflight._steps(_jobs(workflow)[job]) + canon = ci_preflight._steps(_jobs(workflows['ci.yml'])['authz'])[0] + self.assertEqual(steps[0].rstrip(), canon.rstrip()) + self.assertNotIn('needs:', _jobs(workflow)[job]) + for name, text in workflows.items(): + if name == self.NAME: + continue + for body in _jobs(text).values(): + self.assertNotIn(self.JOB, ci_preflight._needs(body), name) + self.assertNotIn('./.github/workflows/' + self.NAME, + ci_preflight._job_values(body, 'uses'), name) + self.assertNotIn(self.JOB, PROOF_JOBS) + + def test_file_job_runner_and_single_job_shape_are_exact(self): + workflow = self.workflow() + self.assert_refused('') + for name in ('other.yml', 'macos-compile.yaml', 'ci-macos.yml'): + with self.subTest(filename=name): + self.assert_refused(workflow, name=name) + for before, after in ( + (' compile-macos:\n', ' build-macos:\n'), + (' name: macOS compile\n', ' name: build\n'), + (' runs-on: macos-latest\n', ' runs-on: ubuntu-24.04\n'), + (' runs-on: macos-latest\n', ' runs-on: macos-26\n'), + (' runs-on: macos-latest\n', ' runs-on: macos-26-xlarge\n'), + (' steps:\n', ' strategy:\n matrix:\n mode: [Debug]\n steps:\n'), + (' steps:\n', ' uses: ./.github/workflows/native-live.yml\n steps:\n')): + with self.subTest(mutation=after): + self.assertIn(before, workflow) + self.assert_refused(workflow.replace(before, after, 1)) + self.assert_refused(workflow + '\n extra:\n runs-on: macos-latest\n' + ' steps:\n - run: cmake --version\n') + + def test_triggers_permissions_authz_and_failure_policy_are_exact(self): + workflow = self.workflow() + for before, after in ( + (' pull_request:\n', ' pull_request_target:\n'), + (' branches: [main]\n', ' branches: [dev]\n'), + (' push:\n', ' schedule:\n - cron: "30 1 * * *"\n push:\n'), + (' workflow_dispatch:\n', ' workflow_call:\n workflow_dispatch:\n'), + (' contents: read\n', ' contents: write\n'), + (' contents: read\n', ' contents: read\n id-token: write\n'), + (' steps:\n', ' environment: release\n steps:\n'), + (' steps:\n', ' if: false\n steps:\n'), + (' steps:\n', ' continue-on-error: true\n steps:\n'), + (' steps:\n', ' timeout-minutes: 30\n steps:\n'), + ('exit 1; }', 'true; }'), + (' set -euo pipefail\n', ' set +e\n'), + (' cmake --build build --parallel "$(sysctl -n hw.ncpu)"', + ' cmake --build build --parallel "$(sysctl -n hw.ncpu)" || true')): + with self.subTest(mutation=after): + self.assertIn(before, workflow) + self.assert_refused(workflow.replace(before, after, 1)) + steps = ci_preflight._steps(_jobs(workflow)[self.JOB]) + self.assert_refused(workflow.replace(steps[0], '', 1)) + self.assert_refused(workflow.replace(steps[0], steps[1], 1)) + + def test_ref_checkout_identity_and_cache_policy_are_exact(self): + workflow = self.workflow() + for before, after in ( + (' persist-credentials: false', ' persist-credentials: true'), + (' ref: ${{ steps.source.outputs.sha }}', ' ref: ${{ github.sha }}'), + (' repository: ${{ github.repository }}', ' repository: other/engine'), + ('^[0-9a-f]{40}$', '^[0-9a-f]{7,40}$'), + ('test "$actual_sha" = "$SOURCE_SHA"', 'test -n "$actual_sha"'), + ('test "$resolved_sha" = "$source_sha"', 'test -n "$resolved_sha"'), + ('actions/cache/restore@', 'actions/cache@'), + ('path: ${{ steps.host.outputs.brew-cache }}', 'path: build'), + ('path: ${{ env.CCACHE_DIR }}', 'path: build'), + ('key: ${{ steps.ccache-restore.outputs.cache-primary-key }}', 'key: ccache-pr'), + ('${{ runner.arch }}-Debug-', '${{ runner.arch }}-Release-')): + with self.subTest(mutation=after): + self.assertIn(before, workflow) + self.assert_refused(workflow.replace(before, after, 1)) + + for step in ('Save downloaded Homebrew dependencies on successful main push', + 'Save ccache on successful main push'): + for before, after in (("github.event_name == 'push'", "github.event_name == 'pull_request'"), + ("github.ref == 'refs/heads/main'", 'true'), + ('success() && ', 'always() && ')): + with self.subTest(cache_save=step, mutation=after): + self.assert_refused(in_step(workflow, self.JOB, step, before, after)) + + def test_configure_and_all_target_build_cannot_become_test_execution(self): + workflow = self.workflow() + build = 'cmake --build build --parallel "$(sysctl -n hw.ncpu)"' + for command in ('ctest --test-dir build', 'python3 scripts/ci_verify.py debug', + 'python3 -m pytest', 'python3 -m unittest', './build/bin/test_ta', + 'cmake --build build --target test', 'cmake --build build --target check', + 'cmake --build build --target pineforge', 'true'): + with self.subTest(command=command): + self.assert_refused(workflow.replace(build, command, 1)) + for option, value in ( + ('PINEFORGE_BUILD_TESTS', 'ON'), ('PINEFORGE_BUILD_SOURCE_LAYER', 'ON'), + ('PINEFORGE_BUILD_TUTORIAL', 'ON'), ('PINEFORGE_BUILD_LIVE_RUNNER', 'OFF'), + ('PINEFORGE_BUILD_CORPUS_STRATEGIES', 'OFF'), ('PINEFORGE_BUILD_EXAMPLES', 'OFF'), + ('PINEFORGE_REQUIRE_ABI_RECEIPTS', 'OFF'), ('CMAKE_EXPORT_COMPILE_COMMANDS', 'ON')): + before = f'-D{option}={value}' + for after in ('', f'-D{option}={"OFF" if value == "ON" else "ON"}'): + with self.subTest(option=option, replacement=after): + self.assertIn(before, workflow) + self.assert_refused(workflow.replace(before, after, 1)) + for line in (' test -s build/lib/libpineforge.a\n', + ' test -x build/bin/test_ta\n', + ' test -x build/bin/test_integration\n'): + self.assertIn(line, workflow) + self.assert_refused(workflow.replace(line, '', 1)) + + def test_existing_gate_and_reusable_call_cannot_depend_on_compile(self): + workflow = self.workflow() + self.assert_refused(workflow.replace(' steps:\n', ' needs: [authz]\n steps:\n', 1)) + post = (ROOT / '.github/workflows/ci-post.yml').read_text() + needs, = ci_preflight._job_values(_jobs(post)['build-gate'], 'needs') + changed = in_job(post, 'build-gate', ' needs: ' + needs, + ' needs: ' + needs[:-1] + ', compile-macos]') + self.assertIn('build-gate must aggregate authz, every proof job, preflight and changes', + ci_preflight.pipeline_workflow_findings(changed, 'ci-post.yml', pr=False)) + for event in ('pull_request', 'push', 'workflow_dispatch'): + caller = (f'on: {event}\njobs:\n call:\n' + ' uses: ./.github/workflows/macos-compile.yml\n') + self.assertIn('caller.yml job call must call a readable local reusable workflow', + ci_preflight.runner_findings({'caller.yml': caller, self.NAME: workflow})) + + def test_source_selection_reads_event_sha_input_and_repository_response(self): + a, b, c = '12' * 20, '34' * 20, 'ef' * 20 + root, env = self.shell_tree({'gh': ( + 'printf "%s\\n" "$*" > "$API_LOG"\n' + 'test "$API_EXIT" = 0 || exit "$API_EXIT"\n' + 'printf "%s\\n" "$API_SHA"\n')}) + base = {**env, 'EVENT': 'push', 'REPO': self.REPO, 'REF': 'refs/heads/main', + 'EVENT_SHA': a, 'PR_HEAD_SHA': b, 'PR_BASE_REF': 'main', 'PR_DRAFT': 'false', + 'INPUT_SOURCE_REF': '', 'API_SHA': a, 'API_EXIT': '0'} + cases = [ + ({}, a, True), ({'EVENT': 'pull_request', 'API_SHA': b}, b, True), + ({'EVENT': 'workflow_dispatch'}, a, True), + ({'EVENT': 'workflow_dispatch', 'INPUT_SOURCE_REF': c, 'API_SHA': c}, c, True), + ({'REF': 'refs/heads/dev'}, None, False), + ({'EVENT': 'pull_request', 'PR_DRAFT': 'true'}, None, False), + ({'EVENT': 'pull_request', 'PR_BASE_REF': 'dev'}, None, False), + ({'REPO': 'outside/engine'}, None, False), + ({'EVENT': 'workflow_run'}, None, False), + ({'INPUT_SOURCE_REF': c}, None, False), + ({'API_EXIT': '22'}, None, True), + ({'API_SHA': c}, None, True), + ] + for value in ('main', a[:12], 'g' * 40, c + '\n', + '$(touch injected)', '`touch injected`', '--help'): + cases.append(({'EVENT': 'workflow_dispatch', 'INPUT_SOURCE_REF': value}, None, False)) + # Use letters for the uppercase control; digit-only SHAs have no uppercase form. + cases.append(({'EVENT': 'workflow_dispatch', 'INPUT_SOURCE_REF': 'AB' * 20}, None, False)) + for index, (change, selected, lookup) in enumerate(cases): + with self.subTest(change=change): + output, log = root / f'output-{index}', root / f'api-{index}' + ran = self.run_script(root, {**base, **change, 'GITHUB_OUTPUT': str(output), + 'API_LOG': str(log)}, 'Select exact source') + self.assertEqual(ran.returncode == 0, selected is not None, ran.stdout + ran.stderr) + self.assertEqual(output.read_text() if output.exists() else '', + f'sha={selected}\n' if selected else '') + self.assertEqual(log.exists(), lookup) + if lookup: + requested = change.get('INPUT_SOURCE_REF') or ( + b if change.get('EVENT') == 'pull_request' else a) + self.assertEqual(log.read_text(), + f'api repos/{self.REPO}/commits/{requested} --jq .sha\n') + self.assertFalse((root / 'injected').exists()) + + def test_checkout_identity_reads_actual_head_commit_and_tree(self): + root, env = self.shell_tree({'git': ( + 'printf "%s\\n" "$*" >> "$GIT_LOG"\n' + 'test "$GIT_EXIT" = 0 || exit "$GIT_EXIT"\n' + 'case "$*" in\n' + ' "rev-parse --verify HEAD") printf "%s\\n" "$ACTUAL_SHA" ;;\n' + ' "rev-parse --verify ${SOURCE_SHA}^{commit}") printf "%s\\n" "$COMMIT_SHA" ;;\n' + ' "rev-parse --verify HEAD^{tree}") printf "%s\\n" "$TREE_SHA" ;;\n' + ' *) exit 29 ;;\n' + 'esac\n')}) + for index, (source, actual, commit, git_exit) in enumerate(( + ('ab' * 20, 'ab' * 20, 'ab' * 20, '0'), + ('cd' * 20, 'cd' * 20, 'cd' * 20, '0'), + ('ab' * 20, 'cd' * 20, 'ab' * 20, '0'), + ('ab' * 20, 'ab' * 20, 'cd' * 20, '0'), + ('ab' * 20, 'ab' * 20, 'ab' * 20, '37'))): + with self.subTest(source=source, actual=actual, commit=commit, git_exit=git_exit): + tree = ('12' if index == 0 else '34') * 20 + log = root / f'git-{index}' + ran = self.run_script(root, {**env, 'SOURCE_SHA': source, 'ACTUAL_SHA': actual, + 'COMMIT_SHA': commit, 'TREE_SHA': tree, + 'GIT_EXIT': git_exit, 'GIT_LOG': str(log)}, + 'Verify and print source identity') + allowed = source == actual == commit and git_exit == '0' + self.assertEqual(ran.returncode == 0, allowed, ran.stdout + ran.stderr) + if allowed: + self.assertIn(f'source HEAD={source}\nsource tree={tree}\n', ran.stdout) + self.assertEqual(log.read_text().splitlines(), [ + 'rev-parse --verify HEAD', f'rev-parse --verify {source}^{{commit}}', + 'rev-parse --verify HEAD^{tree}']) + + def test_darwin_guard_reads_the_host_instead_of_trusting_the_runner_label(self): + root, env = self.shell_tree({'uname': 'test "$*" = -s\nprintf "%s\\n" "$KERNEL"\n'}) + for label, kernel in (('macOS', 'Darwin'), ('macOS', 'Linux'), + ('Linux', 'Darwin'), ('macOS', '')): + with self.subTest(label=label, kernel=kernel): + ran = self.run_script(root, {**env, 'ACTUAL_OS': label, 'KERNEL': kernel}, + 'Require Darwin') + self.assertEqual(ran.returncode == 0, (label, kernel) == ('macOS', 'Darwin')) + + def test_all_build_reads_host_cores_preserves_errors_and_requires_outputs(self): + root, env = self.shell_tree({ + 'cmake': 'printf "%s\\n" "$*" > "$BUILD_LOG"\nexit "$BUILD_EXIT"\n', + 'sysctl': 'test "$*" = "-n hw.ncpu"\nprintf "%s\\n" "$CORES"\n'}) + outputs = ('build/lib/libpineforge.a', 'build/bin/test_ta', 'build/bin/test_integration') + cases = [('3', '0', None), ('7', '0', None), ('3', '41', None), + *(('3', '0', name) for name in outputs)] + for index, (cores, build_exit, missing) in enumerate(cases): + with self.subTest(cores=cores, build_exit=build_exit, missing=missing): + case_root = root / str(index) + case_root.mkdir() + for name in outputs: + if name == missing: + continue + path = case_root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text('#!/bin/bash\necho ran > "$RUNTIME_LOG"\nexit 99\n') + path.chmod(0o755) + log, runtime = case_root / 'build-log', case_root / 'runtime-log' + ran = self.run_script(case_root, {**env, 'CORES': cores, 'BUILD_EXIT': build_exit, + 'BUILD_LOG': str(log), 'RUNTIME_LOG': str(runtime)}, + 'Build library and test binaries') + self.assertEqual(log.read_text(), f'--build build --parallel {cores}\n') + self.assertEqual(ran.returncode == 0, build_exit == '0' and missing is None) + if build_exit != '0': + self.assertEqual(ran.returncode, int(build_exit)) + self.assertFalse(runtime.exists(), 'compile coverage must never execute test binaries') + + class PostLinuxBuildPolicy(unittest.TestCase): """Policy regressions whose inputs can also be constructed from main.""" @@ -4711,6 +5004,25 @@ def test_the_combined_checker_takes_the_file_texts_as_stored(self): # action-pin lint still has to read them as the LF text they always did. self.assertEqual(ci_workflow_findings(*(text.replace('\n', '\r\n') for text in sources)), []) + def test_macos_compile_reader_consumes_changes_and_refuses_a_missing_file(self): + name = '.github/workflows/macos-compile.yml' + original = (ROOT / name).read_text() + code, output = self.run_stage(self.make_tree(), '--check-ci-workflow') + self.assertEqual(code, 0, output) + for changed in ('', original.replace('PINEFORGE_BUILD_TESTS=ON', + 'PINEFORGE_BUILD_TESTS=OFF', 1), None): + with self.subTest(change=changed): + tree = self.make_tree() + path = tree / name + if changed is None: + path.rename(path.with_name('macos-spoof.yml')) + else: + self.assertNotEqual(changed, original) + path.write_text(changed) + code, output = self.run_stage(tree, '--check-ci-workflow') + self.assertEqual(code, 1, output) + self.assertIn('macos-compile.yml', output) + def test_a_file_that_is_not_utf8_is_a_finding_not_a_crash(self): for name in (self.DOCS, '.github/workflows/release.yml', '.github/actions/setup-live-curl/action.yml', self.CMAKE, self.HELPER): @@ -5497,6 +5809,11 @@ def gcp_sites(self): for job, body in _jobs(workflow).items(): if ci_preflight._job_values(body, 'uses'): continue + if (name, job) == ('macos-compile.yml', 'compile-macos'): + # The independent compile contract has its own varied-input + # controls; it does not add a GCP/proof site or change this floor. + self.assertEqual(ci_preflight.runner_findings({name: workflow}), []) + continue gke = EXPECTED_GKE_JOBS.get(name, {}).get(job) gkp = EXPECTED_GKP_JOBS.get(name, {}).get(job) if (not gke and not gkp and job in ci_preflight.HOSTED_JOB_RUNNERS.get(name, {}) @@ -9018,6 +9335,7 @@ def test_new_workflows_require_event_fleets_without_conditional_routes(self): ('>-\n pull_request', 'macos-26-xlarge', True), ('[pull_request]', 'ubuntu-latest', True), ('[pull_request]', 'macos-26', True), + ('[pull_request]', 'macos-latest', True), ('pull_request_target', 'macos-26', True), ('pull_request_target', 'ubuntu-22.04-arm', True), ('[pull_request]', 'ubuntu-22.04-arm', True), @@ -10653,12 +10971,15 @@ def test_resolver_crash_propagates_its_own_exit_without_authorization(self): class CanonAuthz(unittest.TestCase): def test_real_workflow_scripts_admit_our_events_and_refuse_untrusted_identity(self): - paths = (*CI_SOURCES[:2], '.github/workflows/release-ruleset-probe.yml') + paths = (*CI_SOURCES[:2], '.github/workflows/release-ruleset-probe.yml', + '.github/workflows/macos-compile.yml') scripts = [] for path in paths: workflow = (ROOT / path).read_text() - self.assertIn('authz', _jobs(workflow), f'{path} must authorize before repository code') - scripts.append(job_script(workflow, 'authz')) + job = 'compile-macos' if path.endswith('/macos-compile.yml') else 'authz' + self.assertIn(job, _jobs(workflow), f'{path} must authorize before repository code') + scripts.append(job_script(workflow, job, + 'Only our own pull requests and our own events run CI')) for script in scripts[1:]: self.assertEqual(scripts[0], script) base = {'EVENT': 'pull_request', 'REPO': 'owner/engine', 'HEAD_REPO': 'owner/engine', From b37ac33c76d43d1895b4caf63616a64423853baf Mon Sep 17 00:00:00 2001 From: luisleo526 Date: Tue, 10 Nov 2026 09:54:19 +0800 Subject: [PATCH 2/4] ci: add advisory macOS compile coverage Admit only the pinned macOS compile workflow, leaving existing proof aggregates and Linux release artifacts unchanged. --- docs/ci.md | 16 ++- scripts/ci_preflight.py | 233 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 246 insertions(+), 3 deletions(-) diff --git a/docs/ci.md b/docs/ci.md index 6dfa5c4f7..50c9aa78f 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -13,6 +13,18 @@ The current PR admission and post-merge trigger map is: | `corpus-parity.yml` | Not triggered | Not triggered | Full parity and its post-merge subset | | `docs.yml` | Documentation build except `.github/**`-only changes | Skipped by its path filter | Documentation build on its own trigger | | `gke-pr / build-arm` | Hosted arm64 Debug build and tests when `arm_relevant=true` | Skipped | Not triggered | +| `macos-compile / macOS compile` | Advisory Debug library and test-binary compilation | Same compile coverage | Main pushes and manual dispatch only; no nightly trigger | + +`macos-compile.yml` has one independent `compile-macos` job on `macos-latest`. +It authorizes before checkout, compiles the exact same-repository nonfork PR head +or main push SHA, and prints the actual HEAD, tree, compiler and configuration. +Manual dispatch accepts an optional `source_ref`: an existing repository commit's +full lowercase 40-hex SHA, defaulting to the dispatch SHA. Debug enables the +source layer, tests and tutorial, then builds ALL targets without executing tests. +Homebrew downloads and ccache restore on every admitted event; only successful +main pushes save them. This workflow is outside every merge/release aggregate, +required context and release archive. Maintainers may reconsider requiring it only after +three real green main runs; this workflow never changes that policy automatically. The admission workflow is defined on `main` and runs on hosted `ubuntu-24.04` runners with no runner-group allowlist entry. Its proof legs use the same hosted @@ -1648,13 +1660,15 @@ The native matrix is exactly `1..4` with `--ctest-shard I/4`; live sanitizers ar | `docs-post.yml` | Push to `main`, dispatch | `authz` and credentialed `build`: `ubuntu-24.04` | | `release.yml` | Dispatch from `main`; the toolchain caller additionally checks its ref | `release`, `prebuilt-x86`, `upload` and `notify-hub`: hosted `ubuntu-24.04`; `prebuilt-arm`: hosted `ubuntu-22.04-arm` | | `prebuilt-hosted-diagnostic.yml` | Same-repository PRs to `main` | `observe`: hosted `ubuntu-24.04`, read-only host observations | +| `macos-compile.yml` | Admitted PRs to `main`, main pushes, dispatch | One advisory `compile-macos`: hosted `macos-latest`, compile only | | `promote-baseline.yml` | Push to `main`, dispatch from `main` | `promote-guard` and `promote`: `ubuntu-24.04` | | `release-ruleset-probe.yml` | Dispatch from `main` | `authz` and `probe`: `ubuntu-24.04` | Post CI starts on push to `main`, schedule and dispatch; its routing checker refuses all PR events. Reusable workflows inherit their caller's event. `workflow_event_routes` and `workflow_fleet_findings` in `scripts/ci_preflight.py` -follow local calls to a fixed point, refuse mixed event classes and require +follow local calls to a fixed point, refuse mixed event classes except the +complete pinned advisory macOS compile contract, and require the exact hosted image of each pinned job or the exact native profile runner matrix; job conditions cannot excuse routing. Fork PRs on hosted runners run without our secrets, so the VM-only fork-refusal hook is not needed. Pinned verification jobs carry no deployment secrets, effective id-token permissions or environment and declare no job container or services; pull_request workflows cannot name `gke-*` or `gkp-*` routing. All current workflow jobs use hosted images and need no runner-group entry. The exact legacy isolated and hosted-matrix release forms remain admitted for rollback; restoring a protected route also requires its live group membership and committed mirror entry. diff --git a/scripts/ci_preflight.py b/scripts/ci_preflight.py index d5e78929d..65e8d13df 100644 --- a/scripts/ci_preflight.py +++ b/scripts/ci_preflight.py @@ -2617,6 +2617,13 @@ def workflow_fleet_findings(workflows: dict[str, str]) -> list[str]: for name, workflow in workflows.items(): if name == 'gke-pr.yml': continue + if name == MACOS_COMPILE_FILE: + compile_findings = macos_compile_workflow_findings(workflow, name) + findings += compile_findings + # Only the complete advisory compile contract admits mixed events. + # An altered file falls through to the ordinary event/fleet refusals. + if not compile_findings: + continue # Per-job release/probe pins are checked by runner_findings; the probe # shares release.yml's App credential and uses the protected fleet. if name in RELEASE_JOB_RUNNERS: @@ -3052,7 +3059,11 @@ def runner_findings(workflows: dict[str, str]) -> list[str]: split_release_form = name == 'release.yml' and _release_split_requested(jobs) arm_variant = _gke_pr_arm_variant(name, jobs) corpus_variant = _gke_pr_corpus_variant(name, jobs) + compile_exception = (name == MACOS_COMPILE_FILE + and not macos_compile_workflow_findings(workflow, name)) timed = GKE_PR_ARM_JOB_COMMANDS if arm_variant else JOB_COMMANDS.get(name, {}) + if compile_exception: + timed = {'compile-macos': None} gke_pins = GKE_PR_ARM_JOB_LABELS if arm_variant else GKE_JOB_RUNNERS.get(name, {}) if corpus_variant: timed = {**timed, **GKE_PR_CORPUS_JOB_COMMANDS} @@ -3065,6 +3076,8 @@ def runner_findings(workflows: dict[str, str]) -> list[str]: fixed_hosted = {job: label for job, label in hosted_pins.items() if label == HOSTED_X86_RUNNER or name == 'gke-pr.yml' or (routes[name] & POST_EVENTS and 'pull_request' not in routes[name])} + if compile_exception: + fixed_hosted['compile-macos'] = 'macos-latest' if _LARGER_RUNNER_LABEL.search(code): findings.append(f'{name} must not use larger-runner labels; use the GCP fleet or hosted exceptions') fixed_release = (SPLIT_RELEASE_JOB_RUNNERS if split_release_form @@ -4129,6 +4142,219 @@ def _compiler_cache_restore_with(step: str) -> list[str]: ''', } +MACOS_COMPILE_FILE = 'macos-compile.yml' +# This source contract grants one independent compile job its hosted/mixed-event +# exception. Keep the authorization canon shared, and pin every other byte so +# extra steps, permissions, cache writes, event/ref shortcuts or test execution +# cannot inherit the exception. This is workflow policy, never compile evidence. +MACOS_COMPILE_HEADER = r'''name: macOS compile + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review, converted_to_draft] + push: + branches: [main] + workflow_dispatch: + inputs: + source_ref: + description: Existing repository commit to compile (full lowercase 40-hex SHA; empty uses dispatch SHA) + required: false + type: string + default: '' + +permissions: + contents: read + +env: + HOMEBREW_NO_AUTO_UPDATE: '1' + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPILERCHECK: content + +defaults: + run: + shell: bash + +jobs: + compile-macos: + name: macOS compile + runs-on: macos-latest + steps: +''' +MACOS_COMPILE_STEPS = r''' - name: Require Darwin + env: + ACTUAL_OS: ${{ runner.os }} + run: | + set -euo pipefail + test "$ACTUAL_OS" = macOS + test "$(uname -s)" = Darwin + + - name: Select exact source + id: source + env: + EVENT: ${{ github.event_name }} + REPO: ${{ github.repository }} + REF: ${{ github.ref }} + EVENT_SHA: ${{ github.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_BASE_REF: ${{ github.event.pull_request.base.ref }} + PR_DRAFT: ${{ github.event.pull_request.draft }} + INPUT_SOURCE_REF: ${{ inputs.source_ref }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + fail() { echo "::error title=macOS compile::$1" >&2; exit 1; } + test "$REPO" = pineforge-4pass/pineforge-engine || fail "unexpected repository" + case "$EVENT" in + pull_request) + test "$PR_BASE_REF" = main || fail "pull request base is not main" + test "$PR_DRAFT" = false || fail "pull request is a draft" + test -z "$INPUT_SOURCE_REF" || fail "source_ref is dispatch-only" + source_sha="$PR_HEAD_SHA" + ;; + push) + test "$REF" = refs/heads/main || fail "push is not main" + test -z "$INPUT_SOURCE_REF" || fail "source_ref is dispatch-only" + source_sha="$EVENT_SHA" + ;; + workflow_dispatch) + source_sha="${INPUT_SOURCE_REF:-$EVENT_SHA}" + ;; + *) fail "event is not admitted by macOS compile" ;; + esac + [[ "$source_sha" =~ ^[0-9a-f]{40}$ ]] || fail "source_ref must be a full lowercase 40-hex commit SHA" + resolved_sha=$(gh api "repos/$REPO/commits/$source_sha" --jq .sha) || fail "source commit is unknown or unreadable" + test "$resolved_sha" = "$source_sha" || fail "repository commit does not match the requested SHA" + printf 'sha=%s\n' "$source_sha" >> "$GITHUB_OUTPUT" + + - name: Checkout exact source + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + repository: ${{ github.repository }} + ref: ${{ steps.source.outputs.sha }} + fetch-depth: 1 + persist-credentials: false + + - name: Verify and print source identity + env: + SOURCE_SHA: ${{ steps.source.outputs.sha }} + run: | + set -euo pipefail + actual_sha=$(git rev-parse --verify HEAD) + test "$actual_sha" = "$SOURCE_SHA" + test "$(git rev-parse --verify "${SOURCE_SHA}^{commit}")" = "$SOURCE_SHA" + actual_tree=$(git rev-parse --verify 'HEAD^{tree}') + printf 'source HEAD=%s\nsource tree=%s\n' "$actual_sha" "$actual_tree" + + - name: Identify compiler and cache paths + id: host + run: | + set -euo pipefail + sw_vers + uname -m + xcodebuild -version + c_compiler=$(xcrun --find clang) + cxx_compiler=$(xcrun --find clang++) + "$c_compiler" --version + "$cxx_compiler" --version + cmake --version + compiler_digest=$(shasum -a 256 "$cxx_compiler") + compiler_digest=${compiler_digest%% *} + [[ "$compiler_digest" =~ ^[0-9a-f]{64}$ ]] + brew_cache=$(brew --cache) + test -n "$brew_cache" + { + printf 'c-compiler=%s\ncxx-compiler=%s\n' "$c_compiler" "$cxx_compiler" + printf 'compiler=%s\nbrew-cache=%s\n' "$compiler_digest" "$brew_cache" + } >> "$GITHUB_OUTPUT" + + - name: Restore downloaded Homebrew dependencies + id: brew-restore + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ steps.host.outputs.brew-cache }} + key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache-${{ steps.source.outputs.sha }} + restore-keys: | + macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache- + + - name: Install dependencies + run: | + set -euo pipefail + brew install eigen ccache + eigen_prefix=$(brew --prefix eigen) + test -f "$eigen_prefix/share/eigen3/cmake/Eigen3Config.cmake" + echo "CMAKE_PREFIX_PATH=$eigen_prefix${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" >> "$GITHUB_ENV" + ccache --version + + - name: Restore ccache + id: ccache-restore + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ env.CCACHE_DIR }} + key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-${{ steps.host.outputs.compiler }}-ccache-${{ steps.source.outputs.sha }} + restore-keys: | + macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-${{ steps.host.outputs.compiler }}-ccache- + + - name: Configure Debug library and test binaries + env: + C_COMPILER: ${{ steps.host.outputs.c-compiler }} + CXX_COMPILER: ${{ steps.host.outputs.cxx-compiler }} + run: | + set -euo pipefail + cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_COMPILER:FILEPATH="$C_COMPILER" \ + -DCMAKE_CXX_COMPILER:FILEPATH="$CXX_COMPILER" \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DEigen3_DIR:PATH="$(brew --prefix eigen)/share/eigen3/cmake" \ + -DFETCHCONTENT_FULLY_DISCONNECTED=ON \ + -DPINEFORGE_BUILD_TESTS=ON \ + -DPINEFORGE_BUILD_SOURCE_LAYER=ON \ + -DPINEFORGE_BUILD_TUTORIAL=ON \ + -DPINEFORGE_BUILD_LIVE_RUNNER=OFF \ + -DPINEFORGE_BUILD_CORPUS_STRATEGIES=OFF \ + -DPINEFORGE_BUILD_EXAMPLES=OFF \ + -DPINEFORGE_REQUIRE_ABI_RECEIPTS=OFF + sed -n '/^CMAKE_.*COMPILER/p; /^CMAKE_BUILD_TYPE:/p; /^PINEFORGE_BUILD_/p; /^PINEFORGE_REQUIRE_ABI_RECEIPTS:/p; /^Eigen3_DIR:/p' build/CMakeCache.txt + + - name: Build library and test binaries + run: | + set -euo pipefail + cmake --build build --parallel "$(sysctl -n hw.ncpu)" + test -s build/lib/libpineforge.a + test -x build/bin/test_ta + test -x build/bin/test_integration + + - name: Save downloaded Homebrew dependencies on successful main push + if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.brew-restore.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ steps.host.outputs.brew-cache }} + key: ${{ steps.brew-restore.outputs.cache-primary-key }} + + - name: Save ccache on successful main push + if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.ccache-restore.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: ${{ env.CCACHE_DIR }} + key: ${{ steps.ccache-restore.outputs.cache-primary-key }} +''' + + +def macos_compile_workflow_findings(workflow: str, name: str = MACOS_COMPILE_FILE) -> list[str]: + """Validate the supplied file, never a filename/OS or test-fixture shortcut.""" + canon = _steps(_jobs(RELEASE_RULESETS_PROBE_WORKFLOW)['authz'])[0].rstrip('\n') + expected = MACOS_COMPILE_HEADER + canon + '\n\n' + MACOS_COMPILE_STEPS + if name != MACOS_COMPILE_FILE or _universal_newlines(workflow).rstrip('\n') != expected.rstrip('\n'): + return [f'{name} must keep the exact independent advisory macOS compile contract: ' + 'one compile-macos job, canonical authorization, immutable source, read-only ' + 'permissions, main-only cache saves and a Debug ALL build without test execution'] + return [] + + PREBUILT_HOSTED_DIAGNOSTIC = r'''name: Prebuilt hosted diagnostic on: @@ -6487,6 +6713,10 @@ def main() -> int: actions = {path.relative_to(ROOT).as_posix(): read_ci_text(path, findings) for path in sorted((ROOT / '.github/actions').rglob('*')) if path.name in ('action.yml', 'action.yaml') and path.is_file()} + others = {path.name: read_ci_text(path, findings) for path in sorted(workflows.iterdir()) + if path.suffix in ('.yml', '.yaml') and path.name not in named} + if MACOS_COMPILE_FILE not in others: + findings.append(f'{MACOS_COMPILE_FILE}: required advisory compile workflow is missing') checked = ci_workflow_findings( read_ci_text(workflows / 'ci.yml', findings), read_ci_text(workflows / 'native-live.yml', findings), @@ -6496,8 +6726,7 @@ def main() -> int: read_ci_text(workflows / 'docs.yml', findings), read_ci_text(workflows / 'ci-post.yml', findings), read_ci_text(workflows / 'docs-post.yml', findings), - {path.name: read_ci_text(path, findings) for path in sorted(workflows.iterdir()) - if path.suffix in ('.yml', '.yaml') and path.name not in named}, + others, curl_action=read_ci_text(ROOT / '.github/actions/setup-live-curl/action.yml', findings), actions=actions) image_path = ROOT / '.github/engine-toolchain-image.txt' From d8d8b17d9cd70426caca3b5b79f4f5322890ea79 Mon Sep 17 00:00:00 2001 From: luisleo526 Date: Tue, 10 Nov 2026 11:11:25 +0800 Subject: [PATCH 3/4] docs: document advisory macOS compile coverage --- docs/ci.md | 62 +++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/docs/ci.md b/docs/ci.md index 50c9aa78f..f19c45965 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -15,43 +15,29 @@ The current PR admission and post-merge trigger map is: | `gke-pr / build-arm` | Hosted arm64 Debug build and tests when `arm_relevant=true` | Skipped | Not triggered | | `macos-compile / macOS compile` | Advisory Debug library and test-binary compilation | Same compile coverage | Main pushes and manual dispatch only; no nightly trigger | -`macos-compile.yml` has one independent `compile-macos` job on `macos-latest`. -It authorizes before checkout, compiles the exact same-repository nonfork PR head -or main push SHA, and prints the actual HEAD, tree, compiler and configuration. -Manual dispatch accepts an optional `source_ref`: an existing repository commit's -full lowercase 40-hex SHA, defaulting to the dispatch SHA. Debug enables the -source layer, tests and tutorial, then builds ALL targets without executing tests. -Homebrew downloads and ccache restore on every admitted event; only successful -main pushes save them. This workflow is outside every merge/release aggregate, -required context and release archive. Maintainers may reconsider requiring it only after -three real green main runs; this workflow never changes that policy automatically. - -The admission workflow is defined on `main` and runs on hosted `ubuntu-24.04` -runners with no runner-group allowlist entry. Its proof legs use the same hosted -Release, Debug and parity images as the post workflow; the hosted result is red for refusal, +`macos-compile.yml` has one independent advisory `compile-macos` job on `macos-latest` and requires Darwin. +It authorizes before checkout, admits same-repository nonfork, non-draft PRs to `main`, compiles the exact PR head or main push SHA, and prints the actual HEAD, tree, compiler and configuration. +Manual dispatch accepts an optional `source_ref`: an existing repository commit's full lowercase 40-hex SHA, defaulting to the dispatch SHA; checkout verifies the selected commit. +Debug enables the source layer, tests and tutorial, then builds ALL targets without executing tests; this workflow adds no new CTest `slow` rows. +Homebrew downloads and ccache restore on every admitted event; only successful main pushes save them. +This workflow is outside every merge/release aggregate, required context and release archive. +Maintainers may reconsider requiring it only after three real green main runs; this workflow never changes that policy automatically. + +The admission workflow is defined on `main` and runs on hosted `ubuntu-24.04` runners with no runner-group allowlist entry. +Its proof legs use the same hosted Release, Debug and parity images as the post workflow; the hosted result is red for refusal, failure, cancellation, disagreement or an unanswered class. The native x86 GNU 13.3.0 job runs for every admitted PR and every post event, including documentation-only and GitHub-only changes: it checks out the exact head, configures a fresh C++17 Release tree with the source layer enabled and optional targets and tests disabled, then invokes the ordinary all-target Unix Makefiles build with the runner's parallelism, and retains the configure and build logs, the compiler identity, CMake cache and compile commands as failure diagnostics. -The nightly CI schedule is 01:30 UTC. The existing docs-only classification -still skips the existing code proof jobs on a documentation-only PR or main push; the native x86 build remains required. Both -preflight tiers together retain the original full stage inventory; the slow -tier still runs on a docs-only main push. Scheduled and manual runs execute -every profile. `ci.yml` retains authorization and draft event handling; -`gke-pr` owns admission, classification, preflight and proof legs. Docs-only -and GitHub-only changes still run preflight, while only the proof legs skip. +The nightly CI schedule is 01:30 UTC. The existing docs-only classification still skips the existing code proof jobs on a documentation-only PR or main push; the native x86 build remains required. +Both preflight tiers together retain the original full stage inventory; the slow tier still runs on a docs-only main push. Scheduled and manual runs execute every profile. +`ci.yml` retains authorization and draft event handling; `gke-pr` owns admission, classification, preflight and proof legs. Docs-only and GitHub-only changes still run preflight, while only the proof legs skip. Failed, cancelled or unclassified work is red in the hosted result. -`rerun-preempted.yml` retries only failed jobs of completed, failed `CI post-merge` -push/schedule runs on `main`, including called native jobs. Every failed job must -have an amd64 `gke-*` label and runner-loss evidence without an independent error. -Missing logs, mixed failures, arm64/`gkp-*` jobs, stale attempts and changed runs -refuse the retry; three total attempts are allowed. PRs, manual dispatches and -release/publish/deploy/promotion workflows are excluded. The controller runs on -hosted `ubuntu-24.04`, uses its trusted default-branch workflow commit, and never +`rerun-preempted.yml` retries only failed jobs of completed, failed `CI post-merge` push/schedule runs on `main`, including called native jobs. +Every failed job must have an amd64 `gke-*` label and runner-loss evidence without an independent error. Missing logs, mixed failures, arm64/`gkp-*` jobs, stale attempts and changed runs refuse the retry; three total attempts are allowed. +PRs, manual dispatches and release/publish/deploy/promotion workflows are excluded. The controller runs on hosted `ubuntu-24.04`, uses its trusted default-branch workflow commit, and never prints log bodies. Missing `gh`, `python3` or the log escape flag fails the job. The post-merge on-demand amd64 labels are included in the same loss-retry fleet; if that routing is rolled back, land a revert PR for the label commit before the next post-merge run. -A GitHub-only PR changes at least one path, all under `.github/`, including both sides of a rename. -`scripts/ci_*.py` changes, alone or mixed with `.github/`, follow the ordinary proof plan. -`gke-pr` reads the SHA-bound three-dot compare API twice, writes a NUL-separated path file and gives it to the base tree's `scripts/ci_docs_only.py --paths`. +A GitHub-only PR changes at least one path, all under `.github/`, including both sides of a rename. `scripts/ci_*.py` changes, alone or mixed with `.github/`, follow the ordinary proof plan. `gke-pr` reads the SHA-bound three-dot compare API twice, writes a NUL-separated path file and gives it to the base tree's `scripts/ci_docs_only.py --paths`. Empty, missing, malformed, truncated or unreadable lists are neither class; exact `.github/` and `docs/` prefixes prevent lookalikes or the classifier itself from creating a skip. The classifier also emits `arm_relevant`: source/build inputs under `tests/`, `runner/`, `include/`, `src/` or `docker/` set it true, @@ -91,7 +77,7 @@ executables, including `test_abi_layout_probe`, whose size and offset pins apply on Linux x86_64 with GNU libstdc++. Configure refuses missing, disabled, skippable, private-fixture or `slow` rows. The target rebuilds those executables with their library. -PR proof legs build cold; trusted post workflows also build cold and contain +Linux PR proof legs build cold; trusted Linux post workflows also build cold and contain no Actions cache restore or save. Verification jobs keep exact runner pins at the workflow boundary: Every migrated @@ -209,7 +195,7 @@ Release and native profiles also install into a disposable prefix, remove the source-only header trees, and compile the native public roots and examples; the preflight source guard rejects those includes before a build. -CI uses Ubuntu 24.04 amd64 and arm64 cells and selects Python 3.12 explicitly. +For the Linux verification fleet, CI uses Ubuntu 24.04 amd64 and arm64 cells and selects Python 3.12 explicitly. The amd64 post build shards use the hosted `ubuntu-24.04` image and the two arm64 post cells use `ubuntu-24.04-arm`; each runs directly on that image. All three build jobs refuse an OS mismatch. Hosted pins cover every PR and post job outside `release.yml`; the existing hosted release cell keeps `ubuntu-22.04-arm`. @@ -222,7 +208,7 @@ runs each image, and the platform's maximum, is in The two source-only benchmark CTest rows run the 25 harness unit tests and `benchmarks/check_provenance.py`. The latter reads historical commits (including -`933fe583`), so every checkout in the CI workflows and the admission base +`933fe583`), so their verification checkouts in the CI workflows and the admission base checkout fetches full Git history. A depth-1 checkout fails the provenance row even when the current benchmark files are correct. @@ -828,7 +814,7 @@ only examples or tests include fails no profile. A database without the archive's compiles fails the stage. Pass `--ccache` when ccache is installed; it is an empty local directory on -the hosted proof and trusted post jobs. Actions cache restore and save steps were +the Linux hosted proof and trusted post jobs. Actions cache restore and save steps were removed from those jobs, so no PR run can plant an object that a trusted job later restores. The native curl action remains a separate dependency path and is an outstanding allow-list deviation for this change. @@ -842,7 +828,7 @@ maximum is the only bound. The summary records discovered and selected row counts, executed rows, skipped or not-run rows, and stage timings, including when a test fails. -Every trusted post and PR proof job is a cold proof by construction. Manual +Every Linux trusted post and PR proof job is a cold proof by construction. Manual runs select the full main-equivalent row set; there is no cache warm-up exception. A cold proof must inspect each profile's verdict and retained counts, not just the caller aggregate. A local Spot run is evidence about that @@ -1681,7 +1667,7 @@ The four full build checks are `build (ubuntu-24.04, Release)`, Every shard builds the full tree and runs `--ctest-shard I/N` at the runner's core count. Each build refuses an OS mismatch before checkout. Each leg aggregate retains its old check name and requires its own matrix's success. The two arm64 cells share `build-arm` on `ubuntu-24.04-arm`. All three build jobs use the same verification steps and profiles. Shard jobs and leg aggregates skip together only on classified docs-only changes. -Trusted post workflows and PR proof legs build cold; no trusted job restores an Actions cache. +Within the Linux verification fleet, trusted post workflows and PR proof legs build cold; no trusted job restores an Actions cache. `HOSTED_JOB_RUNNERS` pins the hosted x86 and arm64 jobs and the native profile runner matrix; `GKP_JOB_RUNNERS` separately pins the protected release jobs and sizes. Every pinned job runs directly on its hosted image. PR checks are `build`, `build-debug`, `corpus-parity-subset`, `legs` and `result` in `gke-pr.yml`. With the arm leg, the full set is `build`, `build-debug`, `build-arm`, `corpus-parity-subset`, `legs` and `result` in `gke-pr.yml`. @@ -2086,7 +2072,7 @@ A class disagreement is red even when the proof jobs were skipped. The result re-reads with the immutable payload shas to avoid branch races. The code-extension veto can only require proof legs, never skip them. -Trusted post workflows build cold and contain no Actions cache restore or save. +Trusted Linux post workflows build cold and contain no Actions cache restore or save. PR pods also build cold, so their runtime cache credential has no trusted reader. No trusted job consumes an artifact from the admission workflow. The runner group accepts only the main branch admission workflow definition. From 6ab9bdbd387a45971be72180c8f82906590f3038 Mon Sep 17 00:00:00 2001 From: luisleo526 Date: Tue, 10 Nov 2026 13:27:57 +0800 Subject: [PATCH 4/4] ci: pin Eigen 3.4.0 for advisory macOS compilation Install checksum-verified upstream Eigen headers and CMake exports in a job-owned prefix before configuring the engine. Pass the installed typed Eigen3_DIR and keep the engine's disconnected dependency fallback. Synchronize the workflow's exact policy mirror without changing admission predicates, authorization, existing test expectations or engine sources. --- .github/workflows/macos-compile.yml | 38 +++++++++++++++++++++++------ scripts/ci_preflight.py | 38 +++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/.github/workflows/macos-compile.yml b/.github/workflows/macos-compile.yml index 863a48af6..cf5944223 100644 --- a/.github/workflows/macos-compile.yml +++ b/.github/workflows/macos-compile.yml @@ -179,18 +179,41 @@ jobs: uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ steps.host.outputs.brew-cache }} - key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache-${{ steps.source.outputs.sha }} + key: macos-compile-v2-${{ runner.os }}-${{ runner.arch }}-Debug-brew-ccache-${{ steps.source.outputs.sha }} restore-keys: | - macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache- + macos-compile-v2-${{ runner.os }}-${{ runner.arch }}-Debug-brew-ccache- - name: Install dependencies + id: dependencies run: | set -euo pipefail - brew install eigen ccache - eigen_prefix=$(brew --prefix eigen) - test -f "$eigen_prefix/share/eigen3/cmake/Eigen3Config.cmake" - echo "CMAKE_PREFIX_PATH=$eigen_prefix${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" >> "$GITHUB_ENV" + brew install ccache ccache --version + eigen_work=$(mktemp -d "$RUNNER_TEMP/pineforge-eigen-3.4.0.XXXXXX") + eigen_archive="$eigen_work/eigen-3.4.0.tar.gz" + eigen_prefix="$eigen_work/install" + curl --fail --location --show-error --silent \ + --output "$eigen_archive" \ + https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz + printf '8586084f71f9bde545ee7fa6d00288b264a2b7ac3607b974e54d13e7162c1c72 %s\n' "$eigen_archive" | shasum -a 256 --check + tar -xzf "$eigen_archive" -C "$eigen_work" + cmake -S "$eigen_work/eigen-3.4.0" -B "$eigen_work/build" \ + -DCMAKE_INSTALL_PREFIX:PATH="$eigen_prefix" \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DEIGEN_BUILD_DOC=OFF \ + -DEIGEN_BUILD_TESTING=OFF \ + -DBUILD_TESTING=OFF \ + -DEIGEN_BUILD_BLAS=OFF \ + -DEIGEN_BUILD_LAPACK=OFF + cmake --install "$eigen_work/build" + eigen3_dir="$eigen_prefix/share/eigen3/cmake" + eigen_macros="$eigen_prefix/include/eigen3/Eigen/src/Core/util/Macros.h" + test -f "$eigen3_dir/Eigen3Config.cmake" + grep -Eq '^#define EIGEN_WORLD_VERSION[[:space:]]+3[[:space:]]*$' "$eigen_macros" + grep -Eq '^#define EIGEN_MAJOR_VERSION[[:space:]]+4[[:space:]]*$' "$eigen_macros" + grep -Eq '^#define EIGEN_MINOR_VERSION[[:space:]]+0[[:space:]]*$' "$eigen_macros" + printf 'Eigen version=3.4.0\nEigen3_DIR=%s\n' "$eigen3_dir" + printf 'eigen3-dir=%s\n' "$eigen3_dir" >> "$GITHUB_OUTPUT" - name: Restore ccache id: ccache-restore @@ -205,6 +228,7 @@ jobs: env: C_COMPILER: ${{ steps.host.outputs.c-compiler }} CXX_COMPILER: ${{ steps.host.outputs.cxx-compiler }} + EIGEN3_DIR: ${{ steps.dependencies.outputs.eigen3-dir }} run: | set -euo pipefail cmake -S . -B build \ @@ -214,7 +238,7 @@ jobs: -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DEigen3_DIR:PATH="$(brew --prefix eigen)/share/eigen3/cmake" \ + -DEigen3_DIR:PATH="$EIGEN3_DIR" \ -DFETCHCONTENT_FULLY_DISCONNECTED=ON \ -DPINEFORGE_BUILD_TESTS=ON \ -DPINEFORGE_BUILD_SOURCE_LAYER=ON \ diff --git a/scripts/ci_preflight.py b/scripts/ci_preflight.py index 65e8d13df..7d74c7a85 100644 --- a/scripts/ci_preflight.py +++ b/scripts/ci_preflight.py @@ -4274,18 +4274,41 @@ def _compiler_cache_restore_with(step: str) -> list[str]: uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ steps.host.outputs.brew-cache }} - key: macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache-${{ steps.source.outputs.sha }} + key: macos-compile-v2-${{ runner.os }}-${{ runner.arch }}-Debug-brew-ccache-${{ steps.source.outputs.sha }} restore-keys: | - macos-compile-v1-${{ runner.os }}-${{ runner.arch }}-Debug-brew-eigen-ccache- + macos-compile-v2-${{ runner.os }}-${{ runner.arch }}-Debug-brew-ccache- - name: Install dependencies + id: dependencies run: | set -euo pipefail - brew install eigen ccache - eigen_prefix=$(brew --prefix eigen) - test -f "$eigen_prefix/share/eigen3/cmake/Eigen3Config.cmake" - echo "CMAKE_PREFIX_PATH=$eigen_prefix${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" >> "$GITHUB_ENV" + brew install ccache ccache --version + eigen_work=$(mktemp -d "$RUNNER_TEMP/pineforge-eigen-3.4.0.XXXXXX") + eigen_archive="$eigen_work/eigen-3.4.0.tar.gz" + eigen_prefix="$eigen_work/install" + curl --fail --location --show-error --silent \ + --output "$eigen_archive" \ + https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz + printf '8586084f71f9bde545ee7fa6d00288b264a2b7ac3607b974e54d13e7162c1c72 %s\n' "$eigen_archive" | shasum -a 256 --check + tar -xzf "$eigen_archive" -C "$eigen_work" + cmake -S "$eigen_work/eigen-3.4.0" -B "$eigen_work/build" \ + -DCMAKE_INSTALL_PREFIX:PATH="$eigen_prefix" \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DEIGEN_BUILD_DOC=OFF \ + -DEIGEN_BUILD_TESTING=OFF \ + -DBUILD_TESTING=OFF \ + -DEIGEN_BUILD_BLAS=OFF \ + -DEIGEN_BUILD_LAPACK=OFF + cmake --install "$eigen_work/build" + eigen3_dir="$eigen_prefix/share/eigen3/cmake" + eigen_macros="$eigen_prefix/include/eigen3/Eigen/src/Core/util/Macros.h" + test -f "$eigen3_dir/Eigen3Config.cmake" + grep -Eq '^#define EIGEN_WORLD_VERSION[[:space:]]+3[[:space:]]*$' "$eigen_macros" + grep -Eq '^#define EIGEN_MAJOR_VERSION[[:space:]]+4[[:space:]]*$' "$eigen_macros" + grep -Eq '^#define EIGEN_MINOR_VERSION[[:space:]]+0[[:space:]]*$' "$eigen_macros" + printf 'Eigen version=3.4.0\nEigen3_DIR=%s\n' "$eigen3_dir" + printf 'eigen3-dir=%s\n' "$eigen3_dir" >> "$GITHUB_OUTPUT" - name: Restore ccache id: ccache-restore @@ -4300,6 +4323,7 @@ def _compiler_cache_restore_with(step: str) -> list[str]: env: C_COMPILER: ${{ steps.host.outputs.c-compiler }} CXX_COMPILER: ${{ steps.host.outputs.cxx-compiler }} + EIGEN3_DIR: ${{ steps.dependencies.outputs.eigen3-dir }} run: | set -euo pipefail cmake -S . -B build \ @@ -4309,7 +4333,7 @@ def _compiler_cache_restore_with(step: str) -> list[str]: -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DEigen3_DIR:PATH="$(brew --prefix eigen)/share/eigen3/cmake" \ + -DEigen3_DIR:PATH="$EIGEN3_DIR" \ -DFETCHCONTENT_FULLY_DISCONNECTED=ON \ -DPINEFORGE_BUILD_TESTS=ON \ -DPINEFORGE_BUILD_SOURCE_LAYER=ON \