From c33e9e95771aba788fd3ad764bd003ee40c65f2f Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Sat, 14 Nov 2026 13:12:22 -0600 Subject: [PATCH 1/4] chore: retire the settings publisher, sync and audit The owner retired the token-driven settings automation on 2026-11-14. There is no standing organization-owner credential any more, and the rules now live in organization rulesets aimed at all repositories. Remove bin/, lib/, tests/, community-health/, the release scripts, the publish, publish-planning, sync-project, check-project-health, audit and semantic-release workflows, and every config file that only those tools read. Keep config/planning.json unchanged: three agent skills read its Project Status names. Keep the required "Policy validation" job as a small real check: every tracked JSON file parses, relative Markdown links resolve, and every workflow action is pinned to a full commit SHA. Rewrite README.md, AGENTS.md and CONTRIBUTING.md to describe the repository as it is now. Co-Authored-By: Claude --- .github/scripts/check_repository.py | 134 + .github/workflows/audit.yml | 32 - .github/workflows/check-project-health.yml | 34 - .github/workflows/check.yml | 20 +- .github/workflows/publish-planning.yml | 52 - .github/workflows/publish.yml | 31 - .github/workflows/release.yml | 40 - .github/workflows/sync-project.yml | 31 - .releaserc.json | 9 - AGENTS.md | 375 +-- CONTRIBUTING.md | 285 +-- README.md | 2067 +-------------- bin/audit | 730 ------ bin/check-project-health | 375 --- bin/publish | 2212 ----------------- bin/publish-community-health | 122 - bin/publish-planning | 527 ---- bin/publish-repositories | 6 - bin/publish-repository-properties | 205 -- bin/security-readiness | 5 - bin/sync-project | 560 ----- bin/validate | 1705 ------------- bin/verify-manual-settings | 996 -------- .../.github/ISSUE_TEMPLATE/bug.yml | 62 - .../.github/ISSUE_TEMPLATE/config.yml | 5 - .../.github/ISSUE_TEMPLATE/feature.yml | 47 - .../.github/ISSUE_TEMPLATE/task.yml | 38 - .../.github/PULL_REQUEST_TEMPLATE.md | 18 - community-health/CODE_OF_CONDUCT.md | 19 - community-health/CONTRIBUTING.md | 21 - community-health/README.md | 10 - community-health/SECURITY.md | 13 - community-health/profile/README.md | 52 - .../workflows/dependency-review.yml | 215 -- config/actions-permissions.json | 5 - config/actions-selected.json | 12 - config/actions-sha-pinning.json | 4 - config/actions-workflow.json | 4 - config/advisory-merge-windows.json | 3 - config/code-security-advanced.json | 18 - config/code-security.json | 18 - config/codeql-advanced-setup.json | 29 - config/codeql-default-setup-advanced.json | 3 - config/codeql-default-setup.json | 4 - config/community-health.json | 56 - config/immutable-releases.json | 25 - config/manual-settings.json | 651 ----- config/organization.json | 8 - config/planning-health.json | 11 - config/repositories.json | 138 - config/repository-defaults.json | 9 - config/repository-properties.json | 367 --- config/repository-security.json | 13 - config/retired-maintenance-branches.json | 50 - config/retired-required-ci.json | 3 - config/rulesets/code-scanning.json | 34 - .../default-branch-integrity-classic.json | 28 - config/rulesets/default-branch-integrity.json | 22 - ...default-branch-linear-history-classic.json | 25 - .../default-branch-linear-history.json | 25 - config/rulesets/dependency-review.json | 34 - config/rulesets/immutable-release-tags.json | 22 - config/rulesets/maintenance-branch.json | 46 - config/rulesets/merge-queue.json | 34 - .../rulesets/pull-request-gate-classic.json | 32 - config/rulesets/pull-request-gate.json | 32 - config/rulesets/required-ci.json | 29 - config/security-merge-protection.json | 55 - lib/ruleset-policy.jq | 76 - lib/security_readiness.py | 1245 ---------- lib/verify_crate_workflow.py | 372 --- requirements-validation.txt | 2 - scripts/release/release-policy.cjs | 81 - scripts/release/release-rules.cjs | 5 - scripts/release/test-release-policy.cjs | 45 - tests/audit-fixtures.py | 562 ----- tests/audit.sh | 361 --- tests/check-project-health.sh | 810 ------ tests/fixtures/crate-publication.yml | 57 - tests/fixtures/crate-source-release.yml | 66 - tests/publish-community-health.sh | 94 - tests/publish-maintenance-branch.sh | 1868 -------------- tests/publish-maintenance-retirement.sh | 210 -- tests/publish-merge-queue.sh | 368 --- tests/publish-planning.sh | 177 -- tests/publish-policy-comparison.sh | 138 - tests/publish-repository-properties.sh | 142 -- tests/publish-retired-required-ci.sh | 151 -- tests/publish-ruleset-pagination.sh | 270 -- tests/publish-security-merge.sh | 1173 --------- tests/security-readiness.py | 2073 --------------- tests/security-readiness.sh | 5 - tests/sync-project.sh | 459 ---- tests/validate-codeql-advanced.sh | 84 - tests/validate-community-health.sh | 113 - tests/validate-crate-trusted-publishing.sh | 247 -- tests/validate-immutable-releases.sh | 64 - tests/validate-manual-credentials.sh | 508 ---- tests/validate-manual-environments.sh | 289 --- tests/validate-manual-package-access.sh | 115 - tests/validate-merge-queue.sh | 79 - tests/validate-planning-health.sh | 41 - tests/validate-planning.sh | 59 - tests/validate-retired-maintenance.sh | 77 - tests/validate-retired-required-ci.sh | 28 - tests/validate-security-merge.sh | 71 - tests/verify-crate-workflow.sh | 5 - tests/verify-manual-settings.sh | 1259 ---------- tests/verify_crate_workflow.py | 194 -- 109 files changed, 229 insertions(+), 26716 deletions(-) create mode 100644 .github/scripts/check_repository.py delete mode 100644 .github/workflows/audit.yml delete mode 100644 .github/workflows/check-project-health.yml delete mode 100644 .github/workflows/publish-planning.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/sync-project.yml delete mode 100644 .releaserc.json delete mode 100755 bin/audit delete mode 100755 bin/check-project-health delete mode 100755 bin/publish delete mode 100755 bin/publish-community-health delete mode 100755 bin/publish-planning delete mode 100755 bin/publish-repositories delete mode 100755 bin/publish-repository-properties delete mode 100755 bin/security-readiness delete mode 100755 bin/sync-project delete mode 100755 bin/validate delete mode 100755 bin/verify-manual-settings delete mode 100644 community-health/.github/ISSUE_TEMPLATE/bug.yml delete mode 100644 community-health/.github/ISSUE_TEMPLATE/config.yml delete mode 100644 community-health/.github/ISSUE_TEMPLATE/feature.yml delete mode 100644 community-health/.github/ISSUE_TEMPLATE/task.yml delete mode 100644 community-health/.github/PULL_REQUEST_TEMPLATE.md delete mode 100644 community-health/CODE_OF_CONDUCT.md delete mode 100644 community-health/CONTRIBUTING.md delete mode 100644 community-health/README.md delete mode 100644 community-health/SECURITY.md delete mode 100644 community-health/profile/README.md delete mode 100644 community-health/workflows/dependency-review.yml delete mode 100644 config/actions-permissions.json delete mode 100644 config/actions-selected.json delete mode 100644 config/actions-sha-pinning.json delete mode 100644 config/actions-workflow.json delete mode 100644 config/advisory-merge-windows.json delete mode 100644 config/code-security-advanced.json delete mode 100644 config/code-security.json delete mode 100644 config/codeql-advanced-setup.json delete mode 100644 config/codeql-default-setup-advanced.json delete mode 100644 config/codeql-default-setup.json delete mode 100644 config/community-health.json delete mode 100644 config/immutable-releases.json delete mode 100644 config/manual-settings.json delete mode 100644 config/organization.json delete mode 100644 config/planning-health.json delete mode 100644 config/repositories.json delete mode 100644 config/repository-defaults.json delete mode 100644 config/repository-properties.json delete mode 100644 config/repository-security.json delete mode 100644 config/retired-maintenance-branches.json delete mode 100644 config/retired-required-ci.json delete mode 100644 config/rulesets/code-scanning.json delete mode 100644 config/rulesets/default-branch-integrity-classic.json delete mode 100644 config/rulesets/default-branch-integrity.json delete mode 100644 config/rulesets/default-branch-linear-history-classic.json delete mode 100644 config/rulesets/default-branch-linear-history.json delete mode 100644 config/rulesets/dependency-review.json delete mode 100644 config/rulesets/immutable-release-tags.json delete mode 100644 config/rulesets/maintenance-branch.json delete mode 100644 config/rulesets/merge-queue.json delete mode 100644 config/rulesets/pull-request-gate-classic.json delete mode 100644 config/rulesets/pull-request-gate.json delete mode 100644 config/rulesets/required-ci.json delete mode 100644 config/security-merge-protection.json delete mode 100644 lib/ruleset-policy.jq delete mode 100644 lib/security_readiness.py delete mode 100644 lib/verify_crate_workflow.py delete mode 100644 requirements-validation.txt delete mode 100644 scripts/release/release-policy.cjs delete mode 100644 scripts/release/release-rules.cjs delete mode 100644 scripts/release/test-release-policy.cjs delete mode 100755 tests/audit-fixtures.py delete mode 100755 tests/audit.sh delete mode 100755 tests/check-project-health.sh delete mode 100644 tests/fixtures/crate-publication.yml delete mode 100644 tests/fixtures/crate-source-release.yml delete mode 100755 tests/publish-community-health.sh delete mode 100755 tests/publish-maintenance-branch.sh delete mode 100755 tests/publish-maintenance-retirement.sh delete mode 100755 tests/publish-merge-queue.sh delete mode 100755 tests/publish-planning.sh delete mode 100755 tests/publish-policy-comparison.sh delete mode 100755 tests/publish-repository-properties.sh delete mode 100755 tests/publish-retired-required-ci.sh delete mode 100755 tests/publish-ruleset-pagination.sh delete mode 100755 tests/publish-security-merge.sh delete mode 100644 tests/security-readiness.py delete mode 100755 tests/security-readiness.sh delete mode 100755 tests/sync-project.sh delete mode 100755 tests/validate-codeql-advanced.sh delete mode 100755 tests/validate-community-health.sh delete mode 100755 tests/validate-crate-trusted-publishing.sh delete mode 100755 tests/validate-immutable-releases.sh delete mode 100755 tests/validate-manual-credentials.sh delete mode 100755 tests/validate-manual-environments.sh delete mode 100755 tests/validate-manual-package-access.sh delete mode 100755 tests/validate-merge-queue.sh delete mode 100755 tests/validate-planning-health.sh delete mode 100755 tests/validate-planning.sh delete mode 100755 tests/validate-retired-maintenance.sh delete mode 100755 tests/validate-retired-required-ci.sh delete mode 100755 tests/validate-security-merge.sh delete mode 100755 tests/verify-crate-workflow.sh delete mode 100755 tests/verify-manual-settings.sh delete mode 100644 tests/verify_crate_workflow.py diff --git a/.github/scripts/check_repository.py b/.github/scripts/check_repository.py new file mode 100644 index 0000000..e9e368a --- /dev/null +++ b/.github/scripts/check_repository.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +"""Check that this repository's own files are valid. + +- every tracked JSON file parses; +- every relative link in a tracked Markdown file points at a tracked path; +- every `uses:` in a workflow is a local path, a Docker image digest or an + action pinned to a full 40-character commit SHA. + +Prints one line per problem and exits 1 if there is any. Standard library +only; it reads files and never touches the network. +""" + +import json +import pathlib +import re +import subprocess +import sys +import urllib.parse + +ROOT = pathlib.Path(__file__).resolve().parents[2] + +# Inline links and images: [text](target) or ![alt](target "title"). +INLINE_LINK = re.compile(r"!?\[(?:[^\]\\]|\\.)*\]\(\s*]+)>?(?:\s+[\"'][^)]*[\"'])?\s*\)") +# Reference definitions: [label]: target +REFERENCE_LINK = re.compile(r"^\s{0,3}\[[^\]]+\]:\s*?(?:\s+.*)?$") +HTML_LINK = re.compile(r"""<(?:a|img)\b[^>]*?\b(?:href|src)\s*=\s*["']([^"']+)["']""", re.IGNORECASE) +FENCE = re.compile(r"^\s{0,3}(```|~~~)") +INLINE_CODE = re.compile(r"(`+)(?:(?!\1).)+?\1") +USES = re.compile(r"^\s*(?:-\s+)?uses:\s*['\"]?([^\s'\"#]+)") +PINNED = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+(?:/[^@\s]+)?@[0-9a-f]{40}$") +DOCKER_DIGEST = re.compile(r"^docker://\S+@sha256:[0-9a-f]{64}$") + + +def tracked_files(): + output = subprocess.run( + ["git", "ls-files", "-z"], cwd=ROOT, check=True, capture_output=True + ).stdout + return sorted(pathlib.PurePosixPath(name) for name in output.decode().split("\0") if name) + + +def check_json(path, problems): + try: + with open(ROOT / path, encoding="utf-8") as stream: + json.load(stream) + except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: + problems.append(f"{path}: invalid JSON: {error}") + + +def link_targets(text): + in_fence = None + for number, line in enumerate(text.splitlines(), start=1): + fence = FENCE.match(line) + if fence: + marker = fence.group(1) + if in_fence is None: + in_fence = marker + elif marker == in_fence: + in_fence = None + continue + if in_fence is not None: + continue + line = INLINE_CODE.sub("", line) + for pattern in (INLINE_LINK, HTML_LINK): + for match in pattern.finditer(line): + yield number, match.group(1) + reference = REFERENCE_LINK.match(line) + if reference: + yield number, reference.group(1) + + +def check_markdown(path, known, problems): + text = (ROOT / path).read_text(encoding="utf-8") + known_dirs = {parent for item in known for parent in item.parents} + for number, target in link_targets(text): + parsed = urllib.parse.urlsplit(target) + if parsed.scheme or parsed.netloc or target.startswith("#"): + continue + relative = urllib.parse.unquote(parsed.path) + if relative.startswith("/"): + resolved = pathlib.PurePosixPath(relative.lstrip("/")) + else: + resolved = pathlib.PurePosixPath(*_normalize(path.parent / relative)) + if resolved not in known and resolved not in known_dirs: + problems.append(f"{path}:{number}: broken relative link: {target}") + + +def _normalize(path): + parts = [] + for part in path.parts: + if part in ("", "."): + continue + if part == "..": + if parts: + parts.pop() + else: + parts.append("..") + continue + parts.append(part) + return parts + + +def check_workflow(path, problems): + text = (ROOT / path).read_text(encoding="utf-8") + for number, line in enumerate(text.splitlines(), start=1): + match = USES.match(line) + if not match: + continue + reference = match.group(1) + if reference.startswith("./") or PINNED.match(reference) or DOCKER_DIGEST.match(reference): + continue + problems.append(f"{path}:{number}: action is not pinned to a full commit SHA: {reference}") + + +def main(): + files = tracked_files() + known = set(files) + problems = [] + for path in files: + if path.suffix == ".json": + check_json(path, problems) + elif path.suffix == ".md": + check_markdown(path, known, problems) + if path.parent == pathlib.PurePosixPath(".github/workflows") and path.suffix in (".yml", ".yaml"): + check_workflow(path, problems) + for problem in problems: + print(problem) + if problems: + return 1 + print(f"Checked {len(files)} tracked files: no problems.") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml deleted file mode 100644 index e3230c7..0000000 --- a/.github/workflows/audit.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Governance drift audit - -on: - push: - branches: - - main - schedule: - - cron: "17 * * * *" - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: governance-drift-audit - cancel-in-progress: false - -jobs: - audit: - name: Governance drift audit - runs-on: ubuntu-24.04 - timeout-minutes: 20 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Install workflow verification dependencies - run: python3 -m pip install --requirement requirements-validation.txt - - - name: Compare desired state with GitHub - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/audit diff --git a/.github/workflows/check-project-health.yml b/.github/workflows/check-project-health.yml deleted file mode 100644 index 733965e..0000000 --- a/.github/workflows/check-project-health.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Project synchronization health - -on: - workflow_dispatch: - schedule: - - cron: "5,35 * * * *" - workflow_run: - workflows: - - Synchronize project - types: - - completed - -permissions: - actions: read - contents: read - issues: write - -concurrency: - group: project-synchronization-health - cancel-in-progress: false - -jobs: - health: - name: Check Project synchronization health - runs-on: ubuntu-24.04 - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Check freshness and convergence - env: - GH_TOKEN: ${{ github.token }} - ATRINIK_SETTINGS_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/check-project-health --apply diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c2290aa..b4c6305 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -13,22 +13,14 @@ permissions: jobs: policy: + # The ruleset "03 - Required CI - github-settings" requires this exact job name. name: Policy validation runs-on: ubuntu-24.04 + timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - - name: Install workflow verification dependencies - run: python3 -m pip install --requirement requirements-validation.txt - - - name: Validate configuration - run: bin/validate - - - name: Check governance scripts - run: shellcheck bin/* tests/*.sh - - - name: Test governance policy - run: | - for test in tests/*.sh; do - "${test}" - done + - name: Check repository files + run: python3 .github/scripts/check_repository.py diff --git a/.github/workflows/publish-planning.yml b/.github/workflows/publish-planning.yml deleted file mode 100644 index 914f3ee..0000000 --- a/.github/workflows/publish-planning.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Publish planning - -on: - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: publish-planning - cancel-in-progress: false - -jobs: - publish: - name: Publish planning system - runs-on: ubuntu-24.04 - timeout-minutes: 30 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Install workflow verification dependencies - run: python3 -m pip install --requirement requirements-validation.txt - - - name: Verify settings credential inventory - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/verify-manual-settings - - - name: Create issue metadata and shared project - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/publish-planning --apply - - - name: Backfill and synchronize project items - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/sync-project --apply - - - name: Publish organization community health defaults - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/publish-community-health --apply - - - name: Publish repository custom properties - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/publish-repository-properties --apply - - - name: Verify applied governance - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/audit diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index b1a9b88..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Publish settings - -on: - workflow_dispatch: - -permissions: - contents: read - -jobs: - publish: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Install workflow verification dependencies - run: python3 -m pip install --requirement requirements-validation.txt - - - name: Verify settings credential inventory - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/verify-manual-settings - - - name: Apply organization governance and security policy - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/publish --apply - - - name: Verify applied governance - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/audit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 2cf6250..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Semantic Release - -on: - workflow_dispatch: - push: - branches: - - main - - '[0-9]+.[0-9]+.x' - -permissions: - contents: write - issues: write - pull-requests: write - -concurrency: - group: semantic-release - cancel-in-progress: false - -jobs: - release: - name: Semantic release - runs-on: ubuntu-24.04 - timeout-minutes: 15 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 24.18.1 - - name: Verify release branch policy - run: node scripts/release/test-release-policy.cjs - - name: Analyze commits and publish - env: - GH_TOKEN: ${{ github.token }} - run: >- - npx --yes - --package=semantic-release@25.0.9 - --package=conventional-changelog-conventionalcommits@9.3.1 - semantic-release diff --git a/.github/workflows/sync-project.yml b/.github/workflows/sync-project.yml deleted file mode 100644 index b5dc799..0000000 --- a/.github/workflows/sync-project.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Synchronize project - -on: - workflow_dispatch: - schedule: - - cron: "17,47 * * * *" - -permissions: - contents: read - -concurrency: - group: synchronize-project - cancel-in-progress: false - -jobs: - synchronize: - name: Synchronize organization project - runs-on: ubuntu-24.04 - timeout-minutes: 30 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Verify settings credential inventory - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/verify-manual-settings - - - name: Add and update project items - env: - GH_TOKEN: ${{ secrets.ATRINIK_SETTINGS_TOKEN }} - run: bin/sync-project --apply diff --git a/.releaserc.json b/.releaserc.json deleted file mode 100644 index 8ccb547..0000000 --- a/.releaserc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "branches": ["+([0-9]).+([0-9]).x", "main"], - "tagFormat": "v${version}", - "plugins": [ - ["@semantic-release/commit-analyzer", {"preset": "conventionalcommits", "releaseRules": "./scripts/release/release-rules.cjs"}], - ["@semantic-release/release-notes-generator", {"preset": "conventionalcommits"}], - "@semantic-release/github" - ] -} diff --git a/AGENTS.md b/AGENTS.md index ae4858a..9dd723b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,345 +1,34 @@ # Atrinik GitHub settings repository guide -- This repository is the desired-state source for Atrinik organization - repositories, rulesets, merge policy, Actions policy, and manual governance - settings. It also owns organization issue metadata, the shared Project and - synchronization contract, repository custom properties, and generated - community-health defaults. It does not own component implementation. -- Atrinik uses GitHub Team. Keep organization controls Team-compatible and - record unavailable or manual settings explicitly rather than pretending they - were applied. -- Read `README.md`, `CONTRIBUTING.md`, all affected `config/*.json`, and the - publisher before changing policy. Keep repository inventories, archived - status, default branches, rulesets, required checks, merge methods, Actions - allowlists, and security settings coherent. -- Run `bin/publish` in plan mode first and review its entire diff. `--apply` - mutates live organization state and requires explicit authorization; never - use it as routine validation. -- Apply planning state only in the documented dependency order: plan and apply - `bin/publish-planning`, then `bin/sync-project`, - `bin/publish-community-health`, and finally - `bin/publish-repository-properties`. Each script is plan-only by default and - needs the same explicit live-mutation authorization for `--apply`. -- Keep Project synchronization conservative and idempotent. Add every open - issue and pull request from non-archived repositories, preserve a person's - status on open work, set intake status only when absent or reopened, infer - only missing issue types, and converge tracked closed work to `Done`. Do not - infer Priority, Effort, or dates from weak signals. -- Atrinik uses the central synchronizer instead of Team's five-workflow - Project auto-add limit. The scheduled workflow and one-time backfill require - `ATRINIK_SETTINGS_TOKEN` to have the classic PAT `project` scope as well as - the existing organization and repository administration scopes. Personal - issue-dashboard saved views remain documented manual state because GitHub - exposes no public API for them. -- Keep environment-scoped Cloudflare DEV credential lifecycle records bound to - the exact metaserver repository ID, environment, workflow and declared scopes. - Protected-branch environment verification must not request custom branch - policies; derive an empty custom-pattern set from the verified mode. Effective - token permissions and expiry are separate from secret-name metadata. -- Keep every administrative Actions credential value out of Git. Inventory its - stable repository, secret placement, scopes, consumers, accountable owner, - verification date, rotate-by deadline, cadence, and runbook in - `config/manual-settings.json`. Run `bin/verify-manual-settings` to check only - live name/identity metadata, then prove permissions with the owning workflow; - never claim the metadata API verifies a value, expiry, or effective scope. -- Keep Project apply preflight ahead of every mutation: require the advertised - classic-PAT scopes, Project update capability, repository write access for - issue-type changes, and a stable result count exactly matching unique nodes - within GitHub's 1,000-item search window. Exceeding a capability or inventory - boundary fails closed. -- Treat GitHub cron as best-effort. Preserve the separate Project health - workflow, its configured freshness and consecutive-failure thresholds, and - its single bot-authored, marker-owned incident and outage-episode timestamp. - Alert with the ordinary least-privilege `GITHUB_TOKEN` so an absent - administration PAT remains reportable; resolve only after a newer successful - sync in the current episode and a converged zero-mutation plan. -- `community-health/` is authoritative; `atrinik/.github` is a generated - deployment target. Never hand-edit that repository, add independent release - automation to it, or add its issue forms' `projects:` key: public - contributors may not have the Project write permission that key requires. -- Keep the game-first organization description and canonical website in - `config/organization.json`, and publish them only on real drift. Keep the - generated public profile in `community-health/profile/README.md`. Record the - six ordered public pins with stable repository IDs in - `config/manual-settings.json`, verify them read-only through GraphQL, and use - the documented organization-owner UI step instead of an undocumented writer. -- `merge_queue` in `config/repositories.json` is the exhaustive merge-queue - inventory; `playtester` is the pilot. GitHub accepts the rule only in - repository rulesets, so `08 - Merge queue` stays repository-owned in both - scopes. Every queued repository is in `required_ci`, has every required check - reporting on `merge_group` before it is listed, never requires Dependency - review, and drops the up-to-date requirement from required CI only while it - is active and a fresh read verifies its installed queue. Install the queue before relaxing - required CI, restore the strict policy before retiring a queue, and retire - only an unmodified repository-owned rule that passes a fresh identity check - and final re-read. -- Keep required workflow job names synchronized with rulesets. Workflow or - permissions changes also require actionlint, least-privilege review, and - immutable action references according to policy. -- `bin/audit` is the read-only live drift check for the complete active - repository inventory. Run it after governance changes and on its scheduled - workflow; it must fail closed on an unregistered active repository, merge - policy drift, custom-property drift, missing inherited rulesets, or exposed - security-baseline drift. -- New repositories must be registered in the desired-state inventories before - they are treated as governed. The publishers fail closed when an active - repository is absent from those inventories; absent archived repositories - remain historical evidence and are skipped by the property publisher. -- Keep default-branch deletion and non-fast-forward rules non-bypassable during - normal operation. Isolate the organization-owner security-advisory exception - to the explicitly authorized window, and use pull-request-only bypass mode - outside that window so direct pushes never inherit the exception. -- A specifically authorized Classic advisory merge may temporarily split - Classic from those shared rules and use organization-owner `always` bypass. - Keep that window Classic-only, include the integrity rules only because - GitHub requires every reported rule to be bypassable for the advisory merge, - record it only in `config/advisory-merge-windows.json`, and merge and apply - the reviewed empty-inventory rollback immediately after the advisory merge. -- Declare protected non-default lines in `maintenance_branches`. Give each - repository/branch pair a unique entry, and require only status checks that - the branch's workflows already emit. Validate both Team organization rulesets - and the retained repository-level fallback when changing this contract. -- Record a completed maintenance-line retirement in - `config/retired-maintenance-branches.json` with stable repository/ruleset - identities, exact final branch and release commits, recovery assets, and the - rulesets that must remain active. Use the targeted - `bin/publish --retire-maintenance REPOSITORY/BRANCH` plan so the authorized - apply can remove only that exact ruleset. Branch deletion is a later, - separately authorized operation after a second live preflight; the publisher - never deletes a branch, tag, release, or asset. -- Preserve the selected-actions entry for Codecov and the manual GitHub App - repository-access inventory while coverage uploads use OIDC authentication. -- Preserve external-provider App records as value-free manual state with exact - stable identities, permissions, events, and selected repository IDs. Planned - integrations may retain null live App/installation IDs only with an explicit - pending owner-UI state, proposed name-only secret/variable slots, and a - documented follow-up. A shared installation change must retain every - unrelated reviewed repository, must never widen to all repositories, and - requires organization-owner UI readback when the administrative API cannot - enumerate the selected set. -- Record cross-repository private-package consumption in - `config/manual-settings.json` with stable package and repository IDs. Grant - consumer workflows only the `read` role through the package's **Manage - Actions access** UI, preserve visibility and source association, and do not - automate the grant through an undocumented API. A transition from private to - public is a separate, effectively irreversible organization-owner action: - merge reviewed desired-state and consumer-permission changes first, preserve - the source association, verify anonymous digest access, and remove obsolete - repository grants without altering foreign entries. - The private linux-build package keeps its exact package/source identities; - record client-only read grants separately from effective workflow pulls. - Metadata verifies identity/source/visibility, not grants or effective pulls. - Preserve all foreign grants and prove each owning authenticated workflow pulls - its pinned manifest before claiming effective access; never widen visibility. -- Record manually provisioned GitHub Actions environments in - `config/manual-settings.json` with stable repository IDs, exact deployment - branch policies and reviewer sets, and variable and secret names only. Never - record credential values. Provision them only after the owning workflow is - merged and reviewed, and do not imply that `bin/publish` applies them. -- Crates.io Trusted Publishing is a value-free desired contract for protocol - and content-toolkit. Bind exact stable repository IDs, - `publish-crate.yml`, protected `refs/heads/main`, `crates-io-release`, and the - official auth action with a full immutable workflow SHA; allow the reviewed - `rust-lang/crates-io-auth-action@*` pattern for Dependabot updates without a - redundant central action-version lock. Reviewed source/version merge approves - automatic future publication; environments have zero reviewers/wait and no - registry secrets. Keep pending source/environment/registration distinct from - observations; verify live repository/ref/protection and observed environments. - Parse both observed exact-main `publish-crate.yml` and `release.yml` structurally with the declared - `requirements-validation.txt` dependency; comments/plain text or disabled - jobs are not executable source proof. Reject matrix/reusable execution in the - two automatic and source package/sign/release jobs, and recursively confine - all step-context expressions to the exact returned upload-token input and - reviewed confirmation condition. External registration remains sanitized - owner evidence, not a GitHub API fact, and can precede a pending later - automatic source/environment transition. - Source signing alone may request attestation writes/OIDC in a separate inert - job; build and semantic-release jobs have no OIDC. Automatic verification - uses only contents/actions/checks/attestations read, while the isolated inert - publisher adds contents write for atomic upload intent and OIDC. Require - actual protected-main manifest provenance and immutable source-release proof - in the producer helper. Before registry PUT, atomically reserve the global - crate/version Git-reference coordinate; existing/ambiguous reservations block - absent-version retries and must never be automatically deleted or reset. - First owner-local API-token publication is limited to the seven declared - toolkit libraries; exclude CLIs, revoke bootstrap credentials, and - use OIDC only afterward. Protocol 0.2 retains its approved manual path. Before - any broad publisher apply mutation, qualify newly added live immutable - producer selections through fresh scoped source/environment verification; - pending/missing inventory or drift fails closed. Initial draft-first code - qualification is separate from later immutable-release/runtime proof, and - does not require a pre-existing immutable release. -- Keep the crate dependency App separate from unrelated Apps. Select only - client, exactly contents/PR write and metadata read, no events, - bypass or auto-merge; inventory names only for repository secret - `CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY` and variable - `CRATE_DEPENDENCY_UPDATE_APP_ID`. Record observed installation and name-only - provisioning separately from pending reviewed workflow activation and dated - successful-owned-PR proof. Current owner-authorized early provisioning does - not imply effective credentials or a deployed workflow. Retain exact owner UI - or supported App-authenticated repository-selection readback; empty events - do not independently prove a disabled webhook. Preparation must verify - registry readiness before the isolated job writes an owned PR. Keep exact - consumer paths, verified key creation date, verification date, rotation owner, - and a rotate-by deadline within the existing 90-day cadence. The deadline is - internal policy, not upstream expiry; verify replacement workflow use before - revoking the old key. Keep a selected-set change after the recorded readback - as pending `repository_scope_reverification` until a later readback replaces - it. An owner-accepted key exposure stays until rotation, never extends - rotate-by, and is removed on rotation. Both records pin the exact editor - transfer. -- Record GitHub Pages sites with stable repository identity, exact provider URL, - HTTPS enforcement, owning deployment environment, desired Actions source, - workflow path, and immutable deployment-action marker. Before that marker is - present on the default branch, the verifier permits only the documented - legacy source as pending transition state; once merged, anything except the - Actions source is drift. Switch the live source only after the consuming - workflow is merged and reviewed. -- Treat `config/codeql-advanced-setup.json` as the exhaustive exception - inventory for repositories whose component/path-aware CodeQL workflow cannot - use repository-wide default setup. Keep the advanced security configuration - identical to the ordinary enforced baseline except for its descriptive - fields and official `code_scanning_options.allow_advanced` value. The - organization publisher must attach exceptions first; both publisher scopes - must explicitly converge inventory repositories to default-setup - `not-configured` and all other active repositories to `configured` without - weakening dependency, secret-scanning, or vulnerability-reporting features. -- Keep ordinary ruleset publication delta-aware using the shared audit/publisher - comparison contract. Normalize only documented actor-ID equivalence and - reviewed compatible PR/CI extension values; preserve existing writable - extension fields in every replacement payload. Reject unknown or conflicting - restrictions, including additional deployment gates, instead of discarding - them. Verify exact existing ruleset identity and re-read full state immediately - before PUT, refusing observed concurrent edits. Repository merge defaults and - organization workflow permissions write only their real managed-field drift. -- Keep organization security publication delta-aware. Normalize GitHub's - legacy aggregate security response before comparing desired configuration, - update only real configuration/default drift, and never re-attach a - repository that is already attached or enforced on the intended - configuration. Preserve regression coverage for GitHub's asynchronous - enablement-event behavior. -- Never deploy a new advanced CodeQL exception without its target workflow pull - request open and ready to rerun. After applying policy, immediately rerun and - verify the advanced analysis before merging the workflow. If it cannot pass - promptly, restore the baseline/default setup through a reviewed inventory - rollback; do not leave an unobserved scanning gap. -- Metaserver production environment names and immutable-release selection are - desired state only until its reviewed draft-first producer and setup are - qualified. Preserve old mutable releases and tags as historical evidence; - only a new immutable release can satisfy production promotion. Keep setup, - release publication and exact-tag dispatch under their distinct authorizations. -- Treat `config/immutable-releases.json` as the exhaustive owner-enforced - organization inventory. Record stable repository IDs as well as names, fail - closed on live identity drift, and preserve the exact previous mode and - selected-ID set for verified automatic rollback. Stage additions as pending - desired state; apply only after their reviewed draft-first workflows are - merged and qualified. Every registry upload must prove that its actual source - release is immutable; ordinary workflow tokens cannot read administrative - immutability settings, so do not add an unsupported pre-tag settings query. Never apply immutable-release policy from an unmerged branch. - This release delivery activates only the exact immutable-release API policy - after a complete snapshot, identity and freshness check, exact readback and - verified rollback. Preserve foreign live state; do not broad-apply the - publisher plan. Suspend only the three producer source-release workflows in - the reviewed reversible window, retaining and restoring their original states. -- Never print or commit administrative tokens, live secrets, or API responses - containing credentials. -- Run `bin/validate`, `bash -n`, ShellCheck on governance scripts, the publisher - policy-scope tests, actionlint for workflows, inspect plan output, and finish - with `git diff --check`. -- Commits and pull-request titles use Conventional Commits. Repositories with - `release_policy: semantic-release` are released by semantic-release; active - services without a release contract remain pull-request governed with - `release_policy: none` and are omitted from `release_tags`. -- Remove a repository transferred out of the organization from every - desired-state inventory, validator identity map and test fixture in one - change, and record its transfer in `README.md#transferred-repositories`. - Historical evidence sections stay as written. Validated evidence records of - the transfer itself may pin the former identity. -- Update this `AGENTS.md` in the same change when major rework alters governance - ownership, policy scope, publisher behavior, required checks, or validation. - -- `config/security-merge-protection.json` owns CodeQL targets, per-gate - `pending`/`enforced` intent, and required default-setup language minima. - Keep CodeQL targets/activation equal to required CI. Dependency review is - advisory across all active repositories: keep `dependency_review: []` and - `activation.dependency_review: {}`. Never require its context as a desired - vulnerability CI barrier. Preserve ordinary CI and zero required approvals. -- Keep repository-owned `06 - CodeQL security` in both scopes; Team has no - organization code-scanning rules. Pending CodeQL gates only probe readiness; - promote intent through source review after landed successful producer proof. - Enforced gates remain required when deleted or producers fail. Keep language - unions, owner pull-request-only bypass, and existing configuration attachment - behavior. The retained generic `07` tooling must reject advisory producer - evidence and retire only recognized owned old gates with fresh identity and - payload fences; source changes never authorize live settings apply. -- Dependency review uses ordinary PR events without branch/path filters, with - no checkout, secrets, contributor execution, or merge-group trigger. Reporting - requires the workflow on the relevant PR/merge revision; adding it on main - does not cover historical branches automatically or authorize backports, retired-branch - recreation, or additional supported maintenance lines. Keep its official - immutable action, low severity reporting, all scopes, `warn-only: true`, `license-check: true`, - `comment-summary-in-pr: always`, and step `continue-on-error: true` so findings - and operational failures do not block CI. Retain license findings as advice; - license metadata is not compatibility certification, and existing repository - license compatibility rules still apply. - Per-PR/ref concurrency cancels superseded runs; a failure-report step warns and - adds a job-summary notice using the action's raw outcome. Preserve available - reports and state that vulnerability/license results are unknown if absent. - Contents read and PR write support reporting; fork/Dependabot comment denials - warn and fall back to job summaries. - Implementing agents must read the latest run and job summary for the current - PR head before merge, even when an older bot comment exists. Fix actionable - findings, or record explicit maintainer-accepted risk. Inspect - missing-report errors rather than treating them as a clean scan. Do not add - advisory allowlists, human approval requirements, or a duplicate pin catalog. -- Advanced CodeQL readiness parses executable YAML with the declared validation - dependency: bind classification outputs, matrix, scoped config, official - full-SHA init/analyze actions, and the always-running aggregate. Reject - duplicate keys, disconnected or disabled steps, and failure suppression. - Require ordinary pull-request triggers covering the live default branch and - opened/synchronize/reopened events without path filters. - Producer helpers remain trusted; preserve owner-controlled action updates, - category names and paths without a duplicate version/path catalog. -- `config/actions-sha-pinning.json` persists SHA rollout as `pending` with no - canary or `enforced` with an accepted PR coordinate. Promote it through normal - source review only after ordinary PR-bound action-update evidence passes. - Pending command-line canaries only probe readiness; they never enable SHA - enforcement. Enforced policy uses its stored proof to restore drift and fails - if proof cannot be revalidated; audit reports disabled enforced policy as - drift. Preserve existing true settings. Allow action names with `@*`; keep - full SHAs in producer workflows instead of duplicate pin catalogs. Canary - legacy-check absence requires verified protection evidence; a bare or - ambiguous 404 is unreadable. Enumerate and validate every ruleset page before - publisher identity, absence, update or retirement decisions. -- Adoption of existing security gates into enforced source intent requires the - effective default-branch API to prove the repository-owned ruleset and desired - tool/context. Never infer activation from target membership or silently change - source intent. Retire target and activation entries together. Retired targets - lose only exact repository-owned managed security rules; - preserve archived, foreign, and modified same-name rules. Re-read and validate - the exact rule payload after the repository metadata fence immediately before - deletion. Audit retained named security rules on non-target repositories as - drift even when disabled, modified or scoped to another ref. Keep repository - workflow overrides read-only and unable to approve PRs, with delta-aware writes. -- Repository-scope `03 - Required CI` retirement requires reviewed exact prior - repository/ruleset IDs and contexts in `config/retired-required-ci.json`. - Delete only the unchanged Actions-bound template after fresh identity/archive - and payload checks. Preserve modified/foreign rules and missing-provenance - rules with actionable `SKIP`; retain records for idempotent reruns. - -- Before updating an existing security gate, re-read and revalidate its identity - and recognized payload, retaining concurrent modifications. Bind the final - metadata default branch to the branch used for pending-gate qualification - or existing effective-gate proof; changed branches must not activate a gate. - Pending existing-gate proof also requires unchanged enforcement and ref - applicability in the final rule read. Enforced intent retains recognized - restoration. Audit full legacy - protection on active default and declared maintenance branches; any presence - is drift under the canonical ruleset contract. Only verified unprotected - responses count as absent; unreadable evidence fails closed and audit never - removes protections. Compare the complete effective default and maintenance branch policy with - declared allowed rule types and parameters; undeclared integrity or restriction types are drift, - even when every desired rule is present. Only the exact repository-disabled REST response may - fall back to a fixed read-only GraphQL query with matching repository/branch - identity, active state and explicit null legacy-rule association. Missing or - conflicting evidence fails closed; preserve historical rules on other refs. +- This repository is the home of Atrinik's GitHub organization settings + record. Read `README.md` first. Today it holds `config/planning.json` and a + small CI check; a read-only settings check and Atrinik's baseline file are + coming in a later pull request. +- The settings automation that used to live here (publisher, Project + synchronizer, drift audit, Project health check, community-health generator, + semantic release) was retired on 2026-11-14 by owner decision: there is no + standing organization-owner credential any more, and the rules now live in + organization rulesets that target all repositories. Do not restore, run or + imitate those tools, including from an old checkout or release. They are in + the Git history and in release `v2.26.0` for reference only. +- Settings are changed by hand under the owner's login, only when the current + task authorizes that change. Record each change in this repository in the + same task, through a pull request. +- The **Atrinik work** Project is no longer filled automatically. Keep + `config/planning.json` and its Status names as they are: agent skills read + them. +- `atrinik/.github` is edited by hand, through pull requests in that + repository. Nothing here generates it. +- Settled rollouts: required full-SHA action pinning is on; CodeQL as a merge + requirement and the `playtester` merge queue are dropped. +- Keep the two required check names exactly: the `Policy validation` job in + `.github/workflows/check.yml` and `Conventional PR title` in + `.github/workflows/pr-title.yml`. The ruleset `03 - Required CI - + github-settings` requires both. +- Pin every action to a full commit SHA with a version comment. The + organization requires it. +- Before you push, run `python3 .github/scripts/check_repository.py` and + `git diff --check`. Run actionlint when workflows change, if you have it. +- Commits and pull-request titles use Conventional Commits. +- Never print or commit tokens, secrets or API responses that contain + credentials. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 949a792..1a75c8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,277 +1,22 @@ # Contributing -Use a Conventional Commits pull-request title. Validate every JSON policy, -run `bin/validate`, ShellCheck on every governance script, the publisher -policy tests, and actionlint when workflows change. Review the dry-run -publisher output before applying organization changes. Never commit the -administrative token required by the manual publishing workflow. Package -Actions-access grants that lack a documented public API belong in -`config/manual-settings.json`; record stable package and repository IDs, grant -only read access to consumer workflows, and preserve the package's existing -visibility and source-repository association. Making a reusable package public -requires a reviewed desired-state removal, explicit organization-owner -authorization, anonymous immutable-digest verification, and removal of only -the obsolete consumer grant; treat the visibility change as effectively -irreversible. Manually provisioned GitHub -Actions environments belong in the same inventory with a stable repository -ID, exact branch policy and reviewer set, and variable and secret names only. -Never commit their values, and provision them only after the workflow that uses -them is merged and reviewed. -GitHub Pages records likewise bind stable repository identity, the provider -URL, HTTPS, the deployment environment, and an immutable marker in the owning -workflow. Keep a pre-merge legacy source only as the verifier's explicit -pending state, then activate the Actions source after that exact workflow lands. +Use a Conventional Commits pull-request title, for example +`docs: describe the settings baseline`. Pull requests are squash-merged. -Administrative Actions credentials require a value-free lifecycle entry in -`config/manual-settings.json`. Record stable repository identity, secret scope -and name, credential type and required scopes, consumers, accountable owner, -verification and rotate-by dates, cadence, and the runbook. Never add value, -token ID, authorization header, fixture secret, or recoverable credential -material. Changes require credential-schema negative tests, the read-only -`bin/verify-manual-settings` plan, and the documented manual and scheduled -post-rotation checks. +Before you push, run: -Actions GitHub Apps require their own value-free inventory entry with stable -App, installation, and repository IDs; exact permissions and event set; -selected-repository verification; consumer paths; secret and variable names; -accountable ownership; verification and rotation dates; and a runbook. Never -store a private key, installation token, token response, or credential value. -Changes require negative schema tests, read-only installation and metadata-name -verification, and organization-owner confirmation of the exact selected -repository set in GitHub's installation UI. Keep the App out of bypass lists, -preserve read-only Actions defaults, and prove the consumer's disposable pull -request receives ordinary checks without self-approval or self-merge. +```sh +python3 .github/scripts/check_repository.py +git diff --check +``` -External provider GitHub Apps use a separate value-free inventory entry with -stable App, installation, and selected repository IDs; exact permissions and -events; provider purpose and status producer; accountable review ownership; -and a revocation runbook. Preserve every existing selected repository unless a -separate reviewed retirement authorizes its removal, never select all -repositories, and require organization-owner UI proof of the exact set when -GitHub's administrative API cannot enumerate it. Provider tokens, account -coordinates, and credential values do not belong in this repository. +The check confirms that every JSON file parses, that every relative link in +the Markdown files points at a file that exists, and that every action in the +workflows is pinned to a full commit SHA. Run +[actionlint](https://github.com/rhysd/actionlint) as well when you change a +workflow. -Organization identity changes must preserve the exact public description and -canonical website in `config/organization.json`, remain delta-aware in plan and -apply modes, and include unchanged-state coverage. Keep the public profile in -`community-health/profile/README.md`; never edit `atrinik/.github` directly. -Public pins are stable-ID manual state in `config/manual-settings.json`. Verify -their exact count, public/active identity, and order read-only through GraphQL, -and document the organization-owner profile-settings step rather than using an -undocumented mutation interface. +Keep `config/planning.json` unchanged unless the **Atrinik work** Project +itself changes: agent skills read its Status names. -Synchronization authentication tests must distinguish readable from writable -credentials, preserve exact CLI failure statuses, reject missing advertised -classic-PAT scopes and write capabilities before mutation, and fail closed on -GraphQL searches beyond GitHub's 1,000-result window. - -Project synchronization health changes must preserve the separate monitoring -path, the 90-minute freshness/failure contract, one marker-owned incident, and -least-privilege alerting through `GITHUB_TOKEN`. Test fresh, stale, repeated -failure, missing administration credential, trusted ownership, deduplication, -recurrent-outage boundaries, and recovery paths. Do not imply that GitHub's -best-effort cron is an exact 30-minute guarantee or that a monitor on GitHub -Actions is external to GitHub's scheduler. - -When changing organization issue forms, keep them compatible with GitHub's -live validator: omit empty optional metadata and do not add a top-level `type` -key while the live renderer rejects it. Keep form labels synchronized with -`config/planning.json` type inference, and validate the Bug, Feature, and Task -mappings before publishing. - -Keep default-branch deletion and non-fast-forward rules non-bypassable during -normal operation. Any organization-owner exception needed for GitHub's -security-advisory lifecycle must remain isolated to an explicitly authorized -window and must use pull-request-only bypass mode outside that window. - -GitHub does not classify an advisory-level merge as a pull-request action. A -specifically authorized Classic advisory merge window may therefore use -organization-owner `always` bypass for the five Classic rules GitHub reports: -deletion, non-fast-forward, linear history, the pull-request gate, and required -CI. The reviewed rollback must empty `config/advisory-merge-windows.json` and -be applied immediately after the advisory merge. - -An advanced CodeQL inventory change must be coordinated with an open, -review-ready workflow pull request in the target repository. Validate that the -plan attaches the advanced-allowed security configuration before disabling -default setup, and include the immediate workflow rerun and rollback owner in -the deployment handoff. - -An immutable-release inventory change stages desired state and must be activated -only with a merged, qualified draft-first release workflow in every newly -selected repository. Every registry upload must verify the actual source -release is immutable. Ordinary workflow tokens cannot query administrative -immutability settings; keep the supported source-release evidence boundary. Review the -repository name and stable numeric ID, the exact organization selected set, -owner-enforcement verification, and snapshot rollback tests. Merge the policy -before requesting explicit authorization for `bin/publish --apply`; never -deploy the setting from an unmerged policy branch. - -Security publisher changes must test both real drift convergence and a fully -converged rerun. The converged case must not update a security configuration, -replace its default, or re-attach repositories, because attachment starts an -asynchronous enablement event. - -Do not require a new workflow context until that exact aggregate context has -landed and passed on the protected branch. In particular, add Classic's -`CodeQL validation` requirement only after its advanced workflow is merged; -otherwise the required check would prevent the workflow pull request itself -from merging. - -Add a repository to the `merge_queue` inventory only after every one of its -required checks reports on the `merge_group` event on its default branch. Keep -`08 - Merge queue` repository-owned, because GitHub rejects the rule in -organization rulesets. Keep its parameters within GitHub's API ranges, and use -the organization's only merge method. Queued repositories drop the up-to-date -requirement from required CI and never require Dependency review. Merge-queue -changes need schema negative tests and publisher tests for creation, a -converged rerun, drift convergence, required CI that stays strict without a -verified queue, retained foreign or modified rules, the identity and final-read -fences before retirement, and install-before-relax and restore-before-retire -ordering. They also need audit scenarios for a missing queue, parameter drift, -organization ownership, strict drift, and a retained queue. - -Maintenance-branch retirement removes the active entry from -`config/repositories.json` and adds an immutable recovery record to -`config/retired-maintenance-branches.json`. Validate the complete repository, -then review the targeted `bin/publish --retire-maintenance -REPOSITORY/BRANCH` output. It must contain exactly one planned mutation: the -declared ruleset deletion. Merge the desired state before requesting explicit -organization-owner authorization for `--apply`. Re-run the complete preflight -after apply and again before separately authorized exact branch deletion; -never combine either operation with tag, release, asset, default-branch, or -unrelated policy changes. - -Dependency review is advisory across all active repositories. Keep -`dependency_review: []` and `activation.dependency_review: {}` in -`config/security-merge-protection.json`; do not add a required dependency-review -context. Report on eligible ordinary pull-request runs without target-branch -filters or a merge-group trigger. The workflow must exist on the relevant -PR/merge revision; adding it on main does not automatically cover historical -branches or authorize backports, retired-branch recreation, or additional -supported maintenance lines. -Keep low-through-critical vulnerability and license findings advisory, all -dependency scopes, `warn-only: true`, `license-check: true`, summary comments, -and step-level `continue-on-error: true`. License metadata is not compatibility -certification; existing repository license compatibility rules still apply. -Preserve per-PR/ref concurrency and the failure-report step. Operational errors remain nonblocking and visible; -retain available reports, and state that vulnerability/license results are -unknown when a report is absent. Fork/Dependabot comment denials warn and fall -back to job summaries. Implementing agents must read the latest run and job -summary for the current PR head before merge, even when an older bot comment -exists. Fix actionable findings, or record explicit maintainer-accepted risk; -inspect logs and explain missing reports rather than claiming a clean scan. This process adds no required human approvals or vulnerability CI -barrier. Preserve ordinary required CI, CodeQL, SHA policy, and standard lock -files without adding advisory or action-version catalogs. Retained generic -hard-gate tooling must reject advisory producer evidence; it may retire only -recognized owned old dependency gates through the existing fenced process. - -CodeQL merge controls use repository-level rules in both publisher scopes. -Keep CodeQL targets and activation entries in -`config/security-merge-protection.json` aligned with `required_ci` and preserve -ordinary aggregates. New CodeQL gates require successful current-head analyses, -including required languages. Record successful initial qualification in the -policy PR and promote the CodeQL gate's -`activation` entry from `pending` to `enforced` through source review before its -first live installation. Pending publication only probes readiness. Enforced -intent survives missing rules and later producer failures, allowing restoration -without fresh initial proof; it does not claim live installation success. Remove -activation entries with retired targets, preserving exact owned-rule rollback. -Re-read the exact security-rule payload after the repository metadata fence -immediately before deletion, retaining concurrent modifications. Audit retained -named security rules on non-target repositories as drift regardless of their -enforcement or ref applicability. -For an existing repository-owned `03 - Required CI` rule, also record exact repository -and ruleset IDs and its prior contexts in `config/retired-required-ci.json`. -Validate retained/modified/foreign rules and fresh identity checks; keep records -for idempotent retirement. Missing provenance must retain the rule. -Tests must cover missing/failed producers, unreadable evidence, archived targets, language unions, both scopes, -and zero security mutations on a converged rerun. SHA enforcement must remain -pending until an ordinary action-update canary proves successful PR-bound -current-head CI without an allowlist edit and the persistent rollout source is -promoted to `enforced` with that accepted PR. Later disabled enforcement is drift, -not pending rollout; ordinary publication revalidates the recorded proof before -restoring it. Test rule retirement, effective default-branch applicability, and -repository workflow permission overrides. Action allowances use owner/action wildcards; -full commit pins belong in workflows, not redundant version assertions. -Canary legacy-check absence requires verified protection evidence; bare or -ambiguous 404 responses fail closed. Publisher identity and absence decisions -require a complete validated ruleset inventory across all pages, including -retirement and ordinary repository/organization rules. - -Advanced CodeQL readiness must validate executable YAML wiring from classifier -invocation and outputs through the dynamic analysis matrix, scoped generated -configuration, official full-SHA CodeQL actions, and the unconditional aggregate. -Require the live default branch's ordinary pull-request trigger without path -filters, including opened, synchronize and reopened events. Use the existing -validation dependency with duplicate-key rejection. Test -comments-only markers, disconnected inputs, disabled or failure-suppressed steps, -checkout revision drift, and ambiguous YAML; preserve full-SHA updates, formatting -changes, additional partitions, and category renames. Classification path -semantics remain in trusted producer helpers; do not add a central source-path or -action-version catalog or claim resistance to malicious repository writers. - -Security gate updates must re-read and validate ownership and the recognized -payload immediately before PUT, preserving concurrent modifications. Bind the -final metadata default branch to the branch used for pending-gate qualification -or existing effective-gate proof; a changed branch must not activate a gate. -Pending existing-gate proof requires unchanged enforcement and ref applicability -in the final rule read; enforced intent retains recognized restoration. Audit -legacy protection on active default and maintenance branches as drift under the -canonical ruleset contract; distinguish verified unprotected responses from -unreadable evidence, and never remove protection during audit. Compare the -complete effective default and maintenance branch policy with declared allowed -rule types and parameters; additional -undeclared integrity or restriction types are drift. The exact -repository-disabled REST response may use the fixed read-only GraphQL fallback; -require matching repository identity and branch, active state and an explicit -null legacy-rule association. Errors and missing or conflicting fields fail -closed; preserve unrelated historical rules. - -Crates.io publication contracts bind exact repository/workflow/environment and -official auth-action identities with full immutable workflow SHA references; -preserve the reviewed `rust-lang/crates-io-auth-action@*` allowance for normal -Dependabot updates without a central version lock. Automatic publication follows reviewed -source/version merges with zero environment reviewers/wait and no registry -secrets. Keep pending onboarding distinct from observed source/environment and -owner-observed external registration; verify live protected main and exact -refs. First owner-local API-token bootstrap is restricted to the seven -listed toolkit libraries and ends with revocation; subsequent releases -use OIDC only. Protocol 0.2 retains its approved manual path. Crate -publication must qualify both exact-main workflows, isolate inert source -signing from build/semantic-release OIDC, and keep automatic verify permissions -read-only. The inert publisher alone adds contents write for the global -crate/version upload intent and receives its intent token only in the upload -step. Runtime certificate/source-run verification and create-only reservation -readback precede upload. Reject matrix/reusable execution in the automatic -verify/publish and source package/sign/release jobs; recursively reject step -references outside the exact upload-token input and confirmation condition. An -existing/ambiguous intent blocks absent-version -retries and is never automatically reset. Activate immutable-release policy -only through the documented narrow snapshot/readback/verified-rollback window; -do not broad-apply unrelated publisher-plan mutations. Broad apply must qualify -newly added live producer selections before its first mutation, with observed -inventory and fresh scoped source/environment checks. Initial independently -qualified draft-first code is sufficient for setup; actual immutable public -release and registry proof remain later runtime obligations. Dependency-update -App setup is client only, exact contents/PR write and metadata read, -repository credential names only, registry readiness before owned PR creation, -and ordinary review/checks without auto-merge. Distinguish observed installation -and credential-name provisioning from pending reviewed workflow activation and -real successful-owned-PR proof; owner-authorized early setup does not prove -effective secret values. Inventory exact workflow consumer paths, observed key -creation/verification dates, rotation owner, and a deadline within 90 days of key -creation; that internal deadline does not assert upstream expiry. Verify a -replacement key in the owning writing workflow before revoking the old key. -Keep App-authenticated selected-set readback or owner -UI evidence, and do not infer the webhook switch from an empty event set. A -selected-set change after that readback stays pending re-verification until a -later readback is recorded. An owner-accepted key exposure stays until the key -rotates and never extends the rotate-by deadline; both records pin the exact -editor transfer. -Private linux-build consumption needs separate client-only read grants -through owner UI. Keep exact private package/source identities and pending grant -state until observed; metadata and owner pulls do not prove an effective owning -workflow pull. Preserve foreign grants and visibility. Changes require negative schema -and live-metadata fixture tests plus a complete publisher plan; publishers do -not provision these integrations. +Never commit tokens, secrets or API responses that contain credentials. diff --git a/README.md b/README.md index 0ccd5a7..bd9b9e0 100644 --- a/README.md +++ b/README.md @@ -1,2041 +1,58 @@ # Atrinik GitHub settings -[![Project synchronization health](https://github.com/atrinik/github-settings/actions/workflows/check-project-health.yml/badge.svg)](https://github.com/atrinik/github-settings/actions/workflows/check-project-health.yml) +This repository is the home of Atrinik's GitHub organization settings record. +Today it holds very little: -This repository is the source of truth for Atrinik organization settings and -repository rulesets. `bin/publish` uses the GitHub REST API to apply the policy -to every targeted repository in one run. +- [`config/planning.json`](config/planning.json): the **Atrinik work** Project + and its status names. Agent skills read the status names from here. +- A small CI check ([`.github/scripts/check_repository.py`](.github/scripts/check_repository.py)) + that keeps the files in this repository valid. -The same repository owns Atrinik's cross-repository planning system: -organization issue types and fields, the public **Atrinik work** Project and -shared views, scheduled item synchronization, repository custom properties, -and the generated organization community-health repository. +A read-only settings check and Atrinik's settings baseline will be added here +by a later pull request. -The organization description and canonical website are also governed here. -The public profile README is generated from `community-health/profile/README.md`, -while the six public organization pins remain explicit, read-only-verified -manual state because GitHub exposes no supported pin mutation API. +## The old automation is retired -Atrinik uses GitHub Team. The publisher detects the organization plan and uses -organization-level rulesets on Team or Enterprise. On GitHub Free it installs -equivalent repository-level rulesets instead. Archived repositories are -read-only and are skipped on later runs. +On 2026-11-14 the owner retired the automation that used to live here: the +settings publisher, the Project synchronizer, the drift audit, the Project +health check, the community-health generator and semantic release. They were +removed because: -## Policy +- They needed a standing organization-owner credential stored in GitHub. That + credential is gone and will not be replaced. +- The rules they managed now live in organization rulesets that target all + repositories, so a new repository is covered without being registered + anywhere. +- The replacement is a read-only check and a short baseline file, both coming + to this repository. -- Every active repository protects its default branch from deletion and - non-fast-forward pushes without a bypass. A separate linear-history rule - permits organization owners to bypass only through a pull request, preserving - an audit trail for GitHub's security-advisory merge lifecycle. -- Every active repository uses `main` as its default branch. -- Maintained repositories require changes through pull requests. Organization - owners may bypass this gate only through a pull request, including the - temporary private pull request GitHub associates with a security advisory. -- Repositories with reliable CI require checks from the GitHub Actions app. - Replacement repositories require their proven stable aggregate validation - job plus `Conventional PR title`; component/platform jobs remain diagnostic - and are not independent merge gates. The `classic` monorepo requires its - stable aggregate `Classic validation` and `CodeQL validation` jobs plus - `Conventional PR title`. -- Repositories in the `merge_queue` inventory merge through GitHub's merge - queue, and their required CI no longer requires an up-to-date branch because - the queue tests each merged result. `playtester` is the pilot. See - [Enabling a merge queue](#enabling-a-merge-queue). -- Declared maintenance branches reject deletion and non-fast-forward updates, - require linear history and pull requests, and require only checks already - emitted for that branch. -- Release tags in release-producing repositories cannot be moved or deleted. -- Active services without an established release contract may use - `release_policy: none` while remaining in the pull-request and required-CI - inventories; they must be omitted from `release_tags` until that contract - exists. -- Published releases in the exhaustive `config/immutable-releases.json` - inventory declare owner-enforced immutable releases. The inventory preserves - Classic and the qualified library producers and stages metaserver-worker - until its draft-first producer is merged and qualified. This organization - policy is independent of the release-tag ruleset and applies in both - publisher policy scopes. -- Active repositories allow squash merges only. The squash commit uses the - pull-request title and description, and merged head branches are deleted. -- Every repository uses an enforced security baseline: dependency graph, - Dependabot alerts and security updates, secret scanning, push protection, - validity checks, and private vulnerability reporting remain enabled in both - security configurations. Ordinary repositories use CodeQL default setup from - `config/code-security.json`. Repositories in - `config/codeql-advanced-setup.json` instead receive the otherwise-identical - `config/code-security-advanced.json` configuration, whose supported - `code_scanning_options.allow_advanced` setting permits their governed - component-aware workflow. The publisher explicitly disables default setup - for those repositories and configures it everywhere else. The ordinary - baseline remains the default for new repositories. -- Organization members cannot create repositories. Deletion, transfer, and - visibility changes are recorded as required UI settings because GitHub does - not expose them through the public API. -- Only organization owners may create teams or install GitHub Apps. Members may - request GitHub Apps for owner review. These UI-only settings are recorded in - `config/manual-settings.json`. -- Private GitHub Packages consumed across repositories have explicit, - read-only workflow grants recorded in `config/manual-settings.json`. Public - reusable build images instead require anonymous immutable-digest access and - no consumer grant or package permission. A private-to-public transition is a - separately reviewed, effectively irreversible owner action that preserves - the source-repository link. -- GitHub Actions environments that depend on externally issued credentials - have name-only contracts in `config/manual-settings.json`. The inventory - records the stable repository identity, exact deployment branch policy and - reviewer set, and variable and secret names; credential values remain manual - and are never committed. -- Administrative Actions credentials have value-free lifecycle contracts in - `config/manual-settings.json`: stable repository identity, secret placement, - credential type and scopes, consumers, accountable ownership, verification date, - rotate-by deadline, cadence, and runbook. Validation rejects expired records - and any value-like field. `bin/verify-manual-settings` checks credential - secret-name presence plus inventoried environment identity, deployment - branches, reviewer rules, and exact secret and variable name sets without - reading or proving any value. -- Repository-scoped GitHub Apps used by Actions have separate value-free - lifecycle contracts in `config/manual-settings.json`. The inventory binds - the stable App and installation IDs, exact permissions and event set, - intended repository and consumer, credential metadata names, accountable - owner, verification date, rotation deadline, and runbook. The App private - key and installation tokens never belong in this repository. -- External provider GitHub Apps have a distinct value-free inventory. Active - installations bind stable App and installation identities, exact permissions - and events, exact selected repository IDs, provider purpose, review owner and - deadline, revocation procedure, and status producer. Planned integrations - explicitly retain null live IDs, the proposed selected set, and a pending - owner-UI verification state. Provider credentials and account coordinates - remain outside GitHub and this repository. -- GitHub Actions defaults to read-only, cannot approve pull requests, and may - use only Atrinik, GitHub, Codecov coverage, explicitly allowed Docker - actions, and `rust-lang/crates-io-auth-action@*`. Workflow references remain - full commit SHAs; the action allowlist permits routine pin updates. The - publisher also restores per-repository workflow permission overrides to - read-only with PR approvals disabled, applying only real drift. -- Historical repositories listed in `config/repositories.json` are archived. - The five former standalone classic component repositories are already - archived read-only after their history, active work, issues, and release - metadata were preserved for the `atrinik/classic` transition. -- `config/planning.json` defines one public organization Project, its workflow - statuses and shared views, enabled issue types, and public organization issue - fields. New issues enter **Inbox**, pull requests enter **Review**, and the - pre-existing portfolio enters **Backlog**. Human status changes on open work - are preserved; closed work converges to **Done**. -- Organization-wide issue forms omit empty optional metadata and the top-level - `type` key so they pass GitHub's live validator. The Bug and Feature forms - apply `bug` and `enhancement`; the synchronizer maps those labels to **Bug** - and **Feature**, while the unlabeled Task form uses the **Task** fallback. - Parent issues still become **Initiative**, `new feature` remains a recognized - Feature alias, and existing issue types are never overwritten. -- `config/repository-properties.json` declares a complete taxonomy for active - and archived repositories: component role, provider set, lifecycle, and - release policy. -- `community-health/` is the source for organization-wide issue forms, - pull-request guidance, contribution guidance, conduct policy, and security - reporting, including the public organization profile. - `bin/publish-community-health` generates `atrinik/.github` directly from this - released source; the generated repository is not edited or released - independently. -- `config/organization.json` owns the game-first organization description and - preserves `https://atrinik.org` as the canonical website. The publisher - compares every owned field and patches only when live state differs. -- `config/manual-settings.json` owns the exact public repository pin order: - `classic`, `atrinik`, `website`, `content`, `protocol`, and `playtester`, with - stable repository IDs. `bin/verify-manual-settings` reads the ordered pins - through GraphQL and fails closed on count, identity, visibility, archival, or - order drift; it never mutates them. +## How settings change now -The GitHub REST API does not expose every organization control. The desired -values are recorded in `config/manual-settings.json` and must be confirmed in -the organization UI under **Member privileges**, **Authentication security**, -**GitHub Apps**, each listed repository's **Environments** settings, and each -listed private package's **Manage Actions access** section. Public package -identity, visibility, source association, and anonymous digest access use the -separate checked procedure below. Codecov must be installed for the listed -repositories so their OIDC-authenticated coverage uploads and badges remain -available. +- The owner, or an agent session she authorizes, changes settings by hand + under her own login, in GitHub's web pages or with `gh`. +- The change is recorded here in the same task, through a pull request. +- The **Atrinik work** Project board is no longer filled automatically. Add + issues and pull requests to it by hand when they belong there. +- [`atrinik/.github`](https://github.com/atrinik/.github) (issue forms, + pull-request template, contribution guidance, public profile) is no longer + generated from here. Edit it by hand through pull requests in that + repository. -## Staged security merge protection +## Rollouts that were never switched on -`config/security-merge-protection.json` targets the 22 repositories in -`required_ci` for CodeQL, including `service-updater`; `.github` and -`web-platform` are excluded from that CodeQL cohort. Its CodeQL `activation` -map records each target's reviewed `pending` or `enforced` intent. `enforced` -means protection is required, including when the live rule is missing; it is -not evidence of a successful installation. Existing aggregate checks and zero -required approvals remain intact. The publisher also restores -`service-updater`'s inventoried PR, `Updater validation`/title CI, and release-tag -protections. +The old configuration declared three rollouts that were never switched on. +They are now settled: -Both policy scopes install repository-owned `06 - CodeQL security` rules: -GitHub Team does not support organization code-scanning rules. CodeQL blocks -high and critical security findings (`high_or_higher`), with ordinary quality -alerts disabled (`none`). Only organization owners may bypass through a pull -request; direct pushes gain no exception. +- Required full-SHA pinning of actions is on for the organization. +- CodeQL as a merge requirement is dropped. CodeQL alerts stay advisory. +- The merge queue pilot on `playtester` is dropped. -Dependency review is advisory across all active Atrinik repositories, including -those outside the CodeQL cohort. Its required-gate inventory is empty: -`dependency_review: []` and `activation.dependency_review: {}`. The publisher -will not install `07 - Dependency review`. A separately authorized settings -apply can retire only an exact recognized repository-owned old `07` rule, with -the existing identity, archive, payload and final-read fences. Modified or -foreign rules are retained for review; a source merge alone does not remove -live protection. +## History -The dependency workflow reports on eligible ordinary pull-request runs when -opened, updated, reopened, or edited, including a base-branch retarget. It has -no target-branch filter, but the workflow must exist on the relevant PR/merge -revision; adding it on main does not automatically cover historical branches. -It does not run on merge queue groups. Reporting visibility does not declare a branch -supported or maintained or authorize backports or recreating retired branches. -The pinned official action reads event revisions without checkout, contributor -code execution, secrets, or `pull_request_target`. It requests contents read -and pull-request write solely for its report. It reports low through critical -vulnerabilities in runtime, development, and unknown scopes with `warn-only: -true`, keeps license findings advisory, and always attempts a PR summary comment. -License metadata is not a compatibility certification; existing repository -license compatibility rules still apply. -Fork and Dependabot tokens may deny comment writes; the action warns and keeps -its job summary. Operational errors remain visible in logs but step-level -`continue-on-error: true` keeps this advisory job nonblocking. A following -failure-report step warns and adds a job-summary notice without claiming the -action produced no analysis; absent reports mean vulnerability and license -results are unknown. It also attempts to refresh the uniquely identified action -comment with the current head and run link; denied or uncertain comment writes -retain the summary fallback. The action has a five-minute timeout and reporting -a separate two-minute timeout within the ten-minute job. Per-PR/ref concurrency -cancels superseded review runs. +The retired tooling, its configuration and its documentation are in the Git +history. The last release that contains them is +[`v2.26.0`](https://github.com/atrinik/github-settings/releases/tag/v2.26.0). -Implementing agents must read the latest dependency-review run and job summary -for the current PR head before merging, even when an older bot comment exists. -Fix actionable findings, or record a maintainer's explicit acceptance of the -remaining risk. A missing report is not a clean vulnerability result; -inspect the log and explain the reporting failure. This review process adds -no required human approval and no vulnerability CI barrier. Ordinary PR CI -trusts repository writers, who can change a workflow in the same PR; neither -its check context nor the GitHub Actions app attests immutable workflow bytes. +## Contributing -Dependency review relies on GitHub's dependency graph and submitted snapshots; -unsupported or missing manifests cannot provide comprehensive coverage. GitHub's -[Dependabot alert limitations](https://docs.github.com/en/code-security/concepts/supply-chain-security/dependabot-alerts#limitations) -exclude advisory alerts for Actions referenced by commit SHA. SHA pinning and -a clean advisory report therefore do not prove an Action commit is free of -known vulnerabilities; review upstream advisories when updating pins. - -Default CodeQL setup similarly analyzes supported languages and its detected build -coverage; enabling it alone does not prove a successful analysis. Rust in -`content-toolkit` is an explicit minimum, unioned with its existing languages. -Legacy `javascript`/`typescript` aliases use `javascript-typescript` in the -PATCH payload, preserving that coverage and other live language entries. -Read failures never replace that live language set with an incomplete set. - -GitHub's [code-scanning merge-protection limitations](https://docs.github.com/en/code-security/concepts/code-scanning/merge-protection) -exclude Dependabot pull requests analyzed by default setup and merge queue -groups. Advisory dependency review reports on eligible Dependabot pull requests -where its workflow is present. CodeQL merge protection also depends -on the alert's affected lines appearing in the PR diff. Ordinary quality alerts -remain excluded by `alerts_threshold: none`. - -Classic readiness parses the executable workflow with the declared PyYAML -validation dependency. It binds classification outputs to the analysis matrix, -regenerates each selected scope's configuration, and follows that output into -the official CodeQL initialization and analysis steps and the always-running -validation aggregate. Disabled steps, failure suppression, disconnected inputs, -and ambiguous YAML fail closed. The current producer uses `build-mode: none`; -full-SHA action updates remain producer-owned, and classifier source owns path -selection and category names. This structural check trusts repository writers -and their Python helpers; it does not attest that arbitrary writer-controlled -classifier or aggregate code behaves honestly. It adds no approval requirement. - -Rollout is owned by an organization administrator: - -1. Merge the advisory workflow and policy PRs, inspect their dependency reports, - and review `bin/publish`'s plan. Dependency findings do not block CI; CodeQL - retains its separate staged protection. -2. Apply only with separate live-settings authorization. Existing governance, - the wildcard action allowance, and the Rust language correction can converge - while security gates remain `PENDING`. Pending gates only probe - `bin/security-readiness`; even a successful probe cannot activate protection - or silently promote source intent. The retained generic dependency readiness - helper rejects advisory producers as required-gate evidence. CodeQL requires current-head coverage for every configured default-setup - language plus policy minima. Classic instead requires its successful full - advanced producer and all current source-derived analysis partitions. The - advanced inventory independently requires Classic’s client, server, and core - C/C++, Python, and GitHub Actions scope/language pairs, so reducing producer - declarations or executed jobs cannot silently reduce required coverage; - changed-path PR subsets cannot establish readiness. The bounded newest-first - query stops once current coverage is proven; retired categories and old - analysis history do not require manual cleanup. -3. After successful initial producer qualification, promote that gate's - `activation` entry to `enforced` through source review and merge, retaining - the qualification evidence in the policy PR. Adoption of existing protection - instead requires read-only evidence of an active, repository-owned gate with - the intended tool/context applying to the live default branch. Desired target - membership alone never proves activation. Review the next plan and apply only - with live-settings authorization. Persisted intent precedes the first write, - so interrupted installation or later deletion cannot revert to pending. - The publisher creates or restores enforced protection without requiring a - currently healthy producer; audit reports missing or modified protection as - drift even when producer evidence fails or cannot be read. Scope migrations - preserve these repository-owned gates. A converged security gate or language - configuration causes no mutation or security-configuration reattachment. - Existing-rule repair accepts only recognized enforcement and ref-scope drift - on the exact repository-owned rule. Changed bypass, tool, context, severity, - or unknown policy fields are retained and reported for explicit review. - Retiring a CodeQL target removes its required-CI, CodeQL target, and activation - entries together through source review. Dependency advice does not require - removing ordinary CI. The publisher removes only matching - repository-owned security rules from active retired targets, preserving foreign or modified same-name - rules for explicit review and leaving archived repositories untouched. It re-reads - the exact rule payload after the repository metadata fence immediately before - deletion to retain concurrent modifications. Audit reports retained named - security rules on non-target repositories as drift even when disabled, - modified or scoped to another ref. -4. Desired organization `sha_pinning_required` is true. Its durable rollout - contract is `config/actions-sha-pinning.json`: the initial `pending` phase - has no accepted canary and never enables the field. Verify an ordinary - action-pin update PR with `bin/security-readiness sha OWNER/REPOSITORY/PR`. - Qualifying changes update action pins only. Reusable workflow references are - [excluded from GitHub's action SHA enforcement](https://docs.github.com/en/organizations/managing-organization-settings/disabling-or-limiting-github-actions-for-your-organization), so changing one cannot qualify - a canary, even alongside an action update. Unchanged reusable references and - real action subpaths remain supported. - The optional publisher `--sha-pinning-canary` argument only reports readiness - while pending. After successful PR evidence, promote the source to - `{"phase":"enforced","canary":"OWNER/REPOSITORY/PR"}` through the normal - review and merge process before the first separately authorized live apply. - This records the accepted PR, with no duplicate action-version inventory. - The verifier checks the active conservative organization Actions mode, - repository enablement, exact PR changes, and successful PR-bound current-head - checks. These include configured CI and all effective ruleset and legacy - branch-protection status - contexts, with trusted app identities. Advisory dependency review is not a - desired required context; an old effective gate remains part of the live - proof until separately retired. Legacy-check absence requires verified - protection evidence; bare or ambiguous 404 responses fail closed. This proves current policy and PR-run - evidence; it does not attest historical organization settings. - Ordinary subsequent publication uses that stored canary. It first converges - selected mode, then allowed-action patterns, then revalidates the canary - before restoring a disabled SHA setting. A dry run reports the required - staging without claiming that planned settings are active. Unreadable or - failed proof blocks SHA restoration while retaining conservative policy - repairs; the audit reports disabled enforced policy - as drift, never as initial rollout pending. A live true setting is always - preserved. Full SHA pinning does not prove an allowed action is trustworthy. - -Advanced CodeQL qualification also requires ordinary pull-request triggers -covering the live default branch and opened, synchronize and reopened events, -without workflow path filters. Successful manual or scheduled analysis cannot -qualify a missing or retargeted pull-request producer. Before updating an -existing security gate, publication rechecks its ownership and recognized -payload immediately before the write, retaining concurrent policy changes. -Pending-gate qualification and existing effective-gate proof bind the same -default branch as the final metadata fence; a changed branch cannot activate -a gate using proof from the earlier branch. Pending existing-gate proof also -requires unchanged enforcement and ref applicability in the final rule read; -concurrent disabling or retargeting invalidates that proof. Enforced intent -retains its recognized restoration behavior. - -Rulesets are the canonical branch protection contract. Audit also reads legacy -protection on every active default branch and declared maintenance branch. Any -legacy protection is drift requiring separate reviewed manual remediation; -unreadable responses fail closed. Only a verified unprotected-branch response -counts as absent. For the exact repository-disabled REST response, a fixed -read-only GraphQL query may instead prove that the identified active repository -and exact existing branch have an explicitly null legacy-rule association. -Missing, conflicting or unreadable evidence remains drift. Historical rules on -other branches remain untouched. Audit compares the complete effective default and maintenance branch -policy with declared allowed rule types and parameters; extra integrity or restriction types remain -drift even when every desired rule is present. The audit never removes branch protections. - -Publisher identity, absence, update and retirement decisions use the complete -validated ruleset inventory across all pages, including ordinary organization -and repository rules. Unreadable pages cannot count as absent rules. - -Repository-scope retirement of an existing `03 - Required CI` rule also needs a -reviewed `config/retired-required-ci.json` record with its exact repository and -ruleset IDs and previous required contexts. Remove the repository from -`required_ci` and both security target/activation inventories in the same source -change. Publication deletes only the unchanged GitHub Actions-bound template -after fresh repository identity, archive-state and rule-payload checks. Missing -provenance or modified/foreign rules are retained with an actionable `SKIP`; -keep retirement records for idempotent reruns. This does not delete branches or -ordinary branch protections. - -Read-only preflight failures and unfinished producers are explicit pending -controls, never successful rollout evidence. The audit reports pending controls -separately and rejects unreadable evidence. No paid subscription is introduced. -Rollback requires reviewed desired-state changes and separately authorized -apply; reverting a producer while its required gate remains active can prevent -merges. Do not remove a gate merely because a vulnerable PR fails it. - -## Usage - -Requirements: `git`, `gh`, `jq`, `python3`, the packages in -`requirements-validation.txt`, and an authenticated organization-owner account. -Install the declared validation dependencies before local publisher, audit, or -advanced CodeQL readiness checks; the owning workflows install them too. - -```sh -gh auth refresh -h github.com -s admin:org,project,repo -bin/publish -bin/publish --apply -``` - -The default invocation prints the operations without changing GitHub. The -`--apply` form is idempotent: existing Atrinik rulesets, immutable-release -selection, and the security configuration are converged to the declared -policy. On Team, the publisher creates organization rulesets before removing -their repository-level equivalents so protection is never absent during -migration. Before changing immutable releases, it snapshots the exact current -organization mode and selected repository IDs. A failed update or verification -automatically restores and verifies that snapshot. - -Repository merge defaults and organization workflow permissions are written only -when their declared fields differ. Ordinary ruleset updates compare normalized -policy, treating the ignored `OrganizationAdmin.actor_id` and array ordering as -semantically equivalent. Publisher and audit share the comparison contract in -`lib/ruleset-policy.jq`. - -GitHub's additional PR/CI parameters are writable controls. Existing empty -`required_reviewers`, all three `allowed_merge_methods`, -`require_extra_approval_for_unattributed_changes: true`, and -`do_not_enforce_on_create: false` are compatible with this policy and are copied -unchanged into replacement payloads. Other values, unknown parameters, extra -rules (including deployment gates), and unknown condition fields require manual -review; the publisher stops instead of dropping them. Managed fields still -converge on real drift. Existing ruleset updates verify the listed identity and -re-read the full document before PUT, refusing observed concurrent changes. -These reads are not an atomic API transaction. Review the complete plan before -any authorized apply; normalization does not authorize rule retirement or a -live policy change. Queue installation and verification still precede relaxed -required CI. - -The organization security phase compares GitHub's normalized configuration, -default, and repository-association state before writing. It updates only -drifted configurations and attaches only repositories that are not already -attached or enforced on the intended configuration. This is a correctness -boundary as well as an optimization: GitHub handles attachment as an -asynchronous enablement event, including when an already-associated repository -is submitted again, so a no-op publish must not start a replacement event. - -To force the per-repository implementation before or after a downgrade to -GitHub Free, use the retained fallback publisher: - -```sh -bin/publish-repositories -bin/publish-repositories --apply -``` - -This applies merge settings, security features, the inventory-specific CodeQL -setup state, and all rulesets repository by repository. It removes the managed -organization rulesets only after their repository equivalents exist. The -fallback preserves every non-CodeQL security feature for advanced-setup -repositories while converging their default setup to `not-configured`. - -The manual `Publish settings` workflow provides the same operation in GitHub -Actions. It requires an `ATRINIK_SETTINGS_TOKEN` repository secret with -organization administration and repository administration access. Never store -that token in this repository. - -### Settings automation credential - -`ATRINIK_SETTINGS_TOKEN` is a repository-scoped Actions secret on -`atrinik/github-settings`. Its value-free lifecycle record lives in -`config/manual-settings.json`; the current record's `rotate_by` date is an -enforced maximum, not a suggestion. The credential value belongs only in an -approved private credential manager and GitHub Actions. - -Provision or rotate it as an Atrinik organization owner: - -1. Before the current `rotate_by` date, prepare a pull request that updates - `last_verified_on` and a new `rotate_by` no later than the declared rotation - cadence. Keep ownership, consumers, and required scopes accurate. -2. Create a classic PAT with exactly `admin:org`, `project`, and `repo`, an - expiration no later than the recorded deadline, and organization access if - GitHub requires separate authorization. -3. Store it without echoing the value: - - ```sh - gh secret set ATRINIK_SETTINGS_TOKEN --repo atrinik/github-settings - ``` - -4. Verify repository identity and secret-name presence, then dispatch only the - synchronization workflow: - - ```sh - bin/verify-manual-settings - gh workflow run sync-project.yml --repo atrinik/github-settings - gh run list --repo atrinik/github-settings --workflow sync-project.yml --limit 2 - bin/sync-project - ``` - -5. Require the manual run to succeed, the read-only plan to report - `Items to add: 0` and `Total mutations: 0`, and a later scheduled run plus - Project health check to succeed before revoking the previous credential. - -If verification fails, do not run a publisher or expose the token while -debugging. Restore the prior unexpired credential from the approved private -credential manager, or issue a replacement; then repeat the complete check. -For suspected disclosure, revoke the affected PAT immediately, provision a new -one, review Actions logs and organization audit events, and verify every -consumer workflow. `bin/verify-manual-settings` proves only that GitHub exposes -the declared secret name at the stable repository—it cannot inspect the value, -expiry, or effective scopes. The synchronization preflight is the scope and -functionality proof: apply mode verifies the classic PAT's advertised scopes, -Project update capability, and write access for every repository needing an -issue-type change before the first mutation. - -## Metaserver development credentials - -The `development` environment of `atrinik/metaserver-worker` (repository ID -1324297032) holds the three value-free lifecycle entries consumed only by -`.github/workflows/deploy-development.yml`. Zoey Seraphina Rose, an Atrinik -organization owner, is accountable for verification and rotation. - -`CLOUDFLARE_API_TOKEN` is account-owned with intended Workers Scripts Edit and -D1 Read permissions. Its account-wide edit authority can also edit PROD; the -workflow's exact DEV configuration and resource fences provide the target -boundary. `ATRINIK_DELIVERY_RESOURCE_READ_TOKEN` is account-owned with intended -Workers Scripts Read. `ATRINIK_PRODUCTION_BUILDS_READ_TOKEN` is user-scoped -with intended Workers CI Read and Workers Scripts Read for the retained-writer -fence. Do not describe any of these credentials as restricted to one Worker. - -All three environment names were installed and verified on 2026-10-11; bounded -runtime GET checks passed. Effective provider permission metadata is unreadable, -and the deployment token's write permission has not yet been proven by its -owning workflow. Name metadata does not verify values, scope or expiry. -The 2027-01-09 rotate-by deadline is the internal 90-day policy, not a provider -expiry claim; provider expiry remains unverified. - -Before that deadline, prepare a reviewed lifecycle update, provision replacement -credentials under separately authorized scope, and install them without printing -values. Run `bin/verify-manual-settings` for stable repository and environment -secret-name presence, then prove the bounded read paths and the owning DEV -workflow under its normal target gates before revoking predecessors. Retain -private qualification receipts and never change PROD targets or provider -permissions merely to validate rotation. Publishers do not provision tokens. - -### Classic dependency update App - -`atrinik-classic-dependency-updater` is an organization-owned GitHub App used -only by the planned `atrinik/classic` consumer workflow -`.github/workflows/update-content.yml`. App ID `4564008` and installation ID -`153045686` are public stable identifiers. The installation selects only -`atrinik/classic`, repository ID `1327289971`, and has exactly these repository -permissions: - -- metadata: read; -- contents: write; -- pull requests: write. - -The App subscribes to no webhook events and has no Actions, checks, -deployments, environments, issues, packages, secrets, organization -administration, or ruleset-bypass permission. Organization Actions defaults -remain read-only and Actions cannot approve pull-request reviews. The App ID -is stored as the repository Actions variable `DEPENDENCY_UPDATE_APP_ID`; its -private key is stored as the repository Actions secret -`DEPENDENCY_UPDATE_APP_PRIVATE_KEY`. Never commit, print, cache, artifact, or -place either the private key or an installation token in a pull-request body, -step output, command line, fixture, or log. - -The public REST response available to the settings administration credential -proves the organization owner, stable App and installation IDs, selected-mode -installation, exact effective permissions, empty event set, and unsuspended -state. GitHub does not expose the installation's exact selected-repository list -to that credential. An organization owner must therefore also inspect - -and confirm that the only selected repository is `classic` whenever the record -is created, rotated, or reviewed. `repository_scope_verification` records this -manual boundary; `bin/verify-manual-settings` additionally verifies Classic's -stable repository identity and both credential metadata names without reading -or logging their values. - -GitHub App installation access tokens expire after one hour. The consumer must -mint a token only in the branch/PR mutation job, scope it to `classic`, avoid -exporting it beyond the necessary steps, and allow the pinned token action to -revoke it when the job finishes. The automation boundary is the single stable -branch `automation/content-update` and one open pull request from that branch. -Use one non-cancelling concurrency group, `classic-content-update`; a queued -run re-evaluates current state after the prior run completes. A run updates the -existing App-owned branch and PR only when their base, head owner, author, and -changed-path contract are intact. Zero matching PRs permits creation, one -permits refresh, and multiple matches or unexpected commits fail closed. - -GitHub has no branch-only App permission: `contents: write`, which is required -to update the automation branch, also authorizes Git-reference and release API -operations. GitHub likewise has no separate create-or-update-PR permission that -excludes review APIs: `pull requests: write` covers both. The App credential -therefore cannot by itself prove that tag, release, or review calls are -technically impossible. Ordinary pull requests require zero human approvals; -required checks and the pull-request process still apply, and the App has no -bypass. The consumer must never review, approve, merge, tag, publish, -dispatch a release, write the default branch, or change repository settings. -Its reviewed code, exact branch and changed-path checks, ordinary pull-request -gate, protected release-tag rules, workflow contract tests, and audit trail -jointly enforce that operational boundary. Do not describe the credential as -release- or review-incapable; treat any use outside the exact automation branch -and pull-request operations as an incident. - -Provision or rotate the key as an Atrinik organization owner: - -1. Prepare a reviewed change that advances `last_verified_on` and `rotate_by` - by no more than the recorded 90-day cadence. Reconfirm the App owner, - installation ID, Classic-only selection, empty event set, and exact three - permissions in the GitHub UI before changing credentials. -2. Generate a new App private key while the prior key remains valid. Store the - complete new PEM in the approved private credential manager and replace the - `DEPENDENCY_UPDATE_APP_PRIVATE_KEY` repository secret without echoing it. - Keep `DEPENDENCY_UPDATE_APP_ID` equal to the public numeric App ID. -3. Run `bin/verify-manual-settings`. This proves metadata and name presence, - not the key value. After the Classic consumer exists, dispatch only - `update-content.yml` and require one App-authored disposable pull request to - receive ordinary `Classic validation`, `CodeQL validation`, and - `Conventional PR title` checks. -4. Confirm the App-authored pull request receives the required checks, the App - has no bypass, and the consumer does not approve or merge the pull request. - Close the disposable pull request, remove its branch, and only then delete - the previous private key. A later scheduled run must also succeed before - rotation is considered complete. - -For suspected disclosure or misuse, disable the Classic updater workflow, -suspend installation `153045686`, delete the repository secret, and revoke the -affected private key immediately. Review Actions logs, App and organization -audit events, open pull requests, branches, tags, and releases; remove only -verified App-owned disposable state. Rotate to a new key and repeat the full -proof before re-enabling. To revoke permanently, uninstall the App from -Classic, delete its keys plus the repository secret and variable, and reconcile -`config/manual-settings.json` through a reviewed rollback. Do not leave a -credential inventory entry claiming a revoked installation is active. - -Read non-secret live metadata and run the complete verifier with: - -```sh -gh api orgs/atrinik/installations \ - --jq '[.installations[] | {id, app_id, app_slug, repository_selection, permissions, events, suspended_at}]' -gh api repos/atrinik/classic/actions/secrets \ - --jq '{total_count, names: [.secrets[].name]}' -gh api repos/atrinik/classic/actions/variables \ - --jq '{total_count, names: [.variables[].name]}' -bin/verify-manual-settings -``` - -If any ID, permission, event, suspension state, selected repository, or -credential name differs, stop. Disable the consumer and reconcile reviewed -desired state before minting another installation token. - -## Cloudflare GitHub App - -The existing organization installation for the **Cloudflare Workers and -Pages** GitHub App is App ID `85455`, installation ID `152311798`, and selected- -repository mode. Its exact effective GitHub permissions are administration, -checks, contents, deployments, and pull requests write plus metadata read; its -event subscriptions are exactly `pull_request` and `push`. These broad App -permissions are provider-managed GitHub capabilities, not the Cloudflare build -token or runtime authority. Issue -[`atrinik/metaserver-worker#56`](https://github.com/atrinik/metaserver-worker/issues/56) -separately owns the least-privilege Cloudflare identities and provider -connection. - -The selected set must be exactly these two stable repositories: - -- `atrinik/website`, ID `1327107093`, preserving its existing Pages - integration; and -- `atrinik/metaserver-worker`, ID `1324297032`, for the serialized Workers - Builds topology reviewed in metaserver-worker issues 53-56. - -No other repository and never **All repositories** is authorized. GitHub's -organization-installations API verifies the public installation identity, -mode, effective permissions, events, organization owner, and suspension state. -It does not give this administrative token an authoritative enumeration of the -selected set, so an organization owner must verify that exact two-repository -set in -. -`bin/verify-manual-settings` deliberately reports this remaining manual proof; -it also verifies both repository IDs read-only and never reads a credential -value. - -After the metaserver-worker production and review contracts are merged and -validated, a separately authorized organization owner may edit only this -installation: preserve `website`, add only `metaserver-worker`, save selected- -repository mode, and immediately re-open the selection to confirm the exact -two entries. Do not change App permissions, events, the website connection, -repository rulesets, or any unrelated installation. Run -`bin/verify-manual-settings` before and after the UI step and retain the owner -confirmation in the owner-controlled -`atrinik/metaserver-worker#56-private-provider-evidence` record. That stable -coordinate is public governance metadata; the evidence contents remain private -and contain no credential values. `bin/publish` remains plan-only for this -record and never changes installation access. - -The App connection and its former production/review history do not authorize -current metaserver deployment. DEV now runs through its reviewed GitHub Actions -main workflow. PROD accepts only an explicit owner-approved immutable-tag -promotion dispatch with exact digests and predecessor. Retained Cloudflare -Builds require their reviewed command fence and stopped-Build readback; a -branch pause alone cannot fence manual/retry execution. Preserve the shared -website installation and PR-only main policy. Historical #55/#56 automatic -production instructions are evidence, not current activation authority. - -To revoke metaserver access, first disconnect the repository in Cloudflare and -stop its Builds triggers under the recovery procedure owned by #56. Then merge -a reviewed desired-state removal and, with separate organization-owner -authorization, remove only `atrinik/metaserver-worker` from installation -`152311798`. Preserve `atrinik/website` and selected-repository mode. Re-run the -verifier, confirm the website still builds through Pages, and confirm the -metaserver repository no longer appears in the installation UI. Suspending or -deleting the shared installation is not an acceptable metaserver rollback. - -## Deploy-control repository and GitHub App - -`atrinik/deploy-control` is a public MIT seed repository with stable repository -ID `1352850539`, default branch `main`, and no release-tag or semantic-release -contract. Its desired repository properties are `service`, `replacement`, -`seed`, and `none`. It remains pull-request governed and requires the two -contexts emitted by its current workflows: - -- `Deploy-control validation`, from the Check workflow's `npm run check` job; - and -- `Conventional PR title`, from the Pull Request Policy workflow. - -The repository's Dependabot and CodeQL workflows remain enabled, but they are -not merge gates until a stable aggregate check contract exists. The existing -Actions allowlist, read-only default permissions, merge settings, security -baseline, community-health defaults, and Team-compatible rulesets apply. No -Cloudflare resource, package grant, environment, or deployment is part of this -repository registration. - -The future control-plane integration is recorded in -`config/manual-settings.json` as the planned GitHub App -`atrinik-deploy-control`. The App and installation do not exist yet: both live -numeric IDs are deliberately `null`, while the control-plane repository is -recorded as `atrinik/deploy-control`, ID `1352850539`. After owner provisioning, -the installation must select exactly one repository, `atrinik/classic`, ID -`1327289971`, and subscribe only to `workflow_run` with these exact read-only -permissions: - -- `actions: read`; -- `metadata: read`. - -The App is intended to receive successful Classic workflow-run completion for -the reviewed staging-image handoff. It has no authorization for metaserver, -packages, environments, organization-wide selection, source writes, or any -other repository. Its value-free name-only slots are: - -- secrets: `DEPLOY_CONTROL_AGENT_ENROLLMENT_SECRET`, - `DEPLOY_CONTROL_GITHUB_APP_PRIVATE_KEY`, and - `DEPLOY_CONTROL_GITHUB_WEBHOOK_SECRET`; -- variables: `CLOUDFLARE_ACCOUNT_ID`, - `CLOUDFLARE_DURABLE_OBJECT_BINDING`, `CLOUDFLARE_WORKER_NAME`, - `DEPLOY_CONTROL_GITHUB_APP_ID`, and - `DEPLOY_CONTROL_GITHUB_INSTALLATION_ID`. - -These are future secret and variable names only; no values, private key, -installation token, webhook payload, Cloudflare binding, or account credential -is recorded. Atrinik organization owners own the record and review it every 90 -days. `atrinik/deploy-control#3` owns the control-plane follow-up and the -provisioning runbook. `repository_scope_verification` remains -`pending_provisioning` until an owner creates the App, installs it in selected -mode, and reads back the exact Classic-only selection in the GitHub UI. - -GitHub App creation and installation remain owner-only manual UI operations on -Team. `bin/verify-manual-settings` verifies the stable repository identities and -reports this planned integration as `PENDING`; it does not pretend that an -absent App is live. `bin/publish` remains plan-only for this record and never -creates the App or changes an installation. The existing Cloudflare Workers and -Pages installation and its `atrinik/metaserver-worker` boundary remain -unchanged. - -To revoke the future integration, first stop workflow-run delivery and disable -the control-plane consumer, revoke the App keys and webhook secret, remove only -the named control-plane secret and variable slots, uninstall the App from Classic, -and verify the selected set is empty. Preserve the existing Cloudflare -installation and metaserver access record; do not use this runbook to alter -unrelated Apps or repositories. - -## Cross-repository planning - -Review and apply the planning layers in their dependency order: - -```sh -bin/publish-planning -bin/publish-planning --apply -bin/sync-project -bin/sync-project --apply -bin/publish-community-health -bin/publish-community-health --apply -bin/publish-repository-properties -bin/publish-repository-properties --apply -``` - -`bin/publish-planning` creates or updates organization issue metadata, the -single public Project, its Status options, linked organization fields, and the -six shared views. It reuses the new Project's default `View 1` as **Triage** -and preserves any additional manually created shared views. - -`bin/sync-project` is the Team-compatible alternative to Project auto-add -workflows, which are limited to five repository-specific workflows and do not -backfill existing work. It discovers every non-archived repository, adds all -open issues and pull requests, sets intake status only when missing or when -work is reopened, infers only missing issue types, and moves tracked closed -items to **Done**. The scheduled `Synchronize project` workflow requests runs -twice per hour, but GitHub schedules are best-effort and can be delayed or -dropped. The first apply intentionally performs a large one-time backfill; -later runs are incremental and idempotent. - -GitHub caps each GraphQL search at 1,000 results. The synchronizer reads the -reported count, requires it to remain stable across pages, and reconciles it -with the exact number of unique returned node IDs. It fails before mutation or -a success summary if either search is inconsistent or exceeds that window; it -must be changed to enumerate or partition the inventory before a larger -organization can be safely synchronized. - -`config/planning-health.json` sets a 90-minute maximum freshness age and alerts -after two consecutive failed synchronization runs. The separate -`Project synchronization health` workflow runs on its own schedule, after each -completed synchronization, and on manual dispatch. It uses the ordinary -least-privilege `GITHUB_TOKEN` to read Actions and maintain one deduplicated -health incident, so a missing `ATRINIK_SETTINGS_TOKEN` cannot suppress the -alert. It recognizes only marker-bearing incidents authored by -`github-actions[bot]`, ignores foreign copies of the public marker, and records -a hidden timestamp for each new or reopened outage episode. The administration -PAT is used only for the optional read-only convergence plan. - -Inspect health without changing GitHub: - -```sh -bin/check-project-health -gh run list --repo atrinik/github-settings \ - --workflow check-project-health.yml --limit 5 -``` - -The health summary reports the last run, last successful run and revision, -age, consecutive failures, and pending Project mutations. A managed incident -opens or updates after the threshold is crossed. It closes only after a newer -successful synchronization in the current outage episode and a zero-mutation -plan. Do not remove its hidden marker or episode timestamp, create one incident -per missed window, or use the administration PAT for alert publication. The -monitoring owner is the Atrinik organization-owner role. If organization-wide -GitHub scheduling itself becomes an unacceptable single point of failure, -provision an external dispatcher/monitor under a separately reviewed owner and -lifecycle contract; the repository workflow does not pretend to provide that -external guarantee. - -Retire or replace this monitor only through a reviewed governance change. -Establish and prove the replacement signal first, remove the health workflow's -triggers, then remove its badge, configuration, validator rules, and tests in -the same change. Close any marker-owned incident with a final note pointing to -the replacement; preserve the issue and Actions history rather than deleting -the operational record. - -`bin/publish-community-health` creates the public `atrinik/.github` deployment -repository if needed and converges every file listed in -`config/community-health.json`. Local community-health files in a component -repository continue to take precedence over these defaults. - -### Organization identity and public pins - -Review and deploy organization identity only after the governing pull request -is merged. First inspect both complete plans: - -```sh -bin/publish -bin/publish-community-health -``` - -With separate live-mutation authorization, `bin/publish --apply` converges the -description while preserving the canonical website and the other owned -organization defaults. `bin/publish-community-health --apply` publishes -`community-health/profile/README.md` as `.github/profile/README.md`; never edit -the generated repository directly. - -GitHub does not provide a supported public API for organization pins. An -organization owner must open , choose **View as: -Public**, select **Customize pins** in the Pinned section (or **pin -repositories** when the section is empty), select exactly six repositories, -arrange them in this order, and select **Save pins**: - -1. `classic` -2. `atrinik` -3. `website` -4. `content` -5. `protocol` -6. `playtester` - -After saving, verify the exact live order and stable identities without -mutation: - -```sh -bin/verify-manual-settings -``` - -Do not use browser automation or an undocumented endpoint to apply pins. A -change is complete only after the public organization view renders the profile -README and links correctly and the verifier reports the governed pin order. - -`bin/publish-repository-properties` creates the organization property schema -and assigns the complete desired value set to every repository. It runs after -the generated `.github` repository exists so the inventory and live repository -set agree. - -`bin/audit` is the read-only live drift check. It compares every active -repository with the merge defaults, custom-property inventory, inherited -organization rulesets, and exposed security baseline. It also fails when an -active repository is missing from the desired-state inventory or when a -governed active repository is absent or archived. The `Governance drift audit` -workflow runs it on the default branch and on a schedule; repository creation -must therefore be followed by a desired-state change before the new repository -can pass the audit. - -When creating a repository, register it in `config/repositories.json` and -`config/repository-properties.json` in the same pull request. Add required -status checks only after the repository emits the named workflow jobs. Review -`bin/publish` and `bin/publish-repository-properties` in plan mode, apply them -with the organization settings credential, and finish with `bin/audit`. - -The manual `Publish planning` workflow performs those four apply steps in the -same order. Both planning workflows use `ATRINIK_SETTINGS_TOKEN`; in addition -to the existing organization and repository administration access, that token -must have the classic PAT `project` scope. The current GitHub Actions -`GITHUB_TOKEN` cannot administer an organization Project. - -GitHub exposes shared Project views through GraphQL but does not expose a -public API for a person's issue-dashboard saved views. The desired personal -views are therefore recorded in `personal_saved_views` in -`config/planning.json`. Each user creates them once at - using these queries: - -- **My issues:** `org:atrinik is:open is:issue assignee:@me` -- **Review requests:** `org:atrinik is:open is:pr review-requested:@me` -- **Mentions:** `org:atrinik is:open mentions:@me` -- **Unassigned issues:** `org:atrinik is:open is:issue no:assignee` - -## Adding a repository - -Create the repository's `main` branch before applying policy. Default-branch -integrity, merge settings, and security policy are discovered dynamically and -apply to every non-archived organization repository. The Team -security configuration is also the default for newly created repositories. -GitHub's temporary private security-advisory workspaces are the sole discovery -exception: the publisher recognizes their strict `-ghsa-` -name and disabled collaboration-feature signature and leaves them under -GitHub's advisory lifecycle. A private repository that merely resembles that -name, or whose base repository is not governed, remains in policy scope. -Because integrations and status checks cannot access these workspaces, the -base repository's linear-history, pull-request, and required-CI rules allow -organization-owner bypass in pull-request-only mode. Deletion and -non-fast-forward protections remain non-bypassable. -GitHub does not classify the final advisory-level merge as a pull-request -action. During a specifically authorized Classic advisory merge window, -Classic is split from the shared integrity, linear-history, and pull-request -rules and organization owners receive `always` bypass for those Classic rules -and Classic required CI. GitHub requires every rule reported for the target -branch to be bypassable before enabling the advisory-level merge, including -deletion and non-fast-forward. The window is recorded exhaustively in -`config/advisory-merge-windows.json`, and must be rolled back to an empty -inventory and pull-request-only bypass immediately after the advisory merge. -Add repositories to the appropriate arrays in `config/repositories.json` when -they also need a pull-request gate, required CI, immutable release tags, or -archival. - -Immutable releases require a stricter release contract than an immutable tag -alone. Stage repository additions in `config/immutable-releases.json` as pending -activation, then apply only after reviewed workflow qualification proves draft -creation/recovery, complete verified assets, and publication as the final step. -Every registry upload must verify that the actual complete source release is -immutable; a desired inventory entry alone is not publication evidence. Record both the repository name and -the ID reported by GitHub. Validation requires every selected repository to be -active, pull-request governed, and protected by the release-tag ruleset; the -publisher fails closed if a live repository ID differs from the inventory. - -Do not add a repository to `config/codeql-advanced-setup.json` merely because -default setup needs tuning. The inventory is reserved for a reviewed advanced -CodeQL workflow that needs repository-specific build, component, or path -coverage. Its `required_partitions` records semantic scope/language minima, -while the current producer owns display names and upload categories. Readiness -reads literal partition declarations without executing repository Python and -requires a distinct successful job and matching upload for every declaration, -including additions. Changing action versions needs no coverage-inventory edit. -Remove the matching minima when removing an advanced repository; an empty -inventory with an empty minima object is valid. Both security configurations -must remain identical except for their -name, description, and `code_scanning_options.allow_advanced` value. - -Moving a repository to `archive` is an executable policy change: the next -`bin/publish --apply` makes it read-only. Before applying an archival change, -confirm that remaining pull requests and branches have been preserved at their -new location. For `atrinik/classic`, also complete any intentional tag rebuild -before applying immutable release-tag policy. - -## Enabling a merge queue - -`merge_queue` in `config/repositories.json` is the exhaustive list of -repositories that merge through GitHub's merge queue. GitHub accepts the -`merge_queue` rule only in repository rulesets, so both policy scopes install a -repository-owned `08 - Merge queue` ruleset on each listed repository's default -branch, as they do for `06 - CodeQL security`. The rule comes from -`config/rulesets/merge-queue.json`: - -- squash merges, the organization's only merge method; -- `ALLGREEN` grouping, so every queued pull request's own merge result must - pass the required checks, not only the head of its group; -- a build concurrency of 5 and groups of 1 to 5 pull requests, with no wait: - a single queued pull request merges as soon as its checks pass, and pull - requests queued together share a group; -- a 60-minute timeout for required checks to report on a merge group. - -Organization owners keep the usual pull-request-only bypass. During an -advisory merge window, the queue rule gets `always` bypass like that -repository's required CI. - -A queued repository's `03 - Required CI` rule sets -`strict_required_status_checks_policy` to `false`. The queue already tests each -pull request merged onto the latest base, so the branch itself no longer has -to be current. When applying, the publisher re-reads the queue just before it -publishes required CI and relaxes the rule only if that read shows the exact -repository-owned queue. Otherwise it prints a `SKIP` and keeps required CI -strict. Every other repository keeps the strict policy. Validation requires -each listed repository to be in `required_ci`. It also keeps the template's -parameters within GitHub's API ranges and the allowed merge method, and allows -a wait only with a minimum group size above one. -GitHub Team offers merge queue only for public repositories, so the publisher -fails before any write if a listed active repository is private. Like the -security gates, it skips a listed repository that is not active; that -repository's required CI stays strict because no queue was installed. - -Before adding a repository: - -1. Merge a change in that repository so every required check also runs on the - `merge_group` event and reports under its existing name. A required check - that never reports on a merge group stalls the queue until the timeout. - Dependency review stays advisory, has no merge-group trigger, and must never - be a required gate on a queued repository; validation enforces that. -2. Add the repository to `merge_queue`, merge the reviewed change, and review - the `bin/publish` plan. It should create `08 - Merge queue` on that - repository. The publisher re-PUTs every managed ruleset on each run, and - that repository's `03 - Required CI` payload should be the only one whose - content changes. Then apply the plan with the usual explicit - authorization. - -The publisher installs the queue before it relaxes required CI. When a -repository is removed from the inventory, it restores the strict policy first -and only then deletes the managed queue. It deletes only an unmodified, -repository-owned `08 - Merge queue` rule, and checks the repository's identity -and re-reads the rule immediately before the deletion. A modified, foreign or -concurrently edited rule with that name is retained with a `SKIP`, and `bin/audit` reports it until someone -reviews it. The audit also requires each listed repository's exact queue rule, -repository ownership, and non-strict required CI. - -## Protecting and retiring a maintenance branch - -Add a unique repository/branch entry to `maintenance_branches` in -`config/repositories.json`. Branch names are repository-relative, so `1.x` -becomes the exact ruleset ref `refs/heads/1.x`. Every entry receives deletion, -non-fast-forward, linear-history, and pull-request rules. Its `required_ci` -array may contain only stable checks already declared for that repository and -emitted by workflows on the maintenance branch. - -Retired maintenance lines move out of that active array and into -`config/retired-maintenance-branches.json`. The immutable record binds the -stable repository and ruleset IDs, exact final branch commit, final rollback -tag/commit and asset names, and every default-branch/tag ruleset that must stay -active. The targeted publisher refuses missing, ambiguous, or drifted live -state and emits only the exact maintenance-ruleset deletion: - -```sh -bin/validate -bin/publish --retire-maintenance content/1.x -``` - -For the completed content cutover, the final rollback anchor is -`v1.8.19@566bd25f78b80b08d5f75f4b02017ab2429204db`; the preserved retirement -branch tip is `080a9ea41741e4e67adc7b09b3ccb51475d93d3a`. The source archive, -Classic runtime archive, and `SHA256SUMS` must remain accessible and checksum -clean. `content@main` is the sole authored and released source, and the Classic -updater remains justified only for proposing locks to verified main-built -Classic artifacts. - -After the desired-state pull request merges, an organization owner may -explicitly authorize this one policy mutation: - -```sh -bin/publish --apply --retire-maintenance content/1.x -``` - -The targeted apply verifies that only ruleset `20571870` is absent and that -the recorded main and immutable-tag protections remain active. It does not -delete the branch. Before deleting `refs/heads/1.x`, repeat the live repository, -ruleset, open-PR, consumer, tag, release, asset, checksum, and reachability -preflight and obtain a second explicit organization-owner authorization for -that exact Git-reference deletion. After deletion, verify the branch is absent -and every preserved tag/release asset and commit remains reachable. Recreating -`1.x` is a new organization-owner recovery decision, not automatic rollback. - -On GitHub Team the publisher creates one organization ruleset per maintenance -branch. The repository-policy fallback creates the equivalent repository -ruleset. Both paths remove stale managed maintenance rulesets, and migration -creates the destination protection before deleting the previous scope. - -Validate semantic configuration and both publisher scopes when adding or -changing active maintenance protection. For a recorded retirement, additionally -review the targeted plan above before any live authorization: - -```sh -bin/validate -for test in tests/*.sh; do "$test"; done -bin/publish -``` - -## Transitioning a repository to advanced CodeQL - -The inventory currently contains only `classic`. GitHub's -[security configuration API](https://docs.github.com/en/rest/code-security/configurations) -represents its exception as **default setup enabled with advanced setup -allowed**. The publisher attaches that configuration only to the inventory, -then uses the -[repository default-setup API](https://docs.github.com/en/rest/code-scanning/code-scanning#update-a-code-scanning-default-setup-configuration) -to set it explicitly to `not-configured`. All other active repositories are -attached to the enforced ordinary baseline and explicitly set to `configured`. - -Use this order for the first Classic transition so default and advanced scans -do not compete and a failed handoff cannot become a silent permanent gap: - -1. Open the Classic advanced-workflow pull request and let its non-CodeQL - validation complete. Keep the pull request open; do not merge it while - repository-wide default setup still controls CodeQL uploads. -2. Merge this governance policy and, while that Classic pull request is ready, - review `bin/publish` in plan mode and run the explicitly authorized - `bin/publish --apply`. The plan must attach Classic to the advanced-allowed - configuration before setting its default setup to `not-configured`, while - attaching every other active repository to the ordinary baseline and - setting it to `configured`. -3. Immediately rerun the Classic pull request's advanced CodeQL workflow. - Confirm every intended component/path partition completes and GitHub accepts - each CodeQL upload. The short interval after default setup is disabled is an - observed transition window, not a state that may be left unattended. -4. Merge the Classic workflow only after its advanced analysis is green, then - confirm a successful advanced analysis on `main` and that no repository-wide - default CodeQL workflow is scheduled. -5. Only after the Classic workflow is merged and its `CodeQL validation` - aggregate exists on `main`, merge and apply the governance change that adds - that context to Classic's required CI. For the initial release-pipeline - rollout, activate this gate after Classic pull request #20 and before the - separate phase-two change that enables automatic releases. - -If the advanced workflow cannot upload and pass promptly, do not leave Classic -without scheduled analysis. Remove Classic from the inventory in a reviewed -governance change (or revert the exception), run and review the publisher, and -confirm a successful default-setup analysis before rescheduling the migration. -Never delete the advanced workflow first and assume a later policy run will -repair coverage. - -## Metaserver immutable releases and production environment - -The desired selected inventory adds only `atrinik/metaserver-worker`, stable -repository ID `1324297032`, while preserving Classic, content-toolkit and -protocol. This is pending activation until the reviewed metaserver producer -creates a draft, finishes and verifies every release asset, and only then -publishes that draft. Before any broad publisher mutation introducing this -selection, the read-only preflight checks the exact authenticated current-main -draft-first plugin order, both finalizer files, successful main-push `Check` -workflow and unchanged main. Retain that qualified SHA and re-read it after -all library/environment preflights and immediately before the first immutable -policy write; movement stops without mutation. This source check complements independent producer -qualification; marker text alone is not proof of asset assembly. Merge and -qualify that source first. This governance -source neither publishes a release nor promotes a Worker. - -GitHub supports a narrow selected-repository operation, -`PUT /orgs/atrinik/settings/immutable-releases/repositories/1324297032`, when -the organization mode is `selected`. Its -[documented API](https://docs.github.com/en/rest/orgs/orgs#enable-a-selected-repository-for-immutable-releases-in-an-organization) -adds one repository without replacing the existing set. Before any separately -authorized apply, inspect the read-only publisher plan, verify exact repository -and actor identity, and snapshot the complete current selected set and repository -state privately. Do not apply the publisher's unrelated drift. Re-read the -complete selected set and `GET /repos/atrinik/metaserver-worker/immutable-releases` -after the narrow write, requiring `enabled=true` and `enforced_by_owner=true` -with every prior selection preserved. A failed write/readback stops release -publication; reconcile the actual state before any separately reviewed rollback. - -The supported repository-only alternative is -`PUT /repos/atrinik/metaserver-worker/immutable-releases`, which requires -repository administration write, but it does not satisfy this owner-enforced -organization inventory by itself. The UI alternatives are the Releases section -of [repository settings](https://github.com/atrinik/metaserver-worker/settings) -and the selected repository set under -[organization repository settings](https://github.com/organizations/atrinik/settings/repositories). -Follow [GitHub's instructions](https://docs.github.com/en/code-security/how-tos/secure-your-supply-chain/establish-provenance-and-integrity/prevent-release-changes). - -The optional metaserver-only `activation_variable` names -`ATRINIK_RELEASE_IMMUTABILITY_ACTIVE` in repository scope. Publishers never set -it. The producer leaves a verified complete draft while this variable is absent -or disabled; it may publish only after the reviewed draft-first producer is -merged, its exact source passes `Check`, current main remains qualified, and -fresh target immutability readback proves enablement. Recheck source and target -at the point of use before separately authorized activation and publication. -The plain `enabled` value is a release gate, never a substitute for actual -target API proof. The ordinary workflow token cannot read administrative -immutability settings, so retain the authorized owner readback privately and -verify the published release's own `immutable=true` response. Do not publish a -mutable draft and try to repair immutability afterward. - -Immutability applies only to future releases. Existing mutable releases, -including `v4.34.0`, remain historical and cannot satisfy promotion's immutable -release proof. Never delete/recreate one, move its tag, or weaken the promotion -check. Produce a new reviewed stable release after enablement and retain its -exact immutable tag/SHA, successful main validation, completed assets and -provenance for the promotion review. - -The names-only `production` environment inventory declares the reviewed -production-promotion contract: protected branches enabled, -custom policies disabled, no custom patterns and no required reviewers. Solo -owner dispatch of the exact reviewed inputs remains the approval boundary. -The eight secret names and two variable names are desired state, not proof that -the environment or effective credentials exist. The recovery public-key input -remains pending the owning workflow merge; provision it only after that reviewed -consumer is merged. Provision through supported -GitHub environment operations only after source review and separately granted -setup authority. `ATRINIK_PRODUCTION_RECOVERY_PUBLIC_KEY` contains only the -owner's public RSA SPKI PEM (at least 3072 bits). It selects the recipient for -standard JWE RSA-OAEP-256 with A256GCM encryption; the protected recovery policy -pins its canonical DER SPKI SHA-256 and 90-day retention. The private key stays -owner-only outside Actions. Only ciphertext recovery artifacts enter Actions; -verify the completed pre-mutation intent artifact download before any secret -PATCH, and retain a separate post-readback receipt. This public recipient name -confers no mutation authority. Keep DEV and PROD configurations and runtime secrets disjoint; -do not copy a DEV deployment token into PROD. Any new administrative credential -also needs a truthful lifecycle inventory before use, with separately verified -scope and rotation metadata. `bin/verify-manual-settings` verifies names and -identity without reading values; it derives an empty custom-policy list in -protected-branch mode. Publishers never create this environment or dispatch -promotion. Stop until the owner approves the exact future tag and operation. - -## Metaserver production credentials - -Production lifecycle records bind `atrinik/metaserver-worker`, stable repository -ID `1324297032`, environment `production`, consumer -`.github/workflows/promote-production.yml` and this runbook. The schema permits -these exact bindings alongside the existing DEV records; it does not assert -that a production credential has been created, verified or installed. -Environment names distinguish lifecycle entries for otherwise identical secret -names. Duplicate names within one environment remain invalid. - -Use a dedicated account-owned production deployment token with only -`Workers Scripts Edit` and `D1 Read` for the exact reviewed account. These -account-wide permissions can edit either cohort; the reviewed workflow and -resource fences enforce the deployment target. Do not copy the DEV deployment -token. Qualified read-only control-plane credentials may serve both environments -only with separately reviewed production placement and lifecycle evidence; -they are distinct from Worker runtime secrets, which remain disjoint. - -Capture requires only the token through a hidden local prompt. Record dates from -actual qualification and an internal rotation deadline within 90 days, capped -by any observed provider expiry. Missing creation or expiry metadata does not -block capture; never invent it. Preserve any observed date or timestamp precision. -Token verification may prove active status and expose expiry; it does not prove -effective permissions. Retain available permission and account evidence privately -and run bounded read-only Worker and D1 metadata checks. State any unverified -permission or expiry explicitly. Write permission remains unproven until the -owning workflow succeeds. GitHub secret-name metadata proves -placement only. Keep token values, provider token identifiers and private -qualification evidence out of this inventory, commits and logs. - -The dedicated production token was verified on 2026-10-12 as active and distinct -from DEV, with bounded reads of all three PROD Worker settings and the exact D1 -database identity. Required `Workers Scripts Edit` and `D1 Read` permissions -remain the intended deployment contract; provider permission metadata and -write capability are unproven. Provider creation and expiry remain unknown. -Its 2027-01-10 rotation deadline is internal 90-day policy, not provider expiry. -The two owner-authorized shared read-only control-plane credentials retain their -2026-10-11 qualification and 2027-01-09 internal deadlines; expiry remains unknown. -Their separate production lifecycle entries declare desired placement, not -installation or successful use by the production workflow. Provision and verify -only after this inventory is reviewed and accepted. - -## Enabling immutable source releases - -The desired organization-level `selected` inventory preserves Classic -(`1327289971`) and adds protocol (`1327106950`) and content-toolkit -(`1327107043`). Renderer (`1327106998`) was part of the same addition until it -left the organization on 2026-10-17 (see -[Transferred repositories](#transferred-repositories)); the desired inventory -no longer selects it. These additions are pending activation until -reviewed source workflows are merged and qualified. Their release producers -must assemble and verify the complete crate/archive/manifest payload on a draft -before publishing it. A published immutable release must be complete because -its tag and assets can no longer be replaced. Before any registry upload, the crate publication helper verifies the actual -source release has `immutable=true`. Ordinary `GITHUB_TOKEN` cannot read the -administrative immutable-settings endpoint, so source workflows do not add an -unsupported pre-tag query or administrative credentials. This inventory is -activated only after reviewed draft-first source qualification. - -Initial qualification establishes producer code and setup; it does not require -an already published immutable release. The independently accepted producer -candidates and merged main revisions had identical complete Git trees: - -| Repository | Reviewed candidate | Merged main | -| --- | --- | --- | -| protocol | `5f843a69ec52233a5ff66bebe7d04a025ff7295c` | `f9e72b9ebc4f8516f3a1e1f6383ab4484c3c1444` | -| renderer | `9a7e1afcc378cd14d28e56468f6a7cdd16de630c` | `ef70471c87579f3cef0027bf8e126fbaae515f6f` | -| content-toolkit | `c04755ba3936c30171a85ec7ce003413eb75d174` | `0caed7763c1c8d2d83bb3f2636a33d94f3962a71` | - -Local draft-first complete-asset validation, independent source review, and -exact-candidate CI establish this initial code qualification. These historical -revisions do not lock future source or action updates. Workflow parsing alone -does not prove draft assembly; real signing, immutable release assets, and -registry uploads remain runtime proof obligations. - -Before any broad `bin/publish --apply` mutation, its preflight computes producer -IDs newly entering the live immutable selection. Each new producer requires an -observed source/environment inventory record and a fresh scoped -`bin/verify-manual-settings --crate-publication-setup atrinik/REPOSITORY` check. -Pending or missing records, workflow/environment drift, or concurrent immutable -policy changes stop apply before mutation. Existing selected producers and an -already enforced `all` policy need no initial-addition qualification. This guard -does not authorize broad apply for the narrow rollout below. - -For protocol, separately verify that the actual immutable pinned -semantic-release GitHub plugin supports the configured draft-first publication -and the complete asset payload. A configured flag alone is not release proof. -Qualification includes build, packaging, draft assembly, retry/recovery, -actual immutable-release upload gating, and publication paths. - -The rollout order below is the record of the activation that added protocol, -renderer and content-toolkit, and it stays as written. Its three-producer -payload and four-repository checks describe the selection at that time, before -renderer left the organization. Derive the payload for any later change, -including the pending metaserver addition, a rollback or an intentional removal, -from the current `config/immutable-releases.json`, and never select or query -`atrinik/renderer`. - -Use this narrow rollout order for this release activation: - -1. Qualify each reviewed draft-first producer candidate and retain its exact - revision and validation evidence. Before merging, inspect the three - Semantic Release workflows, verify no in-flight run, record their original - enabled states, and temporarily disable only those three workflows. This - reversible window prevents a first mutable automatic source release while - immutable policy awaits activation; preserve Classic and all other workflows. -2. Merge the accepted producer and governance source. Run `bin/publish` in - read-only plan mode and inspect every mutation. The broad plan can include - unrelated drift, so **do not run `bin/publish --apply` for this activation**. - Provision crate environments only after their owning workflows are merged. -3. The authorized coordinator verifies the live organization and repository - identities and snapshots `GET /orgs/atrinik/settings/immutable-releases` - plus the complete paginated - `GET /orgs/atrinik/settings/immutable-releases/repositories` selection. - Normalize the snapshot exactly as `current_immutable_release_payload` in - `bin/publish`: mode `all`/`none`, or mode `selected` with the complete sorted - unique selected IDs. Retain the snapshot privately for verified rollback. -4. Derive the targeted payload from the merged desired inventory, adding only - the three producer IDs and retaining the complete accepted prior selection. - For this inventory it is `enforced_repositories: selected` and - `selected_repository_ids: [1327106950,1327106998,1327107043,1327289971]`. - Require all four current names/IDs to match and preserve Classic. Re-read the - complete live policy immediately before writing; it must still equal the - snapshot. Unexpected mode, unknown selection, identity or concurrent drift - stops activation until the accepted desired state is reconciled. -5. Issue only `PUT /orgs/atrinik/settings/immutable-releases` with that reviewed - payload through the supported API and the coordinator's existing authority. - Do not apply repository settings, rulesets, other Actions policy or other - organization changes from the broad plan. Re-read the organization mode and - complete selection, require exact equality with the attempted payload, then - require every selected repository's immutable-release readback to report - `enabled=true,enforced_by_owner=true`. -6. Restore only the three workflows to their recorded enabled states. Dispatch - exact merged main as authorized and verify a complete immutable source - release, its protected-main provenance, and registry readiness before any - upload or downstream migration. - -Readback uses the same supported endpoints as the publisher: - -```sh -gh api -H 'X-GitHub-Api-Version: 2026-03-10' \ - orgs/atrinik/settings/immutable-releases -gh api --paginate -H 'X-GitHub-Api-Version: 2026-03-10' \ - 'orgs/atrinik/settings/immutable-releases/repositories?per_page=100' \ - --jq '.repositories[] | [.name, .id]' -for repository in classic protocol content-toolkit; do - gh api -H 'X-GitHub-Api-Version: 2026-03-10' \ - "repos/atrinik/${repository}/immutable-releases" -done -``` - -If the targeted write or verification fails, keep the producer workflows -suspended and read the policy again. Restore the exact pre-change snapshot only -when the live state still matches the attempted payload in the coordinator's -owned window; verify the complete restored mode and selection before restoring -workflow states. Ambiguous readback or concurrent foreign drift is a stop -condition, not permission to overwrite it. Retain bounded sanitized evidence -and resolve the conflict before retrying. A later intentional policy removal -requires reviewed desired source and the same narrow snapshot/readback/rollback -procedure. Preserve published releases, tags, assets and durable upload intents. - -## Provisioning the Classic Discord release environment - -The `discord-release` environment is manual desired state for -`atrinik/classic` (repository ID `1327289971`). It permits deployments only -from the selected `main` branch for checked recovery and immutable `v*` tags -for normal releases, has no required reviewers or environment variables, and -contains one value-free secret-name contract: -`DISCORD_APPLICATION_ID`. The Application ID is public package configuration, -but its value remains outside Git so release packaging can be enabled only -through the reviewed environment boundary. `bin/publish` reports this manual -state but does not create, update, or delete it. - -Provision it only after the consuming Classic workflow has been merged and -reviewed. From an organization-owner account with repository administration -access, first verify the stable repository identity and default branch: - -```sh -gh api repos/atrinik/classic \ - --jq '{id, full_name, archived, default_branch}' -``` - -Require exactly `id: 1327289971`, `full_name: atrinik/classic`, -`archived: false`, and `default_branch: main`. Before any mutation, check -whether the environment already exists: - -```sh -gh api --include -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release -``` - -Proceed with the creation commands below only when GitHub returns an explicit -`404 Not Found`. Any authentication, authorization, transport, or other error -is a stop condition. If GitHub returns environment metadata, do not run the -`PUT`, `POST`, or `gh secret set` commands: inspect the complete live state -with the read-only verification commands below and reconcile any difference -through a separately reviewed change. The secret command is an upsert, so an -existing same-name secret must not be replaced without separately authorized -rotation. - -For a confirmed absent environment, create it with no reviewers, no wait timer, -and an exact custom-branch policy, then provide the initial secret: - -```sh -printf '%s\n' '{ - "wait_timer": 0, - "prevent_self_review": false, - "reviewers": [], - "deployment_branch_policy": { - "protected_branches": false, - "custom_branch_policies": true - } -}' | gh api --method PUT \ - -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release \ - --input - && -printf '%s\n' '{"name":"main","type":"branch"}' | \ - gh api --method POST \ - -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release/deployment-branch-policies \ - --input - && -printf '%s\n' '{"name":"v*","type":"tag"}' | \ - gh api --method POST \ - -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release/deployment-branch-policies \ - --input - && -gh secret set DISCORD_APPLICATION_ID \ - --env discord-release --repo atrinik/classic -``` - -Enter the Application ID only at the final prompt; never place it in a shell -argument, environment variable, file in this repository, log, fixture, or pull -request. If either policy creation reports that its exact policy already -exists, stop and verify the complete live state instead of adding a duplicate. - -Verify the exact environment contract without reading the secret value: - -```sh -gh api -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release \ - --jq '{name, deployment_branch_policy, protection_rule_types: [.protection_rules[].type]}' -gh api --paginate -H 'X-GitHub-Api-Version: 2026-03-10' \ - 'repos/atrinik/classic/environments/discord-release/deployment-branch-policies?per_page=100' \ - --jq '[.branch_policies[] | {name, type}]' -gh api -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release/secrets \ - --jq '{total_count, names: [.secrets[].name]}' -gh api -H 'X-GitHub-Api-Version: 2026-03-10' \ - repos/atrinik/classic/environments/discord-release/variables \ - --jq '{total_count, names: [.variables[].name]}' -bin/verify-manual-settings -``` - -Require the environment name to be `discord-release`; the deployment policy -to have custom branch policies enabled and protected-branch mode disabled; -`protection_rule_types` to equal `["branch_policy"]`; the deployment -branch-policy list to equal -`[{"name":"main","type":"branch"},{"name":"v*","type":"tag"}]` (in -either API order); the secret result to equal -`{"total_count":1,"names":["DISCORD_APPLICATION_ID"]}`; and the variable -result to equal `{"total_count":0,"names":[]}`. Finally, run the Classic -release rehearsal and confirm its Discord configuration job is skipped and no -production Application ID appears in rehearsal artifacts. Then run an -explicitly authorized production package workflow for a reviewed release tag -and require its environment-bound configuration job and Windows package -verification to succeed. If any identity, policy, reviewer, name, or count -differs, stop: do not delete or overwrite unknown live settings. Reconcile the -reviewed desired-state contract first, then repeat the complete verification. - -## Activating the Classic performance Pages site - -`atrinik/classic` (repository ID `1327289971`) owns the provider-managed -`https://atrinik.github.io/classic/` site and the `github-pages` deployment -environment. The environment permits only the exact `main` branch and has no -required reviewers, secrets, or variables. The desired Pages build type is -`workflow`; the consuming workflow is -`.github/workflows/daily-client-performance.yml`, bound by the immutable -`actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e` marker. - -The live legacy `main`-root source is a bounded pre-activation state only while -that marker is absent from the default-branch workflow. -`bin/verify-manual-settings` reports it as `PENDING`. Once the reviewed Classic -workflow is merged, the same verifier requires the Actions source and fails on -any lingering legacy source. It never changes the source itself. - -Before activation, verify the repository, current Pages site, environment, and -the merged workflow without changing live state: - -```sh -gh api repos/atrinik/classic --jq '{id,full_name,archived,default_branch}' -gh api repos/atrinik/classic/pages \ - --jq '{html_url,build_type,source,public,https_enforced,cname}' -gh api repos/atrinik/classic/environments/github-pages \ - --jq '{name,deployment_branch_policy,protection_rule_types:[.protection_rules[].type]}' -gh api --paginate \ - 'repos/atrinik/classic/environments/github-pages/deployment-branch-policies?per_page=100' \ - --jq '[.branch_policies[] | {name,type}]' -gh api repos/atrinik/classic/environments/github-pages/secrets \ - --jq '{total_count,names:[.secrets[].name]}' -gh api repos/atrinik/classic/environments/github-pages/variables \ - --jq '{total_count,names:[.variables[].name]}' -gh api 'repos/atrinik/classic/contents/.github/workflows/daily-client-performance.yml?ref=main' \ - --jq -r .content | base64 --decode | \ - grep -F 'actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e' -``` - -Require the stable repository identity and `main` default branch, exact site -URL, public HTTPS with no custom hostname, the exact custom `main` environment -branch policy, no other protection rule, and empty secret/variable lists. Stop -on any difference. Only after the workflow marker is present on `main`, an -organization owner with repository administration access may switch the exact -site to the Actions source: - -```sh -printf '%s\n' '{"build_type":"workflow"}' | gh api --method PUT \ - repos/atrinik/classic/pages --input - -``` - -Immediately run `bin/verify-manual-settings` and require `KEEP atrinik/classic -Pages uses the reviewed Actions workflow source`. Then dispatch `Daily Classic -client performance` from `main` with checkpoint source `final-benchmark-data`, -verify the attempt-qualified evidence/checkpoint artifacts and successful -`github-pages` deployment, and confirm `https://atrinik.github.io/classic/`, -`trend.json`, `v1/state.json`, and `v1/manifest.json`. Subsequent manual and -scheduled runs must use the default `pages` checkpoint. If activation or the -bootstrap run fails, leave or restore the last known-good Pages deployment, -preserve the final `benchmark-data` commit, and do not delete the historical -branch. - -## Retiring a manually inventoried Actions environment - -Removing an entry from `github_actions_environments` records the desired -absence but does not delete the live environment or revoke credentials held by -an external provider. Complete every retirement in this order: - -1. Merge the reviewed desired-state removal only after the consuming workflow - has been removed from its default branch. -2. Record the repository's other environment names, delete only the exact - retired environment through **Settings → Environments**, confirm its API - lookup returns `404`, and confirm the other environments are unchanged. -3. Remove any exact external DNS, domain, or deployment resource owned solely - by that environment, preserving unrelated production resources. -4. Revoke the dedicated external-provider token separately and clear retained - local copies. Deleting a GitHub environment removes its stored secret but - does not revoke the underlying credential. - -`bin/publish --apply` does not provision or delete these manual environments. -Record the exact environment and external-token names in the retirement pull -request handoff without recording their values. - -## Public reusable build images - -`ghcr.io/atrinik/classic-build` (package ID `14345002`) and -`ghcr.io/atrinik/windows-build` (package ID `14204802`) are public reusable -toolchain images linked to `atrinik/devcontainer`. Their public visibility lets -fork-controlled pull-request workflows consume immutable digests without a -package permission, registry login, repository secret, or cross-repository -**Manage Actions access** grant. Accordingly, -`github_packages_actions_access` contains no entry for either package. - -Changing a GitHub Container Registry package from private to public is an -effectively irreversible organization-owner action. Before the change, merge a -reviewed desired-state removal, verify both stable package identities and the -`atrinik/devcontainer` source association, and confirm that every intended -consumer change removes package permissions and registry login. Never change -permission inheritance, detach the source repository, or alter a foreign -Actions-access entry. - -Verify the live contract read-only: - -```sh -gh api /orgs/atrinik/packages/container/classic-build \ - --jq '{id, name, package_type, visibility, source: .repository.full_name}' -gh api /orgs/atrinik/packages/container/windows-build \ - --jq '{id, name, package_type, visibility, source: .repository.full_name}' -gh api /repos/atrinik/classic \ - --jq '{id, full_name, visibility, archived, default_branch}' -``` - -Require the exact package IDs above, type `container`, visibility `public`, and -source `atrinik/devcontainer`. Require Classic repository ID `1327289971`, -visibility `public`, `archived: false`, and default branch `main`. An API -failure, missing field, identity mismatch, private package, detached source, or -unexpected state is a stop condition. - -Then use a new empty Docker configuration to prove anonymous access to every -consumer-pinned digest: - -```sh -anonymous_docker_config=$(mktemp -d) -DOCKER_CONFIG="${anonymous_docker_config}" \ - docker buildx imagetools inspect \ - 'ghcr.io/atrinik/classic-build:1.2.3@sha256:d0ec0a31f97fa1d699f62b81bbe697d95b335f44f1c99fde8704dfc528e2102f' -DOCKER_CONFIG="${anonymous_docker_config}" \ - docker buildx imagetools inspect \ - 'ghcr.io/atrinik/windows-build:1.2.1@sha256:d1f082eb28891600a9cf018a1d4310b9f3e1f985f82139fa48fbd4ac77b623bb' -``` - -Both inspections must succeed without `docker login`. The package settings UI -must not list an obsolete `atrinik/classic` Actions-access grant; remove only -that exact entry if it remains after the visibility transition. Finally, run a -real fork pull request and require its digest pulls and complete required -checks to succeed without package permissions or registry authentication. - -## Private Linux updater build image - -`ghcr.io/atrinik/linux-build` is a private container package, ID `14205615`, -linked to `atrinik/devcontainer` (repository ID `1322185908`). Preserve that -visibility and source association. The owner verified the pinned manifest with -authenticated registry access; the client owning workflow authenticated but -could not resolve that manifest. An owner's successful pull cannot prove a -repository workflow's package access. - -`github_packages_actions_access` records read-only Actions-access setup for -`atrinik/client` (`1327106844`) only. The owner confirmed its **Manage Actions -access** read grant on 2026-10-11; its `grant_state` is -`owner-observed-read-grant`, with dated sanitized owner evidence. The same -2026-10-11 owner observation also covered a read grant for `atrinik/editor` -(`1327106902`); that entry is historical, because the editor left the -organization on 2026-10-17 (see -[Transferred repositories](#transferred-repositories)) and is no longer in the -inventory. -Client's exact-main post-grant run -[38164640476](https://github.com/atrinik/client/actions/runs/38164640476) -subsequently proved a repository-token pull of the pinned image and complete -read-only preparation/application validation. It correctly produced no migration -PR before registry readiness; App-writing jobs were skipped, so no effective -App writer was proved. The grant observation comes from owner UI, not API -enumeration of the grant list. Retain permission inheritance, private -visibility, linked source and every foreign entry. Do not broaden to -organization/all repositories or change a foreign grant. The publisher never -writes these manual grants. - -The read-only verifier checks consumer/source identities, exact package ID, -private visibility and linked source. GitHub package metadata does not expose -proof of the manual grant or effective registry access. Future unprovisioned -intent uses `pending-owner-ui-read-grant` with null `observed_on` and -`evidence_location`; observation requires sanitized owner UI readback and dated -evidence. Separately prove each exact merged owning workflow pulls the pinned -manifest and completes its ordinary required validation. Registry login success -and secret-name presence alone are insufficient. Host registry credentials must -be removed before credential-free Cargo/build preparation; the updater App -remains isolated to its PR-writing job. No package grant supplies a -registry-publication token or proves the dependency App key effective. - -Rollback stops the client's owning updater workflow first and removes only the -client's read grant through supported owner UI after reviewed inventory removal. -Preserve the package, published versions, source, visibility, foreign grants, -and unrelated App credentials. - -## Automatic crate Trusted Publishing - -`config/manual-settings.json` records the desired, value-free contracts below. -The remaining source contracts are `observed-reviewed-workflow`, and their -environments are `observed`: supported live readback qualified both workflow -files at the same protected-main revision, exact repository identities, and -main-only environments with no reviewers, wait, administrator bypass, secrets, -or variables. The narrow immutable-policy activation window is complete; -reviewed source workflows produced the signed immutable releases used for the -initial library publications. -Protocol registration was owner-observed on 2026-10-11 and its manual 0.2 upload -succeeded in [run 38156755961](https://github.com/atrinik/protocol/actions/runs/38156755961). -The fourteen initial renderer/toolkit libraries have been bootstrapped and their -exact Trusted Publisher registrations are owner-observed: the seven -content-toolkit libraries in the table below, and the seven renderer libraries -that were registered for `atrinik/renderer` before it left the organization -(see [Renderer Trusted Publisher revocation](#renderer-trusted-publisher-revocation)). -Their automatic jobs passed OIDC authentication and reconciliation of the -existing published coordinates; -[the onboarding evidence below](#initial-library-onboarding-evidence) records -that scope. A source inventory update records these observations; it does not -perform external registration or publication. - -| Repository | Stable repository ID | Published libraries | -| --- | --- | --- | -| `atrinik/protocol` | `1327106950` | `atrinik-protocol` | -| `atrinik/content-toolkit` | `1327107043` | `atrinik-artifact`, `atrinik-catalog`, `atrinik-diagnostics`, `atrinik-schema`, `atrinik-source`, `atrinik-testkit`, `atrinik-transaction` | - -Every Trusted Publisher binds the exact repository, `publish-crate.yml`, and -`crates-io-release` environment. Publication runs on protected `refs/heads/main` -through `workflow_dispatch`; the owning hourly reconciliation path dispatches eligible reviewed releases after -credential-free preparation. The release approval is the reviewed source and -version merge. Once onboarding is complete, eligible releases publish without -another release confirmation or environment approval. Hourly schedules are -best-effort; manual reconciliation dispatch remains available. - -The desired environment has exactly one selected branch policy, branch `main`, -no required reviewers, zero wait, administrator bypass disabled, and no secret -or variable slots. The actual `main` branch must be protected: a custom branch -pattern alone does not prove that protection. The existing protocol -`crates-io-bootstrap` environment and published 0.1 crate are historical state; -this contract does not modify them. Protocol 0.2 retains its current approved -manual publication path and exact release proof. The generic automatic path -applies to later eligible reviewed versions. - -The reviewed selected-actions allowance is -`rust-lang/crates-io-auth-action@*`, so ordinary Dependabot pin updates do not -require a redundant central version change. Actual executable workflows must -use a full immutable SHA for the official action. The initial observed action -reference is `rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18` -(upstream `v1.0.5`); that inventory observation is not a permanent version lock. -The -[pinned official action](https://github.com/rust-lang/crates-io-auth-action/blob/c6f97d42243bad5fab37ca0427f495c86d5b1a18/README.md) -exchanges GitHub OIDC for a temporary crates.io token and revokes it in its -post step. Within `publish-crate.yml`, only the guarded automatic and retained historical -protocol 0.2 upload jobs request -`id-token: write`; crate preparation -and reconciliation have no OIDC permission. The source workflow has a separate -inert manifest-signing job with only contents read, OIDC write and attestation -write; its build and semantic-release jobs have no OIDC. The automatic publisher -requests only contents write for durable upload intent, actions/checks/attestations -read and OIDC write. Only the inert upload helper receives the temporary registry -token and the step-scoped Git-reference intent token; it runs no Cargo, npm or builds. Preserve the other action allowances and GitHub-owned -Actions access. Registry credentials never belong in GitHub secrets, inventory, -workflow inputs, logs, or committed credential files. - -The [GitHub environment controls](https://docs.github.com/en/actions/reference/workflows-and-actions/deployments-and-environments) -and [crates.io Trusted Publishing documentation](https://crates.io/docs/trusted-publishing) -are the supported provisioning references. Activation proceeds in this order: - -1. Qualify and merge governance and owning workflow source using the narrow - reversible immutable-release activation window above. Run the complete - `bin/publish` read-only plan and inspect every planned mutation; activate only - the authorized exact policy through scoped API/UI operations. Preserve - unrelated live policy and never broad-apply this release delivery. -2. Verify live repository ID/name, active status, default branch, exact main - ref, protected main, and both merged publication/source-signing workflows. Record - `source_state: observed-reviewed-workflow` only after that observation. -3. The fourteen initial renderer and toolkit names (the toolkit libraries in - the table above and the seven renderer libraries listed under - [Renderer Trusted Publisher revocation](#renderer-trusted-publisher-revocation)) - require a first owner-local publication because Trusted Publishing cannot - create their initial crate records. Prepare, review, and verify the exact - release archives, package dependency order, versions, digests, native - prerequisites, and registry readiness first. The owner uses a narrowly - scoped local API token only for that initial bootstrap, then revokes it. - Exclude the renderer CLI - `atrinik-render` and toolkit applications `atrinik-content` and - `atrinik-content-mcp`. Protocol already exists and needs no bootstrap. - No bootstrap token is sent to GitHub or stored in this inventory. -4. Provision each `crates-io-release` environment with the exact branch, - reviewer, wait, bypass, and empty-secret/variable contract. Verify the live - settings, then record `environment_state: observed` in reviewed source. -5. Use the supported crates.io owner UI to register each listed crate against - its exact repository, workflow filename, and environment. Capture sanitized - owner evidence, registration date, and the exact selected identities. - Record `publisher_registration.state: owner-observed-registration`, - `observed_on`, and `evidence_location` only after observation. All future - publication uses OIDC; local API-token publication is not a fallback. -6. Run credential-free readiness and the approved publication paths. Verify - registry version/checksum visibility and release evidence before downstream - migration. Later eligible releases reconcile automatically after merge. - -### Initial library onboarding evidence - -On 2026-10-12 (UTC), the owner confirmed Trusted Publisher registration for all -fourteen renderer/toolkit names, with their respective exact repository, -`publish-crate.yml` and `crates-io-release` environment: the seven -`atrinik/content-toolkit` libraries in the table above, and the seven -`atrinik/renderer` (`1327106998`) libraries `atrinik-render-api`, -`atrinik-render-resources`, `atrinik-render-sdl3`, `atrinik-render-testkit`, -`atrinik-render-ui`, `atrinik-render-wgpu` and `atrinik-scene`. The table no -longer lists the renderer because it left the organization on 2026-10-17. -Registration is external owner evidence; the GitHub metadata API does not -enumerate it. - -The initial renderer libraries are bound to the signed immutable -[v1.8.0 source release](https://github.com/atrinik/renderer/releases/tag/v1.8.0) -at `de7fe1c3f178937c1fb1e655587a169eff9468cd`; toolkit libraries are bound to -[v2.11.0](https://github.com/atrinik/content-toolkit/releases/tag/v2.11.0) at -`e5889d2fe3afcd1ee7b3db45e8924792753136cf`. All fourteen initial 0.1.0 registry -versions were verified against the signed source archives, public version API, -sparse-index checksums and canonical CDN bytes, with owner `zoeyrose` (ID -`437663`) and their permanent upload intents. Later source releases with empty -crate manifests do not replace these initial archive bindings. The inventory's -`bootstrap_crates` lists remain the exact one-time first-publication scope, -not a request to bootstrap those existing coordinates again. - -[Renderer run 38192681802](https://github.com/atrinik/renderer/actions/runs/38192681802) -and [toolkit run 38192866448](https://github.com/atrinik/content-toolkit/actions/runs/38192866448) -succeeded through the guarded automatic jobs: the official action exchanged -OIDC for the temporary registry credential, the helper skipped already published -coordinates and confirmation passed. Subsequent registry/owner/intent checks -matched the prior evidence. These runs prove authentication and reconciliation -of all seven known coordinates per repository. They made no new-coordinate -registry PUT; the first future eligible upload still depends on its reviewed -source/version, actual immutable release, runtime provenance and fresh intent. -Revoke the one-use bootstrap credential after confirmation and use OIDC only -for future publication. - -`bin/publish` reports this manual setup but never performs it. -`bin/verify-manual-settings` always checks actual repository identity, exact -main ref, and protected main. Pending source/environment/registration states -remain explicit. Observed source parses both `publish-crate.yml` and `release.yml` on the same -exact main revision through -`lib/verify_crate_workflow.py`. Install the declared -`requirements-validation.txt` dependency before local observed-source checks; -the policy and publication workflows install it before verification. The -parser rejects duplicate YAML keys, comment-only/plain text, disabled automatic -jobs, missing OIDC, mutable action refs, extra OIDC jobs, widened guards, -inexact checkout/input bindings, shell/workspace overrides, ignored critical -failures, matrix/reusable execution, credential references outside the exact -upload input, and skipped verification/auth/upload steps. Recursive expression -checks include job outputs, names, concurrency, checkout inputs, and nested -step fields, including indexed, case-varied, or aggregate step references. -It verifies executable dispatch, repository/ID/protected-main conditions, -credential-free dependency, environment, scoped permissions, an unconditional -full-SHA official auth action, and only the returned temporary upload token. -Source qualification also verifies a separate inert signer, successful package -and signer dependencies, exact prepared revision/same-run payload, and the -full-SHA official `actions/attest-build-provenance` action over -`build/release/crate-release.json`. Existing `github_owned_allowed: true` covers -that official action and its internal `actions/attest` dependency; actual refs -stay immutable and ordinary Dependabot updates need no central SHA lock. -Safe schedule reconciliation may coexist; its jobs receive no OIDC. Observed -environments require the exact selected main branch, no reviewer or wait -protection rule, disabled administrator bypass, and empty secret/variable name -metadata. Any identity/protection drift fails closed. The verifier reports -crates.io registration as owner-observed evidence: GitHub metadata cannot prove -external registration, token scope, successful upload, or future readiness. -Runtime qualification belongs to the producer helper. It cryptographically -verifies the actual manifest attestation against the exact repository ID, -protected main source/signer revision, source workflow and run attempt; matching -asset digests alone cannot authenticate uploaded release metadata. It also -requires the actual source release to be immutable before registry upload. -Before each new crate PUT, the inert upload helper atomically creates only the -global `refs/tags/crate-upload-intent//` coordinate through the -Git-reference API. Only a successful create response plus exact readback permits -that upload. An existing or ambiguous reservation with an absent registry version -blocks retries, including a retry from another source release; registry absence -alone cannot authorize another PUT. Do not automatically delete/reset these -intents. Reconcile an interrupted upload with owner-observed registry evidence -and the documented producer recovery procedure before any separately reviewed -recovery action. Structural workflow verification does not duplicate runtime -certificate or reservation logic or prove that those live operations succeeded. - -Change each pending state only through reviewed source with its corresponding -observation. External registration can be observed before a later automatic -source/environment transition; it does not activate that transition. A status -edit alone cannot prove publication readiness. - -Rollback begins by stopping new reconciliation/publication through reviewed -source and revoking the exact crates.io publisher through its supported owner -UI. Review removal of only matching environments/action allowance when no -remaining registered contract needs them. Preserve published crate versions, -release assets, tags, unrelated environments, and unrelated Actions access. -Removing unactivated inventory intent is also a valid reviewed rollback. - -### Renderer Trusted Publisher revocation - -The seven renderer libraries `atrinik-render-api`, `atrinik-render-resources`, -`atrinik-render-sdl3`, `atrinik-render-testkit`, `atrinik-render-ui`, -`atrinik-render-wgpu` and `atrinik-scene` are still registered on crates.io with -a Trusted Publisher for `atrinik/renderer`, `publish-crate.yml` and -`crates-io-release`, owner-observed on 2026-10-12. `atrinik/renderer` -(`1327106998`) became `seraphinastudios/tilewright-renderer` on 2026-10-17 (see -[Transferred repositories](#transferred-repositories)), so no contract in this -repository covers those registrations any more. The former name can be reused: -creating a new `atrinik/renderer` in the organization ends GitHub's redirect to -the transferred repository. A new repository with that name, a matching -`publish-crate.yml` workflow and a `crates-io-release` environment would then -match the registrations and could publish new versions of those crates. - -On 2026-10-18 the owner decided to revoke the `atrinik/renderer` Trusted -Publisher from all seven crates through the crates.io owner UI, the first step -of the rollback above. **The revocation is an owner action pending -confirmation.** It has not been observed yet, so treat all seven registrations -as live until it is. After the owner confirms it, record the dated, sanitized -owner observation for each crate here through reviewed source. Revoking a -Trusted Publisher does not yank or delete any published version. - -## Protocol crate Trusted Publishing - -The automatic contract above replaces the former planned per-release -maintainer-review policy. Protocol 0.2 keeps its approved manual release path; -future reviewed source/version merges use the automatic path after observed -onboarding. Protocol registration is owner-observed with the successful manual 0.2 run; -its automatic source/environment setup is observed. Renderer/toolkit initial -publication and owner registration are complete, with the known-coordinate OIDC -proofs above. The renderer's seven registrations now await the owner's -revocation (see -[Renderer Trusted Publisher revocation](#renderer-trusted-publisher-revocation)). -The dependency App's workflow activation is pending: its only -remaining consumer, the client, has not yet run its PR-writing job. - -## Crate dependency update App - -`crate_dependency_update_app` records owner-observed App setup on 2026-10-11. -Its `workflow_activation` is `pending-reviewed-workflows`: the client's reviewed -updater workflow has merged, but no client-owned PR has been observed yet. -Client [run 38192029425](https://github.com/atrinik/client/actions/runs/38192029425) -completed preparation as a no-op and skipped the isolated PR-writing job, so it -does not prove that the writer works. Record `observed-successful-owned-pr` only -after a client run creates its own PR that passes ordinary checks and review. - -Before the editor left the organization, its run 38193476856 created the App's -first owned PR (editor PR 36) on 2026-10-12. The App bot authored the verified -signed commit, all ordinary checks passed, independent review accepted it, and -the maintainer merged it through the ordinary process. That observation belongs -to the transferred repository and does not count as client activation. -The live App is `atrinik-crate-dependency-update`, App ID `5276152`, installation -ID `170332148`. Its expected **selected repositories** set is exactly -`atrinik/client` (ID `1327106844`). App-authenticated supported API readback on -2026-10-11 confirmed the selected set at that time, `atrinik/client` and -`atrinik/editor` (ID `1327106902`), exact contents write/pull requests -write/metadata read permissions, no subscribed events, and the external homepage -`https://www.atrinik.org`. The editor left the organization on 2026-10-17 (see -[Transferred repositories](#transferred-repositories)), which changed the -installation's repository set after that readback. The client-only set is -therefore recorded as pending re-verification: `repository_scope_reverification` -has state `pending-reverification`, reason `repository-transfer-after-readback`, -the 2026-10-11 readback date, the 2026-10-17 change date and the removed editor -identity. No readback of the client-only set has been recorded yet. - -To re-verify, the owner confirms in the installation's organization-owner UI, -or through supported App-authenticated readback, that the selected set is -exactly `atrinik/client`. Reviewed source then records that method in -`repository_scope_verification`, the readback date in `observed_on`, and sets -`repository_scope_reverification` to `null`. Validation pins the record to the -editor transfer. While `observed_on` is on or before 2026-10-17, the pending -record must name exactly that readback, the 2026-10-17 change and -`atrinik/editor` (`1327106902`). It can be cleared only together with a -readback dated after the transfer, and must be cleared once one is recorded. -Preserve every other App and installation, -including the existing Classic updater and provider Apps. The desired disabled -webhook is a separate owner UI setting; `events: []` proves no subscriptions and -does not independently prove the webhook switch is disabled. - -The owner expressly authorized provisioning before the consumer workflows -merge. Each selected repository now has secret name -`CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY` and variable name -`CRATE_DEPENDENCY_UPDATE_APP_ID`; the observed App ID is `5276152`. Name metadata -was verified after creation on 2026-10-11. Never display or copy private-key/token -values or local credential paths into inventory, logs, or public evidence. The -secret value is not readable through GitHub's metadata API, and name presence -cannot prove that a key is valid or effective. These observations do not grant -workflow activation, bypass, self-approval, or self-merge authority. - -The value-free key lifecycle records creation and verification on 2026-10-11, -the consumer path of the client's `released-dependencies.yml` workflow, and -rotation owner `Atrinik organization owners`. Its 90-day internal rotation -deadline is 2027-01-09; this is not an upstream key expiry. Validation rejects -missing, future, overdue, or over-cadence lifecycle dates. Rotate by issuing a -replacement App key, verifying the App identity with it, securely updating only -the client's existing repository secret slot, and proving the client's -PR-writing workflow. Revoke the old key after successful replacement proof; -retain name-only evidence and update creation/verification/deadline metadata -through reviewed source. If replacement proof fails, stop the client's writing -workflow and preserve the old working key until the owner restores service or -explicitly revokes it. - -The editor's transfer also carried a copy of the current key. On 2026-10-17 -`atrinik/editor` became `seraphinastudios/tilewright-editor` (same ID -`1327106902`). GitHub keeps repository secrets and variables with a transferred -repository, so the editor's `CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY` secret and -`CRATE_DEPENDENCY_UPDATE_APP_ID` variable moved with it. Only the Atrinik owner -controls that repository and its organization, and the copy was deleted within -hours: a names-only readback on 2026-10-18 listed no Actions secrets or -variables in the transferred repository. **On 2026-10-18 the owner explicitly -accepted that exposure window instead of rotating the key early.** -`accepted_key_exposures` records the acceptance: the exposure type, the exposed -names, the former and current repository identity, the exposure start, the -removal readback and the acceptance date. The key keeps its ordinary 2027-01-09 -rotate-by deadline; the acceptance does not extend it. Validation pins the -record to the editor transfer (former and current name, ID, the 2026-10-17 -start and both exposed names), and requires an observed removal with the -acceptance on or after it. The record must stay while the current key was -created on or before the transfer. Once a rotation records a newer -`key_created_on`, the list must be empty, so remove the record in that same -reviewed change. - -The read-only verifier checks live installation identity, exact permissions, -empty events, active state, selected repository identities, and credential -**names**. An administrative-token API cannot enumerate the complete selected -repository set; retain current supported App-authenticated readback or owner UI -proof. While `repository_scope_reverification` is pending, the verifier reports -`PENDING` with the recorded change instead of the ordinary `MANUAL` reminder. -It reports `credential_state: observed-name-metadata` separately from -workflow activation. The client's reviewed `released-dependencies.yml` workflow -has merged. The dated editor run/PR above is historical evidence of effective -App use by the transferred repository's writer and does not prove the client's -writer. A no-op run or setup/name metadata alone cannot -prove a successful PR-writing job. Keep new or replacement credential acceptance -bound to the actual owning workflow and its required checks. - -The client's updater runs hourly (`17 * * * *`) and through -`workflow_dispatch`. Its credential-free preparation verifies exact released -versions and registry checksums, resolves dependencies, updates Cargo locks, and -runs aggregate validation before requesting an App token in the isolated -PR-writing job. It maintains only its owned -`automation/released-crate-dependencies` branch and pull request; ordinary -required checks and the pull-request process still govern merging, with zero -required human approvals. -Missing registry readiness produces no migration PR. It never uploads crates, -approves a pull request, merges it, or loosens branch protection. Prove initial -App permissions with a disposable/owned PR and current ordinary checks, without -exposing credentials. On retirement, stop the client's workflow and revoke the -App/key and only the client's named secret and variable slots; preserve -unrelated installations and secrets. - -## Transferred repositories - -On 2026-10-17 two repositories left the organization by GitHub transfer: - -| Former repository | Stable repository ID | New location | -| --- | --- | --- | -| `atrinik/editor` | `1327106902` | `seraphinastudios/tilewright-editor` | -| `atrinik/renderer` | `1327106998` | `seraphinastudios/tilewright-renderer` | - -They are no longer governed here: they are removed from the repository, -required-CI, release-tag, immutable-release, custom-property, CodeQL, Codecov, -Trusted Publishing, package-access and crate dependency App inventories. The -organization rulesets that named them stop matching anything; an authorized -`bin/publish --apply` removes the obsolete `03 - Required CI` rulesets. Atrinik -consumes both projects as external MIT dependencies. Historical evidence in the -sections above that names them is preserved. Where that evidence pointed at a -table row that left with the renderer, it now names the renderer crates -directly. - -Three owner decisions from 2026-10-18 follow up on the transfer: - -- The editor's retained copy of the crate dependency App key is an accepted - exposure, and the key keeps its 2027-01-09 rotate-by deadline (see - [Crate dependency update App](#crate-dependency-update-app)). -- The App's client-only selected set is pending re-verification, because the - transfer changed it after the 2026-10-11 readback (same section). -- The owner is revoking the renderer's crates.io Trusted Publishers; that - revocation is pending confirmation (see - [Renderer Trusted Publisher revocation](#renderer-trusted-publisher-revocation)). +See [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`AGENTS.md`](AGENTS.md). diff --git a/bin/audit b/bin/audit deleted file mode 100755 index 78bf624..0000000 --- a/bin/audit +++ /dev/null @@ -1,730 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 - -for command in gh grep jq sort; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -repositories_config=${root}/config/repositories.json -repository_defaults=${root}/config/repository-defaults.json -repository_properties=${root}/config/repository-properties.json -advisory_windows=${root}/config/advisory-merge-windows.json -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -"${root}/bin/validate" >/dev/null - -github_api() { - gh api --method GET -H "X-GitHub-Api-Version: ${api_version}" "$@" -} - -declare -a findings=() -declare -a pending=() -declare -A ruleset_cache=() - -record_finding() { - findings+=("$1") -} - -is_temporary_security_advisory_repository() { - local repository=$1 - local private=$2 - local visibility=$3 - local disabled=$4 - local fork=$5 - local has_issues=$6 - local has_projects=$7 - local has_wiki=$8 - local base_repository - - if [[ ${repository} =~ ^(.+)-ghsa-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$ ]]; then - base_repository=${BASH_REMATCH[1]} - else - return 1 - fi - - [[ ${private} == true ]] && - [[ ${visibility} == private ]] && - [[ ${disabled} == false ]] && - [[ ${fork} == false ]] && - [[ ${has_issues} == false ]] && - [[ ${has_projects} == false ]] && - [[ ${has_wiki} == false ]] && - jq -e --arg repository "${base_repository}" \ - '(.pull_request_gate | index($repository)) != null' \ - "${repositories_config}" >/dev/null -} - -# Capture before parsing: process substitutions otherwise hide API failures. -if ! github_api --paginate --slurp "orgs/${organization}/repos?per_page=100&type=all" | - jq -e 'add | if type == "array" then . else error("invalid inventory") end' \ - >"${temporary}/inventory.json"; then - echo "error: organization repository inventory could not be read" >&2 - exit 1 -fi - -declare -A live_archived=() -while IFS=$'\t' read -r \ - repository archived private visibility disabled fork has_issues has_projects has_wiki; do - [[ -n ${repository} ]] || continue - if is_temporary_security_advisory_repository \ - "${repository}" "${private}" "${visibility}" "${disabled}" "${fork}" \ - "${has_issues}" "${has_projects}" "${has_wiki}"; then - continue - fi - live_archived["${repository}"]=${archived} -done < <(jq -r ' - .[] | [.name, (.archived | tostring), (.private | tostring), .visibility, - (.disabled | tostring), (.fork | tostring), (.has_issues | tostring), - (.has_projects | tostring), (.has_wiki | tostring)] | @tsv -' "${temporary}/inventory.json") - -declare -A expected_active=() -declare -A expected_archived=() -while IFS=$'\t' read -r repository lifecycle; do - if [[ ${lifecycle} == archived ]]; then - expected_archived["${repository}"]=true - else - expected_active["${repository}"]=true - fi -done < <( - jq -r '.repositories | to_entries[] | [.key, .value.lifecycle] | @tsv' \ - "${repository_properties}" -) - -desired_property_schema=$(jq -c ' - .definitions | - map({property_name, value_type, required, default_value, description, allowed_values}) | - sort_by(.property_name) -' "${repository_properties}") -if current_property_schema=$(github_api \ - "orgs/${organization}/properties/schema" | \ - jq -c 'map({property_name, value_type, required, default_value, description, allowed_values}) | sort_by(.property_name)'); then - if [[ ${current_property_schema} != "${desired_property_schema}" ]]; then - record_finding "organization custom-property schema drift: ${organization}" - fi -else - record_finding "organization custom-property schema could not be read: ${organization}" -fi - -for repository in "${!live_archived[@]}"; do - if [[ ${live_archived["${repository}"]} == false ]] && - [[ ! -v expected_active["${repository}"] ]]; then - record_finding "active repository is not in the desired-state inventory: ${organization}/${repository}" - fi -done - -for repository in "${!expected_active[@]}"; do - if [[ ! -v live_archived["${repository}"] ]]; then - record_finding "governed active repository is missing: ${organization}/${repository}" - elif [[ ${live_archived["${repository}"]} != false ]]; then - record_finding "governed active repository is archived: ${organization}/${repository}" - fi -done - -for repository in "${!expected_archived[@]}"; do - if [[ -v live_archived["${repository}"] ]] && - [[ ${live_archived["${repository}"]} != true ]]; then - record_finding "archived inventory repository is not archived: ${organization}/${repository}" - fi -done - -has_configured_repository() { - local property=$1 - local repository=$2 - - jq -e --arg repository "${repository}" \ - "${property} | index(\$repository) != null" "${repositories_config}" \ - >/dev/null -} - -has_required_ci() { - local repository=$1 - jq -e --arg repository "${repository}" \ - '.required_ci | has($repository)' "${repositories_config}" >/dev/null -} - -has_merge_queue() { - local repository=$1 - jq -e --arg repository "${repository}" \ - '.merge_queue | index($repository) != null' "${repositories_config}" \ - >/dev/null -} - -has_release_tags() { - local repository=$1 - jq -e --arg repository "${repository}" \ - '.release_tags | index($repository) != null' "${repositories_config}" \ - >/dev/null -} - -audit_actions() { - local current - for policy in permissions selected-actions workflow; do - local endpoint="orgs/${organization}/actions/permissions" - local config="${root}/config/actions-permissions.json" - case ${policy} in - selected-actions) endpoint+=/selected-actions; config="${root}/config/actions-selected.json" ;; - workflow) endpoint+=/workflow; config="${root}/config/actions-workflow.json" ;; - esac - if ! current=$(github_api "${endpoint}"); then - record_finding "organization Actions ${policy} could not be read: ${organization}" - continue - fi - if ! jq -e --slurpfile desired "${config}" ' - . as $current | $desired[0] | to_entries | all(.[]; - if .key == "sha_pinning_required" then true - elif .key == "patterns_allowed" then - (.value | sort) == ($current.patterns_allowed | sort) - else $current[.key] == .value end) - ' <<<"${current}" >/dev/null; then - record_finding "organization Actions ${policy} drift: ${organization}" - fi - if [[ ${policy} == permissions ]] && - jq -e '.sha_pinning_required == true' "${config}" >/dev/null; then - case $(jq -r '.sha_pinning_required | if type == "boolean" then tostring else "unreadable" end' <<<"${current}") in - true) ;; - false) - case $(jq -r '.phase' "${root}/config/actions-sha-pinning.json") in - pending) pending+=("Actions SHA pinning deferred pending canary proof: ${organization}") ;; - enforced) record_finding "Actions SHA pinning enforcement drift: ${organization}" ;; - *) record_finding "Actions SHA pinning rollout phase could not be read: ${organization}" ;; - esac - ;; - *) record_finding "Actions SHA pinning state could not be read: ${organization}" ;; - esac - fi - done -} - -audit_actions - -# The branch endpoint proves effective applicability; inherited names alone do not. -# Details additionally prove bypass and ref/repository scope, including tag policy. -# Match the entire publisher-owned repository scope. Being included in a wider -# scope does not prove convergence: a widened tag rule can constrain services -# with no release contract. Repository-level rulesets have only ref conditions. -organization_ruleset_scope() { - local name=$1 repository=$2 - jq -cn --arg name "${name}" --arg repository "${repository}" \ - --slurpfile repositories "${repositories_config}" \ - --slurpfile windows "${advisory_windows}" ' - {include: [], exclude: [], protected: false} | - if $name == "01 - Default branch integrity" or - $name == "01 - Default branch linear history" then - .include = ["~ALL"] | .exclude = $windows[0].repositories - elif $name == "01 - Default branch integrity - classic" or - $name == "01 - Default branch linear history - classic" or - $name == "02 - Changes through pull requests - classic" then - .include = ["classic"] - elif $name == "02 - Changes through pull requests" then - .include = ($repositories[0].pull_request_gate - $windows[0].repositories) - elif ($name | startswith("03 - Required CI - ")) then - .include = [$repository] - elif $name == "04 - Immutable release tags" then - .include = $repositories[0].release_tags - else error("unknown managed ruleset scope") end' -} - -ruleset_normalization=$(cat "${root}/lib/ruleset-policy.jq") - -read_effective_rules() { - local repository=$1 branch=$2 encoded - encoded=$(jq -rn --arg branch "${branch}" '$branch | @uri') - github_api --paginate --slurp \ - "repos/${organization}/${repository}/rules/branches/${encoded}?per_page=100" | jq -e ' - if type == "array" and length > 0 and all(.[]; type == "array") then add - else error("invalid effective-rule pages") end | - if type == "array" and all(.[]; type == "object" and - (.type | type == "string" and length > 0)) then . - else error("invalid effective-rule inventory") end' -} - -audit_effective_policy() { - local repository=$1 branch=$2 effective=$3 desired=$4 - # API provenance is diagnostic metadata. Every policy field, including - # unknown future parameters, must match the declared contract. CI and - # Dependency review may contribute separate rules with the same parameters. - if ! jq -e --argjson desired "${desired}" "${ruleset_normalization}"' - def policy_fields: map(del(.ruleset_id, .ruleset_source, .ruleset_source_type)); - def without_checks: - if .type == "required_status_checks" then .parameters.required_status_checks = [] - else . end; - def checks: - [.[] | select(.type == "required_status_checks") | .parameters.required_status_checks[]] | - unique_by(.context, .integration_id) | sort_by(.context, .integration_id); - ($desired | normalize_rules) as $wanted | - (policy_fields | normalize_rules) as $current | - ([$current[].type] | unique) == ([$wanted[].type] | unique) and - all($current[]; . as $rule | - any($wanted[]; without_checks == ($rule | without_checks))) and - ($current | checks) == ($wanted | checks) - ' <<<"${effective}" >/dev/null 2>&1; then - record_finding "effective branch policy drift requires manual review: ${organization}/${repository}/${branch}" - fi -} - -check_ruleset() { - local repository=$1 name=$2 template=$3 list=$4 - local entry id source endpoint detail wanted scope - entry=$(jq -c --arg name "${name}" '[.[] | select(.name == $name)]' <<<"${list}") - if [[ $(jq length <<<"${entry}") != 1 ]]; then - record_finding "missing or duplicate inherited ruleset '${name}': ${organization}/${repository}" - return - fi - id=$(jq -r '.[0].id' <<<"${entry}") - source=$(jq -r '.[0].source_type' <<<"${entry}") - if [[ ${name} == '06 - CodeQL security' || ${name} == '07 - Dependency review' ]] && - [[ ${source} != Repository ]]; then - record_finding "managed security ruleset must be repository-owned '${name}': ${organization}/${repository}" - return - fi - if [[ ${name} == '08 - Merge queue' && ${source} != Repository ]]; then - record_finding "managed merge-queue ruleset must be repository-owned: ${organization}/${repository}" - return - fi - case ${source} in - Organization) endpoint="orgs/${organization}/rulesets/${id}" ;; - Repository) endpoint="repos/${organization}/${repository}/rulesets/${id}" ;; - *) record_finding "ruleset source could not be read '${name}': ${organization}/${repository}"; return ;; - esac - if [[ ${name} == '04 - Immutable release tags' && ${source} == Repository ]] && - ! has_release_tags "${repository}"; then - record_finding "unexpected managed release-tag protection: ${organization}/${repository}" - return - fi - if [[ ! -v ruleset_cache["${endpoint}"] ]]; then - if ! detail=$(github_api "${endpoint}"); then - record_finding "ruleset contents could not be read '${name}': ${organization}/${repository}" - return - fi - ruleset_cache["${endpoint}"]=${detail} - fi - detail=${ruleset_cache["${endpoint}"]} - wanted=$(cat "${template}") - if [[ ${name} == '03 - Required CI - '* ]]; then - wanted=$(jq --argjson checks "${expected_checks}" \ - '.rules[0].parameters.required_status_checks = $checks' <<<"${wanted}") - # Dependency review is governed by its separate rollout ruleset. - wanted=$(jq '.rules[0].parameters.required_status_checks |= map(select(.context != "Dependency review"))' <<<"${wanted}") - wanted=$(jq --argjson strict "${expected_strict}" \ - '.rules[0].parameters.strict_required_status_checks_policy = $strict' <<<"${wanted}") - fi - if jq -e --arg repository "${repository}" '.repositories | index($repository) != null' \ - "${advisory_windows}" >/dev/null && - [[ ${name} == '03 - Required CI - '* || ${name} == '08 - Merge queue' ]]; then - wanted=$(jq '.bypass_actors[].bypass_mode = "always"' <<<"${wanted}") - fi - if [[ ${source} == Organization ]]; then - scope=$(organization_ruleset_scope "${name}" "${repository}") - wanted=$(jq --argjson scope "${scope}" '.conditions.repository_name = $scope' <<<"${wanted}") - fi - if ! jq -e --argjson wanted "${wanted}" "${ruleset_normalization}"' - .enforcement == $wanted.enforcement and .target == $wanted.target and - (.bypass_actors | normalize_bypass) == ($wanted.bypass_actors | normalize_bypass) and - (.conditions | normalize_conditions) == ($wanted.conditions | normalize_conditions) and - (.rules | normalize_rules) == ($wanted.rules | normalize_rules) - ' <<<"${detail}" >/dev/null; then - record_finding "ruleset scope or policy drift '${name}': ${organization}/${repository}" - fi -} - -# Rulesets are the declared protection contract in both publisher scopes. -# Legacy protection layers additional requirements outside the rules endpoint; -# retain it for manual review rather than silently treating rulesets as complete. -audit_legacy_protection() { - local repository=$1 branch=$2 metadata=$3 encoded response status=0 body - encoded=$(jq -rn --arg branch "${branch}" '$branch | @uri') - response=$(github_api --include \ - "repos/${organization}/${repository}/branches/${encoded}/protection" \ - 2>"${temporary}/legacy-protection.err") || status=$? - response=${response//$'\r'/} - body=${response#*$'\n\n'} - if [[ ${status} == 1 && ${response%%$'\n'*} =~ ^HTTP/[0-9.]+\ 404(\ |$) ]] && - jq -se 'length == 1 and (.[0] | type == "object" and - .message == "Branch not protected" and .status == "404")' \ - <<<"${body}" >/dev/null 2>&1; then - return - fi - # Some repositories report disabled REST protection despite retaining legacy - # rules for other branches. Only an exact-ref GraphQL read can prove absence. - if [[ ${status} == 1 && ${response%%$'\n'*} =~ ^HTTP/[0-9.]+\ 404(\ |$) ]] && - jq -se 'length == 1 and (.[0] | type == "object" and - .message == "Branch protection has been disabled on this repository." and - .status == "404")' <<<"${body}" >/dev/null 2>&1; then - audit_disabled_legacy_protection "${repository}" "${branch}" "${metadata}" - return - fi - if [[ ${status} == 0 && ${response%%$'\n'*} =~ ^HTTP/[0-9.]+\ 200(\ |$) ]] && - jq -se 'length == 1 and (.[0] | type == "object")' \ - <<<"${body}" >/dev/null 2>&1; then - record_finding "unexpected legacy branch protection requires manual review: ${organization}/${repository}/${branch}" - else - record_finding "legacy branch protection could not be read: ${organization}/${repository}/${branch}" - fi -} - -audit_disabled_legacy_protection() { - local repository=$1 branch=$2 metadata=$3 repository_id response - # GraphQL variables are literal; gh supplies their values as separate fields. - # shellcheck disable=SC2016 - local query='query LegacyBranchProtection($owner: String!, $name: String!, $qualifiedName: String!) { repository(owner: $owner, name: $name) { databaseId nameWithOwner isArchived ref(qualifiedName: $qualifiedName) { name branchProtectionRule { id } } } }' - # Fence rename/transfer/recreation against both the fresh REST metadata and - # the enumeration used to select this active repository. - if ! repository_id=$(jq -er --arg repository "${repository}" \ - --arg coordinate "${organization}/${repository}" \ - --slurpfile inventory "${temporary}/inventory.json" ' - . as $metadata | - [$inventory[0][] | select(.name == $repository)] as $entries | - if ($entries | length) == 1 and $entries[0].id == .id and - $entries[0].archived == false and .archived == false and - .name == $repository and .full_name == $coordinate and - (.id | type == "number" and . > 0 and floor == .) - then .id else error("repository identity drift") end - ' "${metadata}" 2>/dev/null) || - ! response=$(gh api --method POST -H "X-GitHub-Api-Version: ${api_version}" \ - graphql -f "query=${query}" -f "owner=${organization}" \ - -f "name=${repository}" -f "qualifiedName=refs/heads/${branch}" \ - 2>"${temporary}/legacy-protection.err") || - ! jq -se --argjson repository_id "${repository_id}" \ - --arg coordinate "${organization}/${repository}" --arg branch "${branch}" ' - length == 1 and (.[0] | type == "object" and (has("errors") | not) and - (.data.repository | type == "object" and - .databaseId == $repository_id and .nameWithOwner == $coordinate and - .isArchived == false and - (.ref | type == "object" and .name == $branch and - has("branchProtectionRule") and - (.branchProtectionRule == null or - (.branchProtectionRule | type == "object" and - (.id | type == "string" and length > 0)))))) - ' <<<"${response}" >/dev/null 2>&1; then - record_finding "legacy branch protection could not be read: ${organization}/${repository}/${branch}" - elif ! jq -e '.data.repository.ref.branchProtectionRule == null' \ - <<<"${response}" >/dev/null; then - record_finding "unexpected legacy branch protection requires manual review: ${organization}/${repository}/${branch}" - fi -} - -audit_security() { - local repository=$1 desired="${root}/config/code-security.json" setup="${root}/config/codeql-default-setup.json" - local current languages - if jq -e --arg repository "${repository}" '.repositories | index($repository) != null' \ - "${root}/config/codeql-advanced-setup.json" >/dev/null; then - desired="${root}/config/code-security-advanced.json" - setup="${root}/config/codeql-default-setup-advanced.json" - fi - if current=$(github_api "repos/${organization}/${repository}/code-security-configuration"); then - if ! jq -e --slurpfile desired "${desired}" ' - .status == "enforced" and (.configuration | . as $config | - . + {code_security: (.code_security // - (if .advanced_security == "enabled" or .advanced_security == "code_security" then "enabled" else "disabled" end)), - secret_protection: (.secret_protection // - (if .advanced_security == "enabled" or .advanced_security == "secret_protection" then "enabled" else "disabled" end))} | - . as $normalized | $desired[0] | to_entries | all(.[]; $normalized[.key] == .value)) - ' <<<"${current}" >/dev/null; then - record_finding "security configuration attachment or baseline drift: ${organization}/${repository}" - fi - else - record_finding "security configuration could not be read: ${organization}/${repository}" - fi - if current=$(github_api "repos/${organization}/${repository}/code-scanning/default-setup"); then - languages=$(jq -c --arg repository "${repository}" '.codeql_required_languages[$repository] // []' \ - "${root}/config/security-merge-protection.json") - if ! jq -e --slurpfile desired "${setup}" --argjson languages "${languages}" ' - . as $current | ($desired[0] | to_entries | all(.[]; $current[.key] == .value)) and - (if $desired[0].state == "configured" then - $current.languages | if type == "array" then all(.[]; type == "string") else false end - else true end) and - (($languages - ($current.languages // [])) | length == 0) - ' <<<"${current}" >/dev/null; then - record_finding "CodeQL setup or required language drift: ${organization}/${repository}" - fi - else - record_finding "CodeQL setup could not be read: ${organization}/${repository}" - fi - if ! github_api "repos/${organization}/${repository}/vulnerability-alerts" >/dev/null; then - record_finding "Dependabot alerts disabled or unreadable: ${organization}/${repository}" - fi - if ! current=$(github_api "repos/${organization}/${repository}/private-vulnerability-reporting") || - ! jq -e '.enabled == true' <<<"${current}" >/dev/null; then - record_finding "private vulnerability reporting disabled or unreadable: ${organization}/${repository}" - fi -} - -for repository in "${!expected_active[@]}"; do - [[ -v live_archived["${repository}"] ]] || continue - [[ ${live_archived["${repository}"]} == false ]] || continue - - metadata_file=${temporary}/${repository}.json - if ! github_api "repos/${organization}/${repository}" >"${metadata_file}"; then - record_finding "repository metadata could not be read: ${organization}/${repository}" - continue - fi - - if current=$(github_api "repos/${organization}/${repository}/actions/permissions/workflow"); then - if ! jq -e --slurpfile desired "${root}/config/actions-workflow.json" ' - . as $current | $desired[0] | to_entries | all(.[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - record_finding "repository Actions workflow permissions drift: ${organization}/${repository}" - fi - else - record_finding "repository Actions workflow permissions could not be read: ${organization}/${repository}" - fi - - if ! jq -e --slurpfile desired "${repository_defaults}" ' - .archived == false and - .default_branch == $desired[0].default_branch and - .allow_merge_commit == $desired[0].allow_merge_commit and - .allow_rebase_merge == $desired[0].allow_rebase_merge and - .allow_squash_merge == $desired[0].allow_squash_merge and - .delete_branch_on_merge == $desired[0].delete_branch_on_merge and - .squash_merge_commit_title == $desired[0].squash_merge_commit_title and - .squash_merge_commit_message == $desired[0].squash_merge_commit_message - ' "${metadata_file}" >/dev/null; then - record_finding "repository merge policy drift: ${organization}/${repository}" - fi - - desired_properties=$(jq -c --arg repository "${repository}" ' - .repositories[$repository] | - to_entries | - map({property_name: .key, value: .value}) | - sort_by(.property_name) - ' "${repository_properties}") - if current_properties=$(github_api \ - "repos/${organization}/${repository}/properties/values" | \ - jq -c 'map({property_name, value}) | sort_by(.property_name)'); then - if [[ ${current_properties} != "${desired_properties}" ]]; then - record_finding "repository custom-property drift: ${organization}/${repository}" - fi - else - record_finding "repository custom properties could not be read: ${organization}/${repository}" - fi - - rulesets='[]' - if ! rulesets=$(github_api --paginate --slurp \ - "repos/${organization}/${repository}/rulesets?includes_parents=true&per_page=100" | jq -e ' - if type == "array" and length > 0 and all(.[]; type == "array") then add - else error("invalid ruleset pages") end | - if type == "array" and all(.[]; - type == "object" and (.name | type == "string" and length > 0)) then . - else error("invalid ruleset inventory") end'); then - record_finding "inherited rulesets could not be read: ${organization}/${repository}" - rulesets='[]' - fi - # Retired/non-target security gates must be absent from the listing, even - # when disabled or scoped away from the default branch. Presence is manual - # drift regardless of ownership or payload; this audit never removes a rule. - for security_kind in dependency_review code_scanning; do - case ${security_kind} in - dependency_review) security_name='07 - Dependency review' ;; - code_scanning) security_name='06 - CodeQL security' ;; - esac - if ! jq -e --arg repository "${repository}" --arg kind "${security_kind}" \ - '.[$kind] | index($repository) != null' \ - "${root}/config/security-merge-protection.json" >/dev/null && - jq -e --arg name "${security_name}" 'any(.[]; .name == $name)' \ - <<<"${rulesets}" >/dev/null; then - record_finding "unexpected retained security ruleset '${security_name}' requires manual review: ${organization}/${repository}" - fi - done - # A retained queue still changes how the branch merges. Report it for review; - # the publisher alone retires recognized managed queues. - if ! has_merge_queue "${repository}" && - jq -e 'any(.[]; .name == "08 - Merge queue")' <<<"${rulesets}" >/dev/null; then - record_finding "unexpected retained merge-queue ruleset requires manual review: ${organization}/${repository}" - fi - branch=$(jq -r '.default_branch' "${repository_defaults}") - audit_legacy_protection "${repository}" "${branch}" "${metadata_file}" - while IFS= read -r maintenance; do - maintenance_branch=$(jq -r .branch <<<"${maintenance}") - audit_legacy_protection "${repository}" "${maintenance_branch}" "${metadata_file}" - if ! maintenance_effective=$(read_effective_rules "${repository}" "${maintenance_branch}"); then - record_finding "effective maintenance-branch rules could not be read: ${organization}/${repository}/${maintenance_branch}" - maintenance_effective='[]' - fi - maintenance_desired=$(jq --argjson checks "$(jq -c .required_ci <<<"${maintenance}")" ' - .rules | map(if .type == "required_status_checks" then - if ($checks | length) == 0 then empty - else .parameters.required_status_checks = - ($checks | map({context: ., integration_id: 15368})) end - else . end) - ' "${root}/config/rulesets/maintenance-branch.json") - audit_effective_policy "${repository}" "${maintenance_branch}" "${maintenance_effective}" "${maintenance_desired}" - done < <(jq -c --arg repository "${repository}" ' - .maintenance_branches[] | select(.repository == $repository) - ' "${repositories_config}") - effective='[]' - if ! effective=$(read_effective_rules "${repository}" "${branch}"); then - record_finding "effective default-branch rules could not be read: ${organization}/${repository}" - effective='[]' - fi - expected_checks=$(jq -c --arg repository "${repository}" \ - '(.required_ci[$repository] // []) | map({context: ., integration_id: 15368})' "${repositories_config}") - # The merge queue tests the merged result instead of requiring a current branch. - expected_strict=true - if has_merge_queue "${repository}"; then - expected_strict=false - fi - dependency_required=false - if jq -e --arg repository "${repository}" '.dependency_review | index($repository) != null' \ - "${root}/config/security-merge-protection.json" >/dev/null; then - if jq -e --arg repository "${repository}" \ - '.activation.dependency_review[$repository] == "enforced"' \ - "${root}/config/security-merge-protection.json" >/dev/null || - jq -e 'any(.[]; .type == "required_status_checks" and - any(.parameters.required_status_checks[]; .context == "Dependency review"))' \ - <<<"${effective}" >/dev/null || - jq -e 'any(.[]; .name == "07 - Dependency review")' <<<"${rulesets}" >/dev/null; then - dependency_required=true - elif "${root}/bin/security-readiness" dependency "${organization}/${repository}" \ - >"${temporary}/${repository}.readiness" 2>&1; then - pending+=("Dependency review merge protection awaits reviewed activation intent: ${organization}/${repository}") - else - readiness_status=$? - if ((readiness_status == 1)); then - pending+=("Dependency review merge protection awaits landed successful producer: ${organization}/${repository}") - else - record_finding "Dependency review readiness could not be read: ${organization}/${repository}" - fi - fi - if ${dependency_required}; then - expected_checks=$(jq '. + [{context: "Dependency review", integration_id: 15368}]' <<<"${expected_checks}") - check_ruleset "${repository}" '07 - Dependency review' \ - "${root}/config/rulesets/dependency-review.json" "${rulesets}" "${metadata_file}" - fi - fi - if ! jq -e --argjson checks "${expected_checks}" --argjson strict "${expected_strict}" ' - ([.[] | select(.type == "required_status_checks") | .parameters.required_status_checks[]] | - unique_by(.context, .integration_id) | sort_by(.context, .integration_id)) == - ($checks | sort_by(.context, .integration_id)) and - all(.[] | select(.type == "required_status_checks"); .parameters.strict_required_status_checks_policy == $strict) - ' <<<"${effective}" >/dev/null; then - record_finding "effective required CI contexts or app drift: ${organization}/${repository}" - fi - desired_effective=$(jq --argjson checks "${expected_checks}" --argjson strict "${expected_strict}" ' - if ($checks | length) == 0 then [] - else .rules | map(.parameters.required_status_checks = $checks | - .parameters.strict_required_status_checks_policy = $strict) end - ' "${root}/config/rulesets/required-ci.json") - for policy in default-branch-integrity default-branch-linear-history; do - template="${root}/config/rulesets/${policy}.json" - if jq -e --arg repository "${repository}" '.repositories | index($repository) != null' \ - "${advisory_windows}" >/dev/null; then - template="${root}/config/rulesets/${policy}-classic.json" - fi - check_ruleset "${repository}" "$(jq -r .name "${template}")" "${template}" "${rulesets}" "${metadata_file}" - desired_effective=$(jq --argjson prior "${desired_effective}" '$prior + .rules' "${template}") - if ! jq -e --slurpfile desired "${template}" \ - '. as $effective | all($desired[0].rules[]; . as $rule | any($effective[]; .type == $rule.type))' \ - <<<"${effective}" >/dev/null; then - record_finding "effective default-branch integrity drift: ${organization}/${repository}" - fi - done - if has_configured_repository '.pull_request_gate' "${repository}"; then - template="${root}/config/rulesets/pull-request-gate.json" - if jq -e --arg repository "${repository}" '.repositories | index($repository) != null' \ - "${advisory_windows}" >/dev/null; then template="${root}/config/rulesets/pull-request-gate-classic.json"; fi - check_ruleset "${repository}" "$(jq -r .name "${template}")" "${template}" "${rulesets}" "${metadata_file}" - desired_effective=$(jq --argjson prior "${desired_effective}" '$prior + .rules' "${template}") - if ! jq -e --slurpfile desired "${template}" \ - "${ruleset_normalization}"'([.[] | select(.type == "pull_request") | {type, parameters}] | - normalize_rules) == ($desired[0].rules | normalize_rules)' \ - <<<"${effective}" >/dev/null; then - record_finding "effective pull-request policy drift: ${organization}/${repository}" - fi - elif jq -e 'any(.[]; .type == "pull_request")' <<<"${effective}" >/dev/null; then - record_finding "unexpected effective pull-request gate: ${organization}/${repository}" - fi - if has_required_ci "${repository}"; then - check_ruleset "${repository}" "03 - Required CI - ${repository}" \ - "${root}/config/rulesets/required-ci.json" "${rulesets}" "${metadata_file}" - fi - if has_merge_queue "${repository}"; then - check_ruleset "${repository}" '08 - Merge queue' \ - "${root}/config/rulesets/merge-queue.json" "${rulesets}" "${metadata_file}" - desired_effective=$(jq --argjson prior "${desired_effective}" '$prior + .rules' \ - "${root}/config/rulesets/merge-queue.json") - if ! jq -e --slurpfile desired "${root}/config/rulesets/merge-queue.json" \ - '[.[] | select(.type == "merge_queue") | {type, parameters}] == $desired[0].rules' \ - <<<"${effective}" >/dev/null; then - record_finding "effective merge queue drift: ${organization}/${repository}" - fi - fi - # Parent listings can contain correctly scoped but nonapplicable rulesets. - # Inspect the exact managed name on nonrelease repositories too, so widening - # its complete scope fails while foreign, unmanaged tag rules remain unowned. - if has_release_tags "${repository}" || - jq -e 'any(.[]; .name == "04 - Immutable release tags")' <<<"${rulesets}" >/dev/null; then - check_ruleset "${repository}" '04 - Immutable release tags' \ - "${root}/config/rulesets/immutable-release-tags.json" "${rulesets}" "${metadata_file}" - fi - if jq -e --arg repository "${repository}" '.code_scanning | index($repository) != null' \ - "${root}/config/security-merge-protection.json" >/dev/null; then - codeql_required=false - if jq -e --arg repository "${repository}" \ - '.activation.code_scanning[$repository] == "enforced"' \ - "${root}/config/security-merge-protection.json" >/dev/null || - jq -e 'any(.[]; .type == "code_scanning")' <<<"${effective}" >/dev/null || - jq -e 'any(.[]; .name == "06 - CodeQL security")' <<<"${rulesets}" >/dev/null; then - codeql_required=true - elif "${root}/bin/security-readiness" codeql "${organization}/${repository}" \ - >"${temporary}/${repository}.codeql-readiness" 2>&1; then - pending+=("CodeQL merge protection awaits reviewed activation intent: ${organization}/${repository}") - else - readiness_status=$? - if ((readiness_status == 1)); then - pending+=("CodeQL merge protection awaits successful analysis: ${organization}/${repository}") - else - record_finding "CodeQL readiness could not be read: ${organization}/${repository}" - fi - fi - if ${codeql_required}; then - check_ruleset "${repository}" '06 - CodeQL security' \ - "${root}/config/rulesets/code-scanning.json" "${rulesets}" "${metadata_file}" - desired_effective=$(jq --argjson prior "${desired_effective}" '$prior + .rules' \ - "${root}/config/rulesets/code-scanning.json") - if ! jq -e --slurpfile desired "${root}/config/rulesets/code-scanning.json" \ - '[.[] | select(.type == "code_scanning") | {type, parameters}] == $desired[0].rules' \ - <<<"${effective}" >/dev/null; then - record_finding "effective CodeQL merge protection drift: ${organization}/${repository}" - fi - fi - elif jq -e 'any(.[]; .type == "code_scanning")' <<<"${effective}" >/dev/null; then - record_finding "unexpected effective CodeQL merge protection: ${organization}/${repository}" - fi - audit_effective_policy "${repository}" "${branch}" "${effective}" "${desired_effective}" - audit_security "${repository}" - - if ! jq -e ' - .security_and_analysis.secret_scanning.status == "enabled" and - .security_and_analysis.secret_scanning_push_protection.status == "enabled" and - .security_and_analysis.secret_scanning_validity_checks.status == "enabled" and - .security_and_analysis.dependabot_security_updates.status == "enabled" - ' "${metadata_file}" >/dev/null; then - record_finding "exposed security baseline drift: ${organization}/${repository}" - fi -done - -if ((${#pending[@]})); then - printf 'PENDING %s\n' "${pending[@]}" | sort -u -fi - -if ((${#findings[@]})); then - printf 'DRIFT %s\n' "${findings[@]}" | sort -u - echo "Governance audit failed: ${#findings[@]} finding(s)." >&2 - exit 1 -fi - -if ((${#pending[@]})); then - echo "Governance audit baseline passed with ${#pending[@]} pending rollout(s): ${#expected_active[@]} active repositories checked." -else - echo "Governance audit passed: ${#expected_active[@]} active repositories checked." -fi diff --git a/bin/check-project-health b/bin/check-project-health deleted file mode 100755 index d939e3d..0000000 --- a/bin/check-project-health +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -api_version=2026-03-10 -apply=false - -case ${1:-} in -"") ;; ---apply) apply=true ;; -*) - echo "usage: $0 [--apply]" >&2 - exit 2 - ;; -esac - -for command in date gh jq; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done -if [[ ${GITHUB_ACTIONS:-false} == true && -z ${GH_TOKEN:-} ]]; then - echo "error: the workflow GITHUB_TOKEN is unavailable; Project health cannot be reported" >&2 - exit 1 -fi - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -health_config=${root}/config/planning-health.json -sync_command=${ATRINIK_PROJECT_HEALTH_SYNC_COMMAND:-${root}/bin/sync-project} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -"${root}/bin/validate" >/dev/null -if [[ ! -x ${sync_command} ]]; then - echo "error: Project synchronization plan command is not executable: ${sync_command}" >&2 - exit 1 -fi - -repository=$(jq -r '.repository' "${health_config}") -sync_workflow=$(jq -r '.sync_workflow' "${health_config}") -freshness_threshold=$(jq -r '.freshness_threshold_minutes' "${health_config}") -failure_threshold=$(jq -r '.consecutive_failure_threshold' "${health_config}") -incident_actor=$(jq -r '.incident_actor' "${health_config}") -incident_marker=$(jq -r '.incident_marker' "${health_config}") -incident_title=$(jq -r '.incident_title' "${health_config}") -monitoring_owner=$(jq -r '.monitoring_owner' "${health_config}") -episode_marker_prefix='")) | - ltrimstr($prefix) | rtrimstr(" -->") - ' <<<"${existing_incident}") - if ((${#incident_episodes[@]} > 1)); then - echo "error: managed Project health incident has multiple episode markers" >&2 - exit 1 - fi - if ((${#incident_episodes[@]} == 1)); then - incident_episode_at=${incident_episodes[0]} - if ! incident_episode_epoch=$(jq -ner \ - --arg value "${incident_episode_at}" '$value | fromdateiso8601'); then - echo "error: managed Project health incident has an invalid episode timestamp" >&2 - exit 1 - fi - if ((incident_episode_epoch > now_epoch)); then - echo "error: managed Project health incident episode is newer than the health-check clock" >&2 - exit 1 - fi - fi - fi -fi - -can_resolve=false -if ${incident_open} && [[ ${convergence} == converged ]] && \ - [[ -n ${last_success_epoch} ]] && \ - ((last_success_epoch > incident_episode_epoch)) && ((${#reasons[@]} == 0)); then - can_resolve=true -elif ${incident_open} && ((${#reasons[@]} == 0)); then - reasons+=("The existing health incident remains open until a newer successful run is followed by a converged plan.") -fi - -if ((${#reasons[@]} == 0)); then - health_state=healthy -else - health_state=stale -fi - -summary=${temporary}/summary.md -{ - echo "# Atrinik work synchronization health" - echo - echo "- State: **${health_state}**" - echo "- Checked: ${now}" - echo "- Monitoring owner: ${monitoring_owner}" - echo "- Latest run: [${latest_conclusion}](${latest_url}) at \`${latest_sha}\`" - echo "- Last successful run: [${last_success_at:-none}](${last_success_url}) at \`${last_success_sha}\`" - echo "- Freshness: ${freshness_age} minutes (limit ${freshness_threshold})" - echo "- Consecutive failures: ${consecutive_failures} (limit ${failure_threshold})" - echo "- Convergence: ${convergence}; mutations ${total_mutations}; add ${items_to_add}; open status ${open_status_changes}; closed to Done ${closed_done_changes}; issue types ${issue_types_to_set}" - if ((${#reasons[@]} > 0)); then - echo - echo "## Reasons" - echo - printf -- '- %s\n' "${reasons[@]}" - fi -} >"${summary}" -cat "${summary}" -if [[ -n ${GITHUB_STEP_SUMMARY:-} ]]; then - cat "${summary}" >>"${GITHUB_STEP_SUMMARY}" -fi - -incident_body=$(printf '%s\n%s%s -->\n\n%s\n\n%s\n' \ - "${incident_marker}" "${episode_marker_prefix}" "${incident_episode_at}" \ - "$(cat "${summary}")" \ - "Managed by \`bin/check-project-health\`. Recovery: restore the settings credential if needed, run \`bin/sync-project --apply\` through the governed workflow, then require a newer successful run and a zero-mutation plan. Do not remove the marker or record credential values here.") - -if ${apply}; then - if [[ ${health_state} == stale ]]; then - if [[ ${existing_incident} == null ]]; then - github_api "create Project health incident" \ - --method POST "repos/${repository}/issues" \ - -f title="${incident_title}" -f body="${incident_body}" >/dev/null - echo "ALERT created managed Project health incident" - else - github_api "update Project health incident ${incident_number}" \ - --method PATCH "repos/${repository}/issues/${incident_number}" \ - -f title="${incident_title}" -f body="${incident_body}" \ - -f state=open >/dev/null - echo "ALERT updated managed Project health incident #${incident_number}" - fi - elif ${can_resolve}; then - recovery_body=$(printf '%s\n%s%s -->\n\n%s\n\n%s\n' \ - "${incident_marker}" "${episode_marker_prefix}" \ - "${incident_episode_at}" \ - "$(cat "${summary}")" \ - "Recovered after a newer successful synchronization run and a converged zero-mutation plan. Managed by \`bin/check-project-health\`; do not remove the marker or record credential values here.") - github_api "resolve Project health incident ${incident_number}" \ - --method PATCH "repos/${repository}/issues/${incident_number}" \ - -f body="${recovery_body}" -f state=closed \ - -f state_reason=completed >/dev/null - echo "RECOVERED managed Project health incident #${incident_number}" - else - echo "KEEP Project synchronization health is current" - fi -fi - -[[ ${health_state} == healthy ]] diff --git a/bin/publish b/bin/publish deleted file mode 100755 index f1b5950..0000000 --- a/bin/publish +++ /dev/null @@ -1,2212 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -policy_scope=${ATRINIK_POLICY_SCOPE:-auto} -api_version=2026-03-10 -apply=false -retire_maintenance= -qualified_metaserver_source_sha= -sha_pinning_canary= - -while (($#)); do - case $1 in - --apply) - apply=true - shift - ;; - --sha-pinning-canary) - if (($# < 2)) || [[ -z $2 ]]; then - echo "error: --sha-pinning-canary requires OWNER/REPOSITORY/PR" >&2 - exit 2 - fi - sha_pinning_canary=$2 - shift 2 - ;; - --retire-maintenance) - if (($# < 2)) || [[ -z $2 ]]; then - echo "error: --retire-maintenance requires REPOSITORY/BRANCH" >&2 - exit 2 - fi - retire_maintenance=$2 - shift 2 - ;; - *) - echo "usage: $0 [--apply] [--retire-maintenance REPOSITORY/BRANCH] [--sha-pinning-canary OWNER/REPOSITORY/PR]" >&2 - exit 2 - ;; - esac -done - -case ${policy_scope} in -auto | organization | repository) ;; -*) - echo "error: ATRINIK_POLICY_SCOPE must be auto, organization, or repository" >&2 - exit 2 - ;; -esac - -for command in gh git jq sort python3; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -organization_config=${root}/config/organization.json -repositories_config=${root}/config/repositories.json -advisory_merge_windows_config=${root}/config/advisory-merge-windows.json -codeql_advanced_config=${root}/config/codeql-advanced-setup.json -immutable_releases_config=${root}/config/immutable-releases.json -retired_maintenance_config=${root}/config/retired-maintenance-branches.json -security_merge_config=${root}/config/security-merge-protection.json -if [[ -n ${sha_pinning_canary} && ${sha_pinning_canary} != "${organization}/"* ]]; then - echo "error: SHA canary must belong to ${organization}" >&2 - exit 2 -fi -temporary_files=() -trap 'rm -f "${temporary_files[@]}"' EXIT - -"${root}/bin/validate" >/dev/null - -github_api() { - gh api -H "X-GitHub-Api-Version: ${api_version}" "$@" -} - -# Capture every page before any caller treats a ruleset as present or absent. -# gh 2.46 emits one JSON array per page; --slurp is unavailable on that host. -list_rulesets() { - local endpoint=$1 pages - pages=$(github_api "${endpoint}" --paginate) || { - echo "error: cannot read complete ruleset inventory: ${endpoint}" >&2 - return 1 - } - jq -ecs ' - if length > 0 and all(.[]; - type == "array" and all(.[]; - type == "object" and - (.id | type == "number" and . > 0 and floor == .) and - (.name | type == "string" and length > 0))) then - add | - if (map(.id) | length == (unique | length)) and - (map(.name) | length == (unique | length)) then . - else error("duplicate ruleset identity or name") end - else error("invalid ruleset page") end - ' <<<"${pages}" || { - echo "error: invalid or ambiguous complete ruleset inventory: ${endpoint}" >&2 - return 1 - } -} - -run_api() { - local method=$1 - local endpoint=$2 - local input=${3:-} - - if ${apply}; then - if [[ -n ${input} ]]; then - github_api --method "${method}" "${endpoint}" --input "${input}" >/dev/null - else - github_api --method "${method}" "${endpoint}" >/dev/null - fi - elif [[ -n ${input} ]]; then - echo "PLAN ${method} /${endpoint} <= ${input#"${root}/"}" - else - echo "PLAN ${method} /${endpoint}" - fi -} - -retire_maintenance_branch_ruleset() { - local coordinate=$1 - local retirement repository branch repository_id default_branch - local branch_commit release_tag release_commit ruleset_id ruleset_name - local repository_metadata ruleset branch_ref tag_ref release open_pulls - local rulesets preserved_id preserved_name - - retirement=$(jq -c --arg coordinate "${coordinate}" ' - [ - .retirements[] | - select("\(.repository)/\(.branch)" == $coordinate) - ] | - if length == 1 then .[0] else empty end - ' "${retired_maintenance_config}") - if [[ -z ${retirement} ]]; then - echo "error: retirement coordinate is absent or ambiguous: ${coordinate}" >&2 - exit 1 - fi - - repository=$(jq -r '.repository' <<<"${retirement}") - branch=$(jq -r '.branch' <<<"${retirement}") - repository_id=$(jq -r '.repository_id' <<<"${retirement}") - default_branch=$(jq -r '.default_branch' <<<"${retirement}") - branch_commit=$(jq -r '.final_branch_commit' <<<"${retirement}") - release_tag=$(jq -r '.final_release.tag' <<<"${retirement}") - release_commit=$(jq -r '.final_release.commit' <<<"${retirement}") - ruleset_id=$(jq -r '.ruleset.id' <<<"${retirement}") - ruleset_name=$(jq -r '.ruleset.name' <<<"${retirement}") - - if jq -e --arg repository "${repository}" --arg branch "${branch}" ' - any( - .maintenance_branches[]; - .repository == $repository and .branch == $branch - ) - ' "${repositories_config}" >/dev/null; then - echo "error: retirement target remains in desired maintenance branches" >&2 - exit 1 - fi - - repository_metadata=$(github_api "repos/${organization}/${repository}") - if ! jq -e --argjson id "${repository_id}" \ - --arg default_branch "${default_branch}" ' - .id == $id and - .archived == false and - .default_branch == $default_branch - ' <<<"${repository_metadata}" >/dev/null; then - echo "error: retirement repository identity or default branch drift" >&2 - exit 1 - fi - - branch_ref=$(github_api \ - "repos/${organization}/${repository}/git/ref/heads/${branch}") - if [[ $(jq -r '.object.sha // empty' <<<"${branch_ref}") != \ - "${branch_commit}" ]]; then - echo "error: retirement branch commit drift" >&2 - exit 1 - fi - - tag_ref=$(github_api \ - "repos/${organization}/${repository}/git/ref/tags/${release_tag}") - if [[ $(jq -r '.object.sha // empty' <<<"${tag_ref}") != \ - "${release_commit}" ]]; then - echo "error: final rollback tag commit drift" >&2 - exit 1 - fi - - release=$(github_api \ - "repos/${organization}/${repository}/releases/tags/${release_tag}") - if ! jq -e --arg tag "${release_tag}" --argjson retirement "${retirement}" ' - .tag_name == $tag and - .draft == false and - .prerelease == false and - ([.assets[].name] | sort) == ($retirement.final_release.assets | sort) - ' <<<"${release}" >/dev/null; then - echo "error: final rollback release or asset inventory drift" >&2 - exit 1 - fi - - open_pulls=$(github_api \ - "repos/${organization}/${repository}/pulls?state=open&base=${branch}&per_page=100") - if [[ $(jq 'length' <<<"${open_pulls}") != 0 ]]; then - echo "error: open pull requests still target the retirement branch" >&2 - exit 1 - fi - - rulesets=$(list_rulesets "orgs/${organization}/rulesets") || return 1 - while IFS=$'\t' read -r preserved_id preserved_name; do - if ! jq -e --argjson id "${preserved_id}" --arg name "${preserved_name}" ' - any(.[]; .id == $id and .name == $name and .enforcement == "active") - ' <<<"${rulesets}" >/dev/null; then - echo "error: preserved ruleset identity or enforcement drift: ${preserved_id}" >&2 - exit 1 - fi - done < <(jq -r '.preserved_rulesets[] | [.id, .name] | @tsv' \ - <<<"${retirement}") - - if ! jq -e --argjson id "${ruleset_id}" --arg name "${ruleset_name}" ' - [.[] | select(.id == $id and .name == $name)] | length == 1 - ' <<<"${rulesets}" >/dev/null; then - echo "error: exact retirement ruleset is missing or ambiguous" >&2 - exit 1 - fi - - ruleset=$(github_api "orgs/${organization}/rulesets/${ruleset_id}") - if ! jq -e --argjson id "${ruleset_id}" --arg name "${ruleset_name}" \ - --arg repository "${repository}" --arg branch "${branch}" \ - --argjson retirement "${retirement}" ' - .id == $id and - .name == $name and - .target == "branch" and - .enforcement == "active" and - .bypass_actors == [{ - actor_id: null, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }] and - .conditions.repository_name.include == [$repository] and - .conditions.repository_name.exclude == [] and - .conditions.ref_name.include == ["refs/heads/\($branch)"] and - .conditions.ref_name.exclude == [] and - ([.rules[].type] | sort) == ([ - "deletion", - "non_fast_forward", - "pull_request", - "required_linear_history", - "required_status_checks" - ] | sort) and - ([.rules[] | select(.type == "pull_request")] | length == 1) and - ([.rules[] | select(.type == "pull_request")][0].parameters == { - allowed_merge_methods: ["merge", "squash", "rebase"], - dismiss_stale_reviews_on_push: false, - require_code_owner_review: false, - require_last_push_approval: false, - required_approving_review_count: 0, - required_review_thread_resolution: true, - required_reviewers: [] - }) and - ([.rules[] | select(.type == "required_status_checks")] | length == 1) and - ([.rules[] | select(.type == "required_status_checks")][0].parameters == { - do_not_enforce_on_create: false, - required_status_checks: ( - $retirement.ruleset.required_ci | - map({context: ., integration_id: 15368}) - ), - strict_required_status_checks_policy: true - }) - ' <<<"${ruleset}" >/dev/null; then - echo "error: exact retirement ruleset payload drift" >&2 - exit 1 - fi - - echo "KEEP ${organization}/${repository} default branch is ${default_branch}" - echo "KEEP refs/heads/${branch} is ${branch_commit}" - echo "KEEP ${release_tag} is ${release_commit} with exact recovery assets" - echo "KEEP no open pull request targets ${branch}" - run_api DELETE "orgs/${organization}/rulesets/${ruleset_id}" - - if ${apply}; then - rulesets=$(list_rulesets "orgs/${organization}/rulesets") || return 1 - if jq -e --argjson id "${ruleset_id}" 'any(.[]; .id == $id)' \ - <<<"${rulesets}" >/dev/null; then - echo "error: retirement ruleset still exists after apply" >&2 - exit 1 - fi - while IFS=$'\t' read -r preserved_id preserved_name; do - if ! jq -e --argjson id "${preserved_id}" --arg name "${preserved_name}" ' - any(.[]; .id == $id and .name == $name and .enforcement == "active") - ' <<<"${rulesets}" >/dev/null; then - echo "error: preserved ruleset changed during retirement: ${preserved_id}" >&2 - exit 1 - fi - done < <(jq -r '.preserved_rulesets[] | [.id, .name] | @tsv' \ - <<<"${retirement}") - echo "APPLY verified only ruleset ${ruleset_id} is absent" - fi -} - -if [[ -n ${retire_maintenance} ]]; then - retire_maintenance_branch_ruleset "${retire_maintenance}" - exit 0 -fi - -converge_organization_settings() { - local current=$1 - local desired - - desired=$(jq -c . "${organization_config}") - if jq -e --argjson desired "${desired}" ' - . as $current | - all($desired | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - echo "KEEP /orgs/${organization} metadata and repository defaults" - return - fi - - jq -r \ - --arg endpoint "/orgs/${organization}" \ - --argjson desired "${desired}" ' - . as $current | - $desired | to_entries[] | - select($current[.key] != .value) | - "DRIFT \($endpoint) \(.key) live=\($current[.key] | tojson) desired=\(.value | tojson)" - ' <<<"${current}" - run_api PATCH "orgs/${organization}" "${organization_config}" -} - -repository_uses_advanced_codeql() { - local repository=$1 - - jq -e --arg repository "${repository}" \ - '(.repositories | index($repository)) != null' \ - "${codeql_advanced_config}" >/dev/null -} - -repository_has_advisory_merge_window() { - local repository=$1 - - jq -e --arg repository "${repository}" \ - '(.repositories | index($repository)) != null' \ - "${advisory_merge_windows_config}" >/dev/null -} - -is_temporary_security_advisory_repository() { - local repository=$1 - local private=$2 - local visibility=$3 - local disabled=$4 - local fork=$5 - local has_issues=$6 - local has_projects=$7 - local has_wiki=$8 - local base_repository - - if [[ ${repository} =~ ^(.+)-ghsa-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$ ]]; then - base_repository=${BASH_REMATCH[1]} - else - return 1 - fi - - [[ ${private} == true ]] && - [[ ${visibility} == private ]] && - [[ ${disabled} == false ]] && - [[ ${fork} == false ]] && - [[ ${has_issues} == false ]] && - [[ ${has_projects} == false ]] && - [[ ${has_wiki} == false ]] && - jq -e --arg repository "${base_repository}" \ - '(.pull_request_gate | index($repository)) != null' \ - "${repositories_config}" >/dev/null -} - -# Compare only declared metadata keys; never PATCH already-converged defaults. -converge_settings() { - local method=$1 endpoint=$2 input=$3 current - current=$(github_api "${endpoint}") || return 1 - if ! jq -e 'type == "object"' <<<"${current}" >/dev/null; then - echo "error: unreadable settings: ${endpoint}" >&2 - return 1 - fi - if jq -e --slurpfile desired "${input}" ' - . as $current | all($desired[0] | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - echo "KEEP /${endpoint}" - else - run_api "${method}" "${endpoint}" "${input}" - fi -} - -# Preserve compatible writable API extensions on a managed-policy update. -# Unknown restrictions fail closed rather than disappearing in a replacement PUT. -update_managed_ruleset() { - local endpoint=$1 input=$2 id=$3 source_type=$4 source=$5 - local current fresh output - current=$(github_api "${endpoint}") || return 1 - if ! jq -e --argjson id "${id}" --arg source_type "${source_type}" \ - --arg source "${source}" --slurpfile desired "${input}" ' - .id == $id and .source_type == $source_type and .source == $source and - .name == $desired[0].name - ' <<<"${current}" >/dev/null; then - echo "error: managed ruleset identity changed; retained: ${endpoint}" >&2 - return 1 - fi - output=$(mktemp) - temporary_files+=("${output}") - jq -L "${root}/lib" --slurpfile desired "${input}" ' - include "ruleset-policy"; prepare_policy($desired[0]) - ' <<<"${current}" >"${output}" || return 1 - if jq -e -L "${root}/lib" --slurpfile desired "${output}" ' - include "ruleset-policy"; - (policy_body | normalize_policy) == ($desired[0] | normalize_policy) - ' <<<"${current}" >/dev/null; then - echo "KEEP /${endpoint} $(jq -r .name "${input}")" - return - fi - # Re-read the full document immediately before a replacement and refuse any - # observed concurrent edit, including changes in unmanaged fields. - fresh=$(github_api "${endpoint}") || return 1 - if ! jq -e --argjson prior "${current}" '. == $prior' <<<"${fresh}" >/dev/null; then - echo "error: managed ruleset changed during planning; retained: ${endpoint}" >&2 - return 1 - fi - run_api PUT "${endpoint}" "${output}" -} - -upsert_repository_ruleset() { - local repository=$1 - local input=$2 - local name id rulesets - - name=$(jq -r '.name' "${input}") - rulesets=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - id=$(jq -r --arg name "${name}" 'map(select(.name == $name))[0].id // empty' <<<"${rulesets}") - - if [[ -n ${id} ]]; then - update_managed_ruleset "repos/${organization}/${repository}/rulesets/${id}" \ - "${input}" "${id}" Repository "${organization}/${repository}" - else - run_api POST "repos/${organization}/${repository}/rulesets" "${input}" - fi -} - -upsert_organization_ruleset() { - local input=$1 - local name id rulesets - - name=$(jq -r '.name' "${input}") - rulesets=$(list_rulesets "orgs/${organization}/rulesets") || return 1 - id=$(jq -r --arg name "${name}" 'map(select(.name == $name))[0].id // empty' <<<"${rulesets}") - - if [[ -n ${id} ]]; then - update_managed_ruleset "orgs/${organization}/rulesets/${id}" \ - "${input}" "${id}" Organization "${organization}" - else - run_api POST "orgs/${organization}/rulesets" "${input}" - fi -} - -make_organization_ruleset() { - local base=$1 - local name=$2 - local repositories=$3 - local excluded_repositories=${4:-[]} - local output - - output=$(mktemp) - temporary_files+=("${output}") - jq --arg name "${name}" \ - --argjson repositories "${repositories}" \ - --argjson excluded_repositories "${excluded_repositories}" ' - .name = $name | - .conditions.repository_name = { - include: $repositories, - exclude: $excluded_repositories, - protected: false - } - ' "${base}" >"${output}" - echo "${output}" -} - -maintenance_ruleset_name() { - local repository=$1 - local branch=$2 - - printf '05 - Maintenance branch - %s - %s' "${repository}" "${branch}" -} - -make_maintenance_ruleset() { - local repository=$1 - local branch=$2 - local required_ci=$3 - local scope=$4 - local output name - - name=$(maintenance_ruleset_name "${repository}" "${branch}") - output=$(mktemp) - temporary_files+=("${output}") - jq --arg name "${name}" \ - --arg repository "${repository}" \ - --arg branch "${branch}" \ - --arg scope "${scope}" \ - --argjson app_id 15368 \ - --argjson required_ci "${required_ci}" ' - .name = $name | - .conditions.ref_name.include = ["refs/heads/\($branch)"] | - .rules = ( - .rules | - map( - if .type == "required_status_checks" then - .parameters.required_status_checks = - ($required_ci | map({context: ., integration_id: $app_id})) - else - . - end - ) | - if ($required_ci | length) == 0 then - map(select(.type != "required_status_checks")) - else - . - end - ) | - if $scope == "organization" then - .conditions.repository_name = { - include: [$repository], - exclude: [], - protected: false - } - else - . - end - ' "${root}/config/rulesets/maintenance-branch.json" >"${output}" - echo "${output}" -} - -maintenance_ruleset_is_desired() { - local repository=$1 - local candidate=$2 - local branch expected - - while IFS= read -r branch; do - expected=$(maintenance_ruleset_name "${repository}" "${branch}") - if [[ ${candidate} == "${expected}" ]]; then - return 0 - fi - done < <( - jq -r --arg repository "${repository}" ' - .maintenance_branches[] | - select(.repository == $repository) | - .branch - ' "${repositories_config}" - ) - return 1 -} - -delete_stale_repository_maintenance_rulesets() { - local repository ruleset name id rulesets - - for repository in "${active_repositories[@]}"; do - rulesets=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - while IFS= read -r ruleset; do - name=$(jq -r '.name' <<<"${ruleset}") - id=$(jq -r '.id' <<<"${ruleset}") - if [[ ${name} != "05 - Maintenance branch - "* ]]; then - continue - fi - if ! maintenance_ruleset_is_desired "${repository}" "${name}"; then - run_api DELETE "repos/${organization}/${repository}/rulesets/${id}" || return 1 - fi - done < <(jq -c '.[]' <<<"${rulesets}") - done -} - -delete_stale_repository_advisory_rulesets() { - local repository ruleset name id window_active rulesets - - while IFS= read -r repository; do - window_active=false - if repository_has_advisory_merge_window "${repository}"; then - window_active=true - fi - rulesets=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - while IFS= read -r ruleset; do - name=$(jq -r '.name' <<<"${ruleset}") - id=$(jq -r '.id' <<<"${ruleset}") - if ${window_active}; then - case ${name} in - "01 - Default branch integrity" | \ - "01 - Default branch linear history" | \ - "02 - Changes through pull requests") - run_api DELETE \ - "repos/${organization}/${repository}/rulesets/${id}" || return 1 - ;; - esac - else - case ${name} in - "01 - Default branch integrity - ${repository}" | \ - "01 - Default branch linear history - ${repository}" | \ - "02 - Changes through pull requests - ${repository}") - run_api DELETE \ - "repos/${organization}/${repository}/rulesets/${id}" || return 1 - ;; - esac - fi - done < <(jq -c '.[]' <<<"${rulesets}") - done < <(jq -r '.pull_request_gate[]' "${repositories_config}") -} - -delete_managed_repository_rulesets() { - local repository=$1 - local ruleset name id rulesets - - rulesets=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - while IFS= read -r ruleset; do - name=$(jq -r '.name' <<<"${ruleset}") - id=$(jq -r '.id' <<<"${ruleset}") - case ${name} in - "01 - Default branch integrity" | \ - "01 - Default branch integrity - classic" | \ - "01 - Default branch linear history" | \ - "01 - Default branch linear history - classic" | \ - "02 - Changes through pull requests" | \ - "02 - Changes through pull requests - classic" | \ - "03 - Required CI" | \ - "04 - Immutable release tags" | \ - "05 - Maintenance branch - "*) - run_api DELETE "repos/${organization}/${repository}/rulesets/${id}" || return 1 - ;; - esac - done < <(jq -c '.[]' <<<"${rulesets}") -} - -delete_managed_organization_rulesets() { - local ruleset name id rulesets - - rulesets=$(list_rulesets "orgs/${organization}/rulesets") || return 1 - while IFS= read -r ruleset; do - name=$(jq -r '.name' <<<"${ruleset}") - id=$(jq -r '.id' <<<"${ruleset}") - case ${name} in - "01 - Default branch integrity" | \ - "01 - Default branch integrity - classic" | \ - "01 - Default branch linear history" | \ - "01 - Default branch linear history - classic" | \ - "02 - Changes through pull requests" | \ - "02 - Changes through pull requests - classic" | \ - "04 - Immutable release tags" | \ - "03 - Required CI - "* | \ - "05 - Maintenance branch - "*) - run_api DELETE "orgs/${organization}/rulesets/${id}" || return 1 - ;; - esac - done < <(jq -c '.[]' <<<"${rulesets}") -} - -retired_required_ci_matches() { - local repository=$1 id=$2 template=$3 current=$4 - jq -e --argjson id "${id}" --arg source "${organization}/${repository}" ' - .id == $id and .source_type == "Repository" and .source == $source - ' <<<"${current}" >/dev/null && security_ruleset_matches "${template}" "${current}" -} - -delete_retired_repository_required_ci() { - local repository listed record id template current metadata fresh - for repository in "${active_repositories[@]}"; do - [[ -v active_repository_ids["${repository}"] ]] || continue - if jq -e --arg repository "${repository}" '.required_ci | has($repository)' \ - "${repositories_config}" >/dev/null; then - continue - fi - listed=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - listed=$(jq -c '[.[] | select(.name == "03 - Required CI")]' <<<"${listed}") - [[ $(jq length <<<"${listed}") != 0 ]] || continue - record=$(jq -c --arg repository "${repository}" \ - '[.retirements[] | select(.repository == $repository)]' "${root}/config/retired-required-ci.json") - if [[ $(jq length <<<"${listed}") != 1 || $(jq length <<<"${record}") != 1 ]]; then - echo "SKIP ${organization}/${repository} 03 - Required CI: retained; requires one reviewed config/retired-required-ci.json record and unique live rule" - continue - fi - record=$(jq -c '.[0]' <<<"${record}") - id=$(jq -r '.ruleset_id' <<<"${record}") - if ! jq -e --argjson id "${id}" '.[0].id == $id' <<<"${listed}" >/dev/null; then - echo "SKIP ${organization}/${repository} 03 - Required CI: recorded ruleset identity differs; retained" - continue - fi - template=$(mktemp) - temporary_files+=("${template}") - jq --argjson record "${record}" ' - .rules[0].parameters.required_status_checks = - ($record.required_ci | map({context: ., integration_id: 15368})) - ' "${root}/config/rulesets/required-ci.json" >"${template}" - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - if ! retired_required_ci_matches "${repository}" "${id}" "${template}" "${current}"; then - echo "SKIP ${organization}/${repository} 03 - Required CI: modified or foreign rule; retained" - continue - fi - metadata=$(github_api "repos/${organization}/${repository}") || return 1 - if ! jq -e --argjson record "${record}" --argjson enumerated "${active_repository_ids["${repository}"]}" \ - --arg full_name "${organization}/${repository}" ' - .id == $record.repository_id and .id == $enumerated and - .full_name == $full_name and .archived == false - ' <<<"${metadata}" >/dev/null; then - echo "SKIP ${organization}/${repository} 03 - Required CI: repository identity or archive state changed; retained" - continue - fi - fresh=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - if ! retired_required_ci_matches "${repository}" "${id}" "${template}" "${fresh}"; then - echo "SKIP ${organization}/${repository} 03 - Required CI: rule changed during retirement preflight; retained" - continue - fi - run_api DELETE "repos/${organization}/${repository}/rulesets/${id}" || return 1 - done -} - -publish_repository_rulesets() { - local repository ruleset_config ci_payload maintenance branch required_ci - local input queued - - # Establish the Classic-specific policy before replacing its shared policy. - for repository in "${active_repositories[@]}"; do - ruleset_config=${root}/config/rulesets/default-branch-linear-history.json - if repository_has_advisory_merge_window "${repository}"; then - ruleset_config=${root}/config/rulesets/default-branch-linear-history-classic.json - fi - upsert_repository_ruleset "${repository}" \ - "${ruleset_config}" || return 1 - done - - for repository in "${active_repositories[@]}"; do - ruleset_config=${root}/config/rulesets/default-branch-integrity.json - if repository_has_advisory_merge_window "${repository}"; then - ruleset_config=${root}/config/rulesets/default-branch-integrity-classic.json - fi - upsert_repository_ruleset "${repository}" \ - "${ruleset_config}" || return 1 - done - - while IFS= read -r repository; do - ruleset_config=${root}/config/rulesets/pull-request-gate.json - if repository_has_advisory_merge_window "${repository}"; then - ruleset_config=${root}/config/rulesets/pull-request-gate-classic.json - fi - upsert_repository_ruleset "${repository}" \ - "${ruleset_config}" || return 1 - done < <(jq -r '.pull_request_gate[]' "${repositories_config}") - - verify_installed_merge_queues || return 1 - queued=${verified_merge_queue_repositories} - while IFS= read -r repository; do - ci_payload=$(mktemp) - temporary_files+=("${ci_payload}") - jq --arg repository "${repository}" \ - --argjson app_id 15368 \ - --argjson queued "${queued}" \ - --slurpfile advisory_windows "${advisory_merge_windows_config}" \ - --slurpfile repositories "${repositories_config}" ' - .bypass_actors |= map( - if ($advisory_windows[0].repositories | index($repository)) != null then - .bypass_mode = "always" - else - . - end - ) | - .rules[0].parameters.required_status_checks = - ($repositories[0].required_ci[$repository] | - map({context: ., integration_id: $app_id})) | - # A merge queue tests the merged result, so its branch need not be current. - .rules[0].parameters.strict_required_status_checks_policy = - (($queued | index($repository)) == null) - ' "${root}/config/rulesets/required-ci.json" >"${ci_payload}" - upsert_repository_ruleset "${repository}" "${ci_payload}" || return 1 - done < <(jq -r '.required_ci | keys[]' "${repositories_config}") - - while IFS= read -r repository; do - upsert_repository_ruleset "${repository}" \ - "${root}/config/rulesets/immutable-release-tags.json" || return 1 - done < <(jq -r '.release_tags[]' "${repositories_config}") - - while IFS= read -r maintenance; do - repository=$(jq -r '.repository' <<<"${maintenance}") - branch=$(jq -r '.branch' <<<"${maintenance}") - required_ci=$(jq -c '.required_ci' <<<"${maintenance}") - input=$(make_maintenance_ruleset \ - "${repository}" "${branch}" "${required_ci}" repository) - temporary_files+=("${input}") - upsert_repository_ruleset "${repository}" "${input}" || return 1 - done < <(jq -c '.maintenance_branches[]' "${repositories_config}") - - delete_retired_repository_required_ci || return 1 - delete_stale_repository_maintenance_rulesets || return 1 - delete_stale_repository_advisory_rulesets || return 1 - - if [[ ${organization_plan} != free ]]; then - delete_managed_organization_rulesets || return 1 - fi -} - -publish_organization_rulesets() { - local input repository ci_payload maintenance branch required_ci queued - local -a desired_rulesets - local repositories ruleset name id desired rulesets - - desired_rulesets=( - "01 - Default branch integrity" - "01 - Default branch linear history" - "02 - Changes through pull requests" - "04 - Immutable release tags" - ) - - # Establish the Classic-specific policies before excluding it from their - # shared counterparts. - if repository_has_advisory_merge_window classic; then - desired_rulesets+=( - "01 - Default branch integrity - classic" - "01 - Default branch linear history - classic" - "02 - Changes through pull requests - classic" - ) - input=$(make_organization_ruleset \ - "${root}/config/rulesets/default-branch-integrity-classic.json" \ - "01 - Default branch integrity - classic" '["classic"]') - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - input=$(make_organization_ruleset \ - "${root}/config/rulesets/default-branch-linear-history-classic.json" \ - "01 - Default branch linear history - classic" '["classic"]') - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - fi - - repositories=$(jq -c '.repositories' "${advisory_merge_windows_config}") - - input=$(make_organization_ruleset \ - "${root}/config/rulesets/default-branch-linear-history.json" \ - "01 - Default branch linear history" '["~ALL"]' "${repositories}") - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - - input=$(make_organization_ruleset \ - "${root}/config/rulesets/default-branch-integrity.json" \ - "01 - Default branch integrity" '["~ALL"]' "${repositories}") - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - - # Establish the Classic-specific policy before excluding it from the shared - # pull-request policy. - if repository_has_advisory_merge_window classic; then - input=$(make_organization_ruleset \ - "${root}/config/rulesets/pull-request-gate-classic.json" \ - "02 - Changes through pull requests - classic" '["classic"]') - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - fi - - repositories=$(jq -c \ - --slurpfile advisory_windows "${advisory_merge_windows_config}" \ - '.pull_request_gate - $advisory_windows[0].repositories' \ - "${repositories_config}") - input=$(make_organization_ruleset \ - "${root}/config/rulesets/pull-request-gate.json" \ - "02 - Changes through pull requests" "${repositories}") - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - - repositories=$(jq -c '.release_tags' "${repositories_config}") - input=$(make_organization_ruleset \ - "${root}/config/rulesets/immutable-release-tags.json" \ - "04 - Immutable release tags" "${repositories}") - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - - verify_installed_merge_queues || return 1 - queued=${verified_merge_queue_repositories} - while IFS= read -r repository; do - name="03 - Required CI - ${repository}" - desired_rulesets+=("${name}") - ci_payload=$(mktemp) - temporary_files+=("${ci_payload}") - jq --arg name "${name}" \ - --arg repository "${repository}" \ - --argjson app_id 15368 \ - --argjson queued "${queued}" \ - --slurpfile advisory_windows "${advisory_merge_windows_config}" \ - --slurpfile repositories "${repositories_config}" ' - .name = $name | - .bypass_actors |= map( - if ($advisory_windows[0].repositories | index($repository)) != null then - .bypass_mode = "always" - else - . - end - ) | - .conditions.repository_name = { - include: [$repository], - exclude: [], - protected: false - } | - .rules[0].parameters.required_status_checks = - ($repositories[0].required_ci[$repository] | - map({context: ., integration_id: $app_id})) | - # A merge queue tests the merged result, so its branch need not be current. - .rules[0].parameters.strict_required_status_checks_policy = - (($queued | index($repository)) == null) - ' "${root}/config/rulesets/required-ci.json" >"${ci_payload}" - upsert_organization_ruleset "${ci_payload}" || return 1 - done < <(jq -r '.required_ci | keys[]' "${repositories_config}") - - while IFS= read -r maintenance; do - repository=$(jq -r '.repository' <<<"${maintenance}") - branch=$(jq -r '.branch' <<<"${maintenance}") - required_ci=$(jq -c '.required_ci' <<<"${maintenance}") - name=$(maintenance_ruleset_name "${repository}" "${branch}") - desired_rulesets+=("${name}") - input=$(make_maintenance_ruleset \ - "${repository}" "${branch}" "${required_ci}" organization) - temporary_files+=("${input}") - upsert_organization_ruleset "${input}" || return 1 - done < <(jq -c '.maintenance_branches[]' "${repositories_config}") - - rulesets=$(list_rulesets "orgs/${organization}/rulesets") || return 1 - while IFS= read -r ruleset; do - name=$(jq -r '.name' <<<"${ruleset}") - id=$(jq -r '.id' <<<"${ruleset}") - case ${name} in - "01 - Default branch integrity - "* | \ - "01 - Default branch linear history - "* | \ - "02 - Changes through pull requests - "* | \ - "03 - Required CI - "* | \ - "05 - Maintenance branch - "*) ;; - *) - continue - ;; - esac - desired=false - for repository in "${desired_rulesets[@]}"; do - if [[ ${repository} == "${name}" ]]; then - desired=true - break - fi - done - if ! ${desired}; then - run_api DELETE "orgs/${organization}/rulesets/${id}" || return 1 - fi - done < <(jq -c '.[]' <<<"${rulesets}") - - for repository in "${active_repositories[@]}"; do - delete_managed_repository_rulesets "${repository}" || return 1 - done -} - -upsert_code_security_configuration() { - local input=$1 - local placeholder=$2 - local name id current - - name=$(jq -r '.name' "${input}") - id=$( - github_api "orgs/${organization}/code-security/configurations" | - jq -r --arg name "${name}" 'map(select(.name == $name))[0].id // empty' - ) - - if [[ -n ${id} ]]; then - current=$(github_api \ - "orgs/${organization}/code-security/configurations/${id}") - if code_security_configuration_matches "${input}" "${current}"; then - echo "KEEP /orgs/${organization}/code-security/configurations/${id} matches ${input#"${root}/"}" - else - run_api PATCH \ - "orgs/${organization}/code-security/configurations/${id}" \ - "${input}" - fi - elif ${apply}; then - id=$( - github_api --method POST \ - "orgs/${organization}/code-security/configurations" \ - --input "${input}" | jq -r '.id' - ) - else - echo "PLAN POST /orgs/${organization}/code-security/configurations <= ${input#"${root}/"}" - id=${placeholder} - fi - - if ${apply} && [[ ! ${id} =~ ^[0-9]+$ ]]; then - echo "error: invalid code security configuration id for ${name}: ${id}" >&2 - exit 1 - fi - - upserted_code_security_configuration_id=${id} -} - -code_security_configuration_matches() { - local input=$1 - local current=$2 - - # GitHub currently returns the legacy advanced_security summary even when - # code_security and secret_protection were written separately. Normalize - # that response before comparing only the fields owned by desired state. - jq -e --slurpfile desired "${input}" ' - . as $current | - ( - $current + { - code_security: ( - if $current.code_security != null then - $current.code_security - elif ( - $current.advanced_security == "enabled" or - $current.advanced_security == "code_security" - ) then - "enabled" - elif ( - $current.advanced_security == "disabled" or - $current.advanced_security == "secret_protection" - ) then - "disabled" - else - "not_set" - end - ), - secret_protection: ( - if $current.secret_protection != null then - $current.secret_protection - elif ( - $current.advanced_security == "enabled" or - $current.advanced_security == "secret_protection" - ) then - "enabled" - elif ( - $current.advanced_security == "disabled" or - $current.advanced_security == "code_security" - ) then - "disabled" - else - "not_set" - end - ) - } - ) as $normalized | - $desired[0] as $wanted | - reduce ($wanted | keys[]) as $key - (true; . and ($normalized[$key] == $wanted[$key])) - ' <<<"${current}" >/dev/null -} - -make_security_attach_payload() { - local advanced=$1 - local expected_id=$2 - local repository repository_is_advanced id current status current_id - local ids='[]' - - security_attachment_wait_needed=false - - for repository in "${active_repositories[@]}"; do - repository_is_advanced=false - if repository_uses_advanced_codeql "${repository}"; then - repository_is_advanced=true - fi - if [[ ${repository_is_advanced} != "${advanced}" ]]; then - continue - fi - - id=${active_repository_ids["${repository}"]} - current= - if current=$(github_api \ - "repos/${organization}/${repository}/code-security-configuration" \ - 2>/dev/null); then - status=$(jq -r '.status // empty' <<<"${current}") - current_id=$(jq -r '.configuration.id // empty' <<<"${current}") - if [[ ${current_id} == "${expected_id}" ]]; then - # Both managed configurations require enforcement. An attached - # relationship must settle to enforced, but must not be re-attached. - case ${status} in - enforced) - continue - ;; - attached | attaching | updating) - security_attachment_wait_needed=true - continue - ;; - esac - fi - fi - - ids=$(jq --argjson id "${id}" '. + [$id]' <<<"${ids}") - security_attachment_wait_needed=true - done - - security_attach_payload=$(mktemp) - jq -n --argjson ids "${ids}" \ - '{scope: "selected", selected_repository_ids: $ids}' \ - >"${security_attach_payload}" - security_attachment_count=$(jq '.selected_repository_ids | length' \ - "${security_attach_payload}") -} - -converge_security_configuration_attachments() { - local advanced=$1 - local expected_id=$2 - local cohort=$3 - - make_security_attach_payload "${advanced}" "${expected_id}" - temporary_files+=("${security_attach_payload}") - - if ((security_attachment_count > 0)); then - run_api POST \ - "orgs/${organization}/code-security/configurations/${expected_id}/attach" \ - "${security_attach_payload}" - elif ! ${security_attachment_wait_needed}; then - echo "KEEP /orgs/${organization}/code-security/configurations/${expected_id}/attach already covers ${cohort} repositories" - fi - - if ${security_attachment_wait_needed}; then - wait_for_code_security_configuration "${advanced}" "${expected_id}" - fi -} - -wait_for_code_security_configuration() { - local advanced=$1 - local expected_id=$2 - local repository response status id attempt - local -r maximum_attempts=30 - - for repository in "${active_repositories[@]}"; do - if repository_uses_advanced_codeql "${repository}"; then - [[ ${advanced} == true ]] || continue - else - [[ ${advanced} == false ]] || continue - fi - - if ! ${apply}; then - echo "PLAN WAIT /repos/${organization}/${repository}/code-security-configuration => ${expected_id}" - continue - fi - - for ((attempt = 1; attempt <= maximum_attempts; attempt++)); do - if response=$(github_api \ - "repos/${organization}/${repository}/code-security-configuration" \ - 2>/dev/null); then - status=$(jq -r '.status // empty' <<<"${response}") - id=$(jq -r '.configuration.id // empty' <<<"${response}") - # "attached" is active but not the enforced terminal state required - # by both managed configurations. - if [[ ${id} == "${expected_id}" ]] && - [[ ${status} == enforced ]]; then - break - fi - if [[ ${id} == "${expected_id}" ]] && - [[ ${status} == failed ]]; then - echo "error: security configuration attachment failed for ${organization}/${repository}" >&2 - exit 1 - fi - fi - - if ((attempt == maximum_attempts)); then - echo "error: timed out waiting for security configuration ${expected_id} on ${organization}/${repository}" >&2 - exit 1 - fi - sleep 2 - done - done -} - -converge_codeql_default_setup() { - local repository input desired_state desired_query current required_languages - local current_state current_query language_match - - for repository in "${active_repositories[@]}"; do - input=${root}/config/codeql-default-setup.json - if repository_uses_advanced_codeql "${repository}"; then - input=${root}/config/codeql-default-setup-advanced.json - fi - required_languages=$(jq -c --arg repository "${repository}" \ - '.codeql_required_languages[$repository] // []' "${security_merge_config}") - desired_state=$(jq -r '.state' "${input}") - desired_query=$(jq -r '.query_suite // empty' "${input}") - current='{}' - if current=$(github_api \ - "repos/${organization}/${repository}/code-scanning/default-setup" \ - 2>/dev/null); then - current_state=$(jq -r '.state // empty' <<<"${current}") - if ! jq -e ' - (.state == "not-configured" and .languages == null) or - (.languages | type == "array" and all(.[]; type == "string" and length > 0)) - ' <<<"${current}" >/dev/null; then - echo "error: invalid existing CodeQL languages for ${repository}" >&2 - return 1 - fi - current_query=$(jq -r '.query_suite // empty' <<<"${current}") - language_match=$(jq --argjson required "${required_languages}" \ - '($required - (.languages // [])) == []' <<<"${current}") - if [[ ${current_state} == "${desired_state}" && ${language_match} == true ]] && - { [[ -z ${desired_query} ]] || [[ ${current_query} == "${desired_query}" ]]; }; then - echo "KEEP /repos/${organization}/${repository}/code-scanning/default-setup is ${desired_state}" - continue - fi - else - # A failed read is unknown state, including repositories with no policy - # language minimum or with advanced setup. Never publish from that state. - echo "error: cannot read existing CodeQL languages for ${repository}" >&2 - return 1 - fi - if [[ ${required_languages} != '[]' ]]; then - local language_payload - language_payload=$(mktemp) - temporary_files+=("${language_payload}") - jq --argjson current "${current}" --argjson required "${required_languages}" \ - '.languages = (($current.languages // []) + $required | - map(if . == "javascript" or . == "typescript" then - "javascript-typescript" else . end) | unique)' \ - "${input}" >"${language_payload}" - input=${language_payload} - fi - run_api PATCH \ - "repos/${organization}/${repository}/code-scanning/default-setup" \ - "${input}" - done -} - -security_ruleset_matches() { - local template=$1 current=$2 - jq -e --slurpfile desired "${template}" ' - # GitHub returns the organization-owner sentinel with a null ID. - def normalize: - .bypass_actors |= (map( - if .actor_type == "OrganizationAdmin" and .actor_id == null then - .actor_id = 1 - else . end) | sort_by(.actor_type, .actor_id, .bypass_mode)) | - # GitHub expands this omitted request parameter to false. Keep true, - # null and unknown parameters visible so modified gates are not retired. - .rules |= map(if .type == "required_status_checks" then - .parameters |= ( - if .do_not_enforce_on_create == false then del(.do_not_enforce_on_create) else . end | - .required_status_checks |= sort_by(.context, .integration_id)) - else . end); - normalize as $current | - all($desired[0] | normalize | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null -} - -security_ruleset_restoration_allowed() { - local repository=$1 id=$2 template=$3 current=$4 - jq -e --argjson id "${id}" --slurpfile desired "${template}" \ - --arg source "${organization}/${repository}" ' - .id == $id and .name == $desired[0].name and - .source_type == "Repository" and .source == $source and - (.enforcement | IN("active", "disabled", "evaluate")) - ' <<<"${current}" >/dev/null && - security_ruleset_matches "${template}" "$(jq --slurpfile desired "${template}" ' - .enforcement = $desired[0].enforcement | - .conditions.ref_name.include = $desired[0].conditions.ref_name.include | - .conditions.ref_name.exclude = $desired[0].conditions.ref_name.exclude - ' <<<"${current}")" -} - -security_gate_applies_to_default_branch() { - local repository=$1 kind=$2 id=$3 metadata branch effective - metadata=$(github_api "repos/${organization}/${repository}") || return 1 - jq -e --argjson id "${active_repository_ids["${repository}"]}" ' - .id == $id and .archived == false and - (.default_branch | type == "string" and length > 0) - ' <<<"${metadata}" >/dev/null || return 1 - branch=$(jq -r '.default_branch | @uri' <<<"${metadata}") - effective=$(github_api "repos/${organization}/${repository}/rules/branches/${branch}") || return 1 - jq -e --argjson id "${id}" --arg kind "${kind}" ' - any(.[]; .ruleset_id == $id and - if $kind == "code_scanning" then - .type == "code_scanning" and - any(.parameters.code_scanning_tools[]?; .tool == "CodeQL") - else - .type == "required_status_checks" and - any(.parameters.required_status_checks[]?; - .context == "Dependency review" and .integration_id == 15368) - end) - ' <<<"${effective}" >/dev/null || return 1 - printf '%s\n' "${branch}" -} - -owned_security_ruleset_matches() { - local repository=$1 id=$2 template=$3 current=$4 - jq -e --argjson id "${id}" --arg source "${organization}/${repository}" ' - .id == $id and .source_type == "Repository" and .source == $source - ' <<<"${current}" >/dev/null && security_ruleset_matches "${template}" "${current}" -} - -delete_removed_security_merge_rulesets() { - local repository kind template name existing rule id current metadata - for repository in "${active_repositories[@]}"; do - [[ -v active_repository_ids["${repository}"] ]] || continue - # The complete live inventory was checked against governed repositories - # before this function; archived repositories never enter this collection. - for kind in code_scanning dependency_review; do - if jq -e --arg kind "${kind}" --arg repository "${repository}" \ - '.[$kind] | index($repository) != null' "${security_merge_config}" >/dev/null; then - continue - fi - if [[ ${kind} == code_scanning ]]; then - template=${root}/config/rulesets/code-scanning.json - else - template=${root}/config/rulesets/dependency-review.json - fi - name=$(jq -r '.name' "${template}") - existing=$(list_rulesets "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - while IFS= read -r rule; do - id=$(jq -r '.id' <<<"${rule}") - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - if owned_security_ruleset_matches "${repository}" "${id}" "${template}" "${current}"; then - metadata=$(github_api "repos/${organization}/${repository}") || return 1 - if jq -e --argjson id "${active_repository_ids["${repository}"]}" \ - --arg full_name "${organization}/${repository}" ' - .id == $id and .full_name == $full_name and .archived == false - ' <<<"${metadata}" >/dev/null; then - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || { - echo "error: security gate final retirement read failed; retained: ${repository} ${name}" >&2 - return 1 - } - if ! owned_security_ruleset_matches "${repository}" "${id}" "${template}" "${current}"; then - echo "SKIP ${organization}/${repository} ${name}: rule changed during retirement preflight; retained" - continue - fi - run_api DELETE "repos/${organization}/${repository}/rulesets/${id}" || return 1 - else - echo "SKIP ${organization}/${repository} ${name}: repository identity or archive state changed; retained" - fi - else - echo "SKIP ${organization}/${repository} ${name}: unrecognized ownership or payload; retained" - fi - done < <(jq -c --arg name "${name}" '.[] | select(.name == $name)' <<<"${existing}") - done - done -} - -# These repository rules remain repository-owned even in organization scope: -# GitHub Team does not support organization-level code-scanning rules. -publish_security_merge_rulesets() { - local repository kind template name existing id current reason status readiness_mode phase metadata effective_branch proven_current preserved_payload - delete_removed_security_merge_rulesets || return 1 - for kind in code_scanning dependency_review; do - if [[ ${kind} == code_scanning ]]; then - template=${root}/config/rulesets/code-scanning.json - readiness_mode=codeql - else - template=${root}/config/rulesets/dependency-review.json - readiness_mode=dependency - fi - name=$(jq -r '.name' "${template}") - while IFS= read -r repository; do - if [[ ! -v active_repository_ids["${repository}"] ]]; then - echo "SKIP ${organization}/${repository} is not active; ${name}" - continue - fi - phase=$(jq -er --arg kind "${kind}" --arg repository "${repository}" \ - '.activation[$kind][$repository] | select(. == "pending" or . == "enforced")' \ - "${security_merge_config}") || { - echo "error: invalid security gate activation intent: ${repository} ${kind}" >&2 - return 1 - } - existing=$(list_rulesets \ - "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - if ! jq -e --arg name "${name}" \ - '[.[] | select(.name == $name)] | length <= 1' <<<"${existing}" >/dev/null; then - echo "error: ambiguous managed ruleset ${name} on ${repository}" >&2 - return 1 - fi - id=$(jq -r --arg name "${name}" \ - '.[] | select(.name == $name) | .id' <<<"${existing}") - current='{}' - if [[ -n ${id} ]]; then - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") - if ! security_ruleset_restoration_allowed "${repository}" "${id}" "${template}" "${current}"; then - echo "error: security gate ownership or managed rule identity changed; retained: ${repository} ${name}" >&2 - return 1 - fi - if security_ruleset_matches "${template}" "${current}"; then - echo "KEEP /repos/${organization}/${repository}/rulesets/${id} ${name}" - continue - fi - fi - # Pending qualification cannot create protection before reviewed intent is - # persisted. Existing effective gates still survive producer failures. - effective_branch= - proven_current=${current} - if [[ ${phase} == pending ]] && { [[ -z ${id} ]] || - ! effective_branch=$(security_gate_applies_to_default_branch "${repository}" "${kind}" "${id}"); }; then - status=0 - reason=$("${root}/bin/security-readiness" "${readiness_mode}" \ - "${organization}/${repository}") || status=$? - if ((status == 0)); then - echo "READY ${organization}/${repository} ${name}: promote reviewed activation intent before installation" - else - echo "PENDING ${organization}/${repository} ${name}: ${reason}" - fi - continue - fi - # Enforced source is durable intent, not a claim about current producer - # health. Restore it only on the same active repository and owned gate. - metadata=$(github_api "repos/${organization}/${repository}") || return 1 - if ! jq -e --argjson id "${active_repository_ids["${repository}"]}" \ - --arg name "${organization}/${repository}" ' - .id == $id and .full_name == $name and .archived == false and - (.default_branch | type == "string" and length > 0) - ' <<<"${metadata}" >/dev/null; then - echo "error: security gate repository identity or archive state changed: ${repository}" >&2 - return 1 - fi - if [[ ${phase} == pending ]] && - [[ $(jq -r '.default_branch | @uri' <<<"${metadata}") != "${effective_branch}" ]]; then - echo "error: default branch changed after existing security gate proof; retained: ${repository} ${name}" >&2 - return 1 - fi - if [[ -n ${id} ]]; then - # Re-read after producer and repository checks: a concurrent policy edit - # must not be overwritten with the earlier restoration decision. - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || { - echo "error: security gate final read failed; retained: ${repository} ${name}" >&2 - return 1 - } - if ! security_ruleset_restoration_allowed "${repository}" "${id}" "${template}" "${current}"; then - echo "error: security gate changed during restoration preflight; retained: ${repository} ${name}" >&2 - return 1 - fi - # Pending intent may preserve a proven effective gate, but cannot - # restore protection revoked after that proof. Only enforced intent - # authorizes enforcement or ref-scope restoration without qualification. - if [[ ${phase} == pending ]] && ! jq -e --argjson proven "${proven_current}" ' - def protection: - {enforcement, ref_name: (.conditions.ref_name | - .include |= sort | .exclude |= sort)}; - protection == ($proven | protection) - ' <<<"${current}" >/dev/null; then - echo "error: existing security gate protection changed after effective proof; retained: ${repository} ${name}" >&2 - return 1 - fi - if security_ruleset_matches "${template}" "${current}"; then - echo "KEEP /repos/${organization}/${repository}/rulesets/${id} ${name}" - continue - fi - preserved_payload=$(mktemp) - temporary_files+=("${preserved_payload}") - jq -L "${root}/lib" --slurpfile desired "${template}" ' - include "ruleset-policy"; prepare_policy($desired[0]) - ' <<<"${current}" >"${preserved_payload}" || return 1 - run_api PUT "repos/${organization}/${repository}/rulesets/${id}" "${preserved_payload}" - else - run_api POST "repos/${organization}/${repository}/rulesets" "${template}" - fi - done < <(jq -r --arg kind "${kind}" '.[$kind][]' "${security_merge_config}") - done -} - -# Required CI stops requiring a current branch only where the queue protects -# the branch: the repository is listed and active and, when applying, a fresh -# read just before required CI is published shows the exact repository-owned -# queue. A plan reports the queue publisher's planned installation instead. -# Sets verified_merge_queue_repositories to a JSON array. -verify_installed_merge_queues() { - local repository name existing id current template - local -a queued=() - - name=$(jq -r '.name' "${root}/config/rulesets/merge-queue.json") - while IFS= read -r repository; do - [[ -v active_repository_ids["${repository}"] ]] || continue - if ${apply}; then - existing=$(list_rulesets \ - "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - id=$(jq -r --arg name "${name}" \ - '.[] | select(.name == $name) | .id' <<<"${existing}") - current='{}' - if [[ -n ${id} ]]; then - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - fi - template=$(make_merge_queue_ruleset "${repository}") - temporary_files+=("${template}") - if [[ -z ${id} ]] || - ! owned_security_ruleset_matches "${repository}" "${id}" "${template}" "${current}"; then - echo "SKIP ${organization}/${repository} ${name}: queue not verified; required CI stays strict" - continue - fi - fi - queued+=("${repository}") - done < <(jq -r '(.merge_queue // [])[]' "${repositories_config}") - verified_merge_queue_repositories=$(jq -cn '$ARGS.positional' --args "${queued[@]}") -} - -repository_uses_merge_queue() { - local repository=$1 - - jq -e --arg repository "${repository}" \ - '(.merge_queue | index($repository)) != null' \ - "${repositories_config}" >/dev/null -} - -make_merge_queue_ruleset() { - local repository=$1 - local output - - output=$(mktemp) - temporary_files+=("${output}") - # An advisory-level merge needs every rule reported for the branch to be - # bypassable, exactly as for required CI. - jq --arg repository "${repository}" \ - --slurpfile advisory_windows "${advisory_merge_windows_config}" ' - .bypass_actors |= map( - if ($advisory_windows[0].repositories | index($repository)) != null then - .bypass_mode = "always" - else - . - end - ) - ' "${root}/config/rulesets/merge-queue.json" >"${output}" - echo "${output}" -} - -# GitHub supports merge-queue rules only in repository rulesets, so this rule -# is repository-owned in both policy scopes. It is published before required -# CI stops requiring an up-to-date branch for the same repository. -publish_merge_queue_rulesets() { - local repository template name existing id current - - name=$(jq -r '.name' "${root}/config/rulesets/merge-queue.json") - while IFS= read -r repository; do - if [[ ! -v active_repository_ids["${repository}"] ]]; then - echo "SKIP ${organization}/${repository} is not active; ${name}" - continue - fi - template=$(make_merge_queue_ruleset "${repository}") - temporary_files+=("${template}") - existing=$(list_rulesets \ - "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - id=$(jq -r --arg name "${name}" \ - '.[] | select(.name == $name) | .id' <<<"${existing}") - if [[ -z ${id} ]]; then - run_api POST "repos/${organization}/${repository}/rulesets" "${template}" || return 1 - continue - fi - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - if ! jq -e --argjson id "${id}" --arg name "${name}" \ - --arg source "${organization}/${repository}" ' - .id == $id and .name == $name and - .source_type == "Repository" and .source == $source - ' <<<"${current}" >/dev/null; then - echo "error: merge-queue ruleset ownership changed; retained: ${repository} ${name}" >&2 - return 1 - fi - if security_ruleset_matches "${template}" "${current}"; then - echo "KEEP /repos/${organization}/${repository}/rulesets/${id} ${name}" - else - run_api PUT "repos/${organization}/${repository}/rulesets/${id}" \ - "${template}" || return 1 - fi - done < <(jq -r '.merge_queue[]' "${repositories_config}") -} - -# Retire a queue only after required CI again requires an up-to-date branch. -# Only an unmodified repository-owned managed rule is removed. -delete_removed_merge_queue_rulesets() { - local repository template name existing id current metadata - - name=$(jq -r '.name' "${root}/config/rulesets/merge-queue.json") - for repository in "${active_repositories[@]}"; do - if repository_uses_merge_queue "${repository}"; then - continue - fi - existing=$(list_rulesets \ - "repos/${organization}/${repository}/rulesets?includes_parents=false") || return 1 - id=$(jq -r --arg name "${name}" \ - '.[] | select(.name == $name) | .id' <<<"${existing}") - [[ -n ${id} ]] || continue - template=$(make_merge_queue_ruleset "${repository}") - temporary_files+=("${template}") - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || return 1 - if ! owned_security_ruleset_matches "${repository}" "${id}" "${template}" "${current}"; then - echo "SKIP ${organization}/${repository} ${name}: unrecognized ownership or payload; retained" - continue - fi - metadata=$(github_api "repos/${organization}/${repository}") || return 1 - if ! jq -e --argjson id "${active_repository_ids["${repository}"]}" \ - --arg full_name "${organization}/${repository}" ' - .id == $id and .full_name == $full_name and .archived == false - ' <<<"${metadata}" >/dev/null; then - echo "SKIP ${organization}/${repository} ${name}: repository identity or archive state changed; retained" - continue - fi - # Re-read immediately before deletion so a concurrent edit is retained. - current=$(github_api "repos/${organization}/${repository}/rulesets/${id}") || { - echo "error: merge-queue final retirement read failed; retained: ${repository} ${name}" >&2 - return 1 - } - if ! owned_security_ruleset_matches "${repository}" "${id}" "${template}" "${current}"; then - echo "SKIP ${organization}/${repository} ${name}: rule changed during retirement preflight; retained" - continue - fi - run_api DELETE "repos/${organization}/${repository}/rulesets/${id}" || return 1 - done -} - -validate_sha_canary_target() { - local canary=$1 owner repository number metadata - IFS=/ read -r owner repository number <<<"${canary}" - if [[ ${owner} != "${organization}" || ! ${number} =~ ^[1-9][0-9]*$ || - ! ${repository} =~ ^[A-Za-z0-9_.-]+$ ]] || - [[ ! -v active_repository_ids["${repository}"] ]]; then - echo "error: SHA canary must identify an active governed repository in ${organization}" >&2 - return 1 - fi - metadata=$(github_api "repos/${organization}/${repository}") - if ! jq -e --argjson id "${active_repository_ids["${repository}"]}" \ - --arg name "${organization}/${repository}" ' - .id == $id and .full_name == $name and .archived == false - ' <<<"${metadata}" >/dev/null; then - echo "error: SHA canary repository identity or archive state changed" >&2 - return 1 - fi -} - -converge_actions_permissions() { - local current selected input reason phase canary staging_needed=false - local permissions_filter='type == "object" and - (.enabled_repositories | IN("all", "none", "selected")) and - (.allowed_actions | IN("all", "local_only", "selected")) and - (.sha_pinning_required == null or (.sha_pinning_required | type == "boolean"))' - current=$(github_api "orgs/${organization}/actions/permissions") || return 1 - if ! jq -e "${permissions_filter}" <<<"${current}" >/dev/null; then - echo "error: cannot read current organization Actions permissions" >&2 - return 1 - fi - phase=$(jq -r '.phase' "${root}/config/actions-sha-pinning.json") - canary=$(jq -r '.canary // empty' "${root}/config/actions-sha-pinning.json") - if [[ ${phase} == pending && -n ${sha_pinning_canary} ]]; then - validate_sha_canary_target "${sha_pinning_canary}" || return 1 - elif [[ ${phase} == enforced ]] && - ! jq -e '.sha_pinning_required == true' <<<"${current}" >/dev/null; then - validate_sha_canary_target "${canary}" || return 1 - fi - - # GitHub requires selected mode before its selected-actions endpoint can be - # updated. Stage both conservative controls before proving SHA compatibility. - # Omit SHA entirely: this preserves an existing value without enabling it - # from a stale read if another actor changes the field during staging. - input=$(mktemp) - temporary_files+=("${input}") - jq 'del(.sha_pinning_required)' "${root}/config/actions-permissions.json" >"${input}" - if jq -e --slurpfile desired "${input}" ' - . as $current | all($desired[0] | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - echo "KEEP /orgs/${organization}/actions/permissions" - else - staging_needed=true - run_api PUT "orgs/${organization}/actions/permissions" "${input}" || return 1 - fi - # This endpoint may require selected mode. A dry run with a mode change - # can plan its update, but cannot claim to have read the staged live policy. - if ! ${apply} && [[ $(jq -r '.allowed_actions' <<<"${current}") != selected ]]; then - selected=null - else - selected=$(github_api "orgs/${organization}/actions/permissions/selected-actions") || return 1 - if ! jq -e ' - (.github_owned_allowed | type == "boolean") and - (.verified_allowed | type == "boolean") and - (.patterns_allowed | type == "array" and all(.[]; type == "string")) - ' <<<"${selected}" >/dev/null; then - echo "error: cannot read current selected Actions policy" >&2 - return 1 - fi - fi - if jq -e --slurpfile desired "${root}/config/actions-selected.json" ' - .github_owned_allowed == $desired[0].github_owned_allowed and - .verified_allowed == $desired[0].verified_allowed and - (.patterns_allowed | sort) == ($desired[0].patterns_allowed | sort) - ' <<<"${selected}" >/dev/null; then - echo "KEEP /orgs/${organization}/actions/permissions/selected-actions" - else - staging_needed=true - run_api PUT "orgs/${organization}/actions/permissions/selected-actions" \ - "${root}/config/actions-selected.json" || return 1 - fi - if ${apply}; then - # Base the SHA decision on live post-staging state: another writer may - # disable it while conservative mode or pattern updates are in flight. - current=$(github_api "orgs/${organization}/actions/permissions") || return 1 - if ! jq -e "${permissions_filter}" <<<"${current}" >/dev/null || - ! jq -e --slurpfile desired "${input}" ' - . as $current | all($desired[0] | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - echo "error: organization Actions permissions unreadable or changed during staging" >&2 - return 1 - fi - fi - # An explicitly requested pending-phase probe is read-only and independent - # of whether SHA pinning is already enabled. Do not let preservation skip it. - if [[ ${phase} == pending && -n ${sha_pinning_canary} ]]; then - validate_sha_canary_target "${sha_pinning_canary}" || return 1 - if reason=$("${root}/bin/security-readiness" sha "${sha_pinning_canary}"); then - echo "READY canary evidence: ${reason}; source rollout phase remains pending" - else - echo "PENDING canary evidence: ${reason}" - fi - fi - if jq -e '.sha_pinning_required == true' <<<"${current}" >/dev/null; then - return 0 - fi - if [[ ${phase} == enforced ]]; then - if ! ${apply} && ${staging_needed}; then - echo "PLAN SHA pinning proof and restoration after Actions policy staging is applied" - return 0 - fi - validate_sha_canary_target "${canary}" || return 1 - if ! reason=$("${root}/bin/security-readiness" sha "${canary}"); then - echo "error: enforced SHA pinning cannot be restored: ${reason}" >&2 - return 1 - fi - echo "READY enforced SHA pinning: ${reason}" - run_api PUT "orgs/${organization}/actions/permissions" \ - "${root}/config/actions-permissions.json" || return 1 - else - echo "PENDING SHA pinning: promote the reviewed source rollout phase and accepted canary after readiness" - fi -} - -converge_repository_workflow_permissions() { - local repository current - for repository in "${active_repositories[@]}"; do - [[ -v active_repository_ids["${repository}"] ]] || continue - current=$(github_api "repos/${organization}/${repository}/actions/permissions/workflow") - if ! jq -e 'type == "object" and - (.default_workflow_permissions | IN("read", "write")) and - (.can_approve_pull_request_reviews | type == "boolean") - ' <<<"${current}" >/dev/null; then - echo "error: cannot read repository workflow permissions: ${repository}" >&2 - return 1 - fi - if jq -e --slurpfile desired "${root}/config/actions-workflow.json" ' - . as $current | all($desired[0] | to_entries[]; $current[.key] == .value) - ' <<<"${current}" >/dev/null; then - echo "KEEP /repos/${organization}/${repository}/actions/permissions/workflow" - else - run_api PUT "repos/${organization}/${repository}/actions/permissions/workflow" \ - "${root}/config/actions-workflow.json" - fi - done -} - -publish_organization_security() { - local advanced_id baseline_id defaults_payload defaults - local advanced_repository_count baseline_repository_count - - # Move governed advanced-setup repositories first. This prevents a baseline - # update from temporarily re-enabling default setup during later publishes. - upsert_code_security_configuration \ - "${root}/config/code-security-advanced.json" \ - '{advanced-codeql-configuration-id}' - advanced_id=${upserted_code_security_configuration_id} - advanced_repository_count=$(jq '.repositories | length' \ - "${codeql_advanced_config}") - if ((advanced_repository_count > 0)); then - converge_security_configuration_attachments \ - true "${advanced_id}" "${advanced_repository_count}" - else - echo "SKIP advanced CodeQL attachment: inventory is empty" - fi - - upsert_code_security_configuration \ - "${root}/config/code-security.json" \ - '{baseline-configuration-id}' - baseline_id=${upserted_code_security_configuration_id} - - defaults_payload=$(mktemp) - temporary_files+=("${defaults_payload}") - jq -n '{default_for_new_repos: "all"}' >"${defaults_payload}" - defaults=$(github_api \ - "orgs/${organization}/code-security/configurations/defaults") - if jq -e --arg id "${baseline_id}" ' - any( - .[]; - ( - ( - .configuration.id // .configuration.value.id // null | - tostring - ) == $id - ) and - .default_for_new_repos == "all" - ) - ' <<<"${defaults}" >/dev/null; then - echo "KEEP /orgs/${organization}/code-security/configurations/${baseline_id}/defaults is all" - else - run_api PUT \ - "orgs/${organization}/code-security/configurations/${baseline_id}/defaults" \ - "${defaults_payload}" - fi - - baseline_repository_count=$((${#active_repositories[@]} - \ - advanced_repository_count)) - converge_security_configuration_attachments \ - false "${baseline_id}" "${baseline_repository_count}" - - converge_codeql_default_setup -} - -publish_repository_security() { - local repository - - for repository in "${active_repositories[@]}"; do - run_api PATCH "repos/${organization}/${repository}" \ - "${root}/config/repository-security.json" - run_api PUT "repos/${organization}/${repository}/vulnerability-alerts" - run_api PUT "repos/${organization}/${repository}/automated-security-fixes" - run_api PUT "repos/${organization}/${repository}/private-vulnerability-reporting" - done - - converge_codeql_default_setup -} - -current_immutable_release_payload() { - local response mode selected_repository_ids - - if ! response=$(github_api \ - "orgs/${organization}/settings/immutable-releases"); then - echo "error: failed to read the organization immutable-release policy" >&2 - return 1 - fi - mode=$(jq -r '.enforced_repositories // empty' <<<"${response}") - case ${mode} in - all | none) - jq -cn --arg mode "${mode}" '{enforced_repositories: $mode}' - ;; - selected) - if ! selected_repository_ids=$( - github_api --paginate \ - "orgs/${organization}/settings/immutable-releases/repositories?per_page=100" \ - --jq '.repositories[].id' | jq -cs 'map(tonumber) | sort | unique' - ); then - echo "error: failed to read repositories selected for immutable releases" >&2 - return 1 - fi - jq -cn \ - --argjson selected_repository_ids "${selected_repository_ids}" \ - '{ - enforced_repositories: "selected", - selected_repository_ids: $selected_repository_ids - }' - ;; - *) - echo "error: unsupported immutable-release policy mode: ${mode:-missing}" >&2 - return 1 - ;; - esac -} - -immutable_release_policy_matches() { - local expected=$1 - local verify_owner_enforcement=$2 - local current repository response - - if ! current=$(current_immutable_release_payload); then - return 1 - fi - if ! jq -e --argjson expected "${expected}" \ - '. == $expected' <<<"${current}" >/dev/null; then - return 1 - fi - - if [[ ${verify_owner_enforcement} != true ]]; then - return 0 - fi - while IFS= read -r repository; do - if ! response=$(github_api \ - "repos/${organization}/${repository}/immutable-releases"); then - return 1 - fi - if ! jq -e \ - '.enabled == true and .enforced_by_owner == true' \ - <<<"${response}" >/dev/null; then - return 1 - fi - done < <(jq -r '.repositories[].name' "${immutable_releases_config}") -} - -write_immutable_release_payload() { - local payload=$1 - local output - - output=$(mktemp) - jq . <<<"${payload}" >"${output}" - printf '%s\n' "${output}" -} - -rollback_immutable_release_policy() { - local snapshot=$1 - local input - - input=$(write_immutable_release_payload "${snapshot}") - temporary_files+=("${input}") - echo "ROLLBACK PUT /orgs/${organization}/settings/immutable-releases <= ${snapshot}" >&2 - if ! github_api --method PUT \ - "orgs/${organization}/settings/immutable-releases" \ - --input "${input}" >/dev/null; then - echo "error: immutable-release policy rollback request failed" >&2 - return 1 - fi - if ! immutable_release_policy_matches "${snapshot}" false; then - echo "error: immutable-release policy rollback verification failed" >&2 - return 1 - fi - echo "ROLLBACK verified the previous immutable-release policy" >&2 -} - -converge_immutable_release_policy() { - local desired snapshot input - - desired=$(jq -c ' - { - enforced_repositories, - selected_repository_ids: ([.repositories[].id] | sort) - } - ' "${immutable_releases_config}") - if immutable_release_policy_matches "${desired}" true; then - echo "KEEP /orgs/${organization}/settings/immutable-releases is ${desired}" - return 0 - fi - - if ! snapshot=$(current_immutable_release_payload); then - return 1 - fi - if ! ${apply}; then - echo "PLAN PUT /orgs/${organization}/settings/immutable-releases <= ${desired}" - while IFS= read -r repository; do - echo "PLAN VERIFY /repos/${organization}/${repository}/immutable-releases" \ - "=> enabled=true,enforced_by_owner=true" - done < <(jq -r '.repositories[].name' "${immutable_releases_config}") - return 0 - fi - - input=$(write_immutable_release_payload "${desired}") - temporary_files+=("${input}") - assert_metaserver_immutable_source_fresh - if github_api --method PUT \ - "orgs/${organization}/settings/immutable-releases" \ - --input "${input}" >/dev/null && - immutable_release_policy_matches "${desired}" true; then - echo "APPLY /orgs/${organization}/settings/immutable-releases <= ${desired}" - return 0 - fi - - echo "error: immutable-release policy apply or verification failed" >&2 - if ! rollback_immutable_release_policy "${snapshot}"; then - echo "error: previous immutable-release policy could not be restored" >&2 - fi - return 1 -} - -qualify_metaserver_immutable_source() { - local source_sha configuration source_runs script_path source_file - - source_sha=$(github_api "repos/${organization}/metaserver-worker/git/ref/heads/main" | - jq -er 'select(.ref == "refs/heads/main" and .object.type == "commit") | .object.sha | - select(test("^[0-9a-f]{40}$"))') - configuration=$(github_api \ - "repos/${organization}/metaserver-worker/contents/.releaserc.json?ref=${source_sha}" | - jq -er 'select(.type == "file" and .encoding == "base64") | .content' | base64 --decode) - if ! jq -e ' - [.plugins[] | select(type == "array" and .[0] == "@semantic-release/github")] as $github | - (.plugins | index([$github[0]])) as $draft_index | - ($github | length) == 1 and $github[0][1].draftRelease == true and - $draft_index != null and .plugins[$draft_index + 1] == "./scripts/release/publish-complete-release.cjs" - ' <<<"${configuration}" >/dev/null; then - echo "error: metaserver immutable selection requires the qualified draft-first producer" >&2 - return 1 - fi - for script_path in scripts/release/publish-complete-release.cjs scripts/release/publish-complete-release.mjs; do - source_file=$(github_api \ - "repos/${organization}/metaserver-worker/contents/${script_path}?ref=${source_sha}") - jq -e 'select(.type == "file" and .encoding == "base64" and - (.size | type == "number" and floor == . and . > 0 and . <= 65536) and - (.content | type == "string" and length <= 90000))' \ - <<<"${source_file}" >/dev/null - done - source_runs=$(github_api \ - "repos/${organization}/metaserver-worker/actions/workflows/check.yml/runs?branch=main&event=push&head_sha=${source_sha}&per_page=100") - if ! jq -e --arg sha "${source_sha}" --arg repository "${organization}/metaserver-worker" ' - any(.workflow_runs[]; - .head_sha == $sha and .head_branch == "main" and .event == "push" and - .head_repository.full_name == $repository and - .status == "completed" and .conclusion == "success") - ' <<<"${source_runs}" >/dev/null; then - echo "error: metaserver immutable selection requires successful exact-main source validation" >&2 - return 1 - fi - if [[ $(github_api "repos/${organization}/metaserver-worker/git/ref/heads/main" | - jq -r '.object.sha') != "${source_sha}" ]]; then - echo "error: metaserver main moved during immutable qualification" >&2 - return 1 - fi - qualified_metaserver_source_sha=${source_sha} - echo "KEEP metaserver draft-first source at ${source_sha}; independent qualification remains required" -} - -assert_metaserver_immutable_source_fresh() { - [[ -n ${qualified_metaserver_source_sha} ]] || return 0 - local current_sha - - current_sha=$(github_api "repos/${organization}/metaserver-worker/git/ref/heads/main" | - jq -er 'select(.ref == "refs/heads/main" and .object.type == "commit") | .object.sha | - select(test("^[0-9a-f]{40}$"))') - if [[ ${current_sha} != "${qualified_metaserver_source_sha}" ]]; then - echo "error: metaserver main moved after source qualification; no initial immutable selection performed" >&2 - return 1 - fi -} - -preflight_new_crate_immutable_selection() { - local snapshot additions repository - ${apply} || return 0 - snapshot=$(current_immutable_release_payload) - additions=$(jq -cn --argjson current "${snapshot}" \ - --slurpfile desired "${immutable_releases_config}" ' - if $current.enforced_repositories == "all" then [] - elif $current.enforced_repositories == "none" then [$desired[0].repositories[].id] - else [$desired[0].repositories[].id] - $current.selected_repository_ids end - ') - if jq -e --argjson additions "${additions}" \ - 'any(.repositories[]; .name == "metaserver-worker" and (.id as $id | $additions | index($id) != null))' \ - "${immutable_releases_config}" >/dev/null; then - qualify_metaserver_immutable_source - fi - while IFS= read -r repository; do - # These are the newly introduced library producers; Classic retains its - # existing separately qualified release policy. Missing manual records fail - # the scoped verifier rather than silently skipping qualification. - "${root}/bin/verify-manual-settings" --crate-publication-setup "${organization}/${repository}" - done < <(jq -r --argjson additions "${additions}" ' - .repositories[] | select(.name | IN("protocol", "content-toolkit")) | - select(.id as $id | $additions | index($id) != null) | .name - ' "${immutable_releases_config}") - if [[ $(current_immutable_release_payload) != "${snapshot}" ]]; then - echo "error: immutable-release policy changed during initial qualification; no broad apply performed" >&2 - exit 1 - fi - assert_metaserver_immutable_source_fresh -} - -organization_metadata=$(github_api "orgs/${organization}") -if ! jq -e 'type == "object" and (.plan.name | type == "string")' \ - <<<"${organization_metadata}" >/dev/null; then - echo "error: GitHub returned invalid organization metadata" >&2 - exit 1 -fi -organization_plan=$(jq -r '.plan.name' <<<"${organization_metadata}") -if [[ ${policy_scope} == auto ]]; then - case ${organization_plan} in - team | enterprise) policy_scope=organization ;; - *) policy_scope=repository ;; - esac -fi - -echo "Organization: ${organization}" -echo "Plan: ${organization_plan}" -echo "Policy scope: ${policy_scope}" -${apply} && echo "Mode: apply" || echo "Mode: plan" - -declare -a active_repositories=() -declare -A active_repository_ids=() -declare -A active_repository_visibility=() -while IFS=$'\t' read -r \ - repository id private visibility disabled fork has_issues has_projects has_wiki; do - if [[ ! ${id} =~ ^[0-9]+$ ]]; then - echo "error: invalid repository id for ${repository}: ${id}" >&2 - exit 1 - fi - if is_temporary_security_advisory_repository \ - "${repository}" "${private}" "${visibility}" "${disabled}" "${fork}" \ - "${has_issues}" "${has_projects}" "${has_wiki}"; then - echo "SKIP ${organization}/${repository} is a temporary security-advisory workspace" - continue - fi - active_repositories+=("${repository}") - active_repository_ids["${repository}"]=${id} - active_repository_visibility["${repository}"]=${visibility} -done < <( - github_api --paginate "orgs/${organization}/repos?per_page=100&type=all" \ - --jq ' - .[] | - select(.archived == false) | - [ - .name, - .id, - .private, - .visibility, - .disabled, - .fork, - .has_issues, - .has_projects, - .has_wiki - ] | - @tsv - ' -) - -declare -A governed_active_repositories=() -while IFS= read -r repository; do - governed_active_repositories["${repository}"]=true -done < <( - jq -r '[".github"] + .pull_request_gate | .[]' "${repositories_config}" -) - -while IFS= read -r repository; do - if [[ ! -v governed_active_repositories["${repository}"] ]]; then - echo "error: live active repository is not in the governance inventory: ${organization}/${repository}" >&2 - exit 1 - fi -done < <(printf '%s\n' "${active_repositories[@]}" | sort) - -while IFS= read -r repository; do - if [[ ! -v active_repository_ids["${repository}"] ]]; then - echo "error: advanced CodeQL inventory repository is not active: ${repository}" >&2 - exit 1 - fi -done < <(jq -r '.repositories[]' "${codeql_advanced_config}") - -# Team offers merge queue only for public repositories. Fail before any write -# rather than relaxing required CI for a repository that cannot use a queue. -# Inactive entries are skipped by the queue publisher, like security gates. -while IFS= read -r repository; do - [[ -v active_repository_ids["${repository}"] ]] || continue - if [[ ${active_repository_visibility["${repository}"]} != public && - ${organization_plan} != enterprise ]]; then - echo "error: merge queue requires a public repository on the ${organization_plan} plan: ${repository}" >&2 - exit 1 - fi -done < <(jq -r '.merge_queue[]' "${repositories_config}") - -while IFS=$'\t' read -r repository expected_id; do - if [[ ! -v active_repository_ids["${repository}"] ]]; then - echo "error: immutable-release inventory repository is not active: ${repository}" >&2 - exit 1 - fi - if [[ ${active_repository_ids["${repository}"]} != "${expected_id}" ]]; then - echo "error: immutable-release inventory id for ${repository} is" \ - "${expected_id}, but GitHub reports" \ - "${active_repository_ids["${repository}"]}" >&2 - exit 1 - fi -done < <( - jq -r '.repositories[] | [.name, .id] | @tsv' \ - "${immutable_releases_config}" -) - -preflight_new_crate_immutable_selection -converge_immutable_release_policy - -converge_organization_settings "${organization_metadata}" -converge_actions_permissions -converge_settings PUT "orgs/${organization}/actions/permissions/workflow" \ - "${root}/config/actions-workflow.json" - -for repository in "${active_repositories[@]}"; do - converge_settings PATCH "repos/${organization}/${repository}" \ - "${root}/config/repository-defaults.json" -done - -converge_repository_workflow_permissions - -publish_merge_queue_rulesets - -if [[ ${policy_scope} == organization ]]; then - publish_organization_rulesets - publish_organization_security -else - publish_repository_rulesets - publish_repository_security -fi - -publish_security_merge_rulesets -delete_removed_merge_queue_rulesets - -while IFS= read -r repository; do - if ! repository_archived=$( - github_api "repos/${organization}/${repository}" --jq '.archived' 2>/dev/null - ); then - echo "SKIP ${organization}/${repository} does not exist" - continue - fi - - if [[ ${repository_archived} == true ]]; then - echo "SKIP ${organization}/${repository} is already archived" - continue - fi - - archive_payload=$(mktemp) - temporary_files+=("${archive_payload}") - jq -n '{archived: true}' >"${archive_payload}" - run_api PATCH "repos/${organization}/${repository}" "${archive_payload}" -done < <(jq -r '.archive[]' "${repositories_config}") - -if [[ $(jq -r '.members_can_create_teams' <<<"${organization_metadata}") != false ]]; then - echo "MANUAL members can still create teams; disable this in Member privileges." -fi -while IFS= read -r external_app; do - app_slug=$(jq -r '.app_slug' <<<"${external_app}") - installation_id=$(jq -r '.installation_id' <<<"${external_app}") - repositories=$(jq -r '[.repositories[].repository] | join(", ")' <<<"${external_app}") - echo "MANUAL ${app_slug} installation ${installation_id} selected repositories: ${repositories}; publisher does not apply" -done < <(jq -c '.external_provider_apps[]' "${root}/config/manual-settings.json") -while IFS= read -r crate_record; do - repository=$(jq -r '.repository' <<<"${crate_record}") - crate=$(jq -r '.crates | join(",")' <<<"${crate_record}") - state=$(jq -r '"source=\(.source_state), environment=\(.environment_state), registration=\(.publisher_registration.state)"' <<<"${crate_record}") - echo "MANUAL ${repository} crates.io ${crate}: ${state}; reviewed source/version merge, automatic crates-io-release environment (zero reviewers/wait), and Trusted Publisher owner setup; publisher does not apply" -done < <(jq -c '.crates_io_trusted_publishing[]' "${root}/config/manual-settings.json") -while IFS= read -r package_record; do - repository=$(jq -r '.actions_repository' <<<"${package_record}") - package_name=$(jq -r '.package_name' <<<"${package_record}") - grant_state=$(jq -r '.grant_state // "manual-owner-ui"' <<<"${package_record}") - echo "MANUAL ${repository} read-only package Actions access to ${package_name}: ${grant_state}; publisher never provisions grants" -done < <(jq -c '.github_packages_actions_access[]' "${root}/config/manual-settings.json") -app_state=$(jq -r '.crate_dependency_update_app | "identity=\(.status), credential_names=\(.credential_state), workflow=\(.workflow_activation.state)"' "${root}/config/manual-settings.json") -echo "MANUAL atrinik-crate-dependency-update ${app_state} selected client App and credential slots; publisher does not apply" -echo "Manual confirmation required for config/manual-settings.json." diff --git a/bin/publish-community-health b/bin/publish-community-health deleted file mode 100755 index 3085b5a..0000000 --- a/bin/publish-community-health +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 -apply=false - -case ${1:-} in -"") ;; ---apply) apply=true ;; -*) - echo "usage: $0 [--apply]" >&2 - exit 2 - ;; -esac - -for command in base64 gh jq; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -community_config=${root}/config/community-health.json -temporary_files=() -trap 'rm -f "${temporary_files[@]}"' EXIT - -"${root}/bin/validate" >/dev/null - -github_api() { - gh api -H "X-GitHub-Api-Version: ${api_version}" "$@" -} - -run_api() { - local method=$1 - local endpoint=$2 - local input=$3 - - if ${apply}; then - github_api --method "${method}" "${endpoint}" --input "${input}" \ - >/dev/null - echo "APPLY ${method} /${endpoint}" - else - echo "PLAN ${method} /${endpoint} <= ${input#"${root}/"}" - fi -} - -repository=$(jq -r '.repository.name' "${community_config}") -repository_created=false -if current_repository=$(github_api "repos/${organization}/${repository}" \ - 2>/dev/null); then - desired_repository=$(jq -c '.repository' "${community_config}") - if jq -e --argjson desired "${desired_repository}" ' - { - name, - description, - private, - has_issues, - has_projects, - has_wiki - } == $desired - ' <<<"${current_repository}" >/dev/null; then - echo "KEEP /repos/${organization}/${repository} metadata" - else - input=$(mktemp) - temporary_files+=("${input}") - jq '.repository | del(.name)' "${community_config}" >"${input}" - run_api PATCH "repos/${organization}/${repository}" "${input}" - fi -else - input=$(mktemp) - temporary_files+=("${input}") - jq '.repository + {auto_init: false}' "${community_config}" >"${input}" - run_api POST "orgs/${organization}/repos" "${input}" - repository_created=true -fi - -first_file=true -while IFS=$'\t' read -r source target; do - local_path=${root}/community-health/${source} - local_content=$(base64 -w 0 "${local_path}") - remote_sha= - remote_content= - if ! ${repository_created}; then - if current=$(github_api \ - "repos/${organization}/${repository}/contents/${target}?ref=main" \ - 2>/dev/null); then - remote_sha=$(jq -r '.sha // empty' <<<"${current}") - remote_content=$(jq -r '.content // empty' <<<"${current}" | tr -d '\n') - fi - fi - - if [[ -n ${remote_sha} ]] && [[ ${remote_content} == "${local_content}" ]]; then - echo "KEEP /repos/${organization}/${repository}/contents/${target}" - first_file=false - continue - fi - - input=$(mktemp) - temporary_files+=("${input}") - omit_branch=false - if ${repository_created} && ${first_file}; then - omit_branch=true - fi - jq -n \ - --arg message "chore: synchronize organization community health defaults" \ - --arg content "${local_content}" \ - --arg sha "${remote_sha}" \ - --arg branch main \ - --argjson omit_branch "${omit_branch}" ' - {message: $message, content: $content} + - (if $sha == "" then {} else {sha: $sha} end) + - (if $omit_branch then {} else {branch: $branch} end) - ' >"${input}" - run_api PUT \ - "repos/${organization}/${repository}/contents/${target}" "${input}" - first_file=false -done < <(jq -r '.files[] | [.source, .target] | @tsv' "${community_config}") - -echo "Organization community health defaults are converged." diff --git a/bin/publish-planning b/bin/publish-planning deleted file mode 100755 index 824cdd0..0000000 --- a/bin/publish-planning +++ /dev/null @@ -1,527 +0,0 @@ -#!/usr/bin/env bash - -# GraphQL variable names are intentionally literal dollar-prefixed strings. -# shellcheck disable=SC2016 - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 -apply=false - -case ${1:-} in -"") ;; ---apply) apply=true ;; -*) - echo "usage: $0 [--apply]" >&2 - exit 2 - ;; -esac - -for command in gh jq; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -planning_config=${root}/config/planning.json - -"${root}/bin/validate" >/dev/null - -github_api() { - gh api -H "X-GitHub-Api-Version: ${api_version}" "$@" -} - -graphql() { - local query=$1 - local variables=$2 - local input response - - input=$(mktemp) - jq -n --arg query "${query}" --argjson variables "${variables}" \ - '{query: $query, variables: $variables}' >"${input}" - if ! response=$(github_api graphql --input "${input}"); then - rm -f "${input}" - return 1 - fi - rm -f "${input}" - printf '%s\n' "${response}" -} - -organization_query='query($login:String!){organization(login:$login){id issueTypes(first:25){nodes{id name description color isEnabled}} issueFields(first:50){nodes{... on IssueFieldCommon{name description dataType visibility} ... on IssueFieldDate{id} ... on IssueFieldNumber{id} ... on IssueFieldText{id} ... on IssueFieldSingleSelect{id options{id name description color}} ... on IssueFieldMultiSelect{id options{id name description color}}}} projectsV2(first:50){nodes{id number title shortDescription readme public closed}}}}' -organization_data=$(graphql "${organization_query}" \ - "$(jq -cn --arg login "${organization}" '{login: $login}')") -if jq -e '.errors | length > 0' <<<"${organization_data}" >/dev/null; then - jq -r '.errors[].message' <<<"${organization_data}" >&2 - exit 1 -fi -organization_data=$(jq -c '.data.organization' <<<"${organization_data}") -organization_id=$(jq -r '.id' <<<"${organization_data}") - -while IFS= read -r desired; do - name=$(jq -r '.name' <<<"${desired}") - current=$(jq -c --arg name "${name}" ' - .issueTypes.nodes | map(select(.name == $name))[0] // null - ' <<<"${organization_data}") - desired_comparison=$(jq -c '{ - name, - description, - color, - isEnabled: .enabled - }' <<<"${desired}") - - if jq -e --argjson desired "${desired_comparison}" ' - {name, description, color, isEnabled} == $desired - ' <<<"${current}" >/dev/null; then - echo "KEEP organization issue type ${name}" - continue - fi - - if [[ ${current} == null ]]; then - variables=$(jq -cn \ - --arg ownerId "${organization_id}" \ - --arg name "${name}" \ - --arg description "$(jq -r '.description' <<<"${desired}")" \ - --arg color "$(jq -r '.color' <<<"${desired}")" \ - --argjson isEnabled "$(jq '.enabled' <<<"${desired}")" ' - {input: { - ownerId: $ownerId, - name: $name, - description: $description, - color: $color, - isEnabled: $isEnabled - }} - ') - if ${apply}; then - response=$(graphql \ - 'mutation($input:CreateIssueTypeInput!){createIssueType(input:$input){issueType{id}}}' \ - "${variables}") - jq -e '.data.createIssueType.issueType.id | length > 0' \ - <<<"${response}" >/dev/null - echo "APPLY create organization issue type ${name}" - else - echo "PLAN create organization issue type ${name}" - fi - else - id=$(jq -r '.id' <<<"${current}") - variables=$(jq -cn \ - --arg issueTypeId "${id}" \ - --arg name "${name}" \ - --arg description "$(jq -r '.description' <<<"${desired}")" \ - --arg color "$(jq -r '.color' <<<"${desired}")" \ - --argjson isEnabled "$(jq '.enabled' <<<"${desired}")" ' - {input: { - issueTypeId: $issueTypeId, - name: $name, - description: $description, - color: $color, - isEnabled: $isEnabled - }} - ') - if ${apply}; then - graphql \ - 'mutation($input:UpdateIssueTypeInput!){updateIssueType(input:$input){issueType{id}}}' \ - "${variables}" >/dev/null - echo "APPLY update organization issue type ${name}" - else - echo "PLAN update organization issue type ${name}" - fi - fi -done < <(jq -c '.issue_types[]' "${planning_config}") - -declare -A issue_field_ids=() -while IFS= read -r desired; do - name=$(jq -r '.name' <<<"${desired}") - current=$(jq -c --arg name "${name}" ' - .issueFields.nodes | map(select(.name == $name))[0] // null - ' <<<"${organization_data}") - desired_comparison=$(jq -c ' - { - name, - description, - dataType: .data_type, - visibility - } + - if has("options") then - {options: [.options[] | {name, description, color}]} - else - {} - end - ' <<<"${desired}") - - if jq -e --argjson desired "${desired_comparison}" ' - ({name, description, dataType, visibility} + - if has("options") then - {options: [.options[] | {name, description, color}]} - else - {} - end) == $desired - ' <<<"${current}" >/dev/null; then - issue_field_ids["${name}"]=$(jq -r '.id' <<<"${current}") - echo "KEEP organization issue field ${name}" - continue - fi - - options=$(jq -c ' - if has("options") then - [.options | to_entries[] | .value + {priority: .key}] - else - null - end - ' <<<"${desired}") - if [[ ${current} == null ]]; then - variables=$(jq -cn \ - --arg ownerId "${organization_id}" \ - --arg name "${name}" \ - --arg description "$(jq -r '.description' <<<"${desired}")" \ - --arg dataType "$(jq -r '.data_type' <<<"${desired}")" \ - --arg visibility "$(jq -r '.visibility' <<<"${desired}")" \ - --argjson options "${options}" ' - {input: ({ - ownerId: $ownerId, - name: $name, - description: $description, - dataType: $dataType, - visibility: $visibility - } + if $options == null then {} else {options: $options} end)} - ') - if ${apply}; then - response=$(graphql \ - 'mutation($input:CreateIssueFieldInput!){createIssueField(input:$input){issueField{... on IssueFieldDate{id} ... on IssueFieldNumber{id} ... on IssueFieldText{id} ... on IssueFieldSingleSelect{id} ... on IssueFieldMultiSelect{id}}}}' \ - "${variables}") - issue_field_ids["${name}"]=$(jq -r \ - '.data.createIssueField.issueField.id' <<<"${response}") - echo "APPLY create organization issue field ${name}" - else - issue_field_ids["${name}"]="{issue-field-${name}}" - echo "PLAN create organization issue field ${name}" - fi - else - id=$(jq -r '.id' <<<"${current}") - issue_field_ids["${name}"]=${id} - options_drift=$(jq -n \ - --argjson desired "${desired_comparison}" \ - --argjson current "${current}" ' - (($desired.options // null) != - (if $current | has("options") then - [$current.options[] | {name, description, color}] - else - null - end)) - ') - description_drift=$(jq -n \ - --arg desired "$(jq -r '.description' <<<"${desired}")" \ - --arg current "$(jq -r '.description // ""' <<<"${current}")" \ - '$desired != $current') - visibility_drift=$(jq -n \ - --arg desired "$(jq -r '.visibility' <<<"${desired}")" \ - --arg current "$(jq -r '.visibility' <<<"${current}")" \ - '$desired != $current') - variables=$(jq -cn \ - --arg id "${id}" \ - --arg description "$(jq -r '.description' <<<"${desired}")" \ - --arg visibility "$(jq -r '.visibility' <<<"${desired}")" \ - --argjson options "${options}" \ - --argjson descriptionDrift "${description_drift}" \ - --argjson visibilityDrift "${visibility_drift}" \ - --argjson optionsDrift "${options_drift}" ' - {input: ( - {id: $id} + - if $descriptionDrift then {description: $description} else {} end + - if $visibilityDrift then {visibility: $visibility} else {} end + - if $optionsDrift then {options: $options} else {} end - )} - ') - if ${apply}; then - graphql \ - 'mutation($input:UpdateIssueFieldInput!){updateIssueField(input:$input){issueField{... on IssueFieldDate{id} ... on IssueFieldNumber{id} ... on IssueFieldText{id} ... on IssueFieldSingleSelect{id} ... on IssueFieldMultiSelect{id}}}}' \ - "${variables}" >/dev/null - echo "APPLY update organization issue field ${name}" - else - echo "PLAN update organization issue field ${name}" - fi - fi -done < <(jq -c '.issue_fields[]' "${planning_config}") - -project_title=$(jq -r '.project.title' "${planning_config}") -project=$(jq -c --arg title "${project_title}" ' - .projectsV2.nodes | map(select(.title == $title))[0] // null -' <<<"${organization_data}") -project_id= -project_number= -if [[ ${project} == null ]]; then - variables=$(jq -cn --arg ownerId "${organization_id}" \ - --arg title "${project_title}" \ - '{input: {ownerId: $ownerId, title: $title}}') - if ${apply}; then - response=$(graphql \ - 'mutation($input:CreateProjectV2Input!){createProjectV2(input:$input){projectV2{id number}}}' \ - "${variables}") - project_id=$(jq -r '.data.createProjectV2.projectV2.id' <<<"${response}") - project_number=$(jq -r '.data.createProjectV2.projectV2.number' \ - <<<"${response}") - echo "APPLY create organization project ${project_title}" - else - project_id='{project-id}' - project_number='{project-number}' - echo "PLAN create organization project ${project_title}" - fi -else - project_id=$(jq -r '.id' <<<"${project}") - project_number=$(jq -r '.number' <<<"${project}") -fi - -desired_project=$(jq -c '.project | { - title, - shortDescription: .short_description, - readme, - public, - closed: false -}' "${planning_config}") -if [[ ${project} != null ]] && jq -e --argjson desired "${desired_project}" ' - {title, shortDescription, readme, public, closed} == $desired -' <<<"${project}" >/dev/null; then - echo "KEEP organization project ${project_title} metadata" -else - variables=$(jq -cn --arg projectId "${project_id}" \ - --argjson desired "${desired_project}" \ - '{input: ($desired + {projectId: $projectId})}') - if ${apply}; then - graphql \ - 'mutation($input:UpdateProjectV2Input!){updateProjectV2(input:$input){projectV2{id}}}' \ - "${variables}" >/dev/null - echo "APPLY update organization project ${project_title} metadata" - else - echo "PLAN update organization project ${project_title} metadata" - fi -fi - -if ! ${apply} && [[ ${project} == null ]]; then - while IFS= read -r field; do - echo "PLAN link organization issue field ${field} to ${project_title}" - done < <(jq -r '.issue_fields[].name' "${planning_config}") - echo "PLAN replace the default Status options for ${project_title}" - while IFS= read -r view; do - echo "PLAN create shared project view ${view}" - done < <(jq -r '.project.views[].name' "${planning_config}") - echo "Project planning configuration is ready to apply." - exit 0 -fi - -project_query='query($id:ID!){node(id:$id){... on ProjectV2{fields(first:100){nodes{... on ProjectV2Field{id name dataType} ... on ProjectV2IterationField{id name dataType} ... on ProjectV2MultiSelectField{id name dataType} ... on ProjectV2SingleSelectField{id name dataType options{id name color description}}}} views(first:50){nodes{id name layout filter fields(first:100){nodes{... on ProjectV2Field{id name} ... on ProjectV2IterationField{id name} ... on ProjectV2MultiSelectField{id name} ... on ProjectV2SingleSelectField{id name}}}}}}}}' -read_project() { - graphql "${project_query}" \ - "$(jq -cn --arg id "${project_id}" '{id: $id}')" | - jq -c '.data.node' -} - -project_data=$(read_project) -while IFS= read -r field_name; do - field_data_type=$(jq -r --arg name "${field_name}" ' - .issue_fields[] | select(.name == $name) | .data_type - ' "${planning_config}") - current_field=$(jq -c --arg name "${field_name}" ' - [.fields.nodes[] | select(.name == $name)][0] // null - ' <<<"${project_data}") - if [[ ${current_field} != null ]]; then - if [[ $(jq -r '.dataType // ""' <<<"${current_field}") != \ - "${field_data_type}" ]]; then - echo "error: ${project_title} field ${field_name} has an incompatible data type" >&2 - exit 1 - fi - echo "KEEP ${project_title} issue field ${field_name}" - continue - fi - variables=$(jq -cn --arg projectId "${project_id}" \ - --arg issueFieldId "${issue_field_ids["${field_name}"]}" ' - {input: {projectId: $projectId, issueFieldId: $issueFieldId}} - ') - if ${apply}; then - graphql \ - 'mutation($input:CreateProjectV2IssueFieldInput!){createProjectV2IssueField(input:$input){clientMutationId}}' \ - "${variables}" >/dev/null - echo "APPLY link organization issue field ${field_name} to ${project_title}" - else - echo "PLAN link organization issue field ${field_name} to ${project_title}" - project_data=$(jq -c \ - --arg id "{project-field-${field_name}}" \ - --arg name "${field_name}" \ - '.fields.nodes += [{id: $id, name: $name}]' \ - <<<"${project_data}") - fi -done < <(jq -r '.issue_fields[].name' "${planning_config}") - -if ${apply}; then - project_data=$(read_project) -fi - -status_field=$(jq -c ' - .fields.nodes | map(select(.name == "Status"))[0] // null -' <<<"${project_data}") -if [[ ${status_field} == null ]]; then - echo "error: ${project_title} has no Status field" >&2 - exit 1 -fi -status_field_id=$(jq -r '.id' <<<"${status_field}") -status_options=$(jq -cn \ - --slurpfile config "${planning_config}" \ - --argjson current "$(jq '.options' <<<"${status_field}")" ' - [ - $config[0].project.statuses[] as $desired | - ( - [$current[] as $option | - select( - $option.name == $desired.name or - ($desired.previous_names | index($option.name)) != null - ) | - $option][0].id // null - ) as $id | - { - name: $desired.name, - color: $desired.color, - description: $desired.description - } + if $id == null then {} else {id: $id} end - ] - ') -status_comparison=$(jq -c '[.[] | {name, color, description}]' \ - <<<"${status_options}") -current_status_comparison=$(jq -c \ - '[.options[] | {name, color, description}]' <<<"${status_field}") -if [[ ${current_status_comparison} == "${status_comparison}" ]]; then - echo "KEEP ${project_title} Status options" -else - variables=$(jq -cn --arg fieldId "${status_field_id}" \ - --argjson singleSelectOptions "${status_options}" ' - {input: { - fieldId: $fieldId, - singleSelectOptions: $singleSelectOptions - }} - ') - if ${apply}; then - graphql \ - 'mutation($input:UpdateProjectV2FieldInput!){updateProjectV2Field(input:$input){projectV2Field{... on ProjectV2SingleSelectField{id}}}}' \ - "${variables}" >/dev/null - echo "APPLY update ${project_title} Status options" - else - echo "PLAN update ${project_title} Status options" - fi -fi - -if ${apply}; then - project_data=$(read_project) -fi - -default_view_id=$(jq -r ' - .views.nodes | map(select(.name == "View 1"))[0].id // empty -' <<<"${project_data}") -while IFS= read -r desired_view; do - view_name=$(jq -r '.name' <<<"${desired_view}") - view_layout=$(jq -r '.layout' <<<"${desired_view}") - supports_visible_fields=true - if [[ ${view_layout} == ROADMAP_LAYOUT ]]; then - supports_visible_fields=false - fi - visible_field_ids=$(jq -cn \ - --argjson view "${desired_view}" \ - --argjson project "${project_data}" ' - [$view.visible_fields[] as $name | - $project.fields.nodes[] | select(.name == $name) | .id] - ') - if [[ $(jq 'length' <<<"${visible_field_ids}") != \ - "$(jq '.visible_fields | length' <<<"${desired_view}")" ]]; then - echo "error: a visible field for ${view_name} is unavailable" >&2 - exit 1 - fi - current_view=$(jq -c --arg name "${view_name}" ' - .views.nodes | map(select(.name == $name))[0] // null - ' <<<"${project_data}") - view_id= - if [[ ${current_view} != null ]]; then - view_id=$(jq -r '.id' <<<"${current_view}") - elif [[ ${view_name} == Triage ]] && [[ -n ${default_view_id} ]]; then - view_id=${default_view_id} - else - variables=$(jq -cn \ - --arg projectId "${project_id}" \ - --arg name "${view_name}" \ - --arg layout "${view_layout}" \ - --argjson visibleFieldIds "${visible_field_ids}" \ - --argjson supportsVisibleFields "${supports_visible_fields}" ' - {input: ({ - projectId: $projectId, - name: $name, - layout: $layout - } + if $supportsVisibleFields then - {configuration: {visibleFieldIds: $visibleFieldIds}} - else - {} - end)} - ') - if ${apply}; then - response=$(graphql \ - 'mutation($input:CreateProjectV2ViewInput!){createProjectV2View(input:$input){projectV2View{id}}}' \ - "${variables}") - view_id=$(jq -r '.data.createProjectV2View.projectV2View.id' \ - <<<"${response}") - echo "APPLY create shared project view ${view_name}" - else - echo "PLAN create shared project view ${view_name}" - continue - fi - fi - - variables=$(jq -cn \ - --arg viewId "${view_id}" \ - --arg name "${view_name}" \ - --arg layout "${view_layout}" \ - --arg filter "$(jq -r '.filter' <<<"${desired_view}")" \ - --argjson visibleFieldIds "${visible_field_ids}" \ - --argjson supportsVisibleFields "${supports_visible_fields}" ' - {input: ({ - viewId: $viewId, - name: $name, - layout: $layout, - filter: $filter - } + if $supportsVisibleFields then - {configuration: {visibleFieldIds: $visibleFieldIds}} - else - {} - end)} - ') - desired_view_comparison=$(jq -cn \ - --arg name "${view_name}" \ - --arg layout "${view_layout}" \ - --arg filter "$(jq -r '.filter' <<<"${desired_view}")" \ - --argjson fields "${visible_field_ids}" \ - --argjson supportsVisibleFields "${supports_visible_fields}" ' - {name: $name, layout: $layout, filter: $filter} + - if $supportsVisibleFields then {fields: ($fields | sort)} else {} end - ') - current_view_comparison=null - if [[ ${current_view} != null ]]; then - current_view_comparison=$(jq -c \ - --argjson supportsVisibleFields "${supports_visible_fields}" ' - {name, layout, filter: (.filter // "")} + - if $supportsVisibleFields then - {fields: ([ (.fields.nodes // [])[].id ] | sort)} - else - {} - end - ' <<<"${current_view}") - fi - if [[ ${current_view} != null ]] && \ - [[ ${current_view_comparison} == "${desired_view_comparison}" ]]; then - echo "KEEP shared project view ${view_name}" - elif ${apply}; then - graphql \ - 'mutation($input:UpdateProjectV2ViewInput!){updateProjectV2View(input:$input){projectV2View{id}}}' \ - "${variables}" >/dev/null - echo "APPLY update shared project view ${view_name}" - else - echo "PLAN update shared project view ${view_name}" - fi -done < <(jq -c '.project.views[]' "${planning_config}") - -echo "Project planning configuration is converged (project ${project_number})." diff --git a/bin/publish-repositories b/bin/publish-repositories deleted file mode 100755 index 9040263..0000000 --- a/bin/publish-repositories +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -ATRINIK_POLICY_SCOPE=repository exec "${root}/bin/publish" "$@" diff --git a/bin/publish-repository-properties b/bin/publish-repository-properties deleted file mode 100755 index 1655a9a..0000000 --- a/bin/publish-repository-properties +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 -apply=false - -case ${1:-} in -"") ;; ---apply) apply=true ;; -*) - echo "usage: $0 [--apply]" >&2 - exit 2 - ;; -esac - -for command in gh jq sort; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -properties_config=${root}/config/repository-properties.json -temporary_files=() -trap 'rm -f "${temporary_files[@]}"' EXIT - -"${root}/bin/validate" >/dev/null - -github_api() { - gh api -H "X-GitHub-Api-Version: ${api_version}" "$@" -} - -is_temporary_security_advisory_repository() { - local repository=$1 - local private=$2 - local visibility=$3 - local disabled=$4 - local fork=$5 - local has_issues=$6 - local has_projects=$7 - local has_wiki=$8 - local base_repository - - if [[ ${repository} =~ ^(.+)-ghsa-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$ ]]; then - base_repository=${BASH_REMATCH[1]} - else - return 1 - fi - - [[ ${private} == true ]] && - [[ ${visibility} == private ]] && - [[ ${disabled} == false ]] && - [[ ${fork} == false ]] && - [[ ${has_issues} == false ]] && - [[ ${has_projects} == false ]] && - [[ ${has_wiki} == false ]] && - jq -e --arg repository "${base_repository}" \ - '(.pull_request_gate | index($repository)) != null' \ - "${root}/config/repositories.json" >/dev/null -} - -run_api() { - local method=$1 - local endpoint=$2 - local input=$3 - - if ${apply}; then - github_api --method "${method}" "${endpoint}" --input "${input}" \ - >/dev/null - echo "APPLY ${method} /${endpoint}" - else - echo "PLAN ${method} /${endpoint} <= ${input#"${root}/"}" - fi -} - -schema=$(github_api "orgs/${organization}/properties/schema") - -while IFS= read -r definition; do - property_name=$(jq -r '.property_name' <<<"${definition}") - current=$(jq -c --arg property_name "${property_name}" ' - map(select(.property_name == $property_name))[0] // null - ' <<<"${schema}") - desired=$(jq -c '{ - property_name, - value_type, - required, - default_value, - description, - allowed_values - }' <<<"${definition}") - - if jq -e --argjson desired "${desired}" ' - { - property_name, - value_type, - required, - default_value, - description, - allowed_values - } == $desired - ' <<<"${current}" >/dev/null; then - echo "KEEP /orgs/${organization}/properties/schema/${property_name}" - continue - fi - - input=$(mktemp) - temporary_files+=("${input}") - jq 'del(.property_name)' <<<"${desired}" >"${input}" - run_api PUT \ - "orgs/${organization}/properties/schema/${property_name}" "${input}" -done < <(jq -c '.definitions[]' "${properties_config}") - -declare -A live_repositories=() -declare -A live_active_repositories=() -while IFS= read -r repository; do - live_repositories["${repository}"]=true -done < <( - github_api --paginate "orgs/${organization}/repos?per_page=100&type=all" \ - --jq '.[].name' -) - -while IFS=$'\t' read -r \ - repository archived private visibility disabled fork has_issues has_projects has_wiki; do - if [[ ${archived} == false ]] && - ! is_temporary_security_advisory_repository \ - "${repository}" "${private}" "${visibility}" "${disabled}" "${fork}" \ - "${has_issues}" "${has_projects}" "${has_wiki}"; then - live_active_repositories["${repository}"]=true - fi -done < <( - github_api --paginate "orgs/${organization}/repos?per_page=100&type=all" \ - --jq ' - .[] | - [ - .name, - (.archived | tostring), - (.private | tostring), - .visibility, - (.disabled | tostring), - (.fork | tostring), - (.has_issues | tostring), - (.has_projects | tostring), - (.has_wiki | tostring) - ] | - @tsv - ' -) - -while IFS= read -r repository; do - if [[ ! -v live_active_repositories["${repository}"] ]]; then - echo "error: governed active repository is missing or archived: ${organization}/${repository}" >&2 - exit 1 - fi -done < <( - jq -r '.repositories | to_entries[] | select(.value.lifecycle != "archived") | .key' \ - "${properties_config}" -) - -while IFS= read -r repository; do - if [[ -v live_active_repositories["${repository}"] ]] && - ! jq -e --arg repository "${repository}" \ - '.repositories | has($repository)' "${properties_config}" >/dev/null; then - echo "error: live active repository is not in the property inventory: ${organization}/${repository}" >&2 - exit 1 - fi -done < <(printf '%s\n' "${!live_active_repositories[@]}" | sort) - -while IFS= read -r repository; do - if [[ ! -v live_repositories["${repository}"] ]]; then - lifecycle=$(jq -r --arg repository "${repository}" \ - '.repositories[$repository].lifecycle' "${properties_config}") - if [[ ${lifecycle} == archived ]]; then - echo "SKIP ${organization}/${repository} is an absent archived repository" - continue - fi - echo "error: repository property inventory is not live: ${organization}/${repository}" >&2 - exit 1 - fi - - desired=$(jq -c --arg repository "${repository}" ' - .repositories[$repository] | - to_entries | - map({property_name: .key, value: .value}) | - sort_by(.property_name) - ' "${properties_config}") - current=$(github_api "repos/${organization}/${repository}/properties/values" | - jq -c 'map({property_name, value}) | sort_by(.property_name)') - if jq -e --argjson desired "${desired}" '. == $desired' \ - <<<"${current}" >/dev/null; then - echo "KEEP /repos/${organization}/${repository}/properties/values" - continue - fi - - input=$(mktemp) - temporary_files+=("${input}") - jq -n --arg repository "${repository}" --argjson properties "${desired}" ' - {repository_names: [$repository], properties: $properties} - ' >"${input}" - run_api PATCH "orgs/${organization}/properties/values" "${input}" -done < <(jq -r '.repositories | keys[]' "${properties_config}") - -echo "Repository custom properties are converged." diff --git a/bin/security-readiness b/bin/security-readiness deleted file mode 100755 index a00982e..0000000 --- a/bin/security-readiness +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -exec python3 "${root}/lib/security_readiness.py" "$@" diff --git a/bin/sync-project b/bin/sync-project deleted file mode 100755 index 75a4a0f..0000000 --- a/bin/sync-project +++ /dev/null @@ -1,560 +0,0 @@ -#!/usr/bin/env bash - -# GraphQL variable names are intentionally literal dollar-prefixed strings. -# shellcheck disable=SC2016 - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 -pause_seconds=${ATRINIK_PROJECT_SYNC_PAUSE_SECONDS:-0.2} -apply=false - -case ${1:-} in -"") ;; ---apply) apply=true ;; -*) - echo "usage: $0 [--apply]" >&2 - exit 2 - ;; -esac - -for command in cat gh jq sleep tr wc; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done -if [[ ! ${pause_seconds} =~ ^[0-9]+([.][0-9]+)?$ ]]; then - echo "error: ATRINIK_PROJECT_SYNC_PAUSE_SECONDS must be numeric" >&2 - exit 2 -fi -if [[ ${GITHUB_ACTIONS:-false} == true && -z ${GH_TOKEN:-} ]]; then - echo "error: ATRINIK_SETTINGS_TOKEN is unavailable: GH_TOKEN is empty in GitHub Actions" >&2 - exit 1 -fi - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -planning_config=${root}/config/planning.json -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -"${root}/bin/validate" >/dev/null - -github_api() { - local operation=$1 - local response - local status - - shift - if response=$(gh api -H "X-GitHub-Api-Version: ${api_version}" "$@"); then - : - else - status=$? - echo "error: GitHub API operation failed: ${operation}" >&2 - return "${status}" - fi - printf '%s\n' "${response}" -} - -verify_token_scopes() { - local advertised_scopes header header_name response scope status - local -A advertised=() - - if response=$(gh api --include \ - -H "X-GitHub-Api-Version: ${api_version}" user); then - : - else - status=$? - echo "error: GitHub API operation failed: verify settings credential scopes" >&2 - return "${status}" - fi - advertised_scopes= - while IFS= read -r header; do - header=${header%$'\r'} - header_name=${header%%:*} - if [[ ${header_name,,} == x-oauth-scopes ]]; then - advertised_scopes=${header#*:} - fi - done <<<"${response}" - if [[ -z ${advertised_scopes//[[:space:]]/} ]]; then - echo "error: settings credential scope metadata is unavailable; ATRINIK_SETTINGS_TOKEN must be a classic PAT" >&2 - return 1 - fi - while IFS= read -r scope; do - scope=${scope#"${scope%%[![:space:]]*}"} - scope=${scope%"${scope##*[![:space:]]}"} - [[ -n ${scope} ]] && advertised["${scope}"]=1 - done < <(tr ',' '\n' <<<"${advertised_scopes}") - for scope in admin:org project repo; do - if [[ ! -v advertised["${scope}"] ]]; then - echo "error: ATRINIK_SETTINGS_TOKEN is missing required classic PAT scope: ${scope}" >&2 - return 1 - fi - done -} - -if ${apply}; then - if verify_token_scopes; then - : - else - status=$? - exit "${status}" - fi -fi - -graphql() { - local operation=$1 - local query=$2 - local variables=$3 - local input response status - - input=${temporary}/graphql-$RANDOM.json - jq -n --arg query "${query}" --argjson variables "${variables}" \ - '{query: $query, variables: $variables}' >"${input}" - if response=$(github_api "${operation}" graphql --input "${input}"); then - : - else - status=$? - return "${status}" - fi - if ! jq -e 'type == "object"' <<<"${response}" >/dev/null; then - echo "error: GitHub GraphQL operation returned invalid JSON: ${operation}" >&2 - return 1 - fi - if jq -e '(.errors // []) | length > 0' <<<"${response}" >/dev/null; then - jq -r '.errors[] | .message // tostring' <<<"${response}" >&2 - echo "error: GitHub GraphQL operation failed: ${operation}" >&2 - return 1 - fi - if ! jq -e '.data | type == "object"' <<<"${response}" >/dev/null; then - echo "error: GitHub GraphQL operation returned an invalid response: ${operation}" >&2 - return 1 - fi - printf '%s\n' "${response}" -} - -graphql_paginate() { - local operation=$1 - local query=$2 - local variables=$3 - local connection_filter=$4 - local nodes_filter=$5 - local connection cursor emitted_count expected_count has_next output page - local response status unique_count - local -A seen_cursors=() - - output=${temporary}/pagination-$RANDOM.jsonl - : >"${output}" - expected_count= - page=1 - while true; do - if response=$(graphql "${operation} (page ${page})" \ - "${query}" "${variables}"); then - : - else - status=$? - return "${status}" - fi - if ! connection=$(jq -ce "${connection_filter}" <<<"${response}"); then - echo "error: GitHub GraphQL response is missing the expected connection: ${operation}" >&2 - return 1 - fi - if ! jq -e ' - (.nodes | type == "array") and - (.pageInfo | type == "object") and - (.pageInfo.hasNextPage | type == "boolean") - ' <<<"${connection}" >/dev/null; then - echo "error: GitHub GraphQL response has invalid pagination data: ${operation}" >&2 - return 1 - fi - if [[ ${connection_filter} == .data.search ]]; then - if ! jq -e ' - .issueCount | type == "number" and floor == . and . >= 0 - ' <<<"${connection}" >/dev/null; then - echo "error: GitHub GraphQL search response omitted a valid result count: ${operation}" >&2 - return 1 - fi - if (( $(jq -r '.issueCount' <<<"${connection}") > 1000 )); then - echo "error: GitHub GraphQL search exceeds the 1000-result API window: ${operation}" >&2 - return 1 - fi - if [[ -z ${expected_count} ]]; then - expected_count=$(jq -r '.issueCount' <<<"${connection}") - elif [[ $(jq -r '.issueCount' <<<"${connection}") != "${expected_count}" ]]; then - echo "error: GitHub GraphQL search result count changed during pagination: ${operation}" >&2 - return 1 - fi - fi - if ! jq -c "${nodes_filter}" <<<"${connection}" >>"${output}"; then - echo "error: GitHub GraphQL response has invalid nodes: ${operation}" >&2 - return 1 - fi - - has_next=$(jq -r '.pageInfo.hasNextPage' <<<"${connection}") - [[ ${has_next} == true ]] || break - cursor=$(jq -r '.pageInfo.endCursor // empty' <<<"${connection}") - if [[ -z ${cursor} ]]; then - echo "error: GitHub GraphQL response omitted the next cursor: ${operation}" >&2 - return 1 - fi - if [[ -v seen_cursors["${cursor}"] ]]; then - echo "error: GitHub GraphQL response repeated the next cursor: ${operation}" >&2 - return 1 - fi - seen_cursors["${cursor}"]=1 - variables=$(jq -c --arg cursor "${cursor}" \ - '. + {endCursor: $cursor}' <<<"${variables}") - ((page += 1)) - done - - if [[ ${connection_filter} == .data.search ]]; then - emitted_count=$(wc -l <"${output}") - if ! unique_count=$(jq -sr ' - if all(.[]; .id | type == "string" and length > 0) then - [.[].id] | unique | length - else - error("search node ID is missing") - end - ' "${output}"); then - echo "error: GitHub GraphQL search returned a node without an ID: ${operation}" >&2 - return 1 - fi - if ((emitted_count != expected_count || unique_count != expected_count)); then - echo "error: GitHub GraphQL search result count does not match unique nodes: ${operation}" >&2 - return 1 - fi - fi - cat "${output}" -} - -project_title=$(jq -r '.project.title' "${planning_config}") -organization_query='query($login:String!){organization(login:$login){issueTypes(first:25){nodes{id name isEnabled}} projectsV2(first:50){nodes{id number title viewerCanUpdate fields(first:100){nodes{... on ProjectV2Field{id name} ... on ProjectV2IterationField{id name} ... on ProjectV2MultiSelectField{id name} ... on ProjectV2SingleSelectField{id name options{id name}}}}}}}}' -organization_variables=$(jq -cn --arg login "${organization}" '{login: $login}') -if organization_response=$(graphql "read organization planning metadata" \ - "${organization_query}" "${organization_variables}"); then - : -else - status=$? - exit "${status}" -fi -if ! organization_data=$(jq -ce \ - '.data.organization | select(type == "object")' \ - <<<"${organization_response}"); then - echo "error: GitHub GraphQL response omitted organization planning metadata" >&2 - exit 1 -fi -project=$(jq -c --arg title "${project_title}" ' - .projectsV2.nodes | map(select(.title == $title))[0] // null -' <<<"${organization_data}") -if [[ ${project} == null ]]; then - echo "error: organization project is missing: ${project_title}" >&2 - echo "run bin/publish-planning --apply first" >&2 - exit 1 -fi -project_id=$(jq -r '.id' <<<"${project}") -project_number=$(jq -r '.number' <<<"${project}") -if ${apply} && ! jq -e '.viewerCanUpdate == true' <<<"${project}" >/dev/null; then - echo "error: ATRINIK_SETTINGS_TOKEN cannot update organization project: ${project_title}" >&2 - exit 1 -fi -status_field=$(jq -c ' - .fields.nodes | map(select(.name == "Status"))[0] // null -' <<<"${project}") -if [[ ${status_field} == null ]]; then - echo "error: project Status field is missing" >&2 - exit 1 -fi -status_field_id=$(jq -r '.id' <<<"${status_field}") - -declare -A status_option_ids=() -while IFS=$'\t' read -r name id; do - status_option_ids["${name}"]=${id} -done < <(jq -r '.options[] | [.name, .id] | @tsv' <<<"${status_field}") -for status in Inbox Backlog Review Done; do - if [[ ! -v status_option_ids["${status}"] ]]; then - echo "error: project Status option is missing: ${status}" >&2 - exit 1 - fi -done - -declare -A issue_type_ids=() -while IFS=$'\t' read -r name id; do - issue_type_ids["${name}"]=${id} -done < <(jq -r '.issueTypes.nodes[] | select(.isEnabled) | [.name, .id] | @tsv' \ - <<<"${organization_data}") -for issue_type in Task Bug Feature Initiative; do - if [[ ! -v issue_type_ids["${issue_type}"] ]]; then - echo "error: enabled organization issue type is missing: ${issue_type}" >&2 - exit 1 - fi -done - -search_query='query($queryString:String!,$endCursor:String){search(query:$queryString,type:ISSUE,first:100,after:$endCursor){issueCount nodes{... on Issue{__typename id url createdAt state issueType{name} repository{name isArchived viewerPermission} labels(first:50){nodes{name}} subIssues(first:1){totalCount}} ... on PullRequest{__typename id url createdAt state isDraft repository{name isArchived viewerPermission}}} pageInfo{hasNextPage endCursor}}}' -open_items=${temporary}/open-items.jsonl -: >"${open_items}" -for qualifier in is:issue is:pr; do - search_variables=$(jq -cn \ - --arg queryString "org:${organization} is:open ${qualifier} archived:false" \ - '{queryString: $queryString, endCursor: null}') - if graphql_paginate "search open ${qualifier} work" \ - "${search_query}" "${search_variables}" '.data.search' \ - '.nodes[] | select(.repository.isArchived == false)' >>"${open_items}"; then - : - else - status=$? - exit "${status}" - fi -done - -if ${apply}; then - unauthorized_repositories=$(jq -sr ' - [ - .[] | - select( - .__typename == "Issue" and - (.issueType.name // "") == "" and - (.repository.viewerPermission | IN("ADMIN", "MAINTAIN", "WRITE") | not) - ) | - .repository.name - ] | unique | join(", ") - ' "${open_items}") - if [[ -n ${unauthorized_repositories} ]]; then - echo "error: ATRINIK_SETTINGS_TOKEN cannot set issue types in repositories: ${unauthorized_repositories}" >&2 - exit 1 - fi -fi - -project_items_query='query($id:ID!,$endCursor:String){node(id:$id){... on ProjectV2{items(first:100,after:$endCursor){nodes{id fieldValueByName(name:"Status"){... on ProjectV2ItemFieldSingleSelectValue{name optionId}} content{... on Issue{__typename id url createdAt state issueType{name} repository{name isArchived} labels(first:50){nodes{name}} subIssues(first:1){totalCount}} ... on PullRequest{__typename id url createdAt state isDraft repository{name isArchived}}}} pageInfo{hasNextPage endCursor}}}}}' -project_items=${temporary}/project-items.jsonl -project_items_variables=$(jq -cn --arg id "${project_id}" \ - '{id: $id, endCursor: null}') -if graphql_paginate "read project items" "${project_items_query}" \ - "${project_items_variables}" '.data.node.items' '.nodes[]' \ - >"${project_items}"; then - : -else - status=$? - exit "${status}" -fi - -declare -A project_item_ids=() -declare -A project_item_statuses=() -while IFS= read -r item; do - content_id=$(jq -r '.content.id // empty' <<<"${item}") - [[ -n ${content_id} ]] || continue - project_item_ids["${content_id}"]=$(jq -r '.id' <<<"${item}") - project_item_statuses["${content_id}"]=$(jq -r \ - '.fieldValueByName.name // empty' <<<"${item}") -done <"${project_items}" - -mutation_count=0 -added_count=0 -status_count=0 -done_count=0 -type_count=0 -task_count=0 -bug_count=0 -feature_count=0 -initiative_count=0 - -pause_after_mutation() { - if ${apply} && [[ ${pause_seconds} != 0 ]] && [[ ${pause_seconds} != 0.0 ]]; then - sleep "${pause_seconds}" - fi -} - -add_project_item() { - local content_id=$1 - local item_id response status - local variables - - variables=$(jq -cn --arg projectId "${project_id}" \ - --arg contentId "${content_id}" \ - '{input: {projectId: $projectId, contentId: $contentId}}') - if response=$(graphql "add ${content_id} to project" \ - 'mutation($input:AddProjectV2ItemByIdInput!){addProjectV2ItemById(input:$input){item{id}}}' \ - "${variables}"); then - : - else - status=$? - return "${status}" - fi - if ! item_id=$(jq -er ' - .data.addProjectV2ItemById.item.id | - select(type == "string" and length > 0) - ' <<<"${response}"); then - echo "error: GitHub GraphQL operation returned an invalid item: add ${content_id} to project" >&2 - return 1 - fi - printf '%s\n' "${item_id}" - pause_after_mutation -} - -set_project_status() { - local item_id=$1 - local status=$2 - local graphql_status response variables - - variables=$(jq -cn \ - --arg projectId "${project_id}" \ - --arg itemId "${item_id}" \ - --arg fieldId "${status_field_id}" \ - --arg optionId "${status_option_ids["${status}"]}" ' - {input: { - projectId: $projectId, - itemId: $itemId, - fieldId: $fieldId, - value: {singleSelectOptionId: $optionId} - }} - ') - if response=$(graphql "set project item ${item_id} status to ${status}" \ - 'mutation($input:UpdateProjectV2ItemFieldValueInput!){updateProjectV2ItemFieldValue(input:$input){projectV2Item{id}}}' \ - "${variables}"); then - : - else - graphql_status=$? - return "${graphql_status}" - fi - if ! jq -e ' - .data.updateProjectV2ItemFieldValue.projectV2Item.id | - type == "string" and length > 0 - ' <<<"${response}" >/dev/null; then - echo "error: GitHub GraphQL operation returned an invalid project item: set project item ${item_id} status to ${status}" >&2 - return 1 - fi - pause_after_mutation -} - -set_issue_type() { - local issue_id=$1 - local issue_type=$2 - local graphql_status response variables - - variables=$(jq -cn --arg id "${issue_id}" \ - --arg issueTypeId "${issue_type_ids["${issue_type}"]}" \ - '{input: {id: $id, issueTypeId: $issueTypeId}}') - if response=$(graphql "set issue ${issue_id} type to ${issue_type}" \ - 'mutation($input:UpdateIssueInput!){updateIssue(input:$input){issue{id}}}' \ - "${variables}"); then - : - else - graphql_status=$? - return "${graphql_status}" - fi - if ! jq -e ' - .data.updateIssue.issue.id | type == "string" and length > 0 - ' <<<"${response}" >/dev/null; then - echo "error: GitHub GraphQL operation returned an invalid issue: set issue ${issue_id} type to ${issue_type}" >&2 - return 1 - fi - pause_after_mutation -} - -infer_issue_type() { - local issue=$1 - jq -r --slurpfile config "${planning_config}" ' - $config[0].type_inference as $inference | - ([.labels.nodes[].name | ascii_downcase]) as $labels | - ($inference.bug_labels | map(ascii_downcase)) as $bugs | - ($inference.feature_labels | map(ascii_downcase)) as $features | - if $inference.initiative_when_parent and .subIssues.totalCount > 0 then - "Initiative" - elif any($labels[]; . as $label | ($bugs | index($label)) != null) then - "Bug" - elif any($labels[]; . as $label | ($features | index($label)) != null) then - "Feature" - else - $inference.default - end - ' <<<"${issue}" -} - -triage_cutover=$(jq -r '.project.triage_cutover' "${planning_config}") -while IFS= read -r content; do - content_id=$(jq -r '.id' <<<"${content}") - content_type=$(jq -r '.__typename' <<<"${content}") - url=$(jq -r '.url' <<<"${content}") - desired_status=Review - if [[ ${content_type} == Issue ]]; then - if [[ $(jq -r '.createdAt' <<<"${content}") < ${triage_cutover} ]]; then - desired_status=Backlog - else - desired_status=Inbox - fi - fi - - item_id=${project_item_ids["${content_id}"]:-} - current_status=${project_item_statuses["${content_id}"]:-} - if [[ -z ${item_id} ]]; then - ((added_count += 1)) - ((status_count += 1)) - ((mutation_count += 2)) - if ${apply}; then - item_id=$(add_project_item "${content_id}") - set_project_status "${item_id}" "${desired_status}" - fi - elif [[ -z ${current_status} ]] || [[ ${current_status} == Done ]]; then - ((status_count += 1)) - ((mutation_count += 1)) - if ${apply}; then - set_project_status "${item_id}" "${desired_status}" - fi - fi - - if [[ ${content_type} == Issue ]] && \ - [[ $(jq -r '.issueType.name // empty' <<<"${content}") == "" ]]; then - issue_type=$(infer_issue_type "${content}") - ((type_count += 1)) - ((mutation_count += 1)) - case ${issue_type} in - Task) ((task_count += 1)) ;; - Bug) ((bug_count += 1)) ;; - Feature) ((feature_count += 1)) ;; - Initiative) ((initiative_count += 1)) ;; - *) - echo "error: unsupported inferred issue type: ${issue_type}" >&2 - exit 1 - ;; - esac - if ${apply}; then - set_issue_type "${content_id}" "${issue_type}" - fi - fi - - if ${apply} && ((mutation_count > 0)) && ((mutation_count % 50 == 0)); then - echo "PROGRESS ${mutation_count} mutations; latest ${url}" - fi -done <"${open_items}" - -while IFS= read -r item; do - content_id=$(jq -r '.content.id // empty' <<<"${item}") - [[ -n ${content_id} ]] || continue - state=$(jq -r '.content.state // empty' <<<"${item}") - current_status=$(jq -r '.fieldValueByName.name // empty' <<<"${item}") - case ${state} in - CLOSED | MERGED) - if [[ ${current_status} != Done ]]; then - ((done_count += 1)) - ((mutation_count += 1)) - if ${apply}; then - set_project_status "$(jq -r '.id' <<<"${item}")" Done - fi - fi - ;; - esac -done <"${project_items}" - -mode=PLAN -${apply} && mode=APPLY -open_count=$(wc -l <"${open_items}") -tracked_count=$(jq -s '[.[] | select(.content.id != null)] | length' \ - "${project_items}") -echo "${mode} project ${project_number} (${project_title})" -echo "Open issues and pull requests: ${open_count}" -echo "Currently tracked items: ${tracked_count}" -echo "Items to add: ${added_count}" -echo "Open-item status changes: ${status_count}" -echo "Closed-item moves to Done: ${done_count}" -echo "Issue types to set: ${type_count} (Initiative ${initiative_count}, Feature ${feature_count}, Bug ${bug_count}, Task ${task_count})" -echo "Total mutations: ${mutation_count}" diff --git a/bin/validate b/bin/validate deleted file mode 100755 index a45ab4f..0000000 --- a/bin/validate +++ /dev/null @@ -1,1705 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -organization_config=${root}/config/organization.json -repositories_config=${root}/config/repositories.json -advisory_merge_windows_config=${root}/config/advisory-merge-windows.json -advanced_codeql_config=${root}/config/codeql-advanced-setup.json -immutable_releases_config=${root}/config/immutable-releases.json -retired_maintenance_config=${root}/config/retired-maintenance-branches.json -manual_settings_config=${root}/config/manual-settings.json -planning_config=${root}/config/planning.json -planning_health_config=${root}/config/planning-health.json -repository_properties_config=${root}/config/repository-properties.json -community_health_config=${root}/config/community-health.json - -for command in date git jq; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done - -validation_today=${ATRINIK_VALIDATION_TODAY:-$(date -u +%F)} -if ! jq -en --arg value "${validation_today}" ' - ($value | test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - ( - try ( - (($value + "T00:00:00Z" | fromdateiso8601) | - strftime("%Y-%m-%d")) == $value - ) catch false - ) -' >/dev/null; then - echo "error: ATRINIK_VALIDATION_TODAY must use YYYY-MM-DD" >&2 - exit 2 -fi - -while IFS= read -r -d '' config; do - jq empty "${config}" >/dev/null -done < <(find "${root}/config" -name '*.json' -print0 | sort -z) - -jq -e ' - . == { - description: "A cooperative, open-source fantasy world founded by Zoey Seraphina Rose (https://zoeysr.com). Playable in Classic and rebuilding for the future.", - blog: "https://atrinik.org", - default_repository_permission: "none", - members_can_create_repositories: false, - members_can_create_public_repositories: false, - members_can_create_private_repositories: false - } -' "${organization_config}" >/dev/null - -jq -e --slurpfile repositories "${repositories_config}" \ - --slurpfile advanced "${advanced_codeql_config}" ' - . as $policy | - (keys == ["activation", "code_scanning", "codeql_required_languages", "dependency_review"]) and - (.activation | type == "object" and keys == ["code_scanning", "dependency_review"]) and - all(["code_scanning", "dependency_review"][]; . as $kind | - ($policy.activation[$kind] | type == "object" and keys == $policy[$kind]) and - all($policy.activation[$kind][]; IN("pending", "enforced"))) and - .dependency_review == [] and - # Dependency review never reports on merge groups; a queued gate would stall. - all(.dependency_review[]; . as $repository | - ($repositories[0].merge_queue | index($repository)) == null) and - .code_scanning == ($repositories[0].required_ci | keys) and - (.codeql_required_languages | type == "object") and - all(.codeql_required_languages | to_entries[]; - .key as $repository | - ($repositories[0].required_ci | has($repository)) and - ($advanced[0].repositories | index($repository)) == null and - (.value | type == "array" and length > 0 and . == (sort | unique)) and - all(.value[]; IN("c-cpp", "csharp", "go", "java-kotlin", - "javascript-typescript", "python", "ruby", "rust", "swift"))) and - .codeql_required_languages["content-toolkit"] == ["rust"] -' "${root}/config/security-merge-protection.json" >/dev/null - -jq -e '.sha_pinning_required == true' \ - "${root}/config/actions-permissions.json" >/dev/null - -jq -e --slurpfile repositories "${repositories_config}" ' - (keys == ["canary", "phase"]) and - if .phase == "pending" then .canary == null - elif .phase == "enforced" then - (.canary | type == "string" and test("^atrinik/[A-Za-z0-9_.-]+/[1-9][0-9]*$")) and - ((.canary | split("/")[1]) as $repository | - ($repositories[0].required_ci | has($repository))) - else false end -' "${root}/config/actions-sha-pinning.json" >/dev/null - -for security_ruleset in code-scanning dependency-review; do - jq -e ' - .target == "branch" and .enforcement == "active" and - .conditions == {ref_name: {include: ["~DEFAULT_BRANCH"], exclude: []}} and - .bypass_actors == [{actor_id: 1, actor_type: "OrganizationAdmin", - bypass_mode: "pull_request"}] - ' "${root}/config/rulesets/${security_ruleset}.json" >/dev/null -done -jq -e ' - .name == "06 - CodeQL security" and - .rules == [{type: "code_scanning", parameters: {code_scanning_tools: [{ - tool: "CodeQL", security_alerts_threshold: "high_or_higher", alerts_threshold: "none" - }]}}] -' "${root}/config/rulesets/code-scanning.json" >/dev/null -jq -e ' - .name == "07 - Dependency review" and - .rules == [{type: "required_status_checks", parameters: { - required_status_checks: [{context: "Dependency review", integration_id: 15368}], - strict_required_status_checks_policy: true - }}] -' "${root}/config/rulesets/dependency-review.json" >/dev/null - -jq -e ' - .bypass_actors == [] and - [.rules[].type] == ["deletion", "non_fast_forward"] -' "${root}/config/rulesets/default-branch-integrity.json" >/dev/null - -jq -e ' - .bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }] and - [.rules[].type] == ["required_linear_history"] -' "${root}/config/rulesets/default-branch-linear-history.json" >/dev/null - -jq -e ' - .bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }] and - [.rules[].type] == ["required_linear_history"] -' "${root}/config/rulesets/default-branch-linear-history-classic.json" \ - >/dev/null - -jq -e ' - .bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }] and - [.rules[].type] == ["pull_request"] -' "${root}/config/rulesets/pull-request-gate.json" >/dev/null - -jq -e ' - .bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }] and - [.rules[].type] == ["pull_request"] -' "${root}/config/rulesets/pull-request-gate-classic.json" >/dev/null - -# The publisher relaxes the up-to-date requirement only for merge-queue -# repositories, whose queue tests the merged result instead. -jq -e ' - .name == "03 - Required CI" and - .target == "branch" and .enforcement == "active" and - .conditions == {ref_name: {exclude: [], include: ["~DEFAULT_BRANCH"]}} and - .bypass_actors == [{actor_id: 1, actor_type: "OrganizationAdmin", - bypass_mode: "pull_request"}] and - .rules == [{type: "required_status_checks", parameters: { - required_status_checks: [], strict_required_status_checks_policy: true - }}] -' "${root}/config/rulesets/required-ci.json" >/dev/null - -# GitHub accepts merge-queue rules only in repository rulesets. Keep the queue -# within the API ranges, merging with the organization's only merge method, -# able to build and merge at least one entry, and without a wait that a -# one-entry minimum can never use. -jq -e --slurpfile defaults "${root}/config/repository-defaults.json" ' - def integer_between($low; $high): - type == "number" and floor == . and . >= $low and . <= $high; - .name == "08 - Merge queue" and - .target == "branch" and .enforcement == "active" and - .conditions == {ref_name: {exclude: [], include: ["~DEFAULT_BRANCH"]}} and - .bypass_actors == [{actor_id: 1, actor_type: "OrganizationAdmin", - bypass_mode: "pull_request"}] and - (.rules | type == "array" and length == 1) and - (.rules[0] | keys == ["parameters", "type"] and .type == "merge_queue") and - (.rules[0].parameters | - keys == [ - "check_response_timeout_minutes", - "grouping_strategy", - "max_entries_to_build", - "max_entries_to_merge", - "merge_method", - "min_entries_to_merge", - "min_entries_to_merge_wait_minutes" - ] and - (.check_response_timeout_minutes | integer_between(1; 360)) and - (.grouping_strategy | IN("ALLGREEN", "HEADGREEN")) and - (.max_entries_to_build | integer_between(1; 100)) and - (.max_entries_to_merge | integer_between(1; 100)) and - (.min_entries_to_merge | integer_between(1; 100)) and - .min_entries_to_merge <= .max_entries_to_merge and - (.min_entries_to_merge_wait_minutes | integer_between(0; 360)) and - # The wait only applies while a group is below its minimum size. - (.min_entries_to_merge > 1 or .min_entries_to_merge_wait_minutes == 0) and - ({MERGE: "allow_merge_commit", SQUASH: "allow_squash_merge", - REBASE: "allow_rebase_merge"}[.merge_method] as $setting | - $setting != null and $defaults[0][$setting] == true)) -' "${root}/config/rulesets/merge-queue.json" >/dev/null - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - (keys == ["repositories"]) and - (.repositories == ["classic"] or .repositories == []) and - all( - .repositories[]; - . as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].required_ci | has($repository)) - ) - ' "${advisory_merge_windows_config}" >/dev/null - -jq -e ' - . as $config | - (.pull_request_gate | type == "array") and - ((.pull_request_gate | length) == (.pull_request_gate | unique | length)) and - all(.pull_request_gate[]; type == "string" and length > 0) and - (.required_ci | type == "object") and - all( - .required_ci | to_entries[]; - (.key | type == "string" and length > 0) and - (.value | type == "array" and length > 0) and - ((.value | length) == (.value | unique | length)) and - all(.value[]; type == "string" and length > 0) and - (.key as $repository | - ($config.pull_request_gate | index($repository)) != null) - ) and - # A queue runs the required checks on each merge result, so it needs them. - (.merge_queue | type == "array") and - ((.merge_queue | length) == (.merge_queue | unique | length)) and - all(.merge_queue[]; type == "string" and length > 0 and - (. as $repository | $config.required_ci | has($repository))) and - (.release_tags | type == "array") and - ((.release_tags | length) == (.release_tags | unique | length)) and - all(.release_tags[]; type == "string" and length > 0) and - (.archive | type == "array") and - ((.archive | length) == (.archive | unique | length)) and - all(.archive[]; type == "string" and length > 0) and - all( - .archive[]; - . as $repository | - ($config.pull_request_gate | index($repository)) == null and - ($config.required_ci | has($repository) | not) and - ($config.release_tags | index($repository)) == null and - all( - $config.maintenance_branches[]; - .repository != $repository - ) - ) and - (.maintenance_branches | type == "array") and - all( - .maintenance_branches[]; - (keys == ["branch", "repository", "required_ci"]) and - (.repository | type == "string" and length > 0) and - (.branch | type == "string" and length > 0 and . != "main") and - (.required_ci | type == "array") and - ((.required_ci | length) == (.required_ci | unique | length)) and - all(.required_ci[]; type == "string" and length > 0) and - (.repository as $repository | - ($config.pull_request_gate | index($repository)) != null) and - (.repository as $repository | - .required_ci | - all( - .[]; - . as $check | - (($config.required_ci[$repository] // []) | index($check)) != null - )) - ) and - ([.maintenance_branches[] | [.repository, .branch]] as $branches | - ($branches | length) == ($branches | unique | length)) -' "${repositories_config}" >/dev/null - -jq -e --slurpfile repositories "${repositories_config}" ' - (keys == ["retirements"]) and (.retirements | type == "array") and - all(.retirements[]; - (keys == ["repository", "repository_id", "required_ci", "ruleset_id"]) and - (.repository | type == "string" and length > 0) and - (.repository_id | type == "number" and floor == . and . > 0) and - (.ruleset_id | type == "number" and floor == . and . > 0) and - (.required_ci | type == "array" and length > 0) and - all(.required_ci[]; type == "string" and test("[^[:space:]]")) and - ((.required_ci | length) == (.required_ci | unique | length)) and - (.repository as $repository | - ($repositories[0].required_ci | has($repository) | not) and - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null) - ) and - ((.retirements | map(.repository) | length) == (.retirements | map(.repository) | unique | length)) and - ((.retirements | map(.repository_id) | length) == (.retirements | map(.repository_id) | unique | length)) and - ((.retirements | map(.ruleset_id) | length) == (.retirements | map(.ruleset_id) | unique | length)) -' "${root}/config/retired-required-ci.json" >/dev/null - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - (keys == ["retirements"]) and - (.retirements | type == "array") and - all( - .retirements[]; - (keys == [ - "branch", - "default_branch", - "final_branch_commit", - "final_release", - "preserved_rulesets", - "repository", - "repository_id", - "ruleset" - ]) and - (.repository | type == "string" and length > 0) and - (.repository_id | type == "number" and floor == . and . > 0) and - .default_branch == "main" and - (. as $retirement | - ($retirement.branch | type == "string" and length > 0) and - $retirement.branch != $retirement.default_branch) and - (.final_branch_commit | test("^[0-9a-f]{40}$")) and - (.final_release | keys == ["assets", "commit", "tag"]) and - (.final_release.tag | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$")) and - (.final_release.commit | test("^[0-9a-f]{40}$")) and - (.final_release.assets | type == "array" and length > 0) and - ((.final_release.assets | length) == - (.final_release.assets | unique | length)) and - all(.final_release.assets[]; type == "string" and length > 0) and - (.ruleset | keys == ["id", "name", "required_ci"]) and - (.ruleset.id | type == "number" and floor == . and . > 0) and - (.ruleset.name == - "05 - Maintenance branch - \(.repository) - \(.branch)") and - (.ruleset.required_ci | type == "array" and length > 0) and - ((.ruleset.required_ci | length) == - (.ruleset.required_ci | unique | length)) and - all(.ruleset.required_ci[]; type == "string" and length > 0) and - (.preserved_rulesets | type == "array" and length > 0) and - all( - .preserved_rulesets[]; - (keys == ["id", "name"]) and - (.id | type == "number" and floor == . and . > 0) and - (.name | type == "string" and length > 0) - ) and - ((.preserved_rulesets | map(.id) | length) == - (.preserved_rulesets | map(.id) | unique | length)) and - (.repository as $repository | .branch as $branch | - all( - $repositories[0].maintenance_branches[]; - .repository != $repository or .branch != $branch - )) - ) and - ((.retirements | map([.repository, .branch]) | length) == - (.retirements | map([.repository, .branch]) | unique | length)) and - ((.retirements | map(.ruleset.id) | length) == - (.retirements | map(.ruleset.id) | unique | length)) - ' "${retired_maintenance_config}" >/dev/null - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - (keys == ["repositories", "required_partitions"]) and - (.required_partitions | type == "object") and - ((.required_partitions | keys) == (.repositories | sort)) and - all(.required_partitions[]; - type == "array" and length > 0 and - all(.[]; - (keys == ["language", "scope"]) and - (.scope | type == "string" and test("^[a-z][a-z0-9+-]*$")) and - (.language | type == "string" and test("^[a-z][a-z0-9+-]*$")) - ) and - ((map([.scope, .language]) | length) == (map([.scope, .language]) | unique | length)) - ) and - (.repositories | type == "array") and - ((.repositories | length) == (.repositories | unique | length)) and - all( - .repositories[]; - type == "string" and length > 0 and - (. as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null) and - (. as $repository | - ($repositories[0].archive | index($repository)) == null) - ) - ' "${advanced_codeql_config}" >/dev/null - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - (keys == ["enforced_repositories", "repositories"]) and - .enforced_repositories == "selected" and - (.repositories | type == "array" and length > 0) and - all( - .repositories[]; - ((keys - ["activation_variable"]) == ["id", "name"]) and - (if has("activation_variable") then - .name == "metaserver-worker" and .activation_variable == { - name: "ATRINIK_RELEASE_IMMUTABILITY_ACTIVE", scope: "repository" - } - else true end) and - (.id | type == "number" and floor == . and . > 0) and - (.name | type == "string" and length > 0) and - ({classic: 1327289971, protocol: 1327106950, - "content-toolkit": 1327107043, "metaserver-worker": 1324297032}[.name] as $id | - $id == null or .id == $id) and - (.name as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null) and - (.name as $repository | - ($repositories[0].release_tags | index($repository)) != null) and - (.name as $repository | - ($repositories[0].archive | index($repository)) == null) - ) and - ([.repositories[].id] as $ids | - ($ids | length) == ($ids | unique | length)) and - ([.repositories[].name] as $names | - ($names | length) == ($names | unique | length) and - $names == ($names | sort)) - ' "${immutable_releases_config}" >/dev/null - -jq -e ' - .code_scanning_default_setup == "enabled" and - .code_scanning_options == {allow_advanced: false} and - .enforcement == "enforced" -' "${root}/config/code-security.json" >/dev/null - -jq -e \ - --slurpfile baseline "${root}/config/code-security.json" ' - .name == "Atrinik advanced CodeQL baseline" and - (.description | type == "string" and length > 0) and - .code_scanning_default_setup == "enabled" and - .code_scanning_options == {allow_advanced: true} and - .enforcement == "enforced" and - ( - del(.name, .description, .code_scanning_options) == - ($baseline[0] | del(.name, .description, .code_scanning_options)) - ) - ' "${root}/config/code-security-advanced.json" >/dev/null - -jq -e '. == {state: "configured", query_suite: "default"}' \ - "${root}/config/codeql-default-setup.json" >/dev/null - -jq -e '. == {state: "not-configured"}' \ - "${root}/config/codeql-default-setup-advanced.json" >/dev/null - -jq -e ' - (keys == [ - "codecov_github_app_repositories", - "crate_dependency_update_app", - "crates_io_trusted_publishing", - "external_provider_apps", - "github_actions_apps", - "github_actions_credentials", - "github_actions_environments", - "github_packages_actions_access", - "github_pages_sites", - "members_can_change_repository_visibility", - "members_can_create_teams", - "members_can_delete_or_transfer_repositories", - "members_can_request_github_apps", - "organization_pins", - "reason", - "repository_admins_can_install_github_apps", - "require_secure_two_factor_methods", - "require_two_factor_authentication" - ]) -' "${manual_settings_config}" >/dev/null - -jq -e \ - --arg today "${validation_today}" \ - --slurpfile repositories "${repositories_config}" ' - def day_epoch($value): - ($value + "T00:00:00Z" | fromdateiso8601); - def valid_day($value): - ($value | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try ((day_epoch($value) | strftime("%Y-%m-%d")) == $value) catch false); - .external_provider_apps as $external_apps | - .github_actions_apps as $apps | - ($external_apps | type == "array" and length == 2) and - ([$external_apps[].status] == ["active", "planned"]) and - ($external_apps[0] | keys == [ - "app_id", - "app_slug", - "events", - "evidence_location", - "exceptional_retry", - "installation_id", - "last_verified_on", - "owner", - "permissions", - "provider", - "purpose", - "repositories", - "repository_scope_verification", - "repository_selection", - "review_by", - "review_cadence_days", - "review_owner", - "revocation", - "runbook", - "status", - "status_producer" - ]) and - ($external_apps[0].status == "active") and - ($external_apps[0].app_id == 85455) and - ($external_apps[0].app_slug == "cloudflare-workers-and-pages") and - ($external_apps[0].installation_id == 152311798) and - ($external_apps[0].repository_selection == "selected") and - ($external_apps[0].repository_scope_verification == "organization_owner_ui") and - ($external_apps[0].events == ["pull_request", "push"]) and - ($external_apps[0].evidence_location == "atrinik/metaserver-worker#56-private-provider-evidence") and - ($external_apps[0].exceptional_retry == { - authorization: "provider-retry-only", - long_lived_production_branches: ["main"], - source: "exact-sha-still-current-main", - stale_policy: "abandon-and-re-evaluate-without-github-bypass" - }) and - ($external_apps[0].permissions == { - administration: "write", - checks: "write", - contents: "write", - deployments: "write", - metadata: "read", - pull_requests: "write" - }) and - ($external_apps[0].provider == "Cloudflare Workers Builds and Pages") and - ($external_apps[0].status_producer == "Cloudflare Workers and Pages GitHub App") and - ($external_apps[0].repositories == [ - { - purpose: "Preserve the existing Cloudflare Pages website connection.", - repository: "atrinik/website", - repository_id: 1327107093 - }, - { - purpose: "Authorize the serialized Workers Builds topology governed by atrinik/metaserver-worker issues 53-56.", - repository: "atrinik/metaserver-worker", - repository_id: 1324297032 - } - ]) and - all( - $external_apps[0].repositories[]; - (.repository | split("/")[1]) as $repository | - (.repository | test("^atrinik/[A-Za-z0-9_.-]+$")) and - (.repository_id | type == "number" and floor == . and . > 0) and - (.purpose | type == "string" and length > 0) and - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - ($external_apps[0].owner | type == "string" and length > 0) and - ($external_apps[0].purpose | type == "string" and length > 0) and - ($external_apps[0].review_owner | type == "string" and length > 0) and - ($external_apps[0].revocation | type == "string" and length > 0) and - ($external_apps[0].runbook == "README.md#cloudflare-github-app") and - ($external_apps[0].review_cadence_days == 90) and - valid_day($external_apps[0].last_verified_on) and - valid_day($external_apps[0].review_by) and - (day_epoch($external_apps[0].last_verified_on) <= day_epoch($today)) and - (day_epoch($external_apps[0].review_by) > day_epoch($today)) and - ((day_epoch($external_apps[0].review_by) - day_epoch($external_apps[0].last_verified_on)) / 86400 == $external_apps[0].review_cadence_days) and - ($external_apps[1] | keys == [ - "app_id", - "app_slug", - "control_plane_repository", - "events", - "evidence_location", - "exceptional_retry", - "installation_id", - "last_verified_on", - "owner", - "permissions", - "provider", - "purpose", - "repositories", - "repository_scope_verification", - "repository_selection", - "review_by", - "review_cadence_days", - "review_owner", - "revocation", - "runbook", - "secret_names", - "status", - "status_producer", - "variable_names" - ]) and - ($external_apps[1].status == "planned") and - ($external_apps[1].app_id == null) and - ($external_apps[1].app_slug == "atrinik-deploy-control") and - ($external_apps[1].control_plane_repository == { - default_branch: "main", - license: "MIT", - repository: "atrinik/deploy-control", - repository_id: 1352850539, - visibility: "public" - }) and - ($external_apps[1].installation_id == null) and - ($external_apps[1].repository_selection == "selected") and - ($external_apps[1].repository_scope_verification == "pending_provisioning") and - ($external_apps[1].events == ["workflow_run"]) and - ($external_apps[1].exceptional_retry == null) and - ($external_apps[1].permissions == { - actions: "read", - metadata: "read" - }) and - ($external_apps[1].provider == "Cloudflare Workers deploy-control control plane") and - ($external_apps[1].status_producer == "Atrinik deploy-control control-plane owner") and - ($external_apps[1].repositories == [{ - purpose: "Authorize only the Classic workflow-run source for the deploy-control control plane.", - repository: "atrinik/classic", - repository_id: 1327289971 - }]) and - ($external_apps[1].control_plane_repository.repository | test("^atrinik/[A-Za-z0-9_.-]+$")) and - ($external_apps[1].control_plane_repository.repository_id | type == "number" and floor == . and . > 0) and - all( - $external_apps[1].repositories[]; - . as $repository_record | - ($repository_record.repository | split("/")[1]) as $repository | - ($repository_record.repository | test("^atrinik/[A-Za-z0-9_.-]+$")) and - ($repository_record.repository_id | type == "number" and floor == . and . > 0) and - ($repository_record.purpose | type == "string" and length > 0) and - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - ($external_apps[1].owner | type == "string" and length > 0) and - ($external_apps[1].purpose | type == "string" and length > 0) and - ($external_apps[1].evidence_location | type == "string" and length > 0) and - ($external_apps[1].review_owner | type == "string" and length > 0) and - ($external_apps[1].revocation | type == "string" and length > 0) and - ($external_apps[1].runbook == "README.md#deploy-control-github-app") and - ($external_apps[1].review_cadence_days == 90) and - valid_day($external_apps[1].last_verified_on) and - valid_day($external_apps[1].review_by) and - (day_epoch($external_apps[1].last_verified_on) <= day_epoch($today)) and - (day_epoch($external_apps[1].review_by) > day_epoch($today)) and - ((day_epoch($external_apps[1].review_by) - day_epoch($external_apps[1].last_verified_on)) / 86400 == $external_apps[1].review_cadence_days) and - ($external_apps[1].secret_names | type == "array" and length > 0 and . == (sort | unique) and all(.[]; type == "string" and test("^[A-Z][A-Z0-9_]*$"))) and - ($external_apps[1].variable_names | type == "array" and length > 0 and . == (sort | unique) and all(.[]; type == "string" and test("^[A-Z][A-Z0-9_]*$"))) and - ($external_apps[1].secret_names == [ - "DEPLOY_CONTROL_AGENT_ENROLLMENT_SECRET", - "DEPLOY_CONTROL_GITHUB_APP_PRIVATE_KEY", - "DEPLOY_CONTROL_GITHUB_WEBHOOK_SECRET" - ]) and - ($external_apps[1].variable_names == [ - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_DURABLE_OBJECT_BINDING", - "CLOUDFLARE_WORKER_NAME", - "DEPLOY_CONTROL_GITHUB_APP_ID", - "DEPLOY_CONTROL_GITHUB_INSTALLATION_ID" - ]) and - all($external_apps[1].secret_names[]; . as $secret | ($external_apps[1].variable_names | index($secret)) == null) and - ($apps | type == "array" and length > 0) and - ([$apps[].app_id] | length == (unique | length)) and - ([$apps[].installation_id] | length == (unique | length)) and - ( - [$apps[] | [.repository, .secret_scope, .secret_name]] | - length == (unique | length) - ) and - ( - [$apps[] | [.repository, .variable_scope, .variable_name]] | - length == (unique | length) - ) and - all( - $apps[]; - (keys == [ - "app_id", - "app_slug", - "consumers", - "events", - "installation_id", - "last_verified_on", - "owner", - "permissions", - "purpose", - "repository", - "repository_id", - "repository_scope_verification", - "repository_selection", - "rotate_by", - "rotation_cadence_days", - "rotation_owner", - "runbook", - "secret_name", - "secret_scope", - "variable_name", - "variable_scope" - ]) and - (.app_id | type == "number" and floor == . and . > 0) and - ( - .app_slug | - type == "string" and - test("^[a-z0-9]+(?:-[a-z0-9]+)*$") - ) and - (.installation_id | type == "number" and floor == . and . > 0) and - .repository_selection == "selected" and - .repository_scope_verification == "organization_owner_ui" and - .events == [] and - .permissions == { - contents: "write", - metadata: "read", - pull_requests: "write" - } and - ( - .repository | - type == "string" and - test("^atrinik/[A-Za-z0-9_.-]+$") - ) and - ( - .repository as $full_name | - ($full_name | split("/")[1]) as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - (.repository_id | type == "number" and floor == . and . > 0) and - .secret_scope == "repository" and - .variable_scope == "repository" and - (.secret_name | type == "string" and test("^[A-Z][A-Z0-9_]*$")) and - (.variable_name | type == "string" and test("^[A-Z][A-Z0-9_]*$")) and - .secret_name != .variable_name and - ( - .consumers | - type == "array" and - length > 0 and - . == (sort | unique) and - all( - .[]; - type == "string" and - test("^\\.github/workflows/[A-Za-z0-9_.-]+\\.ya?ml$") - ) - ) and - (.purpose | type == "string" and length > 0) and - (.owner | type == "string" and length > 0) and - (.rotation_owner | type == "string" and length > 0) and - ( - .rotation_cadence_days | - type == "number" and floor == . and . >= 1 and . <= 365 - ) and - valid_day(.last_verified_on) and - valid_day(.rotate_by) and - (day_epoch(.last_verified_on) <= day_epoch($today)) and - (day_epoch(.rotate_by) >= day_epoch($today)) and - (day_epoch(.rotate_by) > day_epoch(.last_verified_on)) and - ( - (day_epoch(.rotate_by) - day_epoch(.last_verified_on)) / 86400 <= - .rotation_cadence_days - ) and - ( - .runbook | - type == "string" and - test("^[A-Za-z0-9._/-]+\\.md#[a-z0-9-]+$") - ) - ) and - all( - $apps[]; - . as $app | - all( - $apps[]; - .repository != $app.repository or - .repository_id == $app.repository_id - ) - ) -' "${manual_settings_config}" >/dev/null - -jq -e ' - .organization_pins as $pins | - ($pins | keys == ["apply_path", "repositories", "verification"]) and - $pins.apply_path == "https://github.com/atrinik" and - $pins.verification == "read_only_graphql" and - ($pins.repositories | type == "array" and length == 6) and - [$pins.repositories[].name] == [ - "classic", - "atrinik", - "website", - "content", - "protocol", - "playtester" - ] and - ([ $pins.repositories[].repository_id ] | length == (unique | length)) and - all( - $pins.repositories[]; - (keys == ["name", "repository_id"]) and - (.name | type == "string" and length > 0) and - (.repository_id | type == "number" and floor == . and . > 0) - ) -' "${manual_settings_config}" >/dev/null - -jq -e \ - --arg today "${validation_today}" \ - --slurpfile repositories "${repositories_config}" ' - def day_epoch($value): - ($value + "T00:00:00Z" | fromdateiso8601); - def valid_day($value): - ($value | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try ((day_epoch($value) | strftime("%Y-%m-%d")) == $value) catch false); - .github_actions_credentials as $credentials | - ($credentials | type == "array" and length > 0) and - ( - [$credentials[] | [.repository, .secret_scope, (.environment // null), .secret_name]] | - length == (unique | length) - ) and - all( - $credentials[]; - ((keys - ["environment"]) == [ - "consumers", - "credential_type", - "last_verified_on", - "owner", - "purpose", - "repository", - "repository_id", - "required_scopes", - "rotate_by", - "rotation_cadence_days", - "rotation_owner", - "runbook", - "secret_name", - "secret_scope" - ]) and - ( - (if .credential_type == "classic_pat" then - .secret_scope == "repository" and (has("environment") | not) and - .required_scopes == ["admin:org", "project", "repo"] - else - .secret_scope == "environment" and - .repository == "atrinik/metaserver-worker" and .repository_id == 1324297032 and - ((.environment == "development" and - .consumers == [".github/workflows/deploy-development.yml"] and - .runbook == "README.md#metaserver-development-credentials") or - (.environment == "production" and - .consumers == [".github/workflows/promote-production.yml"] and - .runbook == "README.md#metaserver-production-credentials")) and - (if .secret_name == "CLOUDFLARE_API_TOKEN" then - .credential_type == "cloudflare_account_token" and - .required_scopes == ["D1 Read", "Workers Scripts Edit"] - elif .secret_name == "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN" then - .credential_type == "cloudflare_account_token" and - .required_scopes == ["Workers Scripts Read"] - elif .secret_name == "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN" then - .credential_type == "cloudflare_user_token" and - .required_scopes == ["Workers CI Read", "Workers Scripts Read"] - else false end) - end) - ) and - ( - .repository | - type == "string" and - test("^atrinik/[A-Za-z0-9_.-]+$") - ) and - ( - .repository as $full_name | - ($full_name | split("/")[1]) as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - (.repository_id | type == "number" and . > 0 and floor == .) and - (.secret_name | type == "string" and test("^[A-Z][A-Z0-9_]*$")) and - ( - .consumers | - type == "array" and - length > 0 and - . == (sort | unique) and - all( - .[]; - type == "string" and - test("^\\.github/workflows/[A-Za-z0-9_.-]+\\.ya?ml$") - ) - ) and - (.purpose | type == "string" and length > 0) and - (.owner | type == "string" and length > 0) and - (.rotation_owner | type == "string" and length > 0) and - ( - .rotation_cadence_days | - type == "number" and floor == . and . >= 1 and . <= 365 - ) and - valid_day(.last_verified_on) and - valid_day(.rotate_by) and - (day_epoch(.last_verified_on) <= day_epoch($today)) and - (day_epoch(.rotate_by) >= day_epoch($today)) and - (day_epoch(.rotate_by) > day_epoch(.last_verified_on)) and - ( - (day_epoch(.rotate_by) - day_epoch(.last_verified_on)) / 86400 <= - .rotation_cadence_days - ) and - ( - .runbook | - type == "string" and - test("^[A-Za-z0-9._/-]+\\.md#[a-z0-9-]+$") - ) - ) and - all( - $credentials[]; - . as $credential | - all( - $credentials[]; - .repository != $credential.repository or - .repository_id == $credential.repository_id - ) - ) -' "${manual_settings_config}" >/dev/null - -while IFS= read -r credential; do - if [[ $(jq -r ' .credential_type' <<<"${credential}") == classic_pat ]]; then - while IFS= read -r consumer; do - if [[ ! -f ${root}/${consumer} ]]; then - echo "error: credential consumer workflow is missing: ${consumer}" >&2 - exit 1 - fi - done < <(jq -r '.consumers[]' <<<"${credential}") - fi - # External metaserver consumers are constrained by stable identity and exact - # workflow path above; this local validator cannot prove remote source. -done < <(jq -c '.github_actions_credentials[]' "${manual_settings_config}") - -jq -e --arg today "${validation_today}" ' - .github_packages_actions_access as $access | - ($access | type == "array") and - ( - [$access[] | - [.package_owner, .package_type, .package_name, .actions_repository]] | - length - ) == ( - [$access[] | - [.package_owner, .package_type, .package_name, .actions_repository]] | - unique | length - ) and - all( - $access[]; - (keys == [ - "actions_repository", - "actions_repository_id", - "package_id", - "package_name", - "package_owner", - "package_type", - "preserve_visibility", - "role" - ] or keys == ["actions_repository", "actions_repository_id", "evidence_location", - "grant_state", "observed_on", "package_id", "package_name", "package_owner", "package_type", - "preserve_visibility", "role", "source_repository", "source_repository_id"]) and - (.package_owner | type == "string" and length > 0) and - (.package_type | type == "string" and length > 0) and - (.package_name | type == "string" and length > 0) and - (.package_id | type == "number" and . > 0 and floor == .) and - (.preserve_visibility | IN("private", "internal", "public")) and - ( - .actions_repository | - type == "string" and - test("^[^/[:space:]]+/[^/[:space:]]+$") - ) and - ( - .actions_repository_id | - type == "number" and . > 0 and floor == . - ) and - (.role == "read") and - (if has("grant_state") then - .package_owner == "atrinik" and .package_type == "container" and - .package_name == "linux-build" and .package_id == 14205615 and - .preserve_visibility == "private" and - .source_repository == "atrinik/devcontainer" and .source_repository_id == 1322185908 and - (.actions_repository == "atrinik/client" and .actions_repository_id == 1327106844) and - (if .grant_state == "pending-owner-ui-read-grant" then - .observed_on == null and .evidence_location == null - elif .grant_state == "owner-observed-read-grant" then - (.observed_on | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try ((.observed_on + "T00:00:00Z" | fromdateiso8601 | strftime("%Y-%m-%d")) == .observed_on - and .observed_on <= $today) catch false) and - (.evidence_location | type == "string" and test("^[A-Za-z0-9_./#-]+$")) - else false end) - else (.package_owner != "atrinik" or .package_type != "container" or .package_name != "linux-build") end) - ) -' "${manual_settings_config}" >/dev/null - -# Automatic crate publication follows reviewed source/version merges. Manual -# onboarding observations never claim independent crates.io API verification. -jq -e \ - --slurpfile repositories "${repositories_config}" \ - --slurpfile actions "${root}/config/actions-selected.json" \ - --arg today "${validation_today}" ' - def observed_day: - (type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try ((. + "T00:00:00Z" | fromdateiso8601 | strftime("%Y-%m-%d")) == . and . <= $today) catch false); - def observation: - (keys == ["evidence_location", "observed_on", "state"]) and - (if .state == "pending-owner-registration" then - .observed_on == null and .evidence_location == null - elif .state == "owner-observed-registration" then - (.observed_on | observed_day) and - (.evidence_location | type == "string" and test("^[A-Za-z0-9_./#-]+$")) - else false end); - { - protocol: {id: 1327106950, crates: ["atrinik-protocol"], bootstrap: []}, - "content-toolkit": {id: 1327107043, crates: ["atrinik-artifact", "atrinik-catalog", - "atrinik-diagnostics", "atrinik-schema", "atrinik-source", "atrinik-testkit", - "atrinik-transaction"], bootstrap: true} - } as $inventory | - .github_actions_environments as $environments | - .crates_io_trusted_publishing as $publishers | - ($publishers | type == "array" and length <= 2) and - ([$publishers[].repository] | length == (unique | length)) and - all($publishers[]; - (.repository | split("/")[1]) as $name | - $inventory[$name] as $expected | - (keys == ["authentication_action", "bootstrap_crates", "bootstrap_policy", "crates", - "environment", "environment_state", "provider", "publisher_registration", "release_approval", - "repository", "repository_id", "runbook", "source_evidence_policy", "source_state", - "source_workflow_filename", "upload_intent_policy", "workflow_filename", "workflow_ref", "workflow_trigger"]) and - $expected != null and .repository == ("atrinik/" + $name) and - .repository_id == $expected.id and .crates == $expected.crates and - .bootstrap_crates == (if $expected.bootstrap == true then $expected.crates else [] end) and - .bootstrap_policy == "owner-local-api-token-once-then-oidc-only" and - (.authentication_action | type == "string" and - test("^rust-lang/crates-io-auth-action@[0-9a-f]{40}$")) and - (($actions[0].patterns_allowed | map(select(startswith("rust-lang/")))) == - ["rust-lang/crates-io-auth-action@*"]) and - .provider == "github" and - $actions[0].github_owned_allowed == true and - ($repositories[0].pull_request_gate | index($name)) != null and - ($repositories[0].archive | index($name)) == null and - .workflow_filename == "publish-crate.yml" and - .source_workflow_filename == "release.yml" and - .source_evidence_policy == "github-attested-protected-main-manifest" and - .upload_intent_policy == "create-only-global-git-ref-before-upload" and - .workflow_ref == "refs/heads/main" and .workflow_trigger == "workflow_dispatch" and - .runbook == "README.md#automatic-crate-trusted-publishing" and - .release_approval == "reviewed-source-and-version-merge" and - (.source_state | IN("pending-reviewed-workflow", "observed-reviewed-workflow")) and - (.environment_state | IN("pending", "observed")) and - (.publisher_registration | observation) and - (if .environment_state == "observed" then .source_state == "observed-reviewed-workflow" else true end) and - .environment == { - can_admins_bypass: false, - deployment_branch_policy: { - custom_branch_policies: true, - patterns: [{name: "main", type: "branch"}], protected_branches: false - }, - name: "crates-io-release", prevent_self_review: false, - required_reviewers: [], secret_names: [], variable_names: [], wait_timer_minutes: 0 - } - ) and - all($publishers[]; . as $publisher | - all($environments[]; - .repository != $publisher.repository or .environment != $publisher.environment.name)) | - select(.) -' "${manual_settings_config}" >/dev/null - -jq -e --arg today "${validation_today}" ' - def observed_day: - (type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try ((. + "T00:00:00Z" | fromdateiso8601 | strftime("%Y-%m-%d")) == . and . <= $today) catch false); - def evidence_reference: type == "string" and test("^[A-Za-z0-9_./#-]+$"); - # The 2026-10-17 editor transfer (README.md#transferred-repositories) removed - # a selected repository after the 2026-10-11 readback and carried a copy of - # the then-current key. Its evidence records pin this exact identity. - def editor_transfer: { - former_repository: "atrinik/editor", repository: "seraphinastudios/tilewright-editor", - repository_id: 1327106902, transferred_on: "2026-10-17" - }; - .github_actions_apps as $apps | - .external_provider_apps as $external_apps | - .crate_dependency_update_app as $app | - editor_transfer as $transfer | - ($app | keys == ["accepted_key_exposures", "app_id", "app_slug", "consumers", "credential_state", "events", "evidence_location", - "homepage_url", "installation_id", "key_created_on", "last_verified_on", "observed_on", "owner", "permissions", "pull_request_policy", - "readiness", "repositories", "repository_scope_reverification", "repository_scope_verification", "repository_selection", "rotate_by", - "rotation_cadence_days", "rotation_owner", "runbook", "secret_name", "secret_scope", "status", "variable_name", "variable_scope", - "webhook_active", "workflow_activation", "workflow_filename", "workflow_triggers"]) and - ($app.accepted_key_exposures | type == "array") and - ($app.repository_scope_reverification == null or ($app.repository_scope_reverification | type == "object")) and - $app.app_slug == "atrinik-crate-dependency-update" and - $app.homepage_url == "https://www.atrinik.org" and $app.webhook_active == false and - $app.repository_selection == "selected" and - $app.permissions == {contents: "write", metadata: "read", pull_requests: "write"} and - $app.events == [] and $app.owner == "Atrinik organization owners" and - $app.rotation_owner == "Atrinik organization owners" and $app.rotation_cadence_days == 90 and - $app.repositories == [{repository: "atrinik/client", repository_id: 1327106844}] and - $app.secret_name == "CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY" and $app.secret_scope == "repository" and - $app.variable_name == "CRATE_DEPENDENCY_UPDATE_APP_ID" and $app.variable_scope == "repository" and - $app.workflow_filename == "released-dependencies.yml" and - $app.consumers == ["atrinik/client/.github/workflows/released-dependencies.yml"] and - $app.workflow_triggers == ["schedule-hourly", "workflow_dispatch"] and - $app.readiness == "exact-released-crates-and-checksums-before-pr" and - $app.pull_request_policy == "owned-branch-and-pr-only-no-auto-merge" and - $app.runbook == "README.md#crate-dependency-update-app" and - ($app.credential_state | IN("pending-name-metadata", "observed-name-metadata")) and - ($app.workflow_activation | keys == ["evidence_location", "observed_on", "state"]) and - (if $app.workflow_activation.state == "pending-reviewed-workflows" then - $app.workflow_activation.observed_on == null and $app.workflow_activation.evidence_location == null - elif $app.workflow_activation.state == "observed-successful-owned-pr" then - $app.status == "owner-observed" and $app.credential_state == "observed-name-metadata" and - ($app.workflow_activation.observed_on | observed_day) and - ($app.workflow_activation.evidence_location | type == "string" and test("^[A-Za-z0-9_./#-]+$")) - else false end) and - (if $app.status == "planned" then - $app.credential_state == "pending-name-metadata" and - $app.workflow_activation.state == "pending-reviewed-workflows" and - $app.app_id == null and $app.installation_id == null and - $app.repository_scope_verification == "pending-owner-ui" and - $app.observed_on == null and $app.evidence_location == null and - $app.key_created_on == null and $app.last_verified_on == null and $app.rotate_by == null and - $app.accepted_key_exposures == [] and $app.repository_scope_reverification == null - elif $app.status == "owner-observed" then - ($app.app_id | type == "number" and floor == . and . > 0) and - ($app.installation_id | type == "number" and floor == . and . > 0) and - ($app.repository_scope_verification | IN("organization_owner_ui", "app_authenticated_repository_api")) and - # A readback on or before the transfer no longer proves the selected set: - # keep it pending until a later readback replaces observed_on. - (if $app.observed_on <= $transfer.transferred_on then - $app.repository_scope_reverification as $pending | - ($pending | type == "object") and - ($pending | keys == ["evidence_location", "last_readback_on", "reason", "removed_repositories", - "selection_changed_on", "state"]) and - $pending.state == "pending-reverification" and - $pending.reason == "repository-transfer-after-readback" and - $pending.last_readback_on == $app.observed_on and - $pending.selection_changed_on == $transfer.transferred_on and - $pending.last_readback_on < $pending.selection_changed_on and - $pending.removed_repositories == - [{repository: $transfer.former_repository, repository_id: $transfer.repository_id}] and - ($pending.evidence_location | evidence_reference) - else - $app.repository_scope_reverification == null - end) and - # A key that was current at the transfer keeps its exposure acceptance - # until rotation; a newer key has none. Acceptance never extends rotate-by. - (if $app.key_created_on <= $transfer.transferred_on then - ($app.accepted_key_exposures | length == 1) and - ($app.accepted_key_exposures[0] as $exposure | - ($exposure | type == "object") and - ($exposure | keys == ["accepted_by", "accepted_on", "evidence_location", "exposed_names", "exposure", - "exposure_started_on", "former_repository", "removal_observed_on", "repository", "repository_id"]) and - $exposure.exposure == "repository-transfer-retained-copy" and - $exposure.exposed_names == ([$app.secret_name, $app.variable_name] | sort) and - $exposure.former_repository == $transfer.former_repository and - $exposure.repository == $transfer.repository and - $exposure.repository_id == $transfer.repository_id and - $exposure.exposure_started_on == $transfer.transferred_on and - ($exposure.removal_observed_on | observed_day) and - $exposure.removal_observed_on >= $exposure.exposure_started_on and - ($exposure.accepted_on | observed_day) and $exposure.accepted_on >= $exposure.removal_observed_on and - $exposure.accepted_by == $app.owner and - ($exposure.evidence_location | evidence_reference)) - else - $app.accepted_key_exposures == [] - end) and - ($app.observed_on | observed_day) and - ($app.key_created_on | observed_day) and ($app.last_verified_on | observed_day) and - $app.last_verified_on >= $app.key_created_on and - ($app.rotate_by | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and - (try (($app.rotate_by + "T00:00:00Z" | fromdateiso8601 | strftime("%Y-%m-%d")) == $app.rotate_by) catch false) and - $app.rotate_by >= $today and $app.rotate_by > $app.key_created_on and - ((($app.rotate_by + "T00:00:00Z" | fromdateiso8601) - - ($app.key_created_on + "T00:00:00Z" | fromdateiso8601)) / 86400 <= $app.rotation_cadence_days) and - all(($apps + $external_apps)[]; .app_id != $app.app_id and .installation_id != $app.installation_id) and - ($app.evidence_location | type == "string" and test("^[A-Za-z0-9_./#-]+$")) - else false end) -' "${manual_settings_config}" >/dev/null - - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - .github_actions_environments as $environments | - ($environments | type == "array") and - ( - [$environments[] | [.repository, .environment]] | - length == (unique | length) - ) and - all( - $environments[]; - (keys == [ - "deployment_branch_policy", - "environment", - "repository", - "repository_id", - "required_reviewers", - "secret_names", - "variable_names" - ]) and - ( - .repository | - type == "string" and - test("^atrinik/[A-Za-z0-9_.-]+$") - ) and - ( - .repository as $full_name | - ($full_name | split("/")[1]) as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - (.repository_id | type == "number" and . > 0 and floor == .) and - ( - .environment | - type == "string" and - length <= 255 and - test("^[a-z0-9][a-z0-9-]*[a-z0-9]$") - ) and - (.required_reviewers == []) and - ( - .deployment_branch_policy | - (keys == [ - "custom_branch_policies", - "patterns", - "protected_branches" - ]) and - ( - (.custom_branch_policies == false and - .protected_branches == true and .patterns == []) or - ( - .custom_branch_policies == true and - .protected_branches == false and - (.patterns | type == "array" and length > 0) and - ([.patterns[] | [.type, .name]] | length == (unique | length)) and - all( - .patterns[]; - (keys == ["name", "type"]) and - ( - ( - .type == "branch" and - (.name | type == "string" and test("^[A-Za-z0-9._/-]+$")) - ) or - ( - .type == "tag" and - .name == "v*" - ) - ) - ) - ) - ) - ) and - ( - .variable_names | - type == "array" and - length == (unique | length) and - all(.[]; type == "string" and test("^[A-Z][A-Z0-9_]*$")) - ) and - ( - .secret_names | - type == "array" and - length == (unique | length) and - all(.[]; type == "string" and test("^[A-Z][A-Z0-9_]*$")) - ) and - ((.secret_names | length) > 0 or .environment == "github-pages") and - ( - .variable_names as $variables | - all(.secret_names[]; . as $secret | ($variables | index($secret)) == null) - ) - ) and - all( - $environments[]; - . as $environment | - all( - $environments[]; - .repository != $environment.repository or - .repository_id == $environment.repository_id - ) - ) -' "${manual_settings_config}" >/dev/null - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - .github_actions_environments as $environments | - .github_pages_sites as $sites | - ($sites | type == "array") and - ([$sites[].repository] | length == (unique | length)) and - all( - $sites[]; - (keys == [ - "activation_marker", - "build_type", - "environment", - "https_enforced", - "repository", - "repository_id", - "site_url", - "workflow_path" - ]) and - (.build_type == "workflow") and - (.https_enforced == true) and - (.environment == "github-pages") and - ( - .repository | - type == "string" and - test("^atrinik/[A-Za-z0-9_.-]+$") - ) and - ( - .repository as $full_name | - ($full_name | split("/")[1]) as $repository | - ($repositories[0].pull_request_gate | index($repository)) != null and - ($repositories[0].archive | index($repository)) == null - ) and - (.repository_id | type == "number" and . > 0 and floor == .) and - ( - .repository as $repository | - ($repository | split("/")) as $parts | - .site_url == ("https://" + $parts[0] + ".github.io/" + $parts[1] + "/") - ) and - ( - .workflow_path | - type == "string" and - test("^\\.github/workflows/[A-Za-z0-9_.-]+\\.ya?ml$") - ) and - ( - .activation_marker | - type == "string" and - test("^actions/deploy-pages@[0-9a-f]{40}$") - ) - ) and - all( - $sites[]; - . as $site | - any( - $environments[]; - .repository == $site.repository and - .repository_id == $site.repository_id and - .environment == $site.environment - ) - ) -' "${manual_settings_config}" >/dev/null - -jq -e ' - (keys == [ - "issue_fields", - "issue_types", - "personal_saved_views", - "project", - "type_inference" - ]) and - (.project | keys == [ - "public", - "readme", - "short_description", - "statuses", - "title", - "triage_cutover", - "views" - ]) and - (.project.title | type == "string" and length > 0) and - (.project.short_description | type == "string" and length > 0) and - (.project.readme | type == "string" and length > 0) and - (.project.public | type == "boolean") and - (.project.triage_cutover | fromdateiso8601 | type == "number") and - (.project.statuses | type == "array" and length >= 3) and - ([.project.statuses[].name] | length == (unique | length)) and - all( - .project.statuses[]; - (keys == ["color", "description", "name", "previous_names"]) and - (.name | type == "string" and length > 0) and - (.description | type == "string" and length > 0) and - (.color | IN( - "BLUE", "GRAY", "GREEN", "ORANGE", "PINK", "PURPLE", "RED", "YELLOW" - )) and - (.previous_names | type == "array") and - ((.previous_names | length) == (.previous_names | unique | length)) and - all(.previous_names[]; type == "string" and length > 0) - ) and - ([.project.statuses[].previous_names[]] as $previous | - ($previous | length) == ($previous | unique | length)) and - ([.project.statuses[].name] as $status_names | - all( - .project.statuses[].previous_names[]; - . as $previous_name | - ($status_names | index($previous_name)) == null - )) and - ([.project.statuses[].name] | index("Inbox") != null) and - ([.project.statuses[].name] | index("Backlog") != null) and - ([.project.statuses[].name] | index("Review") != null) and - ([.project.statuses[].name] | index("Done") != null) and - (.project.views | type == "array" and length > 0) and - ([.project.views[].name] | length == (unique | length)) and - all( - .project.views[]; - (keys == ["filter", "layout", "name", "visible_fields"]) and - (.name | type == "string" and length > 0) and - (.layout | IN("BOARD_LAYOUT", "ROADMAP_LAYOUT", "TABLE_LAYOUT")) and - (.filter | type == "string") and - (.visible_fields | type == "array") and - (if .layout == "ROADMAP_LAYOUT" then - (.visible_fields | length == 0) - else - (.visible_fields | length > 0) - end) and - ((.visible_fields | length) == (.visible_fields | unique | length)) and - all(.visible_fields[]; type == "string" and length > 0) - ) and - (.issue_types | type == "array" and length > 0) and - ([.issue_types[].name] | length == (unique | length)) and - all( - .issue_types[]; - (keys == ["color", "description", "enabled", "name"]) and - (.name | type == "string" and length > 0) and - (.description | type == "string" and length > 0) and - (.color | IN("BLUE", "GRAY", "GREEN", "ORANGE", "PINK", "PURPLE", "RED", "YELLOW")) and - (.enabled | type == "boolean") - ) and - (.issue_fields | type == "array" and length > 0) and - ([.issue_fields[].name] | length == (unique | length)) and - all( - .issue_fields[]; - (.name | type == "string" and length > 0) and - (.description | type == "string" and length > 0) and - (.data_type | IN("DATE", "MULTI_SELECT", "NUMBER", "SINGLE_SELECT", "TEXT")) and - (.visibility | IN("ALL", "ORG_ONLY")) and - if (.data_type | IN("MULTI_SELECT", "SINGLE_SELECT")) then - (keys == ["data_type", "description", "name", "options", "visibility"]) and - (.options | type == "array" and length > 0) and - ([.options[].name] | length == (unique | length)) and - all( - .options[]; - (keys == ["color", "description", "name"]) and - (.name | type == "string" and length > 0) and - (.description == null or - (.description | type == "string" and length > 0)) and - (.color | IN("BLUE", "GRAY", "GREEN", "ORANGE", "PINK", "PURPLE", "RED", "YELLOW")) - ) - else - (keys == ["data_type", "description", "name", "visibility"]) - end - ) and - ([.issue_types[].name] as $type_names | - (.type_inference | keys == [ - "bug_labels", "default", "feature_labels", "initiative_when_parent" - ]) and - (.type_inference.initiative_when_parent | type == "boolean") and - (.type_inference.default as $name | ($type_names | index($name)) != null) and - all(.type_inference.bug_labels[]; type == "string" and length > 0) and - all(.type_inference.feature_labels[]; type == "string" and length > 0) and - ((.type_inference.bug_labels + .type_inference.feature_labels) | - length == (unique | length))) and - (.personal_saved_views | type == "array" and length > 0) and - ([.personal_saved_views[].name] | length == (unique | length)) and - all( - .personal_saved_views[]; - (keys == ["name", "query"]) and - (.name | type == "string" and length > 0) and - (.query | type == "string" and startswith("org:atrinik ")) - ) -' "${planning_config}" >/dev/null - -jq -e ' - (keys == [ - "consecutive_failure_threshold", - "freshness_threshold_minutes", - "incident_actor", - "incident_marker", - "incident_title", - "monitor_workflow", - "monitoring_owner", - "repository", - "sync_workflow" - ]) and - ( - .consecutive_failure_threshold | - type == "number" and floor == . and . >= 2 and . <= 10 - ) and - ( - .freshness_threshold_minutes | - type == "number" and floor == . and . >= 60 and . <= 1440 - ) and - .incident_actor == "github-actions[bot]" and - .incident_marker == "" and - (.incident_title | type == "string" and length > 0 and length <= 120) and - ( - .monitor_workflow | - type == "string" and test("^[A-Za-z0-9_.-]+\\.ya?ml$") - ) and - (.monitoring_owner | type == "string" and length > 0) and - .repository == "atrinik/github-settings" and - ( - .sync_workflow | - type == "string" and test("^[A-Za-z0-9_.-]+\\.ya?ml$") - ) -' "${planning_health_config}" >/dev/null - -for workflow in $(jq -r '.monitor_workflow, .sync_workflow' \ - "${planning_health_config}"); do - if [[ ! -f ${root}/.github/workflows/${workflow} ]]; then - echo "error: planning health workflow is missing: ${workflow}" >&2 - exit 1 - fi -done - -jq -e \ - --slurpfile repositories "${repositories_config}" ' - . as $config | - ([".github"] + $repositories[0].pull_request_gate + $repositories[0].archive | - sort | unique) as $expected_repositories | - ($config.definitions | - map({key: .property_name, value: .}) | from_entries) as $definitions | - ($config | keys == ["definitions", "repositories"]) and - ($config.definitions | type == "array" and length > 0) and - ([$config.definitions[].property_name] | length == (unique | length)) and - all( - $config.definitions[]; - . as $definition | - (keys == [ - "allowed_values", - "default_value", - "description", - "property_name", - "required", - "value_type" - ]) and - (.property_name | type == "string" and test("^[a-z][a-z0-9_]*$")) and - (.description | type == "string" and length > 0) and - (.value_type | IN("multi_select", "single_select")) and - (.required == true) and - (.allowed_values | type == "array" and length > 0) and - (.allowed_values == (.allowed_values | sort | unique)) and - all(.allowed_values[]; type == "string" and length > 0) and - if $definition.value_type == "multi_select" then - ($definition.default_value | type == "array" and length > 0) and - ($definition.default_value == - ($definition.default_value | sort | unique)) and - all( - $definition.default_value[]; - . as $value | - ($definition.allowed_values | index($value)) != null - ) - else - ($definition.default_value | type == "string") and - ($definition.default_value as $value | - ($definition.allowed_values | index($value)) != null) - end - ) and - ($config.repositories | keys) == $expected_repositories and - all( - $config.repositories | to_entries[]; - (.value | keys) == ($definitions | keys) and - all( - .value | to_entries[]; - .key as $name | - $definitions[$name] as $definition | - if $definition.value_type == "multi_select" then - (.value | type == "array" and length > 0) and - (.value == (.value | sort | unique)) and - all(.value[]; . as $value | ($definition.allowed_values | index($value)) != null) - else - (.value | type == "string") and - (.value as $value | ($definition.allowed_values | index($value)) != null) - end - ) - ) and - all( - $repositories[0].archive[]; - . as $repository | - $config.repositories[$repository].lifecycle == "archived" and - $config.repositories[$repository].release_policy == "none" - ) and - all( - $repositories[0].pull_request_gate[]; - . as $repository | - $config.repositories[$repository].lifecycle != "archived" and - ( - ( - ($repositories[0].release_tags | index($repository)) != null and - $config.repositories[$repository].release_policy == "semantic-release" - ) or - ( - ($repositories[0].release_tags | index($repository)) == null and - $config.repositories[$repository].release_policy == "none" - ) - ) - ) and - $config.repositories[".github"] == { - component_role: ["governance"], - provider_set: ["organization"], - lifecycle: "active", - release_policy: "none" - } - ' "${repository_properties_config}" >/dev/null - -jq -e ' - (keys == ["files", "repository"]) and - (.repository == { - name: ".github", - description: "Atrinik organization-wide community health defaults", - private: false, - has_issues: false, - has_projects: false, - has_wiki: false - }) and - (.files | type == "array" and length > 0) and - any( - .files[]; - . == {source: "profile/README.md", target: "profile/README.md"} - ) and - ([.files[].source] | length == (unique | length)) and - ([.files[].target] | length == (unique | length)) and - all( - .files[]; - (keys == ["source", "target"]) and - (.source | type == "string" and length > 0 and startswith("/") | not) and - (.target | type == "string" and length > 0 and startswith("/") | not) and - (.source | contains("..") | not) and - (.target | contains("..") | not) - ) -' "${community_health_config}" >/dev/null - -while IFS= read -r community_file; do - if [[ ! -s ${root}/community-health/${community_file} ]]; then - echo "error: missing community-health source file: ${community_file}" >&2 - exit 1 - fi -done < <(jq -r '.files[].source' "${community_health_config}") - -profile_readme=${root}/community-health/profile/README.md -# shellcheck disable=SC2016 # Markdown code markers are intentionally literal. -for required_text in \ - '# Atrinik' \ - 'Atrinik is an open-source cooperative fantasy role-playing world' \ - 'GPL-licensed [Atrinik Classic](https://github.com/atrinik/classic)' \ - 'next-generation MIT' \ - 'They do not yet form a complete game release.' \ - 'Game content and' \ - 'media remain separately licensed' \ - '[Tools](https://github.com/atrinik/tools)' \ - 'is MIT by default with a GPL-2.0-or-later `map-checker-qt/` exception; historical' \ - 'tools tags and releases remain under the terms that applied when published' \ - 'historical MIT provenance registry' \ - 'exact, independently separable' \ - 'copy it, migrate or port it, translate or adapt it, or' \ - 'each selected contribution' \ - "applicable named grantor's original work" \ - 'solely authored by that grantor' \ - "row's temporal scope" \ - 'only when each independently' \ - 'satisfies one row' \ - 'jointly authored' \ - 'contributions, generated output, or' \ - 'inseparable mixed work' \ - 'does not relicense the source' \ - 'repositories or by itself' \ - 'GPL dependency, link, or bundle' \ - '[Play Atrinik Classic](https://atrinik.org/downloads/)' \ - '[Follow the next-generation roadmap](https://github.com/atrinik/atrinik/issues/168)' \ - 'Direct human contributions are welcome.'; do - if ! grep -Fq "${required_text}" "${profile_readme}"; then - echo "error: organization profile is missing required text: ${required_text}" >&2 - exit 1 - fi -done - -validate_issue_form() { - local form_name=$1 - local inference_key=$2 - local inferred_type=$3 - local form_file labels_json - - form_file=${root}/community-health/.github/ISSUE_TEMPLATE/${form_name}.yml - if grep -Eq '^(title|type)[[:space:]]*:' "${form_file}"; then - echo "error: ${form_name} issue form uses live-validator-incompatible title or type metadata" >&2 - exit 1 - fi - - if [[ -z ${inference_key} ]]; then - if grep -Eq '^labels[[:space:]]*:' "${form_file}"; then - echo "error: ${form_name} issue form must remain unlabeled for default type inference" >&2 - exit 1 - fi - if ! jq -e --arg inferred_type "${inferred_type}" ' - .type_inference.default == $inferred_type and - any(.issue_types[]; .name == $inferred_type and .enabled) - ' "${planning_config}" >/dev/null; then - echo "error: ${form_name} issue form default type inference is unavailable" >&2 - exit 1 - fi - return - fi - - if [[ $(grep -Ec '^labels[[:space:]]*:' "${form_file}") -ne 1 ]]; then - echo "error: ${form_name} issue form must declare one inline labels array" >&2 - exit 1 - fi - labels_json=$(sed -n 's/^labels[[:space:]]*:[[:space:]]*//p' "${form_file}") - if ! jq -e ' - type == "array" and - length > 0 and - length == (unique | length) and - all(.[]; type == "string" and length > 0) - ' <<<"${labels_json}" >/dev/null; then - echo "error: ${form_name} issue form labels must be a non-empty JSON-style array" >&2 - exit 1 - fi - if ! jq -e \ - --arg inference_key "${inference_key}" \ - --arg inferred_type "${inferred_type}" \ - --argjson form_labels "${labels_json}" ' - any(.issue_types[]; .name == $inferred_type and .enabled) and - ( - ($form_labels | map(ascii_downcase)) as $labels | - (.type_inference[$inference_key] | map(ascii_downcase)) as $inference_labels | - any($labels[]; . as $label | ($inference_labels | index($label)) != null) - ) - ' "${planning_config}" >/dev/null; then - echo "error: ${form_name} issue form labels do not infer enabled type ${inferred_type}" >&2 - exit 1 - fi -} - -# GitHub's live community-health renderer currently rejects direct issue-form -# type metadata. Labels retain Bug and Feature inference; Task is the fallback. -validate_issue_form bug bug_labels Bug -validate_issue_form feature feature_labels Feature -validate_issue_form task "" Task - -while IFS= read -r branch; do - if ! git check-ref-format --branch "${branch}" >/dev/null; then - echo "error: invalid maintenance branch name: ${branch}" >&2 - exit 1 - fi -done < <(jq -r '.maintenance_branches[].branch' "${repositories_config}") - -echo "Governance configuration is valid." diff --git a/bin/verify-manual-settings b/bin/verify-manual-settings deleted file mode 100755 index 796988f..0000000 --- a/bin/verify-manual-settings +++ /dev/null @@ -1,996 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -organization=${ATRINIK_ORGANIZATION:-atrinik} -api_version=2026-03-10 - -crate_setup_repository= -if (($# == 2)) && [[ $1 == --crate-publication-setup ]]; then - crate_setup_repository=$2 -elif (($#)); then - echo "usage: $0 [--crate-publication-setup OWNER/REPOSITORY]" >&2 - exit 2 -fi - -for command in base64 gh jq; do - if ! command -v "${command}" >/dev/null 2>&1; then - echo "error: ${command} is required" >&2 - exit 1 - fi -done -if [[ ${GITHUB_ACTIONS:-false} == true && -z ${GH_TOKEN:-} ]]; then - echo "error: ATRINIK_SETTINGS_TOKEN is unavailable: GH_TOKEN is empty in GitHub Actions" >&2 - exit 1 -fi - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -manual_settings=${root}/config/manual-settings.json -repository_defaults=${root}/config/repository-defaults.json -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -"${root}/bin/validate" >/dev/null -if [[ -n ${crate_setup_repository} ]] && ! jq -e --arg repository "${crate_setup_repository}" ' - [.crates_io_trusted_publishing[] | select(.repository == $repository and - .source_state == "observed-reviewed-workflow" and .environment_state == "observed")] | length == 1 -' "${manual_settings}" >/dev/null; then - echo "error: initial immutable selection requires observed qualified source/environment for ${crate_setup_repository}" >&2 - exit 1 -fi - -github_api() { - local operation=$1 - local response - local status - - shift - if response=$(gh api -H "X-GitHub-Api-Version: ${api_version}" "$@"); then - : - else - status=$? - echo "error: GitHub API operation failed: ${operation}" >&2 - return "${status}" - fi - if ! jq -e 'type == "object"' <<<"${response}" >/dev/null; then - echo "error: GitHub API operation returned invalid JSON: ${operation}" >&2 - return 1 - fi - printf '%s\n' "${response}" -} - -declare -A repository_data_files=() -declare -A repository_secret_files=() -declare -A repository_variable_files=() - -load_repository_identity() { - local repository=$1 - local repository_key status - - if [[ -v repository_data_files["${repository}"] ]]; then - return - fi - - repository_key=${repository//\//-} - repository_data_files["${repository}"]=${temporary}/${repository_key}.json - if github_api "read ${repository} identity" "repos/${repository}" \ - >"${repository_data_files["${repository}"]}"; then - : - else - status=$? - return "${status}" - fi -} - -load_repository_secrets() { - local repository=$1 - local collected expected page page_size repository_key response status - - if [[ -v repository_secret_files["${repository}"] ]]; then - return - fi - if load_repository_identity "${repository}"; then - : - else - status=$? - return "${status}" - fi - - repository_key=${repository//\//-} - repository_secret_files["${repository}"]=${temporary}/${repository_key}-secrets.jsonl - : >"${repository_secret_files["${repository}"]}" - expected= - collected=0 - page=1 - while true; do - if response=$(github_api \ - "list ${repository} Actions secrets (page ${page})" \ - "repos/${repository}/actions/secrets?per_page=100&page=${page}"); then - : - else - status=$? - return "${status}" - fi - if ! jq -e ' - (.total_count | type == "number" and floor == . and . >= 0) and - (.secrets | type == "array") - ' <<<"${response}" >/dev/null; then - echo "error: Actions secret metadata response is invalid for ${repository} (page ${page})" >&2 - return 1 - fi - if [[ -z ${expected} ]]; then - expected=$(jq -r '.total_count' <<<"${response}") - elif [[ $(jq -r '.total_count' <<<"${response}") != "${expected}" ]]; then - echo "error: Actions secret metadata changed while listing ${repository}" >&2 - return 1 - fi - jq -c '.secrets[]' <<<"${response}" \ - >>"${repository_secret_files["${repository}"]}" - page_size=$(jq -r '.secrets | length' <<<"${response}") - ((collected += page_size)) - if ((collected >= expected)); then - break - fi - if ((page_size == 0)); then - echo "error: Actions secret metadata ended before total_count for ${repository}" >&2 - return 1 - fi - ((page += 1)) - done - if ((collected != expected)); then - echo "error: Actions secret metadata count mismatch for ${repository}: expected ${expected}, got ${collected}" >&2 - return 1 - fi -} - -load_repository_variables() { - local repository=$1 - local collected expected page page_size repository_key response status - - if [[ -v repository_variable_files["${repository}"] ]]; then - return - fi - if load_repository_identity "${repository}"; then - : - else - status=$? - return "${status}" - fi - - repository_key=${repository//\//-} - repository_variable_files["${repository}"]=${temporary}/${repository_key}-variables.jsonl - : >"${repository_variable_files["${repository}"]}" - expected= - collected=0 - page=1 - while true; do - if response=$(github_api \ - "list ${repository} Actions variables (page ${page})" \ - "repos/${repository}/actions/variables?per_page=100&page=${page}"); then - : - else - status=$? - return "${status}" - fi - if ! jq -e ' - (.total_count | type == "number" and floor == . and . >= 0) and - (.variables | type == "array") and - all( - .variables[]; - (.name | type == "string") and - (.created_at | type == "string") and - (.updated_at | type == "string") - ) - ' <<<"${response}" >/dev/null; then - echo "error: Actions variable metadata response is invalid for ${repository} (page ${page})" >&2 - return 1 - fi - if [[ -z ${expected} ]]; then - expected=$(jq -r '.total_count' <<<"${response}") - elif [[ $(jq -r '.total_count' <<<"${response}") != "${expected}" ]]; then - echo "error: Actions variable metadata changed while listing ${repository}" >&2 - return 1 - fi - jq -c '.variables[] | {name, created_at, updated_at}' <<<"${response}" \ - >>"${repository_variable_files["${repository}"]}" - page_size=$(jq -r '.variables | length' <<<"${response}") - ((collected += page_size)) - if ((collected >= expected)); then - break - fi - if ((page_size == 0)); then - echo "error: Actions variable metadata ended before total_count for ${repository}" >&2 - return 1 - fi - ((page += 1)) - done - if ((collected != expected)); then - echo "error: Actions variable metadata count mismatch for ${repository}: expected ${expected}, got ${collected}" >&2 - return 1 - fi -} - -load_paginated_metadata() { - local operation=$1 - local endpoint=$2 - local collection=$3 - local output=$4 - local collected=0 - local expected= - local page=1 - local page_size response status - - : >"${output}" - while true; do - if response=$(github_api \ - "${operation} (page ${page})" \ - "${endpoint}?per_page=100&page=${page}"); then - : - else - status=$? - return "${status}" - fi - if ! jq -e --arg collection "${collection}" ' - (.total_count | type == "number" and floor == . and . >= 0) and - (.[$collection] | type == "array") - ' <<<"${response}" >/dev/null; then - echo "error: ${operation} returned invalid metadata (page ${page})" >&2 - return 1 - fi - if [[ -z ${expected} ]]; then - expected=$(jq -r '.total_count' <<<"${response}") - elif [[ $(jq -r '.total_count' <<<"${response}") != "${expected}" ]]; then - echo "error: ${operation} changed while listing metadata" >&2 - return 1 - fi - jq -c --arg collection "${collection}" '.[$collection][]' <<<"${response}" \ - >>"${output}" - page_size=$(jq -r --arg collection "${collection}" '.[$collection] | length' \ - <<<"${response}") - ((collected += page_size)) - if ((collected >= expected)); then - break - fi - if ((page_size == 0)); then - echo "error: ${operation} ended before total_count" >&2 - return 1 - fi - ((page += 1)) - done - if ((collected != expected)); then - echo "error: ${operation} count mismatch: expected ${expected}, got ${collected}" >&2 - return 1 - fi -} - -verify_repository_identity() { - local repository=$1 - local repository_id=$2 - local default_branch repository_data status - - if load_repository_identity "${repository}"; then - : - else - status=$? - return "${status}" - fi - repository_data=$(<"${repository_data_files["${repository}"]}") - default_branch=$(jq -r '.default_branch' "${repository_defaults}") - if ! jq -e \ - --arg repository "${repository}" \ - --arg default_branch "${default_branch}" \ - --argjson repository_id "${repository_id}" ' - .id == $repository_id and - .full_name == $repository and - .archived == false and - .default_branch == $default_branch - ' <<<"${repository_data}" >/dev/null; then - echo "error: repository identity or active-state drift for ${repository}" >&2 - return 1 - fi -} - -missing=0 -if [[ -z ${crate_setup_repository} ]]; then -while IFS= read -r credential; do - repository=$(jq -r '.repository' <<<"${credential}") - repository_owner=${repository%%/*} - repository_id=$(jq -r '.repository_id' <<<"${credential}") - secret_name=$(jq -r '.secret_name' <<<"${credential}") - secret_scope=$(jq -r '.secret_scope' <<<"${credential}") - - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: credential repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - case ${secret_scope} in - repository) - if load_repository_secrets "${repository}"; then :; else - status=$? - exit "${status}" - fi - secrets_file=${repository_secret_files["${repository}"]} - ;; - environment) - environment=$(jq -r '.environment' <<<"${credential}") - secrets_file=${temporary}/${repository//\//-}-${environment}-credential-secrets.jsonl - if load_paginated_metadata \ - "list ${repository} environment ${environment} credential names" \ - "repos/${repository}/environments/${environment}/secrets" \ - secrets "${secrets_file}"; then :; else - status=$? - exit "${status}" - fi - ;; - *) - echo "error: unsupported Actions secret scope for ${repository}: ${secret_scope}" >&2 - exit 1 - ;; - esac - - updated_at=$(jq -sr --arg name "${secret_name}" ' - [.[] | select(.name == $name) | .updated_at] | - if length == 1 then .[0] else empty end - ' "${secrets_file}") - if [[ -z ${updated_at} ]]; then - echo "MISSING ${repository} ${secret_scope} Actions secret ${secret_name}" >&2 - ((missing += 1)) - continue - fi - echo "KEEP ${repository} ${secret_scope} Actions secret ${secret_name} (updated ${updated_at})" -done < <(jq -c '.github_actions_credentials[]' "${manual_settings}") - -if ((missing > 0)); then - echo "error: ${missing} required Actions credential record(s) are missing live secret metadata" >&2 - exit 1 -fi - -while IFS= read -r pages_record; do - repository=$(jq -r '.repository' <<<"${pages_record}") - repository_owner=${repository%%/*} - repository_id=$(jq -r '.repository_id' <<<"${pages_record}") - site_url=$(jq -r '.site_url' <<<"${pages_record}") - workflow_path=$(jq -r '.workflow_path' <<<"${pages_record}") - activation_marker=$(jq -r '.activation_marker' <<<"${pages_record}") - pages_key=${repository//\//-} - - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: Pages repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - - pages_file=${temporary}/${pages_key}-pages.json - workflow_file=${temporary}/${pages_key}-pages-workflow.json - if github_api "read ${repository} Pages metadata" \ - "repos/${repository}/pages" >"${pages_file}" && - github_api "read ${repository} Pages workflow from the default branch" \ - "repos/${repository}/contents/${workflow_path}?ref=main" >"${workflow_file}"; then - : - else - status=$? - exit "${status}" - fi - if ! jq -e --arg site_url "${site_url}" ' - .html_url == $site_url and - .public == true and - .https_enforced == true and - .cname == null and - (.build_type | IN("legacy", "workflow")) - ' "${pages_file}" >/dev/null; then - echo "error: Pages identity or HTTPS drift for ${repository}" >&2 - exit 1 - fi - if ! jq -e ' - .type == "file" and - .encoding == "base64" and - (.content | type == "string") - ' "${workflow_file}" >/dev/null; then - echo "error: Pages workflow metadata is invalid for ${repository}" >&2 - exit 1 - fi - if ! jq -r '.content' "${workflow_file}" | base64 --decode \ - >"${temporary}/${pages_key}-pages-workflow.yml"; then - echo "error: Pages workflow content is not valid base64 for ${repository}" >&2 - exit 1 - fi - - if grep -Fq -- "${activation_marker}" \ - "${temporary}/${pages_key}-pages-workflow.yml"; then - if [[ $(jq -r '.build_type' "${pages_file}") != workflow ]]; then - echo "error: Pages Actions source is not active for merged ${repository} workflow" >&2 - exit 1 - fi - echo "KEEP ${repository} Pages uses the reviewed Actions workflow source" - else - if ! jq -e ' - .build_type == "legacy" and - .source == {branch: "main", path: "/"} - ' "${pages_file}" >/dev/null; then - echo "error: pending Pages activation has unexpected live source for ${repository}" >&2 - exit 1 - fi - echo "PENDING ${repository} Pages remains on the exact legacy main-root source until the reviewed workflow merges" - fi -done < <(jq -c '.github_pages_sites[]' "${manual_settings}") - -# Package metadata proves identity/source/visibility, not a manual Actions-access grant. -while IFS= read -r package_record; do - repository=$(jq -r '.actions_repository' <<<"${package_record}") - repository_id=$(jq -r '.actions_repository_id' <<<"${package_record}") - verify_repository_identity "${repository}" "${repository_id}" - package_owner=$(jq -r '.package_owner' <<<"${package_record}") - package_type=$(jq -r '.package_type' <<<"${package_record}") - package_name=$(jq -r '.package_name' <<<"${package_record}") - package=$(github_api "read ${package_owner}/${package_name} package identity" \ - "orgs/${package_owner}/packages/${package_type}/${package_name}") - if ! jq -en --argjson actual "${package}" --argjson expected "${package_record}" ' - $actual.id == $expected.package_id and $actual.name == $expected.package_name and - $actual.package_type == $expected.package_type and $actual.visibility == $expected.preserve_visibility and - (if $expected.source_repository != null then - $actual.repository.full_name == $expected.source_repository and - $actual.repository.id == $expected.source_repository_id - else true end) - ' >/dev/null; then - echo "error: package Actions-access identity/source/visibility drift for ${package_owner}/${package_name}" >&2 - exit 1 - fi - if jq -e 'has("grant_state")' <<<"${package_record}" >/dev/null; then - source_repository=$(jq -r '.source_repository' <<<"${package_record}") - source_repository_id=$(jq -r '.source_repository_id' <<<"${package_record}") - verify_repository_identity "${source_repository}" "${source_repository_id}" - if [[ $(jq -r '.grant_state' <<<"${package_record}") == pending-owner-ui-read-grant ]]; then - echo "PENDING ${repository} read-only Actions access to private ${package_owner}/${package_name}; exact package/source verified, owner UI grant and effective workflow pull remain unobserved" - else - echo "OWNER-OBSERVED ${repository} read-only Actions access to private ${package_owner}/${package_name}; GitHub metadata does not prove the UI grant or an effective workflow pull" - fi - else - echo "MANUAL ${repository} ${package_owner}/${package_name} read-only Actions access requires owner UI and owning workflow proof" - fi -done < <(jq -c '.github_packages_actions_access[]' "${manual_settings}") -fi - -# Pending setup is not live activation. Every publisher still requires the -# exact live repository, main ref, and protected-main identity. -while IFS= read -r crate_record; do - repository=$(jq -r '.repository' <<<"${crate_record}") - repository_id=$(jq -r '.repository_id' <<<"${crate_record}") - if [[ ${repository%%/*} != "${organization}" ]]; then - echo "error: crate publisher repository owner does not match ${organization}" >&2 - exit 1 - fi - verify_repository_identity "${repository}" "${repository_id}" - branch=$(github_api "read ${repository} protected main" "repos/${repository}/branches/main") - branch_ref=$(github_api "read ${repository} exact main ref" "repos/${repository}/git/ref/heads/main") - if ! jq -en --argjson branch "${branch}" --argjson ref "${branch_ref}" ' - $branch.name == "main" and $branch.protected == true and - ($branch.commit.sha | type == "string" and test("^[0-9a-f]{40}$")) and - $ref.ref == "refs/heads/main" and $ref.object.type == "commit" and - $ref.object.sha == $branch.commit.sha - ' >/dev/null; then - echo "error: crate publisher protected main or ref drift for ${repository}" >&2 - exit 1 - fi - if [[ $(jq -r '.source_state' <<<"${crate_record}") == observed-reviewed-workflow ]]; then - branch_sha=$(jq -r '.object.sha' <<<"${branch_ref}") - workflow=$(github_api "read ${repository} publication workflow at exact main" \ - "repos/${repository}/contents/.github/workflows/publish-crate.yml?ref=${branch_sha}") - workflow_source=$(jq -er 'select(.encoding == "base64" and .type == "file") | .content' \ - <<<"${workflow}" | base64 --decode) - source_workflow=$(github_api "read ${repository} source signing workflow at exact main" \ - "repos/${repository}/contents/.github/workflows/release.yml?ref=${branch_sha}") - source_workflow_file=${temporary}/${repository##*/}-source-release.yml - jq -er 'select(.encoding == "base64" and .type == "file") | .content' \ - <<<"${source_workflow}" | base64 --decode >"${source_workflow_file}" - python3 "${root}/lib/verify_crate_workflow.py" --repository "${repository}" \ - --repository-id "${repository_id}" --source-workflow-file "${source_workflow_file}" <<<"${workflow_source}" - echo "KEEP ${repository} reviewed publication and source signing workflows at ${branch_sha}" - fi - crates=$(jq -r '.crates | join(",")' <<<"${crate_record}") - echo "KEEP ${repository} exact protected main publication identity" - onboarding_status=PENDING - if jq -e '.source_state == "observed-reviewed-workflow" and .environment_state == "observed" and .publisher_registration.state == "owner-observed-registration"' <<<"${crate_record}" >/dev/null; then - onboarding_status=OWNER-OBSERVED - fi - echo "${onboarding_status} ${repository} crates.io ${crates} via publish-crate.yml / crates-io-release: source=$(jq -r '.source_state' <<<"${crate_record}"), environment=$(jq -r '.environment_state' <<<"${crate_record}"), registration=$(jq -r '.publisher_registration.state' <<<"${crate_record}")" - if [[ $(jq -r '.publisher_registration.state' <<<"${crate_record}") == owner-observed-registration ]]; then - echo "MANUAL ${repository} crates.io registration is owner-observed evidence only; GitHub metadata does not verify external registration" - fi -done < <(jq -c --arg repository "${crate_setup_repository}" ' - .crates_io_trusted_publishing[] | select($repository == "" or .repository == $repository) -' "${manual_settings}") - -while IFS= read -r environment_record; do - repository=$(jq -r '.repository' <<<"${environment_record}") - repository_owner=${repository%%/*} - repository_id=$(jq -r '.repository_id' <<<"${environment_record}") - environment=$(jq -r '.environment' <<<"${environment_record}") - environment_key=${repository//\//-}-${environment} - - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: environment repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - - environment_file=${temporary}/${environment_key}.json - if github_api \ - "read ${repository} environment ${environment}" \ - "repos/${repository}/environments/${environment}" >"${environment_file}"; then - : - else - status=$? - exit "${status}" - fi - if ! jq -e --arg environment "${environment}" ' - .name == $environment and - (.deployment_branch_policy | type == "object") and - (.protection_rules | type == "array") - ' "${environment_file}" >/dev/null; then - echo "error: environment metadata is invalid for ${repository} ${environment}" >&2 - exit 1 - fi - - expected_branch_mode=$(jq -c '.deployment_branch_policy | { - protected_branches, - custom_branch_policies - }' <<<"${environment_record}") - live_branch_mode=$(jq -c '.deployment_branch_policy | { - protected_branches, - custom_branch_policies - }' "${environment_file}") - if [[ ${live_branch_mode} != "${expected_branch_mode}" ]]; then - echo "error: deployment branch mode drift for ${repository} ${environment}" >&2 - exit 1 - fi - - expected_branch_policies=$(jq -c \ - '[.deployment_branch_policy.patterns[] | {name, type}] | sort_by(.type, .name)' \ - <<<"${environment_record}") - if jq -e '.deployment_branch_policy.custom_branch_policies == true' \ - <<<"${environment_record}" >/dev/null; then - branch_policies_file=${temporary}/${environment_key}-branch-policies.jsonl - if load_paginated_metadata \ - "list ${repository} environment ${environment} deployment branch policies" \ - "repos/${repository}/environments/${environment}/deployment-branch-policies" \ - branch_policies "${branch_policies_file}"; then - : - else - status=$? - exit "${status}" - fi - live_branch_policies=$(jq -sc \ - '[.[] | {name, type}] | sort_by(.type, .name)' "${branch_policies_file}") - else - # GitHub exposes custom policies only for custom-branch-policy mode. - live_branch_policies='[]' - fi - if [[ ${live_branch_policies} != "${expected_branch_policies}" ]]; then - echo "error: deployment branch policy drift for ${repository} ${environment}" >&2 - exit 1 - fi - - expected_reviewers=$(jq -c \ - '.required_reviewers | sort_by(.type, .id)' <<<"${environment_record}") - reviewer_rule_count=$(jq \ - '[.protection_rules[] | select(.type == "required_reviewers")] | length' \ - "${environment_file}") - live_reviewers=$(jq -c ' - [.protection_rules[] | - select(.type == "required_reviewers") | - .reviewers[] | - {type, id: .reviewer.id}] | - sort_by(.type, .id) - ' "${environment_file}") - if [[ (${expected_reviewers} == '[]' && ${reviewer_rule_count} -ne 0) || - (${expected_reviewers} != '[]' && ${reviewer_rule_count} -ne 1) || - ${live_reviewers} != "${expected_reviewers}" ]]; then - echo "error: required reviewer drift for ${repository} ${environment}" >&2 - exit 1 - fi - expected_protection_rule_types=$(jq -cn \ - --argjson reviewers "${expected_reviewers}" \ - '["branch_policy"] + - (if ($reviewers | length) > 0 then ["required_reviewers"] else [] end) | - sort') - live_protection_rule_types=$(jq -c \ - '[.protection_rules[].type] | sort' "${environment_file}") - if [[ ${live_protection_rule_types} != "${expected_protection_rule_types}" ]]; then - echo "error: protection rule drift for ${repository} ${environment}" >&2 - exit 1 - fi - - if jq -e 'has("wait_timer_minutes")' <<<"${environment_record}" >/dev/null; then - if ! jq -e '.can_admins_bypass == false and - all(.protection_rules[]; .type != "wait_timer" and .type != "required_reviewers")' \ - "${environment_file}" >/dev/null; then - echo "error: automatic crate environment bypass, reviewer, or wait drift for ${repository}" >&2 - exit 1 - fi - fi - - secrets_file=${temporary}/${environment_key}-secrets.jsonl - if load_paginated_metadata \ - "list ${repository} environment ${environment} secrets" \ - "repos/${repository}/environments/${environment}/secrets" \ - secrets "${secrets_file}"; then - : - else - status=$? - exit "${status}" - fi - expected_names=$(jq -c '.secret_names | sort' <<<"${environment_record}") - live_names=$(jq -sc '[.[].name] | sort' "${secrets_file}") - if [[ ${live_names} != "${expected_names}" ]]; then - echo "error: environment secret-name drift for ${repository} ${environment}" >&2 - exit 1 - fi - - variables_file=${temporary}/${environment_key}-variables.jsonl - if load_paginated_metadata \ - "list ${repository} environment ${environment} variables" \ - "repos/${repository}/environments/${environment}/variables" \ - variables "${variables_file}"; then - : - else - status=$? - exit "${status}" - fi - expected_names=$(jq -c '.variable_names | sort' <<<"${environment_record}") - live_names=$(jq -sc '[.[].name] | sort' "${variables_file}") - if [[ ${live_names} != "${expected_names}" ]]; then - echo "error: environment variable-name drift for ${repository} ${environment}" >&2 - exit 1 - fi - - echo "KEEP ${repository} environment ${environment} metadata" -done < <(jq -c --arg repository "${crate_setup_repository}" ' - (.github_actions_environments[] | select($repository == "")), - (.crates_io_trusted_publishing[] | select(.environment_state == "observed") | - select($repository == "" or .repository == $repository) | - . as $publisher | .environment | - {repository: $publisher.repository, repository_id: $publisher.repository_id, - environment: .name, deployment_branch_policy, required_reviewers, - secret_names, variable_names, can_admins_bypass, wait_timer_minutes}) -' "${manual_settings}") - -if [[ -n ${crate_setup_repository} ]]; then - final_branch=$(github_api "recheck ${crate_setup_repository} protected main" \ - "repos/${crate_setup_repository}/branches/main") - final_ref=$(github_api "recheck ${crate_setup_repository} main revision" \ - "repos/${crate_setup_repository}/git/ref/heads/main") - if ! jq -en --arg sha "${branch_sha}" --argjson branch "${final_branch}" --argjson ref "${final_ref}" ' - $branch.name == "main" and $branch.protected == true and $branch.commit.sha == $sha and - $ref.ref == "refs/heads/main" and $ref.object.type == "commit" and $ref.object.sha == $sha - ' >/dev/null; then - echo "error: protected-main setup changed during ${crate_setup_repository} qualification" >&2 - exit 1 - fi - echo "KEEP ${crate_setup_repository} initial immutable selection setup qualified at ${branch_sha}; runtime release/registry operations remain separate" - exit 0 -fi - -installations_file=${temporary}/${organization}-installations.jsonl -if load_paginated_metadata \ - "list ${organization} GitHub App installations" \ - "orgs/${organization}/installations" \ - installations "${installations_file}"; then - : -else - status=$? - exit "${status}" -fi - -while IFS= read -r app_record; do - app_status=$(jq -r '.status' <<<"${app_record}") - app_id=$(jq -r '.app_id' <<<"${app_record}") - app_slug=$(jq -r '.app_slug' <<<"${app_record}") - installation_id=$(jq -r '.installation_id' <<<"${app_record}") - expected_permissions=$(jq -c '.permissions' <<<"${app_record}") - expected_events=$(jq -c '.events' <<<"${app_record}") - - if [[ ${app_status} == planned ]]; then - if jq -s -e --arg app_slug "${app_slug}" \ - 'any(.[]; .app_slug == $app_slug)' "${installations_file}" \ - >/dev/null; then - echo "error: planned external provider App has a live installation for ${app_slug}" >&2 - exit 1 - fi - control_plane_repository=$(jq -r '.control_plane_repository.repository' <<<"${app_record}") - control_plane_repository_id=$(jq -r '.control_plane_repository.repository_id' <<<"${app_record}") - if verify_repository_identity "${control_plane_repository}" "${control_plane_repository_id}"; then - : - else - status=$? - exit "${status}" - fi - control_plane_repository_visibility=$(jq -r '.control_plane_repository.visibility' <<<"${app_record}") - control_plane_repository_license=$(jq -r '.control_plane_repository.license' <<<"${app_record}") - if ! jq -e \ - --arg visibility "${control_plane_repository_visibility}" \ - --arg license "${control_plane_repository_license}" \ - '.visibility == $visibility and .license.spdx_id == $license' \ - "${repository_data_files["${control_plane_repository}"]}" >/dev/null; then - echo "error: repository visibility or license drift for ${control_plane_repository}" >&2 - exit 1 - fi - - while IFS= read -r repository_record; do - repository=$(jq -r '.repository' <<<"${repository_record}") - repository_id=$(jq -r '.repository_id' <<<"${repository_record}") - repository_owner=${repository%%/*} - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: planned external provider App repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - done < <(jq -c '.repositories[]' <<<"${app_record}") - - echo "PENDING ${app_slug} GitHub App installation and credentials; owner UI proof is required for ${control_plane_repository} and selected repository atrinik/classic only" - continue - fi - - installation=$(jq -sc \ - --argjson app_id "${app_id}" \ - --argjson installation_id "${installation_id}" ' - [.[] | select(.app_id == $app_id and .id == $installation_id)] | - if length == 1 then .[0] else empty end - ' "${installations_file}") - if [[ -z ${installation} ]]; then - echo "error: external provider App installation is missing or ambiguous for ${app_slug}" >&2 - exit 1 - fi - if ! jq -e \ - --arg app_slug "${app_slug}" \ - --arg organization "${organization}" \ - --argjson expected_permissions "${expected_permissions}" \ - --argjson expected_events "${expected_events}" ' - .app_slug == $app_slug and - .target_type == "Organization" and - .account.login == $organization and - .account.type == "Organization" and - .repository_selection == "selected" and - .permissions == $expected_permissions and - .events == $expected_events and - .suspended_at == null - ' <<<"${installation}" >/dev/null; then - echo "error: external provider App installation metadata or permission drift for ${app_slug}" >&2 - exit 1 - fi - - while IFS= read -r repository_record; do - repository=$(jq -r '.repository' <<<"${repository_record}") - repository_id=$(jq -r '.repository_id' <<<"${repository_record}") - repository_owner=${repository%%/*} - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: external provider App repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - done < <(jq -c '.repositories[]' <<<"${app_record}") - - echo "KEEP ${app_slug} installation metadata and exact permissions/events" - echo "MANUAL ${app_slug} selected repositories require owner UI proof: atrinik/website and atrinik/metaserver-worker only" -done < <(jq -c '.external_provider_apps[]' "${manual_settings}") - -while IFS= read -r app_record; do - app_id=$(jq -r '.app_id' <<<"${app_record}") - app_slug=$(jq -r '.app_slug' <<<"${app_record}") - installation_id=$(jq -r '.installation_id' <<<"${app_record}") - repository=$(jq -r '.repository' <<<"${app_record}") - repository_owner=${repository%%/*} - repository_id=$(jq -r '.repository_id' <<<"${app_record}") - secret_name=$(jq -r '.secret_name' <<<"${app_record}") - variable_name=$(jq -r '.variable_name' <<<"${app_record}") - - if [[ ${repository_owner} != "${organization}" ]]; then - echo "error: GitHub App repository owner does not match ${organization}: ${repository}" >&2 - exit 1 - fi - if verify_repository_identity "${repository}" "${repository_id}"; then - : - else - status=$? - exit "${status}" - fi - - expected_permissions=$(jq -c '.permissions' <<<"${app_record}") - installation=$(jq -sc \ - --argjson app_id "${app_id}" \ - --argjson installation_id "${installation_id}" ' - [.[] | select(.app_id == $app_id and .id == $installation_id)] | - if length == 1 then .[0] else empty end - ' "${installations_file}") - if [[ -z ${installation} ]]; then - echo "error: GitHub App installation is missing or ambiguous for ${app_slug}" >&2 - exit 1 - fi - if ! jq -e \ - --arg app_slug "${app_slug}" \ - --arg organization "${organization}" \ - --argjson expected_permissions "${expected_permissions}" ' - .app_slug == $app_slug and - .target_type == "Organization" and - .account.login == $organization and - .account.type == "Organization" and - .repository_selection == "selected" and - .permissions == $expected_permissions and - .events == [] and - .suspended_at == null - ' <<<"${installation}" >/dev/null; then - echo "error: GitHub App installation metadata or permission drift for ${app_slug}" >&2 - exit 1 - fi - - if load_repository_secrets "${repository}"; then - : - else - status=$? - exit "${status}" - fi - secret_updated_at=$(jq -sr --arg name "${secret_name}" ' - [.[] | select(.name == $name) | .updated_at] | - if length == 1 then .[0] else empty end - ' "${repository_secret_files["${repository}"]}") - if [[ -z ${secret_updated_at} ]]; then - echo "error: GitHub App Actions secret name is missing for ${repository}: ${secret_name}" >&2 - exit 1 - fi - - if load_repository_variables "${repository}"; then - : - else - status=$? - exit "${status}" - fi - variable_updated_at=$(jq -sr --arg name "${variable_name}" ' - [.[] | select(.name == $name) | .updated_at] | - if length == 1 then .[0] else empty end - ' "${repository_variable_files["${repository}"]}") - if [[ -z ${variable_updated_at} ]]; then - echo "error: GitHub App Actions variable name is missing for ${repository}: ${variable_name}" >&2 - exit 1 - fi - - echo "KEEP ${app_slug} installation metadata and exact permissions" - echo "KEEP ${repository} repository Actions secret ${secret_name} (updated ${secret_updated_at})" - echo "KEEP ${repository} repository Actions variable ${variable_name} (updated ${variable_updated_at})" -done < <(jq -c '.github_actions_apps[]' "${manual_settings}") - -# This dedicated App preserves every unrelated installation. The selected -# repository set needs owner UI proof; administrative APIs cannot enumerate it. -app_record=$(jq -c '.crate_dependency_update_app' "${manual_settings}") -app_slug=$(jq -r '.app_slug' <<<"${app_record}") -if [[ $(jq -r '.status' <<<"${app_record}") == planned ]]; then - if jq -se --arg slug "${app_slug}" 'any(.[]; .app_slug == $slug)' \ - "${installations_file}" >/dev/null; then - echo "error: planned crate dependency App has a live installation; record owner observations" >&2 - exit 1 - fi -else - installation=$(jq -sc --argjson app "${app_record}" ' - [.[] | select(.app_id == $app.app_id and .id == $app.installation_id)] | - if length == 1 then .[0] else empty end - ' "${installations_file}") - if [[ -z ${installation} ]] || ! jq -e --argjson app "${app_record}" \ - --arg organization "${organization}" ' - .app_slug == $app.app_slug and .target_type == "Organization" and - .account.login == $organization and .account.type == "Organization" and - .repository_selection == "selected" and .permissions == $app.permissions and - .events == [] and .suspended_at == null - ' <<<"${installation}" >/dev/null; then - echo "error: crate dependency App installation identity or permission drift" >&2 - exit 1 - fi -fi -while IFS= read -r selected_repository; do - repository=$(jq -r '.repository' <<<"${selected_repository}") - verify_repository_identity "${repository}" "$(jq -r '.repository_id' <<<"${selected_repository}")" - if [[ $(jq -r '.credential_state' <<<"${app_record}") == observed-name-metadata ]]; then - load_repository_secrets "${repository}" - load_repository_variables "${repository}" - for kind in secret variable; do - name=$(jq -r ".${kind}_name" <<<"${app_record}") - if [[ ${kind} == secret ]]; then - metadata_file=${repository_secret_files["${repository}"]} - else - metadata_file=${repository_variable_files["${repository}"]} - fi - if ! jq -se --arg name "${name}" '[.[] | select(.name == $name)] | length == 1' \ - "${metadata_file}" >/dev/null; then - echo "error: crate dependency App ${kind} name missing for ${repository}" >&2 - exit 1 - fi - done - echo "KEEP ${repository} crate dependency App credential name metadata; values and scope remain unverified" - fi -done < <(jq -c '.repositories[]' <<<"${app_record}") -if [[ $(jq -r '.status' <<<"${app_record}") == planned ]]; then - echo "PENDING ${app_slug} selected client App installation and repository credential slots; no provisioning applied" -else - # A selected-set change after the recorded readback stays pending until a - # fresh owner UI or App-authenticated readback is recorded. - if [[ $(jq -c '.repository_scope_reverification' <<<"${app_record}") != null ]]; then - echo "PENDING ${app_slug} selected repositories await re-verification: $(jq -r ' - .repository_scope_reverification | - "a \(.selection_changed_on) repository transfer removed \(.removed_repositories | map(.repository) | join(", ")) after the \(.last_readback_on) readback" - ' <<<"${app_record}"); fresh owner UI or App-authenticated API proof is required: atrinik/client only" - else - echo "MANUAL ${app_slug} selected repositories require current owner UI or App-authenticated API proof: atrinik/client only" - fi - activation_status=PENDING - if [[ $(jq -r '.workflow_activation.state' <<<"${app_record}") == observed-successful-owned-pr ]]; then - activation_status=OWNER-OBSERVED - fi - echo "${activation_status} ${app_slug} owning workflow activation evidence: $(jq -r '.workflow_activation.state' <<<"${app_record}"); name metadata alone does not prove effective values or a successful PR" -fi - -# GraphQL variables must remain literal for GitHub to substitute. -# shellcheck disable=SC2016 -pins_response=$(github_api \ - "read ${organization} organization pins" \ - graphql \ - -f query='query($login:String!){organization(login:$login){login pinnedItems(first:10,types:REPOSITORY){totalCount nodes{... on Repository{name databaseId nameWithOwner isArchived visibility}}}}}' \ - -F login="${organization}") -if ! jq -e \ - --arg organization "${organization}" ' - .data.organization as $organization_data | - ($organization_data | type == "object") and - $organization_data.login == $organization and - ($organization_data.pinnedItems.totalCount | type == "number") and - ($organization_data.pinnedItems.nodes | type == "array") and - $organization_data.pinnedItems.totalCount == - ($organization_data.pinnedItems.nodes | length) and - all( - $organization_data.pinnedItems.nodes[]; - (.name | type == "string" and length > 0) and - (.databaseId | type == "number" and floor == . and . > 0) and - .nameWithOwner == "\($organization)/\(.name)" and - .isArchived == false and - .visibility == "PUBLIC" - ) - ' <<<"${pins_response}" >/dev/null; then - echo "error: GitHub returned invalid organization pin metadata for ${organization}" >&2 - exit 1 -fi - -desired_pins=$(jq -c '.organization_pins.repositories' "${manual_settings}") -live_pins=$(jq -c ' - [.data.organization.pinnedItems.nodes[] | - {name, repository_id: .databaseId}] -' <<<"${pins_response}") -if [[ ${live_pins} != "${desired_pins}" ]]; then - echo "error: organization pin order or identity drift for ${organization}" >&2 - echo "desired: ${desired_pins}" >&2 - echo "live: ${live_pins}" >&2 - exit 1 -fi -echo "KEEP ${organization} organization pins match the exact governed order" - -echo "Manual settings live credential, GitHub App, external provider App, Pages, environment, and organization pin metadata is present; planned integrations are recorded without live provisioning." diff --git a/community-health/.github/ISSUE_TEMPLATE/bug.yml b/community-health/.github/ISSUE_TEMPLATE/bug.yml deleted file mode 100644 index e5a1550..0000000 --- a/community-health/.github/ISSUE_TEMPLATE/bug.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Bug report -description: Report reproducible behavior that is not working as intended -labels: ["bug"] -body: - - type: markdown - attributes: - value: | - Search existing issues first. Security vulnerabilities must use a private vulnerability report instead of this form. - - type: textarea - id: problem - attributes: - label: What happened? - description: Describe the actual behavior and its impact. - placeholder: A concise description of the problem. - validations: - required: true - - type: textarea - id: expected - attributes: - label: What did you expect? - description: Describe the behavior you expected instead. - validations: - required: true - - type: textarea - id: reproduce - attributes: - label: Reproduction - description: Give the smallest deterministic sequence that reproduces the problem. - placeholder: | - 1. Start ... - 2. Run ... - 3. Observe ... - validations: - required: true - - type: input - id: revision - attributes: - label: Version or revision - description: Release, branch, or commit where the problem occurs. - placeholder: main at abc1234 - validations: - required: true - - type: textarea - id: environment - attributes: - label: Environment - description: Relevant operating system, architecture, client/server topology, and configuration. - - type: textarea - id: evidence - attributes: - label: Logs or other evidence - description: Paste only relevant, redacted output. Drag files here when appropriate. - render: shell - - type: checkboxes - id: checks - attributes: - label: Submission checks - options: - - label: I searched for an existing issue describing this problem. - required: true - - label: This report does not contain credentials, private player data, or an undisclosed vulnerability. - required: true diff --git a/community-health/.github/ISSUE_TEMPLATE/config.yml b/community-health/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 6547885..0000000 --- a/community-health/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: Security vulnerability - url: https://github.com/atrinik/atrinik/security/advisories/new - about: Report vulnerabilities privately; do not open a public issue. diff --git a/community-health/.github/ISSUE_TEMPLATE/feature.yml b/community-health/.github/ISSUE_TEMPLATE/feature.yml deleted file mode 100644 index 21732d0..0000000 --- a/community-health/.github/ISSUE_TEMPLATE/feature.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Feature request -description: Propose a user-visible capability or improvement -labels: ["enhancement"] -body: - - type: textarea - id: outcome - attributes: - label: Desired outcome - description: Describe the user or contributor outcome, not only an implementation. - validations: - required: true - - type: textarea - id: motivation - attributes: - label: Motivation - description: Who benefits, and what problem does this solve? - validations: - required: true - - type: textarea - id: scope - attributes: - label: Scope and constraints - description: Identify affected components, compatibility constraints, and deliberate non-goals. - validations: - required: true - - type: textarea - id: acceptance - attributes: - label: Acceptance criteria - description: List observable results that would make the request complete. - placeholder: | - - [ ] ... - - [ ] ... - validations: - required: true - - type: textarea - id: alternatives - attributes: - label: Alternatives considered - description: Describe existing workarounds or competing approaches. - - type: checkboxes - id: checks - attributes: - label: Submission checks - options: - - label: I searched for existing issues and project items covering this outcome. - required: true diff --git a/community-health/.github/ISSUE_TEMPLATE/task.yml b/community-health/.github/ISSUE_TEMPLATE/task.yml deleted file mode 100644 index 9dcc7a9..0000000 --- a/community-health/.github/ISSUE_TEMPLATE/task.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Task -description: Propose a bounded maintenance, documentation, or engineering task -body: - - type: textarea - id: objective - attributes: - label: Objective - description: State the concrete result this task should produce. - validations: - required: true - - type: textarea - id: context - attributes: - label: Context - description: Explain why the work is needed and link prerequisite decisions or issues. - validations: - required: true - - type: textarea - id: acceptance - attributes: - label: Acceptance criteria - placeholder: | - - [ ] ... - - [ ] ... - validations: - required: true - - type: textarea - id: verification - attributes: - label: Verification - description: Describe how completion can be demonstrated. - - type: checkboxes - id: checks - attributes: - label: Submission checks - options: - - label: I searched for existing issues and project items covering this task. - required: true diff --git a/community-health/.github/PULL_REQUEST_TEMPLATE.md b/community-health/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e94c47c..0000000 --- a/community-health/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,18 +0,0 @@ -## Summary - - - -## Verification - - - -## Related work - - - -## Checklist - -- [ ] The title uses Conventional Commits style. -- [ ] Repository-specific instructions have been followed. -- [ ] Tests, documentation, and dependency inventory are updated where needed. -- [ ] No confidential or unreleased information is exposed. diff --git a/community-health/CODE_OF_CONDUCT.md b/community-health/CODE_OF_CONDUCT.md deleted file mode 100644 index 0adc3c3..0000000 --- a/community-health/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,19 +0,0 @@ -# Code of conduct - -Atrinik is committed to a welcoming, respectful, and harassment-free community. -Participate in good faith, assume honest intent, give actionable feedback, and -respect different backgrounds, identities, experiences, and skill levels. - -Unacceptable behavior includes harassment, threats, discrimination, deliberate -intimidation, sustained disruption, sexualized attention, publishing another -person's private information, or retaliation against someone who reports a -concern. - -Project maintainers may remove, edit, or reject contributions and may restrict -participation when behavior harms the community. Enforcement decisions should -be proportionate, private where possible, and focused on protecting affected -people. - -Report conduct concerns privately to the Atrinik organization owners through -[GitHub's organization contact page](https://github.com/orgs/atrinik/people). -Do not use a public issue for a sensitive report. diff --git a/community-health/CONTRIBUTING.md b/community-health/CONTRIBUTING.md deleted file mode 100644 index 6545d90..0000000 --- a/community-health/CONTRIBUTING.md +++ /dev/null @@ -1,21 +0,0 @@ -# Contributing to Atrinik - -Atrinik was founded by [Zoey Seraphina Rose](https://zoeysr.com) and grows -through the work of its community. - -Thank you for helping Atrinik. Search existing issues and the -[Atrinik work project](https://github.com/orgs/atrinik/projects) before opening -new work so related efforts can share one discussion. - -Use the repository that owns the affected component. Bug reports should include -the smallest reproducible scenario, expected behavior, actual behavior, and -relevant logs. Feature requests should describe the user-visible outcome and -acceptance criteria before proposing an implementation. - -Pull-request titles and commits use Conventional Commits style, for example -`fix(server): reject malformed login packets`. Keep changes focused, link the -issue they resolve, and include automated and manual verification. Repository -instructions and contribution guides override this organization default. - -By participating, you agree to follow the -[Atrinik code of conduct](https://github.com/atrinik/.github/blob/main/CODE_OF_CONDUCT.md). diff --git a/community-health/README.md b/community-health/README.md deleted file mode 100644 index 785dd3b..0000000 --- a/community-health/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Atrinik community health defaults - -This repository provides Atrinik's public organization profile, organization-wide -issue forms, pull-request template, contribution guidance, and security policy. -A repository's local file takes precedence when it needs more specific -instructions. - -The source of truth is -[`atrinik/github-settings`](https://github.com/atrinik/github-settings). Do not -edit the generated `atrinik/.github` repository directly. diff --git a/community-health/SECURITY.md b/community-health/SECURITY.md deleted file mode 100644 index bba2817..0000000 --- a/community-health/SECURITY.md +++ /dev/null @@ -1,13 +0,0 @@ -# Security policy - -Do not disclose a suspected vulnerability in a public issue. Use the affected -repository's **Security** tab and open a private vulnerability report. If the -repository cannot be identified, start with -[`atrinik/atrinik`](https://github.com/atrinik/atrinik/security/advisories/new). - -Include affected versions or revisions, impact, reproduction details, and any -known mitigation. Maintainers will coordinate validation, remediation, and -disclosure through the private advisory. - -Only supported default and explicitly maintained branches receive security -fixes. Archived repositories are retained for history and are not supported. diff --git a/community-health/profile/README.md b/community-health/profile/README.md deleted file mode 100644 index 4ae16bf..0000000 --- a/community-health/profile/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# Atrinik - -> A world of crystal, memory, and unfinished paths. - -Atrinik is an open-source cooperative fantasy role-playing world of islands, -ruins, and crystal-lit mysteries. Founded by -[Zoey Seraphina Rose](https://zoeysr.com), it is built with its community. - -The maintained GPL-licensed [Atrinik Classic](https://github.com/atrinik/classic) -line keeps the world playable today. In parallel, a next-generation MIT -implementation is being developed with Go, Rust, and Protobuf foundations. -They do not yet form a complete game release. Game content and -media remain separately licensed under the terms in their source repositories. - -Classic remains GPL as distributed. [Tools](https://github.com/atrinik/tools) -is MIT by default with a GPL-2.0-or-later `map-checker-qt/` exception; historical -tools tags and releases remain under the terms that applied when published. -Under the -[historical MIT provenance registry](https://github.com/atrinik/atrinik/blob/main/docs/PROVENANCE.md), -an MIT destination may inspect exact, independently separable material as -source reference, copy it, migrate or port it, translate or adapt it, or -relicense it only after the canonical audit proves each selected contribution -is the applicable named grantor's original work. Each contribution must be -solely authored by that grantor and fall within the row's temporal scope. -Distinct contributions may cite different rows only when each independently -satisfies one row. Rows cannot be combined to cover jointly authored -contributions, generated output, or inseparable mixed work. Later material needs -contemporaneous compatible permission. This does not relicense the source -repositories or by itself approve a GPL dependency, link, or bundle. - -## Start here - -- [Play Atrinik Classic](https://atrinik.org/downloads/) -- [Explore the development workspace](https://github.com/atrinik/atrinik) -- [Follow the next-generation roadmap](https://github.com/atrinik/atrinik/issues/168) -- [Discover the world](https://atrinik.org/) - -## The project - -| Repository | Purpose | -| --- | --- | -| [classic](https://github.com/atrinik/classic) | The playable, maintained C17 client, server, editor, libraries, and protocol | -| [content](https://github.com/atrinik/content) | Atrinik's authored maps, quests, archetypes, and world data | -| [client](https://github.com/atrinik/client) | Rust and SDL3 foundation for the next-generation MIT client | -| [server](https://github.com/atrinik/server) | Go foundation for the next-generation MIT authoritative server | -| [protocol](https://github.com/atrinik/protocol) | Game Protocol 1 schemas, QUIC specifications, and Go/Rust bindings | - -Atrinik's creators shape the game world with whatever tools serve the work, -including AI tools; every asset keeps its exact credit and license. -Software is developed publicly—primarily through Codex-driven workflows under -maintainer direction, review, provenance controls, and repository validation. -Direct human contributions are welcome. diff --git a/community-health/workflows/dependency-review.yml b/community-health/workflows/dependency-review.yml deleted file mode 100644 index d2ff903..0000000 --- a/community-health/workflows/dependency-review.yml +++ /dev/null @@ -1,215 +0,0 @@ -name: Dependency review - -on: - pull_request: - types: [opened, synchronize, reopened, edited] - -concurrency: - group: dependency-review-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -permissions: - contents: read - pull-requests: write - -jobs: - dependency-review: - name: Dependency review - runs-on: ubuntu-24.04 - timeout-minutes: 10 - steps: - # Advisories and operational errors are nonblocking; read the latest current-head run summary. - # Fork/Dependabot comment restrictions fall back to the job summary. - - name: Review dependency changes - id: dependency_review - timeout-minutes: 5 - continue-on-error: true - uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 - with: - fail-on-severity: low - fail-on-scopes: runtime,development,unknown - warn-only: true - # License metadata only; repository license compatibility rules still apply. - license-check: true - comment-summary-in-pr: always - show-openssf-scorecard: false - retry-on-snapshot-warnings: true - retry-on-snapshot-warnings-timeout: 120 - - name: Report advisory review failures - if: ${{ !cancelled() && steps.dependency_review.outcome == 'failure' }} - continue-on-error: true - timeout-minutes: 2 - env: - GITHUB_TOKEN: ${{ github.token }} - PR_NUMBER: ${{ github.event.pull_request.number }} - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - PR_BASE_REF: ${{ github.event.pull_request.base.ref }} - PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} - shell: python - run: | - import json - import os - import re - import signal - import urllib.error - import urllib.request - - MARKER = '' - NOTICE = ('Dependency review needs attention: the action reported a failure. ' - 'Inspect the available report, annotations, and logs. ' - 'An absent report means the result is unknown, not clean.') - - - def summary(text): - print('::warning::' + text, flush=True) - with open(os.environ['GITHUB_STEP_SUMMARY'], 'a', encoding='utf-8') as stream: - stream.write('\n' + text + '\n') - - - class Stop(Exception): - pass - - - class NoRedirect(urllib.request.HTTPRedirectHandler): - def redirect_request(self, req, fp, code, msg, headers, newurl): - raise Stop('API redirect refused; PR comment was not refreshed.') - - - def report(): - summary(NOTICE) # Preserve visible evidence before any API operation. - env = os.environ - repo, number, head = env['GITHUB_REPOSITORY'], env['PR_NUMBER'], env['PR_HEAD_SHA'] - run, attempt = env['GITHUB_RUN_ID'], env['GITHUB_RUN_ATTEMPT'] - base_ref, base_sha = env['PR_BASE_REF'], env['PR_BASE_SHA'] - if (env['GITHUB_API_URL'] != 'https://api.github.com' - or env['GITHUB_SERVER_URL'] != 'https://github.com' - or env['GITHUB_EVENT_NAME'] != 'pull_request' - or not re.fullmatch(r'atrinik/[A-Za-z0-9_.-]+', repo) - or not all(re.fullmatch(r'[1-9][0-9]*', value) for value in (number, run, attempt)) - or not re.fullmatch(r'[0-9a-f]{40}', head) - or not re.fullmatch(r'[0-9a-f]{40}', base_sha) - or not 1 <= len(base_ref) <= 1024 - or re.search(r'[\x00-\x1f\x7f-\x9f]', base_ref)): - raise Stop('Invalid reporting context; PR comment was not refreshed.') - run_url = f'https://github.com/{repo}/actions/runs/{run}/attempts/{attempt}' - body = (f'## Dependency review needs attention\n\n{NOTICE}\n\n' - f'PR head: `{head}`\n\n[Current run summary and logs]({run_url})\n\n{MARKER}') - summary(f'Review head `{head}`: {run_url}. Always inspect the latest run for the current PR head.') - base = f'https://api.github.com/repos/{repo}' - comments_url = f'{base}/issues/{number}/comments' - opener = urllib.request.build_opener(NoRedirect()) - - def api(method, url, data=None): - request = urllib.request.Request(url, method=method, - data=None if data is None else json.dumps(data).encode('utf-8'), - headers={'Authorization': 'Bearer ' + env['GITHUB_TOKEN'], - 'Accept': 'application/vnd.github+json', - 'Content-Type': 'application/json', - 'X-GitHub-Api-Version': '2022-11-28'}) - with opener.open(request, timeout=10) as response: - raw = response.read(8 * 1024 * 1024 + 1) - if len(raw) > 8 * 1024 * 1024: - raise Stop('API response exceeded the reporting bound; PR comment was not refreshed.') - return json.loads(raw), response.headers.get('Link', '') - - def owned(comment): - return (comment['user']['login'] == 'github-actions[bot]' - and comment['user']['type'] == 'Bot' - and comment['body'].count(MARKER) == 1 - and comment['body'].rstrip().endswith(MARKER)) - - repository, _ = api('GET', base) - repository_id = repository['id'] - if (repository['full_name'] != repo - or type(repository_id) is not int or repository_id <= 0): - raise Stop('Repository identity mismatch; PR comment was not refreshed.') - numeric_comments_url = f'https://api.github.com/repositories/{repository_id}/issues/{number}/comments' - comment_routes = (comments_url, numeric_comments_url) - candidates, seen = [], set() - for page in range(1, 11): - comments, links = api('GET', f'{comments_url}?per_page=100&page={page}') - if not isinstance(comments, list) or len(comments) > 100: - raise Stop('Invalid comment pagination; PR comment was not refreshed.') - relations = {} - for link in links.split(',') if links else []: - match = re.fullmatch(r'\s*<([^>]+)>;\s*rel="(next|prev|first|last)"\s*', link) - if not match or match[2] in relations: - raise Stop('Invalid comment pagination; PR comment was not refreshed.') - if not any(re.fullmatch(re.escape(route) + r'\?per_page=100&page=[1-9][0-9]*', match[1]) for route in comment_routes): - raise Stop('Unexpected pagination destination; PR comment was not refreshed.') - relations[match[2]] = match[1] - for relation, destination in relations.items(): - target_page = int(destination.rsplit('=', 1)[1]) - if ((relation == 'first' and target_page != 1) - or (relation == 'prev' and target_page != page - 1) - or (relation == 'last' and (target_page < page or (target_page > page and 'next' not in relations)))): - raise Stop('Inconsistent comment pagination; PR comment was not refreshed.') - if 'next' in relations and (len(comments) != 100 or int(relations['next'].rsplit('=', 1)[1]) != page + 1): - raise Stop('Inconsistent comment pagination; PR comment was not refreshed.') - for comment in comments: - cid = comment['id'] - if type(cid) is not int or cid <= 0 or cid in seen or not isinstance(comment['body'], str): - raise Stop('Invalid or repeated comment; PR comment was not refreshed.') - seen.add(cid) - if MARKER in comment['body']: - if not owned(comment): - raise Stop('Ambiguous dependency review marker; PR comment was not refreshed.') - candidates.append(comment) - # A full page always requires another request, even without Link. - if len(comments) < 100: - break - else: - raise Stop('Comment pagination bound reached; PR comment was not refreshed.') - if len(candidates) > 1: - raise Stop('Duplicate dependency review comments; PR comment was not refreshed.') - if candidates: - candidate = candidates[0] - target = f"{base}/issues/comments/{candidate['id']}" - fresh, _ = api('GET', target) - - def identity(comment): - user = comment['user'] - if (type(comment['id']) is not int or comment['id'] <= 0 - or not isinstance(comment['body'], str) - or type(user['id']) is not int or user['id'] <= 0 - or user['login'] != 'github-actions[bot]' or user['type'] != 'Bot' - or not isinstance(comment['updated_at'], str) - or not re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z', comment['updated_at']) - or comment['issue_url'] not in tuple(route.removesuffix('/comments') for route in comment_routes)): - raise Stop('Invalid dependency review comment identity; PR comment was not refreshed.') - return (comment['id'], comment['body'], user['id'], user['login'], - user['type'], comment['updated_at'], comment['issue_url']) - - if identity(fresh) != identity(candidate) or not owned(fresh): - raise Stop('Dependency review comment changed; PR comment was not refreshed.') - fresh_pr, _ = api('GET', f'{base}/pulls/{number}') - if (fresh_pr['number'] != int(number) - or fresh_pr['base']['repo']['full_name'] != repo - or fresh_pr['base']['ref'] != base_ref - or fresh_pr['base']['sha'] != base_sha - or fresh_pr['head']['sha'] != head): - raise Stop('PR head or base changed; stale run did not refresh the PR comment.') - api('PATCH' if candidates else 'POST', target if candidates else comments_url, {'body': body}) - - - def main(): - def deadline(signum, frame): - raise Stop('Reporting deadline reached; inspect the run summary for current evidence.') - signal.signal(signal.SIGALRM, deadline) - signal.alarm(90) - try: - report() - except Stop as error: - summary(str(error)) # Only fixed, locally defined messages. - except urllib.error.HTTPError as error: - error.close() - summary('PR comment could not be refreshed (API permission denied).' if error.code == 403 - else 'PR comment could not be refreshed (API request failed).') - except Exception: - summary('PR comment could not be refreshed (reporting or network error). Inspect the current run summary.') - finally: - signal.alarm(0) - - - if __name__ == '__main__': - main() diff --git a/config/actions-permissions.json b/config/actions-permissions.json deleted file mode 100644 index 8ed7a80..0000000 --- a/config/actions-permissions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "enabled_repositories": "all", - "allowed_actions": "selected", - "sha_pinning_required": true -} diff --git a/config/actions-selected.json b/config/actions-selected.json deleted file mode 100644 index 33aac03..0000000 --- a/config/actions-selected.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "github_owned_allowed": true, - "verified_allowed": false, - "patterns_allowed": [ - "atrinik/*", - "codecov/codecov-action@*", - "docker/login-action@*", - "docker/setup-buildx-action@*", - "docker/build-push-action@*", - "rust-lang/crates-io-auth-action@*" - ] -} diff --git a/config/actions-sha-pinning.json b/config/actions-sha-pinning.json deleted file mode 100644 index 8e5861e..0000000 --- a/config/actions-sha-pinning.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "phase": "pending", - "canary": null -} diff --git a/config/actions-workflow.json b/config/actions-workflow.json deleted file mode 100644 index 35b998a..0000000 --- a/config/actions-workflow.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "default_workflow_permissions": "read", - "can_approve_pull_request_reviews": false -} diff --git a/config/advisory-merge-windows.json b/config/advisory-merge-windows.json deleted file mode 100644 index 4544b61..0000000 --- a/config/advisory-merge-windows.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "repositories": [] -} diff --git a/config/code-security-advanced.json b/config/code-security-advanced.json deleted file mode 100644 index f00a052..0000000 --- a/config/code-security-advanced.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Atrinik advanced CodeQL baseline", - "description": "Atrinik security baseline for repositories with governed CodeQL advanced setup.", - "code_security": "enabled", - "secret_protection": "enabled", - "dependency_graph": "enabled", - "dependabot_alerts": "enabled", - "dependabot_security_updates": "enabled", - "code_scanning_default_setup": "enabled", - "code_scanning_options": { - "allow_advanced": true - }, - "secret_scanning": "enabled", - "secret_scanning_push_protection": "enabled", - "secret_scanning_validity_checks": "enabled", - "private_vulnerability_reporting": "enabled", - "enforcement": "enforced" -} diff --git a/config/code-security.json b/config/code-security.json deleted file mode 100644 index b0a148f..0000000 --- a/config/code-security.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Atrinik security baseline", - "description": "Required security features for all Atrinik repositories.", - "code_security": "enabled", - "secret_protection": "enabled", - "dependency_graph": "enabled", - "dependabot_alerts": "enabled", - "dependabot_security_updates": "enabled", - "code_scanning_default_setup": "enabled", - "code_scanning_options": { - "allow_advanced": false - }, - "secret_scanning": "enabled", - "secret_scanning_push_protection": "enabled", - "secret_scanning_validity_checks": "enabled", - "private_vulnerability_reporting": "enabled", - "enforcement": "enforced" -} diff --git a/config/codeql-advanced-setup.json b/config/codeql-advanced-setup.json deleted file mode 100644 index 808abec..0000000 --- a/config/codeql-advanced-setup.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "repositories": [ - "classic" - ], - "required_partitions": { - "classic": [ - { - "scope": "client", - "language": "c-cpp" - }, - { - "scope": "server", - "language": "c-cpp" - }, - { - "scope": "core-cpp", - "language": "c-cpp" - }, - { - "scope": "python", - "language": "python" - }, - { - "scope": "actions", - "language": "actions" - } - ] - } -} diff --git a/config/codeql-default-setup-advanced.json b/config/codeql-default-setup-advanced.json deleted file mode 100644 index 5eaa507..0000000 --- a/config/codeql-default-setup-advanced.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "state": "not-configured" -} diff --git a/config/codeql-default-setup.json b/config/codeql-default-setup.json deleted file mode 100644 index 7178f4e..0000000 --- a/config/codeql-default-setup.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "state": "configured", - "query_suite": "default" -} diff --git a/config/community-health.json b/config/community-health.json deleted file mode 100644 index e49bbd8..0000000 --- a/config/community-health.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "repository": { - "name": ".github", - "description": "Atrinik organization-wide community health defaults", - "private": false, - "has_issues": false, - "has_projects": false, - "has_wiki": false - }, - "files": [ - { - "source": "profile/README.md", - "target": "profile/README.md" - }, - { - "source": "README.md", - "target": "README.md" - }, - { - "source": "CONTRIBUTING.md", - "target": "CONTRIBUTING.md" - }, - { - "source": "CODE_OF_CONDUCT.md", - "target": "CODE_OF_CONDUCT.md" - }, - { - "source": "SECURITY.md", - "target": "SECURITY.md" - }, - { - "source": ".github/PULL_REQUEST_TEMPLATE.md", - "target": ".github/PULL_REQUEST_TEMPLATE.md" - }, - { - "source": ".github/ISSUE_TEMPLATE/bug.yml", - "target": ".github/ISSUE_TEMPLATE/bug.yml" - }, - { - "source": ".github/ISSUE_TEMPLATE/feature.yml", - "target": ".github/ISSUE_TEMPLATE/feature.yml" - }, - { - "source": ".github/ISSUE_TEMPLATE/task.yml", - "target": ".github/ISSUE_TEMPLATE/task.yml" - }, - { - "source": ".github/ISSUE_TEMPLATE/config.yml", - "target": ".github/ISSUE_TEMPLATE/config.yml" - }, - { - "source": "workflows/dependency-review.yml", - "target": ".github/workflows/dependency-review.yml" - } - ] -} diff --git a/config/immutable-releases.json b/config/immutable-releases.json deleted file mode 100644 index 094e958..0000000 --- a/config/immutable-releases.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "enforced_repositories": "selected", - "repositories": [ - { - "id": 1327289971, - "name": "classic" - }, - { - "id": 1327107043, - "name": "content-toolkit" - }, - { - "id": 1324297032, - "name": "metaserver-worker", - "activation_variable": { - "name": "ATRINIK_RELEASE_IMMUTABILITY_ACTIVE", - "scope": "repository" - } - }, - { - "id": 1327106950, - "name": "protocol" - } - ] -} diff --git a/config/manual-settings.json b/config/manual-settings.json deleted file mode 100644 index e1f02ff..0000000 --- a/config/manual-settings.json +++ /dev/null @@ -1,651 +0,0 @@ -{ - "members_can_delete_or_transfer_repositories": false, - "members_can_change_repository_visibility": false, - "members_can_create_teams": false, - "repository_admins_can_install_github_apps": false, - "members_can_request_github_apps": true, - "organization_pins": { - "apply_path": "https://github.com/atrinik", - "repositories": [ - { - "name": "classic", - "repository_id": 1327289971 - }, - { - "name": "atrinik", - "repository_id": 15810595 - }, - { - "name": "website", - "repository_id": 1327107093 - }, - { - "name": "content", - "repository_id": 1325219730 - }, - { - "name": "protocol", - "repository_id": 1327106950 - }, - { - "name": "playtester", - "repository_id": 1329284051 - } - ], - "verification": "read_only_graphql" - }, - "codecov_github_app_repositories": [ - "atrinik", - "classic", - "client", - "content-toolkit", - "protocol", - "server" - ], - "crates_io_trusted_publishing": [ - { - "authentication_action": "rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18", - "bootstrap_crates": [], - "bootstrap_policy": "owner-local-api-token-once-then-oidc-only", - "crates": [ - "atrinik-protocol" - ], - "environment": { - "can_admins_bypass": false, - "deployment_branch_policy": { - "custom_branch_policies": true, - "patterns": [ - { - "name": "main", - "type": "branch" - } - ], - "protected_branches": false - }, - "name": "crates-io-release", - "prevent_self_review": false, - "required_reviewers": [], - "secret_names": [], - "variable_names": [], - "wait_timer_minutes": 0 - }, - "environment_state": "observed", - "publisher_registration": { - "state": "owner-observed-registration", - "observed_on": "2026-10-11", - "evidence_location": "atrinik/protocol/actions/runs/38156755961" - }, - "provider": "github", - "repository": "atrinik/protocol", - "repository_id": 1327106950, - "runbook": "README.md#automatic-crate-trusted-publishing", - "source_evidence_policy": "github-attested-protected-main-manifest", - "source_state": "observed-reviewed-workflow", - "source_workflow_filename": "release.yml", - "upload_intent_policy": "create-only-global-git-ref-before-upload", - "workflow_filename": "publish-crate.yml", - "workflow_ref": "refs/heads/main", - "workflow_trigger": "workflow_dispatch", - "release_approval": "reviewed-source-and-version-merge" - }, - { - "authentication_action": "rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18", - "bootstrap_crates": [ - "atrinik-artifact", - "atrinik-catalog", - "atrinik-diagnostics", - "atrinik-schema", - "atrinik-source", - "atrinik-testkit", - "atrinik-transaction" - ], - "bootstrap_policy": "owner-local-api-token-once-then-oidc-only", - "crates": [ - "atrinik-artifact", - "atrinik-catalog", - "atrinik-diagnostics", - "atrinik-schema", - "atrinik-source", - "atrinik-testkit", - "atrinik-transaction" - ], - "environment": { - "can_admins_bypass": false, - "deployment_branch_policy": { - "custom_branch_policies": true, - "patterns": [ - { - "name": "main", - "type": "branch" - } - ], - "protected_branches": false - }, - "name": "crates-io-release", - "prevent_self_review": false, - "required_reviewers": [], - "secret_names": [], - "variable_names": [], - "wait_timer_minutes": 0 - }, - "environment_state": "observed", - "publisher_registration": { - "state": "owner-observed-registration", - "observed_on": "2026-10-12", - "evidence_location": "README.md#initial-library-onboarding-evidence" - }, - "provider": "github", - "repository": "atrinik/content-toolkit", - "repository_id": 1327107043, - "runbook": "README.md#automatic-crate-trusted-publishing", - "source_evidence_policy": "github-attested-protected-main-manifest", - "source_state": "observed-reviewed-workflow", - "source_workflow_filename": "release.yml", - "upload_intent_policy": "create-only-global-git-ref-before-upload", - "workflow_filename": "publish-crate.yml", - "workflow_ref": "refs/heads/main", - "workflow_trigger": "workflow_dispatch", - "release_approval": "reviewed-source-and-version-merge" - } - ], - "external_provider_apps": [ - { - "app_id": 85455, - "app_slug": "cloudflare-workers-and-pages", - "events": [ - "pull_request", - "push" - ], - "evidence_location": "atrinik/metaserver-worker#56-private-provider-evidence", - "exceptional_retry": { - "authorization": "provider-retry-only", - "long_lived_production_branches": [ - "main" - ], - "source": "exact-sha-still-current-main", - "stale_policy": "abandon-and-re-evaluate-without-github-bypass" - }, - "installation_id": 152311798, - "last_verified_on": "2026-08-15", - "owner": "Atrinik organization owners", - "permissions": { - "administration": "write", - "checks": "write", - "contents": "write", - "deployments": "write", - "metadata": "read", - "pull_requests": "write" - }, - "provider": "Cloudflare Workers Builds and Pages", - "purpose": "Allow the existing website Pages connection and the reviewed metaserver-worker Workers Builds connection to receive GitHub events, read source, and publish provider-owned checks and deployments without access to any other Atrinik repository.", - "repositories": [ - { - "purpose": "Preserve the existing Cloudflare Pages website connection.", - "repository": "atrinik/website", - "repository_id": 1327107093 - }, - { - "purpose": "Authorize the serialized Workers Builds topology governed by atrinik/metaserver-worker issues 53-56.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032 - } - ], - "repository_scope_verification": "organization_owner_ui", - "repository_selection": "selected", - "review_by": "2026-11-13", - "review_cadence_days": 90, - "review_owner": "Atrinik organization owners", - "revocation": "Remove only atrinik/metaserver-worker from installation 152311798 after disconnecting its Cloudflare repository connection; preserve atrinik/website unless its separately governed Pages connection is retired.", - "runbook": "README.md#cloudflare-github-app", - "status": "active", - "status_producer": "Cloudflare Workers and Pages GitHub App" - }, - { - "app_id": null, - "app_slug": "atrinik-deploy-control", - "control_plane_repository": { - "default_branch": "main", - "license": "MIT", - "repository": "atrinik/deploy-control", - "repository_id": 1352850539, - "visibility": "public" - }, - "events": [ - "workflow_run" - ], - "evidence_location": "atrinik/deploy-control#3", - "exceptional_retry": null, - "installation_id": null, - "last_verified_on": "2026-08-31", - "owner": "Atrinik organization owners", - "permissions": { - "actions": "read", - "metadata": "read" - }, - "provider": "Cloudflare Workers deploy-control control plane", - "purpose": "Receive only successful workflow_run events from atrinik/classic for the reviewed deploy-control staging-image handoff; do not authorize source, package, environment, metaserver, or organization-wide access.", - "repositories": [ - { - "purpose": "Authorize only the Classic workflow-run source for the deploy-control control plane.", - "repository": "atrinik/classic", - "repository_id": 1327289971 - } - ], - "repository_scope_verification": "pending_provisioning", - "repository_selection": "selected", - "review_by": "2026-11-29", - "review_cadence_days": 90, - "review_owner": "Atrinik organization owners", - "revocation": "Before retiring the control plane, disable its workflow-run delivery, revoke the App keys and webhook secret, remove only the named control-plane secret/variable slots, and verify the App installation no longer selects atrinik/classic; leave the Cloudflare Workers and Pages installation and metaserver boundary unchanged.", - "runbook": "README.md#deploy-control-github-app", - "secret_names": [ - "DEPLOY_CONTROL_AGENT_ENROLLMENT_SECRET", - "DEPLOY_CONTROL_GITHUB_APP_PRIVATE_KEY", - "DEPLOY_CONTROL_GITHUB_WEBHOOK_SECRET" - ], - "status": "planned", - "status_producer": "Atrinik deploy-control control-plane owner", - "variable_names": [ - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_DURABLE_OBJECT_BINDING", - "CLOUDFLARE_WORKER_NAME", - "DEPLOY_CONTROL_GITHUB_APP_ID", - "DEPLOY_CONTROL_GITHUB_INSTALLATION_ID" - ] - } - ], - "github_actions_environments": [ - { - "deployment_branch_policy": { - "custom_branch_policies": true, - "patterns": [ - { - "name": "main", - "type": "branch" - }, - { - "name": "v*", - "type": "tag" - } - ], - "protected_branches": false - }, - "environment": "discord-release", - "repository": "atrinik/classic", - "repository_id": 1327289971, - "required_reviewers": [], - "secret_names": [ - "DISCORD_APPLICATION_ID" - ], - "variable_names": [] - }, - { - "deployment_branch_policy": { - "custom_branch_policies": true, - "patterns": [ - { - "name": "main", - "type": "branch" - } - ], - "protected_branches": false - }, - "environment": "github-pages", - "repository": "atrinik/classic", - "repository_id": 1327289971, - "required_reviewers": [], - "secret_names": [], - "variable_names": [] - }, - { - "deployment_branch_policy": { - "custom_branch_policies": false, - "patterns": [], - "protected_branches": true - }, - "environment": "development", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_reviewers": [], - "secret_names": [ - "ATRINIK_DELIVERY_RESOURCE_POLICY", - "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "ATRINIK_DEVELOPMENT_CORE_CONFIG", - "ATRINIK_DEVELOPMENT_PUBLISHER_CONFIG", - "ATRINIK_DEVELOPMENT_RENDEZVOUS_CONFIG", - "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_API_TOKEN" - ], - "variable_names": [ - "ATRINIK_PRODUCTION_WRITER_FENCE_POLICY" - ] - }, - { - "deployment_branch_policy": { - "custom_branch_policies": false, - "patterns": [], - "protected_branches": true - }, - "environment": "production", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_reviewers": [], - "secret_names": [ - "ATRINIK_DELIVERY_RESOURCE_POLICY", - "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", - "ATRINIK_PRODUCTION_CORE_CONFIG", - "ATRINIK_PRODUCTION_PUBLISHER_CONFIG", - "ATRINIK_PRODUCTION_RENDEZVOUS_CONFIG", - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_API_TOKEN" - ], - "variable_names": [ - "ATRINIK_PRODUCTION_RECOVERY_PUBLIC_KEY", - "ATRINIK_PRODUCTION_WRITER_FENCE_POLICY" - ] - } - ], - "github_pages_sites": [ - { - "activation_marker": "actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e", - "build_type": "workflow", - "environment": "github-pages", - "https_enforced": true, - "repository": "atrinik/classic", - "repository_id": 1327289971, - "site_url": "https://atrinik.github.io/classic/", - "workflow_path": ".github/workflows/daily-client-performance.yml" - } - ], - "github_actions_apps": [ - { - "app_id": 4564008, - "app_slug": "atrinik-classic-dependency-updater", - "consumers": [ - ".github/workflows/update-content.yml" - ], - "events": [], - "installation_id": 153045686, - "last_verified_on": "2026-08-11", - "owner": "Atrinik organization owners", - "permissions": { - "contents": "write", - "metadata": "read", - "pull_requests": "write" - }, - "purpose": "Authenticate the branch and pull-request operations for one reviewed Classic content-lock update without access to other Atrinik repositories.", - "repository": "atrinik/classic", - "repository_id": 1327289971, - "repository_scope_verification": "organization_owner_ui", - "repository_selection": "selected", - "rotate_by": "2026-11-09", - "rotation_cadence_days": 90, - "rotation_owner": "Atrinik organization owners", - "runbook": "README.md#classic-dependency-update-app", - "secret_name": "DEPENDENCY_UPDATE_APP_PRIVATE_KEY", - "secret_scope": "repository", - "variable_name": "DEPENDENCY_UPDATE_APP_ID", - "variable_scope": "repository" - } - ], - "github_actions_credentials": [ - { - "credential_type": "classic_pat", - "consumers": [ - ".github/workflows/check-project-health.yml", - ".github/workflows/publish-planning.yml", - ".github/workflows/publish.yml", - ".github/workflows/sync-project.yml" - ], - "last_verified_on": "2026-08-10", - "owner": "Atrinik organization owners", - "purpose": "Administer Atrinik organization governance and synchronize the shared organization Project from GitHub Actions.", - "repository": "atrinik/github-settings", - "repository_id": 1324382941, - "required_scopes": [ - "admin:org", - "project", - "repo" - ], - "rotate_by": "2026-11-08", - "rotation_cadence_days": 90, - "rotation_owner": "Atrinik organization owners", - "runbook": "README.md#settings-automation-credential", - "secret_name": "ATRINIK_SETTINGS_TOKEN", - "secret_scope": "repository" - }, - { - "credential_type": "cloudflare_account_token", - "consumers": [ - ".github/workflows/deploy-development.yml" - ], - "environment": "development", - "last_verified_on": "2026-10-11", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Deploy the DEV three-Worker cohort and read its D1 ledger. The account-wide edit scope can also edit PROD; workflow target and resource fences provide the environment boundary.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "D1 Read", - "Workers Scripts Edit" - ], - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-development-credentials", - "secret_name": "CLOUDFLARE_API_TOKEN", - "secret_scope": "environment" - }, - { - "credential_type": "cloudflare_account_token", - "consumers": [ - ".github/workflows/deploy-development.yml" - ], - "environment": "development", - "last_verified_on": "2026-10-11", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Read the exact all-cohort resource inventory without mutation.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "Workers Scripts Read" - ], - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-development-credentials", - "secret_name": "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "secret_scope": "environment" - }, - { - "credential_type": "cloudflare_user_token", - "consumers": [ - ".github/workflows/deploy-development.yml" - ], - "environment": "development", - "last_verified_on": "2026-10-11", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Read retained Builds and Worker settings to prove the stopped-writer fence without deployment.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "Workers CI Read", - "Workers Scripts Read" - ], - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-development-credentials", - "secret_name": "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", - "secret_scope": "environment" - }, - { - "consumers": [ - ".github/workflows/promote-production.yml" - ], - "credential_type": "cloudflare_account_token", - "environment": "production", - "last_verified_on": "2026-10-12", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Dedicated PROD deployment credential, distinct from DEV. Requires account-wide Workers Scripts Edit and D1 Read. Active-token, PROD Worker settings and D1 identity GETs verified; provider permission metadata and write capability remain unproven. Creation and expiry are unknown; rotate_by is internal policy, not provider expiry. Production secret placement is pending.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "D1 Read", - "Workers Scripts Edit" - ], - "rotate_by": "2027-01-10", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-production-credentials", - "secret_name": "CLOUDFLARE_API_TOKEN", - "secret_scope": "environment" - }, - { - "consumers": [ - ".github/workflows/promote-production.yml" - ], - "credential_type": "cloudflare_account_token", - "environment": "production", - "last_verified_on": "2026-10-11", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Read the exact all-cohort resource inventory without mutation. Reuse in the production control-plane workflow is owner-authorized; this record declares production placement, which remains pending. Provider expiry is unknown and rotate_by is internal policy.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "Workers Scripts Read" - ], - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-production-credentials", - "secret_name": "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "secret_scope": "environment" - }, - { - "consumers": [ - ".github/workflows/promote-production.yml" - ], - "credential_type": "cloudflare_user_token", - "environment": "production", - "last_verified_on": "2026-10-11", - "owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "purpose": "Read retained Builds and Worker settings to prove the stopped-writer fence without deployment. Reuse in the production control-plane workflow is owner-authorized; this record declares production placement, which remains pending. Provider expiry is unknown and rotate_by is internal policy.", - "repository": "atrinik/metaserver-worker", - "repository_id": 1324297032, - "required_scopes": [ - "Workers CI Read", - "Workers Scripts Read" - ], - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Zoey Seraphina Rose (Atrinik organization owner)", - "runbook": "README.md#metaserver-production-credentials", - "secret_name": "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", - "secret_scope": "environment" - } - ], - "github_packages_actions_access": [ - { - "actions_repository": "atrinik/client", - "actions_repository_id": 1327106844, - "evidence_location": "README.md#private-linux-updater-build-image", - "grant_state": "owner-observed-read-grant", - "observed_on": "2026-10-11", - "package_id": 14205615, - "package_name": "linux-build", - "package_owner": "atrinik", - "package_type": "container", - "preserve_visibility": "private", - "role": "read", - "source_repository": "atrinik/devcontainer", - "source_repository_id": 1322185908 - } - ], - "require_two_factor_authentication": true, - "require_secure_two_factor_methods": true, - "reason": "The public GitHub API does not expose supported update parameters for every setting in this file, including organization pins and the exact selected-repository set for an organization GitHub App installation to an administrative token, and external credential values must never be stored here. Confirm these settings, the exact ordered pin set, credential lifecycle metadata and live secret-name presence, GitHub App repository selection, Codecov GitHub App repository access, any listed GitHub Pages sites and GitHub Actions environments, and GitHub Packages Actions access in the corresponding organization, repository, and package settings UI.", - "crate_dependency_update_app": { - "app_id": 5276152, - "app_slug": "atrinik-crate-dependency-update", - "consumers": [ - "atrinik/client/.github/workflows/released-dependencies.yml" - ], - "key_created_on": "2026-10-11", - "last_verified_on": "2026-10-11", - "rotate_by": "2027-01-09", - "rotation_cadence_days": 90, - "rotation_owner": "Atrinik organization owners", - "accepted_key_exposures": [ - { - "exposure": "repository-transfer-retained-copy", - "exposed_names": [ - "CRATE_DEPENDENCY_UPDATE_APP_ID", - "CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY" - ], - "former_repository": "atrinik/editor", - "repository": "seraphinastudios/tilewright-editor", - "repository_id": 1327106902, - "exposure_started_on": "2026-10-17", - "removal_observed_on": "2026-10-18", - "accepted_by": "Atrinik organization owners", - "accepted_on": "2026-10-18", - "evidence_location": "README.md#crate-dependency-update-app" - } - ], - "installation_id": 170332148, - "status": "owner-observed", - "repository_selection": "selected", - "repository_scope_verification": "app_authenticated_repository_api", - "repository_scope_reverification": { - "state": "pending-reverification", - "reason": "repository-transfer-after-readback", - "last_readback_on": "2026-10-11", - "selection_changed_on": "2026-10-17", - "removed_repositories": [ - { - "repository": "atrinik/editor", - "repository_id": 1327106902 - } - ], - "evidence_location": "README.md#crate-dependency-update-app" - }, - "owner": "Atrinik organization owners", - "permissions": { - "contents": "write", - "metadata": "read", - "pull_requests": "write" - }, - "events": [], - "repositories": [ - { - "repository": "atrinik/client", - "repository_id": 1327106844 - } - ], - "secret_name": "CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY", - "secret_scope": "repository", - "variable_name": "CRATE_DEPENDENCY_UPDATE_APP_ID", - "variable_scope": "repository", - "workflow_filename": "released-dependencies.yml", - "workflow_triggers": [ - "schedule-hourly", - "workflow_dispatch" - ], - "readiness": "exact-released-crates-and-checksums-before-pr", - "pull_request_policy": "owned-branch-and-pr-only-no-auto-merge", - "observed_on": "2026-10-11", - "evidence_location": "README.md#crate-dependency-update-app", - "runbook": "README.md#crate-dependency-update-app", - "homepage_url": "https://www.atrinik.org", - "webhook_active": false, - "credential_state": "observed-name-metadata", - "workflow_activation": { - "state": "pending-reviewed-workflows", - "observed_on": null, - "evidence_location": null - } - } -} diff --git a/config/organization.json b/config/organization.json deleted file mode 100644 index a1edb8c..0000000 --- a/config/organization.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": "A cooperative, open-source fantasy world founded by Zoey Seraphina Rose (https://zoeysr.com). Playable in Classic and rebuilding for the future.", - "blog": "https://atrinik.org", - "default_repository_permission": "none", - "members_can_create_repositories": false, - "members_can_create_public_repositories": false, - "members_can_create_private_repositories": false -} diff --git a/config/planning-health.json b/config/planning-health.json deleted file mode 100644 index 8bbe275..0000000 --- a/config/planning-health.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "consecutive_failure_threshold": 2, - "freshness_threshold_minutes": 90, - "incident_actor": "github-actions[bot]", - "incident_marker": "", - "incident_title": "Atrinik work synchronization is stale", - "monitor_workflow": "check-project-health.yml", - "monitoring_owner": "Atrinik organization owners", - "repository": "atrinik/github-settings", - "sync_workflow": "sync-project.yml" -} diff --git a/config/repositories.json b/config/repositories.json deleted file mode 100644 index 5fb7d68..0000000 --- a/config/repositories.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "pull_request_gate": [ - "agent-integrations", - "atrinik", - "classic", - "client", - "content", - "content-toolkit", - "deploy-control", - "devcontainer", - "github-settings", - "metaserver-worker", - "observatory", - "pathfinder", - "playtester", - "protocol", - "resources", - "server", - "service-updater", - "sound", - "tools", - "web-platform", - "website" - ], - "required_ci": { - "atrinik": [ - "Integration validation", - "Conventional PR title" - ], - "classic": [ - "Classic validation", - "CodeQL validation", - "Conventional PR title" - ], - "client": [ - "Client validation", - "Conventional PR title" - ], - "content-toolkit": [ - "Content toolkit validation", - "Conventional PR title" - ], - "protocol": [ - "Protocol validation", - "Conventional PR title" - ], - "server": [ - "Server validation", - "Conventional PR title" - ], - "service-updater": [ - "Updater validation", - "Conventional PR title" - ], - "website": [ - "Website validation", - "Conventional PR title" - ], - "sound": [ - "Asset validation", - "Conventional PR title" - ], - "content": [ - "Content validation", - "Conventional PR title" - ], - "deploy-control": [ - "Deploy-control validation", - "Conventional PR title" - ], - "resources": [ - "Asset validation", - "Conventional PR title" - ], - "tools": [ - "Tools validation", - "Conventional PR title" - ], - "devcontainer": [ - "Required checks", - "Conventional PR title" - ], - "metaserver-worker": [ - "verify", - "Conventional PR title" - ], - "observatory": [ - "Validate dashboard and Workers", - "Conventional PR title" - ], - "playtester": [ - "Playtester validation", - "Conventional PR title" - ], - "github-settings": [ - "Policy validation", - "Conventional PR title" - ], - "agent-integrations": [ - "Required checks", - "Conventional PR title" - ], - "pathfinder": [ - "Pathfinder validation", - "Conventional PR title" - ] - }, - "merge_queue": [ - "playtester" - ], - "maintenance_branches": [], - "release_tags": [ - "atrinik", - "classic", - "client", - "content", - "content-toolkit", - "devcontainer", - "github-settings", - "metaserver-worker", - "playtester", - "protocol", - "resources", - "server", - "service-updater", - "sound", - "tools", - "website" - ], - "archive": [ - "legacy-client", - "legacy-editor", - "legacy-libatrinik", - "legacy-protocol", - "legacy-server", - "nawerhals" - ] -} diff --git a/config/repository-defaults.json b/config/repository-defaults.json deleted file mode 100644 index ac53076..0000000 --- a/config/repository-defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "default_branch": "main", - "allow_merge_commit": false, - "allow_rebase_merge": false, - "allow_squash_merge": true, - "delete_branch_on_merge": true, - "squash_merge_commit_title": "PR_TITLE", - "squash_merge_commit_message": "PR_BODY" -} diff --git a/config/repository-properties.json b/config/repository-properties.json deleted file mode 100644 index 19cd692..0000000 --- a/config/repository-properties.json +++ /dev/null @@ -1,367 +0,0 @@ -{ - "definitions": [ - { - "property_name": "component_role", - "value_type": "multi_select", - "required": true, - "description": "Logical roles owned or served by the repository", - "allowed_values": [ - "aggregate", - "assets", - "client", - "content", - "coordination", - "editor", - "governance", - "historical", - "infrastructure", - "library", - "protocol", - "renderer", - "server", - "service", - "tooling", - "unclassified", - "website" - ], - "default_value": [ - "unclassified" - ] - }, - { - "property_name": "provider_set", - "value_type": "multi_select", - "required": true, - "description": "Atrinik provider cohort represented by the repository", - "allowed_values": [ - "classic", - "organization", - "replacement", - "shared", - "unclassified" - ], - "default_value": [ - "unclassified" - ] - }, - { - "property_name": "lifecycle", - "value_type": "single_select", - "required": true, - "description": "Current support and delivery stage", - "allowed_values": [ - "active", - "archived", - "maintenance", - "seed" - ], - "default_value": "seed" - }, - { - "property_name": "release_policy", - "value_type": "single_select", - "required": true, - "description": "How changes in the repository are released", - "allowed_values": [ - "none", - "semantic-release" - ], - "default_value": "none" - } - ], - "repositories": { - ".github": { - "component_role": [ - "governance" - ], - "provider_set": [ - "organization" - ], - "lifecycle": "active", - "release_policy": "none" - }, - "agent-integrations": { - "component_role": [ - "tooling" - ], - "provider_set": [ - "organization" - ], - "lifecycle": "active", - "release_policy": "none" - }, - "atrinik": { - "component_role": [ - "coordination" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "classic": { - "component_role": [ - "aggregate", - "client", - "editor", - "library", - "protocol", - "server" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "client": { - "component_role": [ - "client" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "content": { - "component_role": [ - "content" - ], - "provider_set": [ - "classic", - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "content-toolkit": { - "component_role": [ - "tooling" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "deploy-control": { - "component_role": [ - "service" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "seed", - "release_policy": "none" - }, - "devcontainer": { - "component_role": [ - "infrastructure" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "github-settings": { - "component_role": [ - "governance" - ], - "provider_set": [ - "organization" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "legacy-client": { - "component_role": [ - "client", - "historical" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "legacy-editor": { - "component_role": [ - "editor", - "historical" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "legacy-libatrinik": { - "component_role": [ - "historical", - "library" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "legacy-protocol": { - "component_role": [ - "historical", - "protocol" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "legacy-server": { - "component_role": [ - "historical", - "server" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "metaserver-worker": { - "component_role": [ - "service" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "observatory": { - "component_role": [ - "service" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "none" - }, - "nawerhals": { - "component_role": [ - "historical", - "tooling" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "archived", - "release_policy": "none" - }, - "pathfinder": { - "component_role": [ - "service" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "seed", - "release_policy": "none" - }, - "playtester": { - "component_role": [ - "tooling" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "protocol": { - "component_role": [ - "protocol" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "resources": { - "component_role": [ - "assets" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "server": { - "component_role": [ - "server" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "service-updater": { - "component_role": [ - "infrastructure", - "service" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "sound": { - "component_role": [ - "assets" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "tools": { - "component_role": [ - "tooling" - ], - "provider_set": [ - "classic" - ], - "lifecycle": "maintenance", - "release_policy": "semantic-release" - }, - "website": { - "component_role": [ - "website" - ], - "provider_set": [ - "replacement" - ], - "lifecycle": "active", - "release_policy": "semantic-release" - }, - "web-platform": { - "component_role": [ - "library" - ], - "provider_set": [ - "shared" - ], - "lifecycle": "seed", - "release_policy": "none" - } - } -} diff --git a/config/repository-security.json b/config/repository-security.json deleted file mode 100644 index 3df5292..0000000 --- a/config/repository-security.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "security_and_analysis": { - "secret_scanning": { - "status": "enabled" - }, - "secret_scanning_push_protection": { - "status": "enabled" - }, - "secret_scanning_validity_checks": { - "status": "enabled" - } - } -} diff --git a/config/retired-maintenance-branches.json b/config/retired-maintenance-branches.json deleted file mode 100644 index 47f1354..0000000 --- a/config/retired-maintenance-branches.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "retirements": [ - { - "repository": "content", - "repository_id": 1325219730, - "default_branch": "main", - "branch": "1.x", - "final_branch_commit": "080a9ea41741e4e67adc7b09b3ccb51475d93d3a", - "final_release": { - "tag": "v1.8.19", - "commit": "566bd25f78b80b08d5f75f4b02017ab2429204db", - "assets": [ - "SHA256SUMS", - "atrinik-content-1.8.19-runtime.tar.gz", - "atrinik-content-1.8.19.tar.gz" - ] - }, - "ruleset": { - "id": 20571870, - "name": "05 - Maintenance branch - content - 1.x", - "required_ci": [ - "Content validation", - "Conventional PR title" - ] - }, - "preserved_rulesets": [ - { - "id": 20522685, - "name": "01 - Default branch integrity" - }, - { - "id": 20593745, - "name": "01 - Default branch linear history" - }, - { - "id": 20522686, - "name": "02 - Changes through pull requests" - }, - { - "id": 20522693, - "name": "03 - Required CI - content" - }, - { - "id": 20522688, - "name": "04 - Immutable release tags" - } - ] - } - ] -} diff --git a/config/retired-required-ci.json b/config/retired-required-ci.json deleted file mode 100644 index 80b8b75..0000000 --- a/config/retired-required-ci.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retirements": [] -} diff --git a/config/rulesets/code-scanning.json b/config/rulesets/code-scanning.json deleted file mode 100644 index a3a0f14..0000000 --- a/config/rulesets/code-scanning.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "06 - CodeQL security", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "code_scanning", - "parameters": { - "code_scanning_tools": [ - { - "tool": "CodeQL", - "security_alerts_threshold": "high_or_higher", - "alerts_threshold": "none" - } - ] - } - } - ] -} diff --git a/config/rulesets/default-branch-integrity-classic.json b/config/rulesets/default-branch-integrity-classic.json deleted file mode 100644 index 7e961b4..0000000 --- a/config/rulesets/default-branch-integrity-classic.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "01 - Default branch integrity - classic", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "always" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "deletion" - }, - { - "type": "non_fast_forward" - } - ] -} diff --git a/config/rulesets/default-branch-integrity.json b/config/rulesets/default-branch-integrity.json deleted file mode 100644 index 8756757..0000000 --- a/config/rulesets/default-branch-integrity.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "01 - Default branch integrity", - "target": "branch", - "enforcement": "active", - "bypass_actors": [], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "deletion" - }, - { - "type": "non_fast_forward" - } - ] -} diff --git a/config/rulesets/default-branch-linear-history-classic.json b/config/rulesets/default-branch-linear-history-classic.json deleted file mode 100644 index b240c19..0000000 --- a/config/rulesets/default-branch-linear-history-classic.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "01 - Default branch linear history - classic", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "always" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "required_linear_history" - } - ] -} diff --git a/config/rulesets/default-branch-linear-history.json b/config/rulesets/default-branch-linear-history.json deleted file mode 100644 index f654f47..0000000 --- a/config/rulesets/default-branch-linear-history.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "01 - Default branch linear history", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "required_linear_history" - } - ] -} diff --git a/config/rulesets/dependency-review.json b/config/rulesets/dependency-review.json deleted file mode 100644 index 2fe155b..0000000 --- a/config/rulesets/dependency-review.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "07 - Dependency review", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "required_status_checks", - "parameters": { - "required_status_checks": [ - { - "context": "Dependency review", - "integration_id": 15368 - } - ], - "strict_required_status_checks_policy": true - } - } - ] -} diff --git a/config/rulesets/immutable-release-tags.json b/config/rulesets/immutable-release-tags.json deleted file mode 100644 index 0ac85e6..0000000 --- a/config/rulesets/immutable-release-tags.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "04 - Immutable release tags", - "target": "tag", - "enforcement": "active", - "bypass_actors": [], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "refs/tags/v[0-9]*" - ] - } - }, - "rules": [ - { - "type": "deletion" - }, - { - "type": "non_fast_forward" - } - ] -} diff --git a/config/rulesets/maintenance-branch.json b/config/rulesets/maintenance-branch.json deleted file mode 100644 index 844f9bf..0000000 --- a/config/rulesets/maintenance-branch.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "05 - Maintenance branch", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [] - } - }, - "rules": [ - { - "type": "deletion" - }, - { - "type": "non_fast_forward" - }, - { - "type": "required_linear_history" - }, - { - "type": "pull_request", - "parameters": { - "require_code_owner_review": false, - "require_last_push_approval": false, - "dismiss_stale_reviews_on_push": false, - "required_approving_review_count": 0, - "required_review_thread_resolution": true - } - }, - { - "type": "required_status_checks", - "parameters": { - "required_status_checks": [], - "strict_required_status_checks_policy": true - } - } - ] -} diff --git a/config/rulesets/merge-queue.json b/config/rulesets/merge-queue.json deleted file mode 100644 index 872e23f..0000000 --- a/config/rulesets/merge-queue.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "08 - Merge queue", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "merge_queue", - "parameters": { - "check_response_timeout_minutes": 60, - "grouping_strategy": "ALLGREEN", - "max_entries_to_build": 5, - "max_entries_to_merge": 5, - "merge_method": "SQUASH", - "min_entries_to_merge": 1, - "min_entries_to_merge_wait_minutes": 0 - } - } - ] -} diff --git a/config/rulesets/pull-request-gate-classic.json b/config/rulesets/pull-request-gate-classic.json deleted file mode 100644 index 3c5702a..0000000 --- a/config/rulesets/pull-request-gate-classic.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "02 - Changes through pull requests - classic", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "always" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "pull_request", - "parameters": { - "require_code_owner_review": false, - "require_last_push_approval": false, - "dismiss_stale_reviews_on_push": false, - "required_approving_review_count": 0, - "required_review_thread_resolution": true - } - } - ] -} diff --git a/config/rulesets/pull-request-gate.json b/config/rulesets/pull-request-gate.json deleted file mode 100644 index aa98ca5..0000000 --- a/config/rulesets/pull-request-gate.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "02 - Changes through pull requests", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "pull_request", - "parameters": { - "require_code_owner_review": false, - "require_last_push_approval": false, - "dismiss_stale_reviews_on_push": false, - "required_approving_review_count": 0, - "required_review_thread_resolution": true - } - } - ] -} diff --git a/config/rulesets/required-ci.json b/config/rulesets/required-ci.json deleted file mode 100644 index 3936e0f..0000000 --- a/config/rulesets/required-ci.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "03 - Required CI", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_id": 1, - "actor_type": "OrganizationAdmin", - "bypass_mode": "pull_request" - } - ], - "conditions": { - "ref_name": { - "exclude": [], - "include": [ - "~DEFAULT_BRANCH" - ] - } - }, - "rules": [ - { - "type": "required_status_checks", - "parameters": { - "required_status_checks": [], - "strict_required_status_checks_policy": true - } - } - ] -} diff --git a/config/security-merge-protection.json b/config/security-merge-protection.json deleted file mode 100644 index 1ddf4c0..0000000 --- a/config/security-merge-protection.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "dependency_review": [], - "code_scanning": [ - "agent-integrations", - "atrinik", - "classic", - "client", - "content", - "content-toolkit", - "deploy-control", - "devcontainer", - "github-settings", - "metaserver-worker", - "observatory", - "pathfinder", - "playtester", - "protocol", - "resources", - "server", - "service-updater", - "sound", - "tools", - "website" - ], - "codeql_required_languages": { - "content-toolkit": [ - "rust" - ] - }, - "activation": { - "code_scanning": { - "agent-integrations": "pending", - "atrinik": "pending", - "classic": "pending", - "client": "pending", - "content": "pending", - "content-toolkit": "pending", - "deploy-control": "pending", - "devcontainer": "pending", - "github-settings": "pending", - "metaserver-worker": "pending", - "observatory": "pending", - "pathfinder": "pending", - "playtester": "pending", - "protocol": "pending", - "resources": "pending", - "server": "pending", - "service-updater": "pending", - "sound": "pending", - "tools": "pending", - "website": "pending" - }, - "dependency_review": {} - } -} diff --git a/lib/ruleset-policy.jq b/lib/ruleset-policy.jq deleted file mode 100644 index f430cae..0000000 --- a/lib/ruleset-policy.jq +++ /dev/null @@ -1,76 +0,0 @@ -# Reviewed compatible values for writable API extensions, not response metadata. -# Comparison may omit them; update payloads must preserve the live values. -# Nondefault, malformed and unknown fields remain observable drift. -def normalize_rules: - map(if .type == "pull_request" then - .parameters |= ( - if .required_reviewers == [] then del(.required_reviewers) else . end | - if .require_extra_approval_for_unattributed_changes == true then - del(.require_extra_approval_for_unattributed_changes) else . end | - if (.allowed_merge_methods | type) == "array" and - (.allowed_merge_methods | sort) == ["merge", "rebase", "squash"] then - del(.allowed_merge_methods) else . end) - elif .type == "required_status_checks" then - .parameters |= ( - if .do_not_enforce_on_create == false then del(.do_not_enforce_on_create) else . end | - .required_status_checks |= sort_by(.context, .integration_id)) - else . end) | sort_by(.type); - -# OrganizationAdmin.actor_id is ignored by the REST API. -# https://docs.github.com/en/rest/orgs/rules?apiVersion=2026-03-10 -def normalize_bypass: - map(if .actor_type == "OrganizationAdmin" then .actor_id = 1 else . end) | - sort_by(.actor_type, .actor_id, .bypass_mode); -def normalize_conditions: - with_entries(if .key == "ref_name" or .key == "repository_name" then - .value.include |= sort | .value.exclude |= sort else . end); -def normalize_policy: - .bypass_actors |= normalize_bypass | - .conditions |= normalize_conditions | - .rules |= normalize_rules; -def policy_body: - del(.id, .node_id, .source, .source_type, .created_at, .updated_at, ._links, - .current_user_can_bypass); - -# Validate keys recursively before replacing managed values. Arrays other than -# rules are atomic policy values. New restrictions require source review. -def recognized_keys($wanted): - if type == "object" then - ($wanted | type == "object") and - all(to_entries[]; . as $entry | - ($wanted | has($entry.key)) and - ($entry.value | recognized_keys($wanted[$entry.key]))) - elif type == "array" then - ($wanted | type == "array") and - all(.[]; . as $item | - if type == "object" or type == "array" then - any($wanted[]; . as $shape | $item | recognized_keys($shape)) - else true end) - else true end; -def prepare_policy($wanted): - policy_body as $live | - ($live | normalize_policy) as $normalized | - ($wanted | normalize_policy) as $normalized_wanted | - if ($live | type) != "object" or - ($live.rules | type) != "array" or - ($live.rules | map(.type) | length != (unique | length)) or - (($normalized | del(.rules) | recognized_keys($normalized_wanted | del(.rules))) | not) or - (all($normalized.rules[]; . as $rule | - any($normalized_wanted.rules[]; - . as $candidate | .type == $rule.type and ($rule | recognized_keys($candidate)))) | not) - then error("unrecognized ruleset fields or restrictions require manual review") - else - # A known extension is approved only at its reviewed compatible value. - # normalize_rules removed exactly those values; leftover extension keys - # therefore failed recognized_keys above. Copy actual values, never defaults. - $wanted | .rules |= map(. as $rule | - ([$live.rules[] | select(.type == $rule.type)][0] // {}) as $prior | - if .type == "pull_request" then - .parameters = (($prior.parameters // {} | with_entries(select( - .key == "required_reviewers" or .key == "allowed_merge_methods" or - .key == "require_extra_approval_for_unattributed_changes"))) + .parameters) - elif .type == "required_status_checks" then - .parameters = (($prior.parameters // {} | with_entries(select( - .key == "do_not_enforce_on_create"))) + .parameters) - else . end) - end; diff --git a/lib/security_readiness.py b/lib/security_readiness.py deleted file mode 100644 index 7b721b2..0000000 --- a/lib/security_readiness.py +++ /dev/null @@ -1,1245 +0,0 @@ -#!/usr/bin/env python3 -"""Read-only preflight for security controls; 0 ready, 1 deferred, 2 unreadable.""" - -import argparse -import ast -import base64 -import binascii -import difflib -import fnmatch -import json -from pathlib import Path -import re -import shlex -import subprocess -import sys -from urllib.parse import quote, urlencode - - -ROOT = Path(__file__).resolve().parent.parent -VERSION = "2026-03-10" -ACTION_APP = 15368 -SHA = re.compile(r"[0-9a-fA-F]{40}\Z") -COORDINATE = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+\Z") -SIMPLE_NAME = r"(?:[A-Za-z][A-Za-z0-9 ._/-]*|'[A-Za-z][A-Za-z0-9 ._/-]*'|\"[A-Za-z][A-Za-z0-9 ._/-]*\")" -USES = re.compile( - r"(?P[ \t]*(?:-[ \t]+)?uses:[ \t]+)" - r"(?P[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+)@" - r"(?P[0-9a-fA-F]{40})(?P[ \t]*)" - r"(?P#[ \t]*v?[0-9]+(?:\.[0-9A-Za-z_-]+)*(?:[ \t]*)?)?" - r"(?P\r?\n)?\Z" -) - - -class Deferred(Exception): - pass - - -class EvidenceError(Exception): - pass - - -class APIError(EvidenceError): - def __init__(self, endpoint, status=None, response=None): - self.status = status - self.response = response - super().__init__(f"API unreadable: {endpoint.split('?')[0]}" - + (f" (HTTP {status})" if status else "")) - - -def api(endpoint): - """Use GET explicitly: query parameters must never select gh's POST default.""" - try: - result = subprocess.run( - ["gh", "api", "--method", "GET", "-H", f"X-GitHub-Api-Version: {VERSION}", - "-H", "Accept: application/vnd.github+json", endpoint], - capture_output=True, text=True, timeout=30, check=False, - ) - except (OSError, subprocess.TimeoutExpired) as exc: - raise APIError(endpoint) from exc - if result.returncode: - status = re.search(r"HTTP (\d{3})", result.stderr) - try: - response = json.loads(result.stdout) - except json.JSONDecodeError: - response = None - raise APIError(endpoint, int(status[1]) if status else None, response) - try: - return json.loads(result.stdout) - except json.JSONDecodeError as exc: - raise EvidenceError("API returned invalid JSON") from exc - - -def config(name): - return json.loads((ROOT / "config" / name).read_text()) - - -def require(condition, reason): - if not condition: - raise Deferred(reason) - - -def repository(coordinate): - metadata = api(f"repos/{coordinate}") - if metadata["full_name"].lower() != coordinate.lower(): - raise EvidenceError("repository identity changed") - require(metadata["archived"] is False, "repository archived") - if not isinstance(metadata["default_branch"], str) or not metadata["default_branch"]: - raise EvidenceError("default branch missing") - return metadata - - -def contents(coordinate, path, ref): - endpoint = f"repos/{coordinate}/contents/{path}?{urlencode({'ref': ref})}" - try: - value = api(endpoint) - except APIError as exc: - if exc.status == 404: - raise Deferred(f"{path} missing at required revision") from exc - raise - if value.get("type") != "file" or value.get("encoding") != "base64": - raise EvidenceError("workflow content is not an encoded file") - try: - # GitHub wraps content with newlines; reject other non-base64 bytes. - return base64.b64decode(value["content"].replace("\n", ""), validate=True) - except (binascii.Error, ValueError) as exc: - raise EvidenceError("workflow content encoding invalid") from exc - - -def pages(endpoint, key=None): - """Bound enumeration; missing or oversized evidence cannot imply readiness.""" - results = [] - for page in range(1, 11): - value = api(endpoint + ("&" if "?" in endpoint else "?") - + urlencode({"per_page": 100, "page": page})) - entries = value[key] if key else value - if not isinstance(entries, list): - raise EvidenceError("API collection malformed") - results.extend(entries) - if len(entries) < 100: - if key and "total_count" in value and len(results) != value["total_count"]: - raise EvidenceError("API collection changed during enumeration") - return results - raise Deferred("evidence exceeds bounded enumeration") - - -def latest_dependency_run(coordinate): - try: - value = api(f"repos/{coordinate}/actions/workflows/dependency-review.yml/runs" - "?event=pull_request&per_page=1") - except APIError as exc: - if exc.status == 404: - raise Deferred("dependency-review workflow not landed") from exc - raise - require(bool(value["workflow_runs"]), "dependency-review PR run missing") - return value["workflow_runs"][0] - - -def dependency_contract(data): - """Allow producer-owned immutable pin bumps without weakening the contract. - - Keep indentation and every policy value intact. Ignore blank lines, standalone - comments and trailing whitespace; normalize only this official action's SHA - and its optional same-line version annotation. - """ - lines = [] - pins = 0 - for line in data.decode("utf-8").splitlines(): - if not line.strip() or line.lstrip().startswith("#"): - continue - match = USES.fullmatch(line) - if match and match["action"] == "actions/dependency-review-action": - pins += 1 - line = match["prefix"] + "actions/dependency-review-action@" - if re.fullmatch("name: " + SIMPLE_NAME, line.rstrip()): - line = "name: Dependency review" - lines.append(line.rstrip()) - require(pins == 1, "dependency-review workflow requires one official full-SHA action") - normalized = [] - index = 0 - while index < len(lines): - line = lines[index] - step_name = re.fullmatch(r"( *)- name: " + SIMPLE_NAME, line) - if step_name and index + 1 < len(lines): - following = lines[index + 1] - if following == step_name[1] + " uses: actions/dependency-review-action@": - line = step_name[1] + "- uses: actions/dependency-review-action@" - index += 1 - # Producers may spell the same one-element branch filter as a block - # list or a flow list. Preserve key indentation and reject extra items. - flow = re.fullmatch(r"( *)branches: *\[ *(?:main|'main'|\"main\") *\]", line) - block = re.fullmatch(r"( *)branches:", line) - if flow: - line = flow[1] + "branches: [main]" - elif block and index + 1 < len(lines): - item = re.fullmatch(r"( *)- +(?:main|'main'|\"main\")", lines[index + 1]) - if item and len(item[1]) > len(block[1]): - line = block[1] + "branches: [main]" - index += 1 - # Activity order and flow/block spelling do not change which PR or - # merge-group events trigger review. Keep duplicates and unknown events visible to the - # contract comparison rather than silently broadening the trigger. - activity_flow = re.fullmatch(r"( *)types: *\[(.*)\]", line) - activity_block = re.fullmatch(r"( *)types:", line) - activities = None - if activity_flow: - activities = [item.strip() for item in activity_flow[2].split(",")] - indentation = activity_flow[1] - elif activity_block: - activities = [] - indentation = activity_block[1] - while index + 1 < len(lines): - item = re.fullmatch(r"( *)- +(.+)", lines[index + 1]) - if not item or len(item[1]) <= len(indentation): - break - activities.append(item[2]) - index += 1 - if activities is not None: - values = [] - for activity in activities: - value = re.fullmatch(r"(?:([a-z_]+)|'([a-z_]+)'|\"([a-z_]+)\")", activity) - require(value is not None, "dependency-review activity types unsupported") - values.append(next(part for part in value.groups() if part is not None)) - line = indentation + "types: [" + ", ".join(sorted(values)) + "]" - normalized.append(line) - index += 1 - # YAML mapping key order does not change the PR trigger. Reorder only the - # two recognized, already-normalized keys; retain every value and any - # additional or duplicated key for the exact contract comparison below. - for index in range(len(normalized) - 2): - if (normalized[index] == " pull_request:" - and normalized[index + 1].startswith(" types: [") - and normalized[index + 2] == " branches: [main]"): - normalized[index + 1:index + 3] = [normalized[index + 2], normalized[index + 1]] - return normalized - - -def pull_identity(pr): - return {"number": pr["number"], "state": pr["state"], "merged": pr["merged"], "draft": pr["draft"], - "head": (pr["head"]["sha"], pr["head"]["repo"]["full_name"]), - "base": (pr["base"]["sha"], pr["base"]["ref"], pr["base"]["repo"]["full_name"])} - - -def merged_run_pull(coordinate, run, default_branch): - """Recover only an unambiguous, fully fetched merged PR after refs disappear.""" - require(run["event"] == "pull_request" - and re.fullmatch(r"\.github/workflows/[^/]+\.ya?ml", run["path"]) is not None, - "merged PR association requires a PR workflow") - require(bool(SHA.fullmatch(run["head_sha"])), "merged PR association head missing") - associated = pages(f"repos/{coordinate}/commits/{run['head_sha']}/pulls") - require(len(associated) == 1, "merged PR association missing or ambiguous") - pr = api(f"repos/{coordinate}/pulls/{associated[0]['number']}") - require(pr["number"] == associated[0]["number"] and pr["merged"] is True - and pr["state"] == "closed" and pr["head"]["sha"] == run["head_sha"] - and pr["head"]["repo"]["full_name"].lower() == run["head_repository"]["full_name"].lower() - and pr["base"]["repo"]["full_name"].lower() == coordinate.lower() - and pr["base"]["ref"] == default_branch, - "merged PR association identity does not match run/default branch") - return pr - - -def association_references(coordinate, run, suite, default_branch, recovered): - if run["pull_requests"] and suite["pull_requests"]: - return run["pull_requests"], suite["pull_requests"] - pr = merged_run_pull(coordinate, run, default_branch) - for references in (run["pull_requests"], suite["pull_requests"]): - require(all(item["number"] == pr["number"] - and item["head"]["sha"] == pr["head"]["sha"] - and item["base"]["sha"] == pr["base"]["sha"] - and item["base"]["ref"] == pr["base"]["ref"] for item in references), - "nonempty PR association conflicts with merged PR") - recovered.append((run, default_branch, pull_identity(pr))) - return [pr], [pr] - - -def verify_recovered_associations(coordinate, recovered): - for run, default_branch, identity in recovered: - require(pull_identity(merged_run_pull(coordinate, run, default_branch)) == identity, - "merged PR association changed during preflight") - - -def workflow_yaml(source, label): - """Read executable YAML without duplicate keys or implicit boolean keys.""" - try: - import yaml - except ImportError as exc: - raise EvidenceError("install requirements-validation.txt for workflow verification") from exc - - class UniqueLoader(yaml.SafeLoader): - # Actions uses `on` as a mapping key. Preserve scalar booleans as text, - # as in the existing publication verifier, and validate them explicitly. - yaml_implicit_resolvers = { - key: [(tag, regex) for tag, regex in values if tag != "tag:yaml.org,2002:bool"] - for key, values in yaml.SafeLoader.yaml_implicit_resolvers.items() - } - - def unique_mapping(loader, node, deep=False): - result = {} - for key_node, value_node in node.value: - key = loader.construct_object(key_node, deep=deep) - if key in result: - raise ValueError(f"duplicate YAML key: {key}") - result[key] = loader.construct_object(value_node, deep=deep) - return result - - UniqueLoader.add_constructor("tag:yaml.org,2002:map", unique_mapping) - try: - workflow = yaml.load(source, Loader=UniqueLoader) - except (yaml.YAMLError, ValueError, TypeError) as exc: - raise EvidenceError(f"{label} workflow YAML malformed or ambiguous") from exc - - return workflow - - -def dependency_enforces_findings(source): - workflow = workflow_yaml(source, "dependency-review") - jobs = workflow.get("jobs", {}) if isinstance(workflow, dict) else {} - job = jobs.get("dependency-review", {}) if isinstance(jobs, dict) else {} - require(isinstance(job, dict) and "uses" not in job and "if" not in job - and job.get("continue-on-error", "false") == "false", - "advisory or conditional dependency job cannot qualify a required gate") - steps = job.get("steps", []) - require(isinstance(steps, list), "dependency-review steps unreadable") - matches = [step for step in steps if isinstance(step, dict) - and isinstance(step.get("uses"), str) - and step["uses"].startswith("actions/dependency-review-action@")] - require(len(matches) == 1, "required gate needs one dependency-review action") - step = matches[0] - inputs = step.get("with", {}) - require("if" not in step and step.get("continue-on-error", "false") == "false" - and isinstance(inputs, dict) and inputs.get("warn-only", "false") == "false", - "advisory or failure-suppressed dependency action cannot qualify a required gate") - - -def dependency(coordinate): - path = ".github/workflows/dependency-review.yml" - desired_source = (ROOT / path).read_bytes() - dependency_enforces_findings(desired_source) - metadata = repository(coordinate) - desired = dependency_contract(desired_source) - landed = contents(coordinate, path, metadata["default_branch"]) - require(dependency_contract(landed) == desired, - "dependency-review workflow not landed with desired enforcement contract") - run = latest_dependency_run(coordinate) - require(run["event"] == "pull_request" and run["status"] == "completed" - and run["conclusion"] == "success", "latest dependency-review PR run not successful") - require(run["path"] == path, "dependency-review run workflow path changed") - suite_endpoint = f"repos/{coordinate}/check-suites/{run['check_suite_id']}" - suite = api(suite_endpoint) - require(suite["id"] == run["check_suite_id"] and suite["app"]["id"] == ACTION_APP - and suite["status"] == "completed" and suite["conclusion"] == "success", - "dependency-review execution check suite not successful") - executed = suite["head_sha"] - require(bool(SHA.fullmatch(executed)), "dependency-review executed SHA missing") - merge_parents = None - if executed != run["head_sha"]: - merge_commit = api(f"repos/{coordinate}/commits/{executed}") - merge_parents = [parent["sha"] for parent in merge_commit["parents"]] - recovered, pulls = [], [] - references, suite_references = association_references( - coordinate, run, suite, metadata["default_branch"], recovered) - for reference in references: - pr = api(f"repos/{coordinate}/pulls/{reference['number']}") - require(pr["base"]["repo"]["full_name"].lower() == coordinate.lower() - and pr["base"]["ref"] == metadata["default_branch"], - "dependency-review PR does not target default branch") - require(pr["head"]["sha"] == run["head_sha"], "dependency-review PR head changed") - require(reference["head"]["sha"] == pr["head"]["sha"] - and reference["base"]["sha"] == pr["base"]["sha"] - and reference["base"]["ref"] == pr["base"]["ref"], - "dependency-review run PR association is stale") - require(any(item["number"] == pr["number"] - and item["head"]["sha"] == pr["head"]["sha"] - and item["base"]["sha"] == pr["base"]["sha"] - and item["base"]["ref"] == pr["base"]["ref"] - for item in suite_references), - "dependency-review execution PR association missing or stale") - if merge_parents is not None: - require(len(merge_parents) == 2 and set(merge_parents) - == {pr["head"]["sha"], pr["base"]["sha"]}, - "dependency-review executed merge does not match current PR head/base") - pulls.append(pr) - require(contents(coordinate, path, executed) == landed, - "dependency-review run used different workflow bytes") - jobs = pages(f"repos/{coordinate}/actions/runs/{run['id']}/attempts/{run['run_attempt']}/jobs", "jobs") - matches = [job for job in jobs if job["name"] == "Dependency review"] - require(len(matches) == 1 and matches[0]["status"] == "completed" - and matches[0]["conclusion"] == "success", "Dependency review job not successful") - fresh = latest_dependency_run(coordinate) - run_keys = ("id", "run_attempt", "status", "conclusion", "event", "head_sha", - "check_suite_id", "pull_requests", "path", "head_repository") - require(all(fresh[key] == run[key] for key in run_keys), - "dependency-review run changed during preflight") - fresh_suite = api(suite_endpoint) - suite_keys = ("id", "head_sha", "app", "status", "conclusion", "pull_requests") - require(all(fresh_suite[key] == suite[key] for key in suite_keys), - "dependency-review execution check suite changed during preflight") - for pr in pulls: - fresh_pr = api(f"repos/{coordinate}/pulls/{pr['number']}") - require(fresh_pr["head"]["sha"] == pr["head"]["sha"] - and fresh_pr["base"]["sha"] == pr["base"]["sha"] - and fresh_pr["base"]["ref"] == pr["base"]["ref"] - and fresh_pr["base"]["repo"]["full_name"] == pr["base"]["repo"]["full_name"] - and all(fresh_pr[key] == pr[key] for key in ("state", "draft", "merged")), - "dependency-review PR changed during preflight") - verify_recovered_associations(coordinate, recovered) - require(contents(coordinate, path, metadata["default_branch"]) == landed, - "default-branch dependency-review workflow changed during preflight") - require(repository(coordinate)["default_branch"] == metadata["default_branch"], - "repository default branch changed during preflight") - return "workflow enforcement contract landed; latest PR job successful with same workflow bytes" - - -def pin_changes(before, after, selected): - """Compare complete files, so API's potentially truncated patches grant nothing.""" - old = before.decode("utf-8").splitlines(keepends=True) - new = after.decode("utf-8").splitlines(keepends=True) - changed = 0 - for tag, old_start, old_end, new_start, new_end in difflib.SequenceMatcher( - None, old, new, autojunk=False).get_opcodes(): - if tag == "equal": - continue - require(tag == "replace" and old_end - old_start == new_end - new_start, - "canary changes more than action pins") - for left, right in zip(old[old_start:old_end], new[new_start:new_end]): - left_match, right_match = USES.fullmatch(left), USES.fullmatch(right) - require(bool(left_match and right_match), "canary changes more than action pins") - for key in ("prefix", "action", "space", "newline"): - require(left_match[key] == right_match[key], "canary changes action structure") - require(left_match["sha"] != right_match["sha"], "canary contains unrelated comment changes") - action = right_match["action"] - # GitHub's action SHA requirement excludes reusable workflow refs. - # The canary admits only action-pin changes, including in mixed PRs. - require(re.fullmatch(r"[^/]+/[^/]+/\.github/workflows/[^/]+\.ya?ml", action, - flags=re.IGNORECASE) is None, - "canary changes a reusable workflow reference, not only action pins") - identity = f"{action}@{right_match['sha']}" - require((selected["github_owned_allowed"] and action.split("/")[0].lower() - in {"actions", "github"}) - or any(fnmatch.fnmatchcase(identity, pattern) - for pattern in selected["patterns_allowed"]), - "new action pin is outside desired selected-actions patterns") - changed += 1 - require(changed > 0, "canary has no full-SHA action update") - return changed - - -def merge_check_run(coordinate, check, pr, merges, proofs, recovered): - """Establish PR association before selecting the latest check, even if failing.""" - if check["head_sha"] != pr["head"]["sha"] and check["head_sha"] not in merges: - return False - suite_id = check["check_suite"]["id"] - if suite_id not in proofs: - endpoint = f"repos/{coordinate}/actions/runs?check_suite_id={suite_id}&per_page=1" - value = api(endpoint) - runs = value["workflow_runs"] - valid = bool(len(runs) == 1 and runs[0]["event"] == "pull_request" - and runs[0]["head_sha"] == pr["head"]["sha"] - and runs[0]["check_suite_id"] == suite_id) - suite, bases = None, set() - if valid: - suite = api(f"repos/{coordinate}/check-suites/{suite_id}") - references, suite_references = association_references( - coordinate, runs[0], suite, pr["base"]["ref"], recovered) - association_bases = [ - {item["base"]["sha"] for item in refs if item["number"] == pr["number"] - and item["head"]["sha"] == pr["head"]["sha"] - and item["base"]["ref"] == pr["base"]["ref"]} - for refs in (references, suite_references)] - bases = association_bases[0] & association_bases[1] - # Open PRs require the current base. Merged PRs retain the common - # recorded base from their run and suite, even after main advances. - if not pr["merged"]: - bases &= {pr["base"]["sha"]} - valid = suite["id"] == suite_id and suite["app"]["id"] == ACTION_APP and bool(bases) - proofs[suite_id] = {"endpoint": endpoint, "run": runs[0] if valid else None, - "suite": suite, "bases": bases, "parents": {}} - proof = proofs[suite_id] - if proof["run"] is None: - return False - if check["head_sha"] != pr["head"]["sha"]: - if check["head_sha"] not in proof["parents"]: - commit = api(f"repos/{coordinate}/commits/{check['head_sha']}") - proof["parents"][check["head_sha"]] = [item["sha"] for item in commit["parents"]] - parents = proof["parents"][check["head_sha"]] - return len(parents) == 2 and any(set(parents) == {base, pr["head"]["sha"]} - for base in proof["bases"]) - return True - - -def canary_actions_policy(coordinate, metadata): - organization = coordinate.split('/')[0] - if type(metadata["id"]) is not int or metadata["id"] < 1: - raise EvidenceError("canary repository identity malformed") - current = api(f"orgs/{organization}/actions/permissions") - if (current["allowed_actions"] not in {"all", "local_only", "selected"} - or current["enabled_repositories"] not in {"all", "none", "selected"}): - raise EvidenceError("organization Actions permissions malformed") - require(current["allowed_actions"] == "selected", "organization Actions selected policy is not active") - require(current["enabled_repositories"] != "none", "organization Actions are disabled") - membership = [] - if current["enabled_repositories"] == "selected": - membership = pages(f"orgs/{organization}/actions/permissions/repositories", "repositories") - require(any(item["id"] == metadata["id"] and item["full_name"].lower() == coordinate.lower() - for item in membership), "canary repository is not enabled for organization Actions") - repository_policy = api(f"repos/{coordinate}/actions/permissions") - if (not isinstance(repository_policy["enabled"], bool) - or repository_policy["allowed_actions"] not in {"all", "local_only", "selected"}): - raise EvidenceError("repository Actions permissions malformed") - require(repository_policy["enabled"] and repository_policy["allowed_actions"] != "local_only", - "canary repository does not allow external Actions") - # Repository 'all' cannot relax the organization's selected-actions ceiling. - selected = api(f"orgs/{organization}/actions/permissions/selected-actions") - desired = config("actions-selected.json") - require(desired["github_owned_allowed"] is True and desired["verified_allowed"] is False, - "desired selected-actions policy is not conservative") - for value in (selected, desired): - if (not isinstance(value["github_owned_allowed"], bool) - or not isinstance(value["verified_allowed"], bool) - or not isinstance(value["patterns_allowed"], list) - or not all(isinstance(item, str) for item in value["patterns_allowed"])): - raise EvidenceError("selected-actions policy malformed") - require(selected["github_owned_allowed"] is True and selected["verified_allowed"] is False - and sorted(selected["patterns_allowed"]) == sorted(desired["patterns_allowed"]), - "live selected-actions policy differs from desired policy") - return {"mode": current["allowed_actions"], "enabled": current["enabled_repositories"], - "membership": sorted((item["id"], item["full_name"]) for item in membership), - "repository": repository_policy, "selected": selected} - - -def disabled_legacy_absent(coordinate, metadata): - """Prove absence only for the exact REST repository-disabled response.""" - branch = metadata["default_branch"] - fresh = repository(coordinate) - if (type(metadata["id"]) is not int or metadata["id"] <= 0 - or fresh["id"] != metadata["id"] or type(fresh["id"]) is not int - or fresh["full_name"] != coordinate or metadata["full_name"] != coordinate - or fresh["default_branch"] != branch): - raise EvidenceError("legacy protection repository identity/default branch changed") - # This fixed query is read-only. GraphQL requires POST; variables remain - # separate literal fields and cannot add operations to the query. - query = ("query LegacyBranchProtection($owner: String!, $name: String!, $qualifiedName: String!) " - "{ repository(owner: $owner, name: $name) { databaseId nameWithOwner isArchived " - "ref(qualifiedName: $qualifiedName) { name branchProtectionRule { id } } } }") - owner, name = coordinate.split("/") - try: - result = subprocess.run( - ["gh", "api", "--method", "POST", "-H", f"X-GitHub-Api-Version: {VERSION}", - "graphql", "-f", f"query={query}", "-f", f"owner={owner}", "-f", f"name={name}", - "-f", f"qualifiedName=refs/heads/{branch}"], - capture_output=True, text=True, timeout=30, check=False, - ) - except (OSError, subprocess.TimeoutExpired) as exc: - raise EvidenceError("legacy protection GraphQL unreadable") from exc - if result.returncode: - raise EvidenceError("legacy protection GraphQL unreadable") - try: - response = json.loads(result.stdout) - repo = response["data"]["repository"] - ref = repo["ref"] - valid = ("errors" not in response and type(repo["databaseId"]) is int - and repo["databaseId"] == metadata["id"] and repo["nameWithOwner"] == coordinate - and repo["isArchived"] is False and ref["name"] == branch - and "branchProtectionRule" in ref and ref["branchProtectionRule"] is None) - except (json.JSONDecodeError, KeyError, TypeError): - valid = False - if not valid: - raise EvidenceError("legacy protection absence not proven for repository/default branch") - - -def canary_legacy_checks(coordinate, metadata): - branch = quote(metadata["default_branch"], safe="") - try: - protection = api(f"repos/{coordinate}/branches/{branch}/protection") - except APIError as exc: - body = exc.response - if exc.status != 404 or not isinstance(body, dict) or body.get("status") != "404": - raise - if body.get("message") == "Branch not protected": - return None - if body.get("message") == "Branch protection has been disabled on this repository.": - disabled_legacy_absent(coordinate, metadata) - return None - raise - if not isinstance(protection, dict) or "required_status_checks" not in protection: - raise EvidenceError("legacy branch protection malformed") - return protection["required_status_checks"] - - -def canary_required_checks(coordinate, metadata): - branch = metadata["default_branch"] - rules = pages(f"repos/{coordinate}/rules/branches/{quote(branch, safe='')}") - entries = [] - for rule in rules: - if rule["type"] == "required_status_checks": - entries.extend((item["context"], item["integration_id"]) - for item in rule["parameters"]["required_status_checks"]) - legacy = canary_legacy_checks(coordinate, metadata) - if legacy is not None: - if (not isinstance(legacy, dict) or not isinstance(legacy["checks"], list) - or not isinstance(legacy["contexts"], list) - or not all(isinstance(value, str) and value for value in legacy["contexts"])): - raise EvidenceError("legacy required status checks malformed") - entries.extend((item["context"], item["app_id"]) for item in legacy["checks"]) - entries.extend((context, None) for context in legacy["contexts"]) - for context, app in entries: - if not isinstance(context, str) or not context or (app is not None and type(app) is not int): - raise EvidenceError("effective required status check malformed") - require(app in (None, -1, ACTION_APP), - f"effective required check is bound to a non-Actions app: {context}") - repository_name = coordinate.split('/')[1] - configured = config("repositories.json")["required_ci"].get(repository_name) - require(bool(configured), "canary has no configured required contexts") - if not isinstance(configured, list) or not all(isinstance(value, str) and value for value in configured): - raise EvidenceError("configured required checks malformed") - required = set(configured) | {context for context, _ in entries} - if repository_name in config("security-merge-protection.json")["dependency_review"]: - required.add("Dependency review") - return (list(dict.fromkeys(configured)) + sorted(required - set(configured)), - sorted(json.dumps(item) for item in entries)) - - -def sha(coordinate, number): - metadata = repository(coordinate) - pr = api(f"repos/{coordinate}/pulls/{number}") - require(pr["merged"] is True or (pr["state"] == "open" and not pr["draft"]), - "action-update canary must be merged or open and review-ready") - require(pr["base"]["repo"]["full_name"].lower() == coordinate.lower() - and pr["base"]["ref"] == metadata["default_branch"], - "canary does not target default branch") - require(bool(SHA.fullmatch(pr["head"]["sha"])), "canary head SHA missing") - actions_policy = canary_actions_policy(coordinate, metadata) - selected = config("actions-selected.json") - required, required_evidence = canary_required_checks(coordinate, metadata) - files = pages(f"repos/{coordinate}/pulls/{number}/files") - require(bool(files) and len(files) == pr["changed_files"], "canary file evidence incomplete") - updates = 0 - for item in files: - path = item["filename"] - require(item["status"] == "modified" and - re.fullmatch(r"\.github/workflows/[^/]+\.ya?ml", path) is not None, - "canary contains changes outside existing workflows") - updates += pin_changes(contents(coordinate, path, pr["base"]["sha"]), - contents(pr["head"]["repo"]["full_name"], path, pr["head"]["sha"]), selected) - merge = pr.get("merge_commit_sha") if not pr["merged"] else None - merges, recovered = set(), [] - if merge: - require(bool(SHA.fullmatch(merge)), "canary merge SHA malformed") - commit = api(f"repos/{coordinate}/commits/{merge}") - require({parent["sha"] for parent in commit["parents"]} - == {pr["base"]["sha"], pr["head"]["sha"]}, "canary merge SHA is stale") - merges.add(merge) - if pr["merged"]: - # After squash/rebase merge, merge_commit_sha identifies publication, - # not the temporary merge commit that PR Actions checks evaluated. - runs = pages(f"repos/{coordinate}/actions/runs?event=pull_request&head_sha={pr['head']['sha']}", - "workflow_runs") - for run in runs: - if run["event"] != "pull_request" or run["head_sha"] != pr["head"]["sha"]: - continue - suite = api(f"repos/{coordinate}/check-suites/{run['check_suite_id']}") - references, _ = association_references( - coordinate, run, suite, metadata["default_branch"], recovered) - references = [item for item in references if item["number"] == number] - if not references: - continue - candidate = suite["head_sha"] - if candidate == pr["head"]["sha"]: - continue - require(bool(SHA.fullmatch(candidate)), "historical canary merge SHA malformed") - commit = api(f"repos/{coordinate}/commits/{candidate}") - require(any(item["head"]["sha"] == pr["head"]["sha"] - and item["base"]["ref"] == metadata["default_branch"] - and {parent["sha"] for parent in commit["parents"]} - == {item["base"]["sha"], pr["head"]["sha"]} for item in references), - "historical canary merge does not match PR head/base") - merges.add(candidate) - checks = [] - for ref in [pr["head"]["sha"], *sorted(merges)]: - checks.extend(pages(f"repos/{coordinate}/commits/{ref}/check-runs?filter=all&app_id={ACTION_APP}", - "check_runs")) - proofs, selected_checks = {}, [] - for context in required: - candidates = [check for check in checks if check["name"] == context - and check["app"]["id"] == ACTION_APP - and check["app"]["slug"] == "github-actions" - and merge_check_run(coordinate, check, pr, merges, proofs, recovered)] - require(bool(candidates), f"required check missing for canary head: {context}") - # Check IDs order creation, including queued checks with no started_at. - # Scheduling/start time must not let an older green check hide a newer - # PR-associated check or suite that has not completed successfully. - latest = max(candidates, key=lambda check: check["id"]) - run = proofs[latest["check_suite"]["id"]]["run"] - require(run["status"] == "completed" and run["conclusion"] == "success", - f"required PR workflow run not successful for canary head: {context}") - require(latest["status"] == "completed" and latest["conclusion"] == "success", - f"required check not successful for canary head: {context}") - selected_checks.append(latest) - run_keys = ("id", "run_attempt", "event", "head_sha", "check_suite_id", "status", "conclusion", - "pull_requests", "path", "head_repository") - check_keys = ("id", "name", "head_sha", "status", "conclusion", "app", "check_suite", "started_at") - fresh_checks = [] - for ref in [pr["head"]["sha"], *sorted(merges)]: - fresh_checks.extend(pages(f"repos/{coordinate}/commits/{ref}/check-runs?filter=all&app_id={ACTION_APP}", - "check_runs")) - def check_snapshot(values): - return sorted(json.dumps({key: check[key] for key in check_keys}, sort_keys=True) - for check in values if check["name"] in required) - require(check_snapshot(fresh_checks) == check_snapshot(checks), - "canary required check collection changed during preflight") - for suite_id in {check["check_suite"]["id"] for check in selected_checks}: - proof = proofs[suite_id] - fresh_runs = api(proof["endpoint"])["workflow_runs"] - require(len(fresh_runs) == 1 and all(fresh_runs[0][key] == proof["run"][key] for key in run_keys), - "canary PR workflow-run evidence changed during preflight") - fresh_suite = api(f"repos/{coordinate}/check-suites/{suite_id}") - suite_keys = ("id", "head_sha", "app", "status", "conclusion", "pull_requests") - require(all(fresh_suite[key] == proof["suite"][key] for key in suite_keys), - "canary check-suite evidence changed during preflight") - verify_recovered_associations(coordinate, recovered) - for check in selected_checks: - fresh_check = api(f"repos/{coordinate}/check-runs/{check['id']}") - require(all(fresh_check[key] == check[key] for key in check_keys), - "canary required check evidence changed during preflight") - fresh = api(f"repos/{coordinate}/pulls/{number}") - require(fresh["head"]["sha"] == pr["head"]["sha"] - and fresh["base"]["sha"] == pr["base"]["sha"] - and fresh.get("merge_commit_sha") == pr.get("merge_commit_sha") - and fresh["state"] == pr["state"] and fresh["merged"] == pr["merged"] - and (fresh["merged"] or not fresh["draft"]), "canary changed during preflight") - require(canary_actions_policy(coordinate, metadata) == actions_policy, - "live Actions permissions changed during preflight") - require(canary_required_checks(coordinate, metadata) - == (required, required_evidence), "effective required checks changed during preflight") - fresh_metadata = repository(coordinate) - require(fresh_metadata["default_branch"] == metadata["default_branch"] - and fresh_metadata["id"] == metadata["id"], "repository identity/default branch changed during preflight") - return f"ordinary action-update PR #{number}: {updates} allowed full-SHA updates; required checks passed" - - -def canonical_language(value): - return {"javascript/typescript": "javascript-typescript", "javascript": "javascript-typescript", - "typescript": "javascript-typescript"}.get(value, value) - - -def analysis_language(analysis): - environment = json.loads(analysis.get("environment") or "{}") - language = environment.get("language") - if not language: - match = re.search(r"(?:^|/)language:([a-z0-9+-]+)(?:/|$)", analysis["category"]) - language = match[1] if match else None - return canonical_language(language), environment - - -def successful_analysis(analysis, head): - require(analysis["commit_sha"] == head, "latest CodeQL analysis does not cover current default head") - require(analysis["error"] in ("", None) and analysis["rules_count"] > 0, - "latest CodeQL analysis failed or contains no executed rules") - - -def newest_analysis_pages(coordinate, branch): - endpoint = f"repos/{coordinate}/code-scanning/analyses?" + urlencode( - {"ref": f"refs/heads/{branch}", "tool_name": "CodeQL"}) - for page in range(1, 11): - entries = api(endpoint + f"&per_page=100&page={page}") - if not isinstance(entries, list): - raise EvidenceError("CodeQL analysis collection malformed") - yield entries - if len(entries) < 100: - return - - -def configured_codeql_languages(setup): - values = setup["languages"] - if not isinstance(values, list) or not all(isinstance(item, str) and item for item in values): - raise EvidenceError("CodeQL default-setup languages malformed") - return {canonical_language(value) for value in values} - - -def default_codeql_coverage(coordinate, branch, head, languages): - """Select only the newest canonical analyses within the bounded history.""" - found = {} - for entries in newest_analysis_pages(coordinate, branch): - for analysis in entries: - if analysis["tool"]["name"] != "CodeQL" or analysis["ref"] != f"refs/heads/{branch}": - continue - language, _ = analysis_language(analysis) - # Default setup owns one canonical category per configured language. - # Retired advanced partitions, even in that language, are historical. - category_language = canonical_language(analysis["category"].removeprefix("/language:")) - if (not analysis["category"].startswith("/language:") - or category_language not in languages or category_language in found): - continue - successful_analysis(analysis, head) - require(language == category_language, "default CodeQL analysis language does not match its category") - found[language] = analysis - if set(found) == languages: - return found - raise Deferred("required configured CodeQL language analysis missing within bounded evidence") - - -def default_codeql(coordinate, branch, head, minima): - endpoint = f"repos/{coordinate}/code-scanning/default-setup" - setup = api(endpoint) - require(setup["state"] == "configured", "CodeQL default setup not configured") - languages = configured_codeql_languages(setup) - require(bool(languages), "CodeQL default setup has no configured languages") - require(set(minima) <= languages, "required CodeQL languages not configured") - coverage = default_codeql_coverage(coordinate, branch, head, languages) - fresh = api(endpoint) - require(fresh["state"] == setup["state"] - and configured_codeql_languages(fresh) == languages, - "CodeQL default setup changed during preflight") - require(default_codeql_coverage(coordinate, branch, head, languages) == coverage, - "CodeQL default-setup analysis coverage changed during preflight") - return "latest canonical default-setup analyses cover every configured language on current head" - - -def classifier_full_events(source): - """Read the owner's full-event contract without executing fetched Python.""" - tree = ast.parse(source) - assignments = [node for node in tree.body if isinstance(node, ast.Assign) - and any(isinstance(target, ast.Name) and target.id == "FULL_EVENTS" for target in node.targets)] - require(len(assignments) == 1, "advanced CodeQL classifier full-event contract missing") - events = ast.literal_eval(assignments[0].value) - mains = [node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == "main"] - require(len(mains) == 1, "advanced CodeQL classifier main contract missing") - full = False - for node in ast.walk(mains[0]): - if (isinstance(node, ast.If) and isinstance(node.test, ast.Compare) - and ast.unparse(node.test) == "arguments.event in FULL_EVENTS"): - full = any(isinstance(item, ast.Assign) and isinstance(item.value, ast.Constant) - and item.value.value is True and any(isinstance(target, ast.Name) - and target.id == "full" for target in item.targets) for item in node.body) - require(full and {"push", "schedule", "workflow_dispatch"} <= set(events), - "advanced CodeQL classifier does not select full analysis for full events") - return set(events) & {"push", "schedule", "workflow_dispatch"} - - -def advanced_partition_minima(policy, repository_name): - """Validate source-owned coverage even when preflight is called directly.""" - inventories = policy.get("required_partitions") - if (not isinstance(inventories, dict) or set(inventories) != set(policy["repositories"]) - or not isinstance(inventories.get(repository_name), list) - or not inventories[repository_name]): - raise EvidenceError("advanced CodeQL required partition inventory malformed/missing") - minima = set() - for item in inventories[repository_name]: - if (not isinstance(item, dict) or set(item) != {"scope", "language"} - or any(not isinstance(item[key], str) - or not re.fullmatch(r"[a-z][a-z0-9+-]*", item[key]) for key in item)): - raise EvidenceError("advanced CodeQL required partition identity malformed") - identity = (item["scope"], canonical_language(item["language"])) - if identity in minima: - raise EvidenceError("advanced CodeQL required partition identity duplicated") - minima.add(identity) - return minima - - -def classifier_partitions(source, minima): - """Inspect literal matrix declarations; never execute repository Python.""" - tree = ast.parse(source) - functions = [node for node in tree.body if isinstance(node, ast.FunctionDef) - and node.name == "write_outputs"] - require(len(functions) == 1, "advanced CodeQL partition declarations missing") - function = functions[0] - assignments = [node for node in ast.walk(function) if isinstance(node, ast.Name) - and node.id == "entries" and isinstance(node.ctx, ast.Store)] - initializers = [node for node in function.body if isinstance(node, ast.Assign) - and len(node.targets) == 1 and isinstance(node.targets[0], ast.Name) - and node.targets[0].id == "entries" and isinstance(node.value, ast.List) - and not node.value.elts] - require(len(assignments) == len(initializers) == 1, - "advanced CodeQL partition declaration shape unsupported") - declarations, identities, categories = {}, set(), set() - for node in ast.walk(function): - if not (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) - and isinstance(node.func.value, ast.Name) and node.func.value.id == "entries"): - continue - require(node.func.attr == "append" and len(node.args) == 1 and not node.keywords, - "advanced CodeQL partition declaration shape unsupported") - try: - item = ast.literal_eval(node.args[0]) - except (ValueError, TypeError): - raise Deferred("advanced CodeQL partition declaration is not literal") from None - require(isinstance(item, dict) and set(item) == {"display", "category", "scope", "language", "run"} - and item["run"] is True and all(isinstance(item[key], str) and item[key] - for key in ("display", "category", "scope", "language")), - "advanced CodeQL partition declaration malformed") - identity = (item["scope"], canonical_language(item["language"])) - require(item["display"] not in declarations and item["category"] not in categories - and identity not in identities, "advanced CodeQL partition declarations duplicated") - declarations[item["display"]] = item - categories.add(item["category"]) - identities.add(identity) - require(bool(declarations) and minima <= identities, - "advanced CodeQL producer omits required partition coverage") - return declarations - - -def latest_full_codeql_run(coordinate, branch, head, events): - value = api(f"repos/{coordinate}/actions/workflows/codeql.yml/runs?head_sha={head}&per_page=100") - candidates = [run for run in value["workflow_runs"] if run["event"] in events - and run["head_sha"] == head and run["head_branch"] == branch] - require(bool(candidates), "current-head full-event CodeQL workflow run missing") - run = candidates[0] - require(run["path"] == ".github/workflows/codeql.yml" and run["status"] == "completed" - and run["conclusion"] == "success", "latest full-event CodeQL workflow run not successful") - return run - - -def advanced_codeql_coverage(coordinate, branch, head, minima, selected, declarations): - """Select current producer uploads, ignoring retired categories and history.""" - found, categories, languages = {}, set(), set() - for entries in newest_analysis_pages(coordinate, branch): - for analysis in entries: - if (analysis["tool"]["name"] != "CodeQL" or analysis["ref"] != f"refs/heads/{branch}" - or analysis.get("analysis_key") != ".github/workflows/codeql.yml:analyze"): - continue - category = analysis["category"] - if category in categories: - continue - categories.add(category) - language, environment = analysis_language(analysis) - display = environment.get("display") - if display not in selected: - continue - job = selected[display] - declaration = declarations[display] - if analysis["created_at"] < job["started_at"]: - continue - require(display not in found, "advanced CodeQL selected display has ambiguous upload categories") - successful_analysis(analysis, head) - category_language = re.search(r"(?:^|/)language:([a-z0-9+-]+)$", category) - require(environment.get("category") == category == declaration["category"] - and environment.get("scope") == declaration["scope"] - and language == canonical_language(declaration["language"]) - and category_language is not None - and canonical_language(category_language[1]) == language - and job["started_at"] <= analysis["created_at"] <= job["completed_at"], - "advanced CodeQL analysis upload does not belong to selected full-run job") - found[display] = analysis - languages.add(language) - if set(found) == set(selected): - break - if set(found) == set(selected): - require({canonical_language(value) for value in minima} <= languages, - "required CodeQL language analysis missing") - return found - raise Deferred("required advanced CodeQL partition upload missing within bounded evidence") - - -def advanced_workflow_wiring(source, default_branch): - """Check executable dataflow, not the honesty of repository-owned Python. - - The supported ordinary-job shape is deliberately bounded. Producer-owned - action SHAs and classifier path/category declarations are not central pins. - """ - workflow = workflow_yaml(source, "advanced CodeQL") - - def check(condition, detail): - require(condition, "advanced CodeQL executable workflow contract: " + detail) - - def expression(value, expected, wrapped=True): - if not isinstance(value, str): - return False - value = value.strip() - if value.startswith("${{") and value.endswith("}}"): - value = value[3:-2].strip() - elif wrapped: - return False - # Ignore token spacing, preserving string contents (including spaces). - def tokens(text): - return re.findall(r"'(?:[^']|'')*'|[A-Za-z_][A-Za-z_0-9]*|==|\S", text) - return tokens(value) == tokens(expected) - - def execution_settings(value, context): - check(isinstance(value, dict), context + " must be a mapping") - check(not value.get("env") and not value.get("defaults"), context + " execution overrides") - check(value.get("continue-on-error", "false") == "false", context + " suppresses failure") - check(not any(key in value for key in ("shell", "working-directory", "container", "services")), - context + " changes execution context") - - def step(value, context, condition=None): - execution_settings(value, context) - check(set(value) <= {"name", "id", "uses", "with", "run", "env", "if", "continue-on-error"}, - context + " unsupported step execution") - check(("if" not in value) if condition is None else expression(value.get("if"), condition, False), - context + " condition disconnected") - - def action(value, name): - check(isinstance(value.get("uses"), str) - and re.fullmatch(re.escape(name) + r"@[0-9a-fA-F]{40}", value["uses"]) is not None - and "run" not in value, "expected official full-SHA " + name) - - def checkout(value): - step(value, "checkout") - action(value, "actions/checkout") - inputs = value.get("with", {}) - check(isinstance(inputs, dict) - and set(inputs) <= {"fetch-depth", "ref", "repository", "persist-credentials"}, - "checkout must use the current complete workspace") - check("ref" not in inputs or expression(inputs["ref"], "github.sha"), - "checkout revision differs from run") - check("repository" not in inputs or expression(inputs["repository"], "github.repository"), - "checkout repository differs from run") - - def command(value, prefix): - check(isinstance(value.get("run"), str) and "uses" not in value and "with" not in value, - "helper must execute a run step") - try: - # Retain shell quoting as well as argument values: single-quoted or - # escaped $EVENT_NAME is a literal, not the bound event environment. - source = value["run"].replace("\\\r\n", "").replace("\\\n", "") - raw = shlex.split(source, comments=True, posix=False) - decoded = [shlex.split(token) for token in raw] - check(all(len(item) == 1 for item in decoded), "helper shell arguments unsupported") - tokens = [item[0] for item in decoded] - except ValueError: - raw, tokens = [], [] - check(tokens[:len(prefix)] == prefix, "helper invocation disconnected") - arguments, raw_arguments = tokens[len(prefix):], raw[len(prefix):] - check(len(arguments) % 2 == 0, "helper arguments malformed") - options, quoted_options = {}, {} - for index in range(0, len(arguments), 2): - key, argument = arguments[index:index + 2] - check(key.startswith("--") and key not in options, "helper arguments ambiguous") - options[key] = argument - quoted_options[key] = raw_arguments[index + 1] - return options, quoted_options - - def classifier(value, scoped=False): - expected_env = {"BASE_SHA": "github.event.pull_request.base.sha", - "EVENT_NAME": "github.event_name", "HEAD_SHA": "github.event.pull_request.head.sha"} - environment = value.get("env") - check(isinstance(environment, dict) and set(environment) == set(expected_env) - and all(expression(environment[key], expected) for key, expected in expected_env.items()), - "classifier event/revision environment disconnected") - # Environment is validated above; every other execution override is rejected. - step({key: item for key, item in value.items() if key != "env"}, "classifier") - check(value.get("id") == "classify", "classifier step identity disconnected") - options, quoted = command(value, ["python3", "tools/ci/classify_changes.py"]) - expected = {"--event": "EVENT_NAME", "--base": "BASE_SHA", "--head": "HEAD_SHA", - "--github-output": "GITHUB_OUTPUT"} - check(set(options) == set(expected) | {"--codeql-config"} | ({"--codeql-scope"} if scoped else set()), - "classifier arguments disconnected") - check(all(quoted[key] in ("$" + variable, "${" + variable + "}", - '"$' + variable + '"', '"${' + variable + '}"') - for key, variable in expected.items()), "classifier event/output arguments disconnected") - path = options["--codeql-config"] - check(re.fullmatch(r"(?:[A-Za-z0-9_.-]+/)*[A-Za-z0-9_.-]+\.ya?ml", path) is not None - and ".." not in path.split("/"), "classifier config destination unsupported") - if scoped: - check(expression(options["--codeql-scope"], "matrix.scope"), "classifier scope disconnected") - return path - - execution_settings(workflow, "workflow") - check(isinstance(default_branch, str) and bool(default_branch), "default branch missing") - events = workflow.get("on") - if isinstance(events, str): - events = {events: None} - elif isinstance(events, list): - check(all(isinstance(event, str) for event in events) - and len(events) == len(set(events)), "workflow events malformed") - events = dict.fromkeys(events) - check(isinstance(events, dict) and "pull_request" in events, - "pull_request trigger missing") - pull_request = events["pull_request"] - if pull_request is None: - pull_request = {} - # Do not partially interpret GitHub glob/exclusion or workflow path filters: - # they can leave a required producer pending. Path selection belongs in the - # trusted classifier after the workflow has started for the pull request. - check(isinstance(pull_request, dict) and set(pull_request) <= {"branches", "types"}, - "pull_request filters unsupported") - if "branches" in pull_request: - branches = pull_request["branches"] - check(isinstance(branches, list) and bool(branches) - and all(isinstance(branch, str) and branch - and not any(char in branch for char in "*?[]!+\\") for branch in branches) - and default_branch in branches, "pull_request does not cover the default branch") - activities = {"opened", "synchronize", "reopened"} - if "types" in pull_request: - # Values need an explicit enum: the Actions loader preserves YAML - # booleans as text, so an invalid `false` must not become an event name. - supported = activities | {"assigned", "unassigned", "labeled", "unlabeled", "edited", "closed", - "converted_to_draft", "locked", "unlocked", "enqueued", "dequeued", - "milestoned", "demilestoned", "ready_for_review", "review_requested", - "review_request_removed", "auto_merge_enabled", "auto_merge_disabled"} - types = pull_request["types"] - check(isinstance(types, list) and all(isinstance(value, str) and value in supported for value in types) - and len(types) == len(set(types)) and activities <= set(types), - "pull_request activity coverage incomplete") - jobs = workflow.get("jobs") - check(isinstance(jobs, dict) and set(jobs) == {"classify", "analyze", "codeql-validation"}, - "requires ordinary classification, analysis and validation jobs") - for name, job in jobs.items(): - execution_settings(job, name) - check(set(job) <= {"name", "runs-on", "timeout-minutes", "outputs", "steps", "if", "needs", - "strategy", "continue-on-error"}, name + " unsupported job execution") - runner = job.get("runs-on") - check((isinstance(runner, str) and bool(runner)) or - (isinstance(runner, list) and bool(runner) and - all(isinstance(item, str) and item for item in runner)), name + " runner missing") - steps = job.get("steps") - check(isinstance(steps, list) and all(isinstance(item, dict) for item in steps), - name + " executable steps missing") - identifiers = [item["id"] for item in steps if "id" in item] - check(all(isinstance(item, str) for item in identifiers) - and len(identifiers) == len(set(identifiers)), name + " duplicate step identities") - classify, analyze, validation = (jobs[name] for name in ("classify", "analyze", "codeql-validation")) - check(classify.get("name") == "CodeQL classification" - and not any(key in classify for key in ("if", "needs", "strategy")) - and len(classify["steps"]) == 2, "classification job execution disconnected") - outputs = classify.get("outputs", {}) - check(isinstance(outputs, dict) and set(outputs) == {"matrix", "run"} - and expression(outputs["matrix"], "steps.classify.outputs.codeql_matrix") - and expression(outputs["run"], "steps.classify.outputs.codeql_run"), "classifier outputs disconnected") - checkout(classify["steps"][0]) - config_path = classifier(classify["steps"][1]) - - check(analyze.get("needs") in ("classify", ["classify"]) - and expression(analyze.get("if"), "needs.classify.outputs.run == 'true'", False), - "analysis dependency/condition disconnected") - name = analyze.get("name", "") - match = re.fullmatch(r"CodeQL analysis \((\$\{\{.*\}\})\)", name) if isinstance(name, str) else None - check(match is not None and expression(match[1], "matrix.display"), "analysis display disconnected") - strategy = analyze.get("strategy", {}) - check(isinstance(strategy, dict) and set(strategy) == {"fail-fast", "matrix"} - and strategy["fail-fast"] == "false" - and expression(strategy["matrix"], "fromJSON(needs.classify.outputs.matrix)"), - "analysis matrix disconnected") - check("outputs" not in analyze and len(analyze["steps"]) == 4, "analysis step order unsupported") - checkout(analyze["steps"][0]) - check(classifier(analyze["steps"][1], scoped=True) == config_path, "analysis config destination disconnected") - initialize, analyze_step = analyze["steps"][2:] - step(initialize, "CodeQL init", "matrix.run == true") - action(initialize, "github/codeql-action/init") - inputs = initialize.get("with", {}) - check(isinstance(inputs, dict) and set(inputs) == {"build-mode", "config-file", "languages"} - and inputs["build-mode"] == "none" - and expression(inputs["config-file"], "steps.classify.outputs.codeql_config") - and expression(inputs["languages"], "matrix.language"), "CodeQL init/config/language disconnected") - step(analyze_step, "CodeQL analysis", "matrix.run == true") - action(analyze_step, "github/codeql-action/analyze") - inputs = analyze_step.get("with", {}) - check(isinstance(inputs, dict) and set(inputs) == {"category"} - and expression(inputs["category"], "matrix.category"), "CodeQL analysis category disconnected") - - check(validation.get("name") == "CodeQL validation" - and expression(validation.get("if"), "always()", False) - and isinstance(validation.get("needs"), list) and sorted(validation["needs"]) == ["analyze", "classify"] - and not any(key in validation for key in ("strategy", "outputs")) - and len(validation["steps"]) == 2, "validation dependency/condition disconnected") - checkout(validation["steps"][0]) - aggregate = validation["steps"][1] - step(aggregate, "validation aggregate") - options, _ = command(aggregate, ["python3", "tools/ci/require_checks.py", "optional"]) - check(set(options) == {"--label", "--classifier-result", "--required", "--result"} - and options["--label"] == "CodeQL" - and expression(options["--classifier-result"], "needs.classify.result") - and expression(options["--required"], "needs.classify.outputs.run") - and expression(options["--result"], "needs.analyze.result"), "validation result arguments disconnected") - - -def advanced_codeql(coordinate, branch, head, minima, partition_minima): - sources = {} - for path in (".github/workflows/codeql.yml", "tools/ci/classify_changes.py", "tools/ci/require_checks.py"): - sources[path] = contents(coordinate, path, branch) - require(contents(coordinate, path, head) == sources[path], "advanced CodeQL producer source is stale") - advanced_workflow_wiring(sources[".github/workflows/codeql.yml"], branch) - declarations = classifier_partitions(sources["tools/ci/classify_changes.py"], partition_minima) - events = classifier_full_events(sources["tools/ci/classify_changes.py"]) - run = latest_full_codeql_run(coordinate, branch, head, events) - jobs_endpoint = f"repos/{coordinate}/actions/runs/{run['id']}/attempts/{run['run_attempt']}/jobs" - jobs = pages(jobs_endpoint, "jobs") - require(bool(jobs) and all(job["head_sha"] == head and job["status"] == "completed" - and job["conclusion"] == "success" for job in jobs), - "advanced CodeQL full-run jobs not all successful on current head") - require(len([job for job in jobs if job["name"] == "CodeQL classification"]) == 1, - "advanced CodeQL classification job missing") - validation = [job for job in jobs if job["name"] == "CodeQL validation"] - require(len(validation) == 1, "advanced CodeQL validation job missing") - expected_url = f"https://api.github.com/repos/{coordinate}/check-runs/" - check_url = validation[0]["check_run_url"] - require(check_url.startswith(expected_url) and check_url[len(expected_url):].isdigit(), - "advanced CodeQL validation check identity missing") - check_endpoint = f"repos/{coordinate}/check-runs/{check_url[len(expected_url):]}" - check = api(check_endpoint) - require(check["name"] == "CodeQL validation" and check["head_sha"] == head - and check["app"]["id"] == ACTION_APP and check["app"]["slug"] == "github-actions" - and check["check_suite"]["id"] == run["check_suite_id"] - and check["status"] == "completed" and check["conclusion"] == "success", - "advanced CodeQL validation check is not the trusted current-head producer") - selected = {} - for job in jobs: - match = re.fullmatch(r"CodeQL analysis \((.+)\)", job["name"]) - if match: - require(match[1] not in selected, "advanced CodeQL analysis jobs duplicated") - selected[match[1]] = job - require(set(selected) == set(declarations), - "advanced CodeQL full run does not cover every declared partition") - coverage = advanced_codeql_coverage(coordinate, branch, head, minima, selected, declarations) - fresh = latest_full_codeql_run(coordinate, branch, head, events) - require(all(fresh[key] == run[key] for key in - ("id", "run_attempt", "head_sha", "head_branch", "event", "path", "check_suite_id")), - "advanced CodeQL full run changed during preflight") - require(api(check_endpoint) == check, "advanced CodeQL validation check changed during preflight") - require(pages(jobs_endpoint, "jobs") == jobs, "advanced CodeQL full-run jobs changed during preflight") - for path, source in sources.items(): - require(contents(coordinate, path, branch) == source, - "advanced CodeQL producer source changed during preflight") - require(advanced_codeql_coverage(coordinate, branch, head, minima, selected, declarations) == coverage, - "advanced CodeQL analysis coverage changed during preflight") - return "current full-event CodeQL producer covers policy minima and every declared partition upload" - - -def codeql(coordinate): - metadata = repository(coordinate) - branch = metadata["default_branch"] - branch_endpoint = f"repos/{coordinate}/branches/{quote(branch, safe='')}" - head = api(branch_endpoint)["commit"]["sha"] - require(bool(SHA.fullmatch(head)), "default-branch head missing") - required = config("security-merge-protection.json")["codeql_required_languages"].get( - coordinate.split('/')[1], []) - advanced = config("codeql-advanced-setup.json") - if coordinate.split('/')[1] in advanced["repositories"]: - partition_minima = advanced_partition_minima(advanced, coordinate.split('/')[1]) - reason = advanced_codeql(coordinate, branch, head, required, partition_minima) - else: - reason = default_codeql(coordinate, branch, head, [canonical_language(value) for value in required]) - require(api(branch_endpoint)["commit"]["sha"] == head, "default branch changed during CodeQL preflight") - require(repository(coordinate)["default_branch"] == branch, - "repository default branch changed during preflight") - return reason - - -def main(argv=None): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("mode", choices=("dependency", "sha", "codeql")) - parser.add_argument("target", help="OWNER/REPO, or OWNER/REPO/PR for sha") - args = parser.parse_args(argv) - try: - parts = args.target.split("/") - coordinate = "/".join(parts[:2]) - if not COORDINATE.fullmatch(coordinate) or len(parts) != (3 if args.mode == "sha" else 2): - raise EvidenceError("invalid repository or PR coordinate") - if args.mode == "sha": - if not parts[2].isdigit() or int(parts[2]) < 1: - raise EvidenceError("invalid PR number") - reason = sha(coordinate, int(parts[2])) - else: - reason = {"dependency": dependency, "codeql": codeql}[args.mode](coordinate) - print(f"ready: {reason}") - return 0 - except Deferred as exc: - print(f"deferred: {exc}") - return 1 - except (EvidenceError, OSError, ValueError, KeyError, TypeError, AttributeError, SyntaxError) as exc: - reason = str(exc) if isinstance(exc, EvidenceError) else "local or API evidence malformed/unreadable" - print(f"error: {reason}") - return 2 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/lib/verify_crate_workflow.py b/lib/verify_crate_workflow.py deleted file mode 100644 index 73be7e4..0000000 --- a/lib/verify_crate_workflow.py +++ /dev/null @@ -1,372 +0,0 @@ -#!/usr/bin/env python3 -"""Verify the executable OIDC publication contract on exact-main workflow bytes.""" - -import argparse -import re -import shlex -import sys -from pathlib import Path - -try: - import yaml -except ImportError: - sys.exit("error: install requirements-validation.txt to verify observed crate workflows") - - -class UniqueLoader(yaml.SafeLoader): - """Reject ambiguous duplicate keys and preserve Actions' `on` YAML key.""" - - yaml_implicit_resolvers = { - key: [(tag, regex) for tag, regex in values if tag != "tag:yaml.org,2002:bool"] - for key, values in yaml.SafeLoader.yaml_implicit_resolvers.items() - } - - -def unique_mapping(loader, node, deep=False): - result = {} - for key_node, value_node in node.value: - key = loader.construct_object(key_node, deep=deep) - if key in result: - raise ValueError(f"duplicate YAML key: {key}") - result[key] = loader.construct_object(value_node, deep=deep) - return result - - -UniqueLoader.add_constructor("tag:yaml.org,2002:map", unique_mapping) - - -def require(condition, message): - if not condition: - raise ValueError(message) - - -def expression(value): - require(isinstance(value, str), "missing executable job condition") - value = value.strip() - if value.startswith("${{") and value.endswith("}}"): - value = value[3:-2].strip() - return value - - -def run_configuration(value, context): - defaults = value.get("defaults", {}) - require(isinstance(defaults, dict), f"invalid {context} run defaults") - run_defaults = defaults.get("run", {}) - require(isinstance(run_defaults, dict) and not run_defaults, - f"{context} run defaults must not override executable helper semantics") - - -def critical_step(step, context): - require("shell" not in step and "working-directory" not in step, - f"{context} must use the standard runner shell and workspace") - require(step.get("continue-on-error", "false") == "false", - f"{context} must fail on execution errors") - - -def job_execution_shape(job, context): - require(not any(key in job for key in ("strategy", "uses", "with", "secrets")), - f"{context} must be one ordinary job without matrix or reusable execution") - - -def confined_step_references(job, upload_index=None): - """Whitelist the two reviewed step references, including expression casing/index variants.""" - def visit(value, path=()): - if isinstance(value, dict): - for key, item in value.items(): - visit(key, path + ("mapping-key",)) - visit(item, path + (key,)) - elif isinstance(value, list): - for index, item in enumerate(value): - visit(item, path + (index,)) - elif isinstance(value, str): - if "${{" not in value or not re.search(r"\bsteps\b", value, flags=re.IGNORECASE): - return - token = (upload_index is not None and - path == ("steps", upload_index, "env", "CARGO_REGISTRY_TOKEN") and - value == "${{ steps.auth.outputs.token }}") - confirmation = (len(path) == 3 and path[0] == "steps" and path[2] == "if" and - value == "${{ !cancelled() && (steps.upload.outcome == 'success' || steps.upload.outcome == 'failure') }}") - require(token or confirmation, "step references must not expose the authentication token outside validated upload") - visit(job) - - -def helper_run(step, operation): - if "if" in step or not isinstance(step.get("run"), str): - return False - try: - tokens = shlex.split(step["run"], comments=False) - except ValueError: - return False - expected = ["python3", "tools/crate_release.py", operation, "--release-id", - "SOURCE_RELEASE_ID", "--revision", "SOURCE_REVISION", "--manifest-sha256", "MANIFEST_SHA256"] - if len(tokens) != len(expected): - return False - return all(token in ("$" + expected[index], "${" + expected[index] + "}") - if index in (4, 6, 8) else token == expected[index] - for index, token in enumerate(tokens)) - - -def verify(source, repository, repository_id): - workflow = yaml.load(source, Loader=UniqueLoader) - require(isinstance(workflow, dict), "workflow must be a YAML mapping") - run_configuration(workflow, "workflow") - triggers = workflow.get("on") - require(isinstance(triggers, dict) and "workflow_dispatch" in triggers - and set(triggers) <= {"workflow_dispatch", "schedule"}, - "publication must offer workflow_dispatch with only optional reconciliation schedule") - operation = triggers["workflow_dispatch"]["inputs"]["operation"] - require(isinstance(operation, dict) and operation.get("type") == "choice" - and isinstance(operation.get("options"), list) and "automatic" in operation["options"], - "dispatch must offer the automatic operation") - require(workflow.get("permissions") == {"contents": "read"}, - "workflow default permission must be contents read only") - require(workflow.get("env", {}) in ({}, {"PYTHONDONTWRITEBYTECODE": "1"}), - "publication workflow must not override helper execution through global environment") - require("CARGO_REGISTRY_TOKEN" not in workflow.get("env", {}), - "registry token must not be workflow scoped") - jobs = workflow.get("jobs") - require(isinstance(jobs, dict), "missing executable publication jobs") - guard = { - f"github.repository == '{repository}'", - f"github.repository_id == '{repository_id}'", - "github.ref == 'refs/heads/main'", - "github.event_name == 'workflow_dispatch'", - "inputs.operation == 'automatic'", - } - matching = {name: job for name, job in jobs.items() if isinstance(job, dict) - and isinstance(job.get("if"), str) - and {term.strip() for term in expression(job["if"]).split("&&")} == guard} - publish_names = [name for name, job in matching.items() - if isinstance(job.get("permissions"), dict) - and job["permissions"].get("id-token") == "write"] - require(len(matching) == 2 and len(publish_names) == 1, - "automatic operation needs one credential-free verify job and one OIDC publish job") - publish_name = publish_names[0] - verify_name = next(name for name in matching if name != publish_name) - for name in (verify_name, publish_name): - job = jobs.get(name) - require(isinstance(job, dict), f"missing job {name}") - job_execution_shape(job, name) - require("outputs" not in job, f"{name} must not export credentials through job outputs") - run_configuration(job, name) - require(job.get("continue-on-error", "false") == "false", - f"{name} must fail on execution errors") - terms = expression(job.get("if")).split("&&") - require(len(terms) == len(guard) and {term.strip() for term in terms} == guard, - f"{name} must enforce exactly the repository/id/main/dispatch/automatic guard") - require(job.get("runs-on") == "ubuntu-24.04" and "container" not in job and "services" not in job, - f"{name} must use the reviewed hosted runner without execution overrides") - require("CARGO_REGISTRY_TOKEN" not in job.get("env", {}), - f"{name} must not scope the registry token to the job") - for key, value in { - "GH_READ_TOKEN": "${{ github.token }}", - "SOURCE_RELEASE_ID": "${{ inputs.source_release_id }}", - "SOURCE_REVISION": "${{ inputs.source_revision }}", - "MANIFEST_SHA256": "${{ inputs.manifest_sha256 }}", - }.items(): - require(job.get("env", {}).get(key) == value, - f"{name} must bind {key} to the reviewed dispatch input") - require(set(job.get("env", {})) == {"GH_READ_TOKEN", "SOURCE_RELEASE_ID", "SOURCE_REVISION", "MANIFEST_SHA256"}, - f"{name} must not override helper execution through extra environment") - steps = job.get("steps") - require(isinstance(steps, list) and steps, f"{name} has no executable steps") - checkouts = [step for step in steps if isinstance(step, dict) - and str(step.get("uses", "")).startswith("actions/checkout@")] - require(len(checkouts) == 1, f"{name} must check out the exact main revision") - checkout = checkouts[0] - critical_step(checkout, f"{name} checkout") - require(re.fullmatch(r"actions/checkout@[0-9a-f]{40}", checkout["uses"]) is not None - and checkout.get("with", {}).get("ref") == "${{ github.sha }}" - and str(checkout.get("with", {}).get("persist-credentials")).lower() == "false" - and set(checkout.get("with", {})) <= {"ref", "persist-credentials", "fetch-depth"} - and str(checkout.get("with", {}).get("fetch-depth", "0")) == "0" - and "env" not in checkout and "run" not in checkout - and "if" not in checkout, f"{name} checkout identity/credential drift") - for step in steps: - require(isinstance(step, dict), f"invalid {name} step") - if "uses" in step: - require(re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@[0-9a-f]{40}", - str(step["uses"])) is not None, - f"{name} action reference must be a full immutable SHA") - for name in (verify_name, publish_name): - for step in jobs[name]["steps"]: - if helper_run(step, "verify"): - critical_step(step, f"{name} verification") - verify_job = jobs[verify_name] - read_permissions = {"contents": "read", "actions": "read", "checks": "read", "attestations": "read"} - require(verify_job.get("permissions") == read_permissions, - "automatic verification needs only source/provenance/run/check read permissions") - require(any(helper_run(step, "verify") for step in verify_job["steps"]), - "automatic verification helper must run unconditionally") - publish = jobs[publish_name] - require(publish.get("needs") in (verify_name, [verify_name]), - "automatic publication must depend on credential-free verification") - require(publish.get("environment") == "crates-io-release", "wrong publication environment") - require(publish.get("permissions") == dict(read_permissions, contents="write", **{"id-token": "write"}), - "automatic upload needs only provenance reads, upload-intent contents write and OIDC write") - auth_steps = [(index, step) for index, step in enumerate(publish["steps"]) - if str(step.get("uses", "")).startswith("rust-lang/crates-io-auth-action@")] - require(len(auth_steps) == 1, "automatic upload needs one official authentication action") - auth_index, auth = auth_steps[0] - critical_step(auth, "official authentication step") - require(auth.get("id") == "auth" and "if" not in auth - and "with" not in auth and "env" not in auth and "run" not in auth, - "official authentication step must be executable and have id auth") - require(any(helper_run(step, "verify") for step in publish["steps"][:auth_index]), - "upload must reverify bytes before requesting OIDC") - uploads = [(index, step) for index, step in enumerate(publish["steps"]) - if "CARGO_REGISTRY_TOKEN" in step.get("env", {})] - require(len(uploads) == 1, "only one upload step may receive the registry token") - upload_index, upload = uploads[0] - critical_step(upload, "registry upload step") - require(upload_index > auth_index and upload.get("id") in (None, "upload") and "if" not in upload - and upload["env"]["CARGO_REGISTRY_TOKEN"] == "${{ steps.auth.outputs.token }}" - and upload["env"].get("GH_INTENT_TOKEN") == "${{ github.token }}" - and helper_run(upload, "upload"), - "upload must execute after auth with only the returned temporary token") - for name in (verify_name, publish_name): - confined_step_references(jobs[name], upload_index if name == publish_name else None) - require(jobs[name].get("env", {}).get("GH_READ_TOKEN") == "${{ github.token }}" - and "GH_INTENT_TOKEN" not in jobs[name].get("env", {}) - and "GH_INTENT_TOKEN" not in workflow.get("env", {}), - "read authority must be explicit; upload-intent token must be step scoped") - for step in jobs[name]["steps"]: - if step is upload: - require(set(step.get("env", {})) == {"CARGO_REGISTRY_TOKEN", "GH_INTENT_TOKEN"}, - "upload step must receive only the temporary registry and intent tokens") - continue - require("GH_INTENT_TOKEN" not in step.get("env", {}), - "only upload may receive the intent token") - if "uses" in step: - require(str(step["uses"]).startswith("actions/checkout@") or step is auth, - "automatic jobs may run only immutable checkout and official authentication actions") - else: - critical_step(step, f"{name} inert helper") - require("env" not in step, "verification/confirmation must not override helper environment") - confirm = dict(step) - confirm.pop("if", None) - require(helper_run(step, "verify") or (name == publish_name - and helper_run(confirm, "confirm") and step.get("if") in ( - "${{ !cancelled() }}", - "${{ !cancelled() && (steps.upload.outcome == 'success' || steps.upload.outcome == 'failure') }}")), - "automatic jobs may execute only the inert verify/upload/confirm helpers") - for name, job in jobs.items(): - if name in (verify_name, publish_name): - continue - if repository == "atrinik/protocol" and name == "publish": - # Protocol 0.2 retains its separately reviewed manual upload path. - manual_guard = (guard - {"inputs.operation == 'automatic'"}) | { - "inputs.operation == 'publish'", "needs.verify.outputs.ready == 'true'"} - terms = expression(job.get("if")).split("&&") - require(job.get("environment") == "crates-io-release" - and len(terms) == len(manual_guard) - and {term.strip() for term in terms} == manual_guard - and job.get("needs") in ("verify", ["verify"]) - and job.get("permissions") == {"contents": "read", "id-token": "write"}, - "protocol manual upload path identity/permission drift") - for step in job.get("steps", []): - if "uses" in step: - require(re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@[0-9a-f]{40}", - str(step["uses"])) is not None, - "protocol manual path action reference must be immutable") - continue - permissions = job.get("permissions", workflow["permissions"]) - require(isinstance(permissions, dict) and permissions.get("id-token", "none") == "none", - f"unexpected OIDC permission on {name}") - require(permissions.get("attestations", "none") == "none", - f"unexpected attestation permission on {name}") - return auth["uses"] - - -def verify_source_release(source, repository): - """Qualify the signing boundary; runtime certificate/claim checks belong to the producer.""" - workflow = yaml.load(source, Loader=UniqueLoader) - require(isinstance(workflow, dict), "source release must be a YAML mapping") - run_configuration(workflow, "source workflow") - require(workflow.get("permissions") == {"contents": "read"}, - "source workflow default must be contents read only") - require(not workflow.get("env", {}), "source workflow must not supply signing environment overrides") - triggers = workflow.get("on") - require(isinstance(triggers, dict) and set(triggers) == {"push", "workflow_dispatch"} - and triggers["push"].get("branches") == ["main", "[0-9]+.[0-9]+.x"], - "source release must use the reviewed main/maintenance push and dispatch triggers") - jobs = workflow.get("jobs") - require(isinstance(jobs, dict) and jobs, "missing source release jobs") - signers = [] - for name, job in jobs.items(): - require(isinstance(job, dict), "invalid source release job") - job_execution_shape(job, f"source {name}") - permissions = job.get("permissions", workflow["permissions"]) - require(isinstance(permissions, dict), "invalid source permissions") - if permissions.get("id-token", "none") != "none" or permissions.get("attestations", "none") != "none": - require(permissions == {"contents": "read", "id-token": "write", "attestations": "write"}, - "only the isolated signer may request OIDC and attestation writes") - signers.append(name) - require(len(signers) == 1, "source release needs exactly one isolated signer") - signer_name = signers[0] - signer = jobs[signer_name] - run_configuration(signer, "source signer") - require(signer.get("continue-on-error", "false") == "false", "signer must fail on errors") - require(not signer.get("env", {}), "signer must not override inert execution environment") - require(signer.get("runs-on") == "ubuntu-24.04" and "container" not in signer and "services" not in signer, - "signer must use the reviewed hosted runner without execution overrides") - package_name = signer.get("needs") - require(package_name == "package" and package_name in jobs, - "signer must depend on one credential-free package job") - package = jobs[package_name] - require(package.get("permissions", workflow["permissions"]) == {"contents": "read"}, - "source package preparation must be credential-free") - require(package.get("continue-on-error", "false") == "false", "package preparation must fail on errors") - guard = f"needs.{package_name}.outputs.version != ''" - require(expression(signer.get("if")) == guard, "signer must use the package version readiness guard") - release = jobs.get("release", {}) - require(set(release.get("needs", [])) == {package_name, signer_name} - and expression(release.get("if")) == guard - and release.get("continue-on-error", "false") == "false", - "source publication must depend on successful package preparation and signing") - steps = signer.get("steps") - require(isinstance(steps, list) and len(steps) == 4, - "signer must contain only checkout, payload download, inert finalization and official attestation") - checkout, download, finalize, attest = steps - for step in steps: - require(isinstance(step, dict) and "if" not in step, "signing steps must be unconditional") - critical_step(step, "source signing step") - revision = "${{ needs." + package_name + ".outputs.revision }}" - version = "${{ needs." + package_name + ".outputs.version }}" - artifact = "source-release-${{ github.sha }}" - require(re.fullmatch(r"actions/checkout@[0-9a-f]{40}", str(checkout.get("uses"))) is not None - and checkout.get("with") == {"ref": revision, "persist-credentials": "false"}, - "signer checkout must use the exact prepared revision without persisted credentials") - require(re.fullmatch(r"actions/download-artifact@[0-9a-f]{40}", str(download.get("uses"))) is not None - and download.get("with") == {"name": artifact, "path": "build/release/"}, - "signer must download only its same-run prepared payload") - require(finalize.get("env") == {"ATRINIK_RELEASE_BRANCH": "${{ github.ref_name }}", - "EXPECTED_SOURCE_REVISION": revision, "EXPECTED_SOURCE_VERSION": version} - and shlex.split(finalize.get("run", "")) == ["python3", "tools/crate_release.py", "finalize", - "--source-tag", "v${EXPECTED_SOURCE_VERSION}", "--archives", "build/release"], - "signer may run only the inert payload finalizer with exact prepared inputs") - require(re.fullmatch(r"actions/attest-build-provenance@[0-9a-f]{40}", str(attest.get("uses"))) is not None - and attest.get("with") == {"subject-path": "build/release/crate-release.json", "push-to-registry": "false"}, - "signer must attest the exact manifest through the immutable official action") - for step in (checkout, download, attest): - require("run" not in step and "env" not in step, - "source signing action must not execute extra commands or receive credential overrides") - return attest["uses"] - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--repository", required=True) - parser.add_argument("--repository-id", required=True) - parser.add_argument("--source-workflow-file", required=True) - args = parser.parse_args() - try: - action = verify(sys.stdin.read(), args.repository, args.repository_id) - signer_action = verify_source_release(Path(args.source_workflow_file).read_text(), args.repository) - except (ValueError, KeyError, TypeError, OSError, yaml.YAMLError) as error: - sys.exit(f"error: crate publication executable workflow drift: {error}") - print(f"Executable automatic publication and inert source signing contracts verified; immutable actions {action}, {signer_action}") - - -if __name__ == "__main__": - main() diff --git a/requirements-validation.txt b/requirements-validation.txt deleted file mode 100644 index ad78371..0000000 --- a/requirements-validation.txt +++ /dev/null @@ -1,2 +0,0 @@ -# YAML parsing for executable publication and CodeQL workflow verification. -PyYAML==6.0.3 diff --git a/scripts/release/release-policy.cjs b/scripts/release/release-policy.cjs deleted file mode 100644 index b8b971d..0000000 --- a/scripts/release/release-policy.cjs +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; - -const MAINTENANCE_BRANCH = /^[0-9]+\.[0-9]+\.x$/; -const RELEASE_RANK = {patch: 1, minor: 2, major: 3}; - -const MAIN_RULES = [ - {breaking: true, release: "major"}, - {type: "feat", release: "minor"}, - {type: "*", release: "minor"}, -]; - -const MAINTENANCE_RULES = [ - {breaking: true, release: "major"}, - {type: "feat", release: "minor"}, - {type: "*", release: "patch"}, -]; - -function currentBranch() { - const refName = process.env.GITHUB_REF_NAME; - const branch = - process.env.ATRINIK_RELEASE_BRANCH || - (typeof refName === "string" && /^\d+\/merge$/.test(refName) - ? process.env.GITHUB_BASE_REF || "main" - : refName || process.env.GITHUB_HEAD_REF); - if (typeof branch !== "string" || branch.length === 0) { - throw new Error("ATRINIK_RELEASE_BRANCH is required"); - } - return branch; -} - -function rulesForBranch(branch) { - if (branch === "main") { - return MAIN_RULES.map((rule) => ({...rule})); - } - if (MAINTENANCE_BRANCH.test(branch)) { - return MAINTENANCE_RULES.map((rule) => ({...rule})); - } - throw new Error("unsupported semantic-release branch: " + branch); -} - -function releaseForCommit(branch, commit) { - const matches = rulesForBranch(branch).filter((rule) => { - if (rule.breaking === true) { - return commit.breaking === true; - } - return rule.type === "*" || rule.type === commit.type; - }); - if (matches.length === 0) { - return null; - } - return matches.reduce((release, rule) => - RELEASE_RANK[rule.release] > RELEASE_RANK[release] ? rule.release : release, - "patch"); -} - -function nextVersion(value, release) { - const match = /^([0-9]+)\.([0-9]+)\.([0-9]+)$/.exec(value); - if (!match || !Object.hasOwn(RELEASE_RANK, release)) { - throw new Error("version or release level is invalid"); - } - let [major, minor, patch] = match.slice(1).map(Number); - if (release === "major") { - major += 1; - minor = 0; - patch = 0; - } else if (release === "minor") { - minor += 1; - patch = 0; - } else { - patch += 1; - } - return major + "." + minor + "." + patch; -} - -module.exports = { - MAINTENANCE_BRANCH, - currentBranch, - nextVersion, - releaseForCommit, - rulesForBranch, -}; diff --git a/scripts/release/release-rules.cjs b/scripts/release/release-rules.cjs deleted file mode 100644 index 384045f..0000000 --- a/scripts/release/release-rules.cjs +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; - -const {currentBranch, rulesForBranch} = require("./release-policy.cjs"); - -module.exports = rulesForBranch(currentBranch()); diff --git a/scripts/release/test-release-policy.cjs b/scripts/release/test-release-policy.cjs deleted file mode 100644 index 7a046a8..0000000 --- a/scripts/release/test-release-policy.cjs +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; - -const assert = require("node:assert/strict"); -const { - currentBranch, - nextVersion, - releaseForCommit, - rulesForBranch, -} = require("./release-policy.cjs"); - -assert.equal( - releaseForCommit("main", {type: "docs", breaking: false}), - "minor", -); -assert.equal(nextVersion("8.0.0", "minor"), "8.1.0"); -assert.equal( - releaseForCommit("8.3.x", {type: "fix", breaking: false}), - "patch", -); -assert.equal(nextVersion("8.3.0", "patch"), "8.3.1"); -assert.equal( - releaseForCommit("8.3.x", {type: "feat", breaking: false}), - "minor", -); -assert.equal( - releaseForCommit("main", {type: "fix", breaking: true}), - "major", -); -assert.throws(() => rulesForBranch("release"), /unsupported/); - -delete process.env.ATRINIK_RELEASE_BRANCH; -process.env.GITHUB_REF_NAME = "421/merge"; -process.env.GITHUB_BASE_REF = "8.3.x"; -assert.equal(currentBranch(), "8.3.x"); -delete process.env.GITHUB_REF_NAME; -delete process.env.GITHUB_BASE_REF; - -process.env.ATRINIK_RELEASE_BRANCH = "main"; -delete require.cache[require.resolve("./release-rules.cjs")]; -assert.equal(require("./release-rules.cjs").at(-1).release, "minor"); -process.env.ATRINIK_RELEASE_BRANCH = "8.3.x"; -delete require.cache[require.resolve("./release-rules.cjs")]; -assert.equal(require("./release-rules.cjs").at(-1).release, "patch"); - -console.log("release policy: mainline and maintenance transitions verified"); diff --git a/tests/audit-fixtures.py b/tests/audit-fixtures.py deleted file mode 100755 index 9aef19e..0000000 --- a/tests/audit-fixtures.py +++ /dev/null @@ -1,562 +0,0 @@ -#!/usr/bin/env python3 -"""Read-only GitHub API double for the effective-governance audit tests.""" -import copy -import fnmatch -import json -import os -import sys -from pathlib import Path -from urllib.parse import unquote - -root = Path(os.environ['AUDIT_CONFIG_ROOT']) -scenario = os.environ.get('GH_TEST_SCENARIO', 'pass') - - -def config(name): - return json.loads((root / 'config' / name).read_text()) - - -def reject(message): - print(message, file=sys.stderr) - sys.exit(2) - - -args = sys.argv[1:] -if not args or args.pop(0) != 'api': - reject('API only') -slurp = False -include = False -endpoint = None -method = None -fields = {} -while args: - arg = args.pop(0) - if arg == '--method': - method = args.pop(0) - elif arg == '-H': - args.pop(0) - elif arg == '--paginate': - pass - elif arg == '--slurp': - slurp = True - elif arg == '--include': - include = True - elif arg == '-f': - key, separator, value = args.pop(0).partition('=') - if not separator or key in fields: - reject('invalid or duplicated GraphQL variable') - fields[key] = value - elif arg.startswith('-'): - reject(f'unexpected or mutating API flag: {arg}') - else: - endpoint = arg -if endpoint is None: - reject('endpoint missing') -query = 'query LegacyBranchProtection($owner: String!, $name: String!, $qualifiedName: String!) { repository(owner: $owner, name: $name) { databaseId nameWithOwner isArchived ref(qualifiedName: $qualifiedName) { name branchProtectionRule { id } } } }' -if endpoint == 'graphql': - if (method != 'POST' or set(fields) != {'query', 'owner', 'name', 'qualifiedName'} - or fields['query'] != query or fields['owner'] != 'atrinik' - or fields['name'] != 'observatory' - or fields['qualifiedName'] not in ('refs/heads/main', 'refs/heads/release/next#candidate') - or not scenario.startswith(('legacy-disabled-', 'legacy-maintenance-disabled-'))): - reject('unexpected or mutating GraphQL request') -elif method != 'GET' or fields: - reject('audit attempted API mutation') -with open(os.environ['AUDIT_API_LOG'], 'a', encoding='utf-8') as log: - log.write(endpoint + '\n') - -properties = config('repository-properties.json') -repositories = config('repositories.json') -policy = config('security-merge-protection.json') -active = sorted(name for name, value in properties['repositories'].items() - if value['lifecycle'] != 'archived') - - -def rulesets(repository): - specs = [('default-branch-integrity', None), ('default-branch-linear-history', None)] - if repository in repositories['pull_request_gate']: - specs.append(('pull-request-gate', None)) - if repository in repositories['required_ci']: - specs.append(('required-ci', '03 - Required CI - ' + repository)) - queued = repository in repositories['merge_queue'] - if (queued and scenario != 'queue-missing') or ( - scenario == 'queue-retained' and repository == 'observatory'): - specs.append(('merge-queue', None)) - if repository in repositories['release_tags'] or scenario in ( - 'inherited-tag-unaffected', 'tag-extra-nonrelease', 'tag-all-nonrelease', 'tag-repository-nonrelease'): - specs.append(('immutable-release-tags', None)) - if repository in policy['code_scanning'] and scenario not in ('pending-codeql', 'ready-missing-codeql', 'codeql-readiness-unreadable', 'enforced-missing-codeql', 'enforced-unreadable-codeql'): - specs.append(('code-scanning', None)) - if repository in policy['dependency_review'] and scenario not in ('pending', 'ready-missing', 'dependency-readiness-unreadable', 'enforced-missing-dependency', 'enforced-unreadable-dependency'): - specs.append(('dependency-review', None)) - if scenario == 'foreign-tag': - specs.append(('immutable-release-tags', 'Foreign tag retention')) - retained_template = None - if scenario.startswith(('retained-', 'retired-')): - kind = scenario.split('-')[1] - retained_template = {'codeql': 'code-scanning', 'dependency': 'dependency-review'}.get(kind) - if retained_template: - specs.append((retained_template, None)) - if scenario.endswith('-duplicate'): - specs.append((retained_template, None)) - result = [] - for index, (template, name) in enumerate(specs, 1): - item = config('rulesets/' + template + '.json') - if name: - item['name'] = name - if template == 'required-ci': - item['rules'][0]['parameters']['required_status_checks'] = [ - {'context': context, 'integration_id': 15368} - for context in repositories['required_ci'][repository]] - # The publisher relaxes the up-to-date requirement for queued merges. - if queued and scenario != 'queue-strict': - item['rules'][0]['parameters']['strict_required_status_checks_policy'] = False - if template == 'merge-queue' and scenario == 'queue-parameter': - item['rules'][0]['parameters']['check_response_timeout_minutes'] = 30 - # Actual ruleset GET responses expand omitted request parameters. - for rule in item['rules']: - if rule['type'] == 'pull_request': - rule['parameters'].update(required_reviewers=[], - require_extra_approval_for_unattributed_changes=True, - allowed_merge_methods=['merge', 'squash', 'rebase']) - deviations = { - 'api-required-reviewers': ('required_reviewers', [{'reviewer': {'id': 42, 'type': 'Team'}, 'minimum_approvals': 1}]), - 'api-extra-approval': ('require_extra_approval_for_unattributed_changes', False), - 'api-restricted-merges': ('allowed_merge_methods', ['squash']), - 'api-duplicate-merges': ('allowed_merge_methods', ['merge', 'squash', 'rebase', 'merge']), - 'api-malformed-reviewers': ('required_reviewers', None), - 'api-malformed-approval': ('require_extra_approval_for_unattributed_changes', 'true'), - 'api-malformed-merges': ('allowed_merge_methods', 'merge,squash,rebase'), - 'api-unknown-pr-field': ('unknown_future_control', False), - } - if scenario in deviations: - key, value = deviations[scenario] - rule['parameters'][key] = value - if scenario == 'api-default-order': - rule['parameters']['allowed_merge_methods'].reverse() - if rule['type'] == 'required_status_checks': - rule['parameters']['do_not_enforce_on_create'] = False - if scenario == 'api-create-exemption': - rule['parameters']['do_not_enforce_on_create'] = True - if scenario == 'api-malformed-create-exemption': - rule['parameters']['do_not_enforce_on_create'] = None - if scenario == 'api-defaults-omitted': - for rule in item['rules']: - for key in ('required_reviewers', 'require_extra_approval_for_unattributed_changes', - 'allowed_merge_methods', 'do_not_enforce_on_create'): - rule.get('parameters', {}).pop(key, None) - item.update(id=active.index(repository) * 10 + index, - source_type='Repository' if scenario == 'repository-rulesets' or - template in ('code-scanning', 'dependency-review', 'merge-queue') else 'Organization') - if scenario == 'queue-organization-owner' and template == 'merge-queue': - item['source_type'] = 'Organization' - if ((scenario == 'organization-codeql-owner' and template == 'code-scanning') or - (scenario == 'organization-dependency-owner' and template == 'dependency-review')): - item['source_type'] = 'Organization' - if scenario == 'tag-repository-nonrelease' and template == 'immutable-release-tags': - item['source_type'] = 'Repository' - # Match GitHub's actual owner representation, including repository rulesets. - for actor in item['bypass_actors']: - if actor['actor_type'] == 'OrganizationAdmin': - actor['actor_id'] = None - if scenario == 'owner-id-ignored' and repository == 'observatory' and template == 'pull-request-gate': - item['bypass_actors'][0]['actor_id'] = 2 - if item['source_type'] == 'Organization': - if template in ('default-branch-integrity', 'default-branch-linear-history'): - included = ['~ALL'] - excluded = config('advisory-merge-windows.json')['repositories'] - elif template == 'pull-request-gate': - windows = config('advisory-merge-windows.json')['repositories'] - included = [name for name in repositories['pull_request_gate'] if name not in windows] - excluded = [] - elif template == 'immutable-release-tags': - included, excluded = repositories['release_tags'], [] - elif template == 'code-scanning': - included, excluded = policy['code_scanning'], [] - elif template == 'dependency-review': - included, excluded = policy['dependency_review'], [] - else: - included, excluded = [repository], [] - item['conditions']['repository_name'] = { - 'include': list(included), 'exclude': list(excluded), 'protected': False} - if scenario == 'scope-order' and 'repository_name' in item['conditions']: - item['conditions']['repository_name']['include'].reverse() - item['conditions']['repository_name']['exclude'].reverse() - if scenario == 'repository-scope-extra' and template == 'dependency-review': - item['conditions']['repository_name'] = {'include': ['~ALL'], 'exclude': [], 'protected': False} - if scenario in ('tag-all-scope', 'tag-all-nonrelease') and template == 'immutable-release-tags': - item['conditions']['repository_name']['include'] = ['~ALL'] - if scenario in ('tag-extra-repo', 'tag-extra-nonrelease') and template == 'immutable-release-tags': - item['conditions']['repository_name']['include'].append('.github') - if scenario == 'tag-extra-exclude' and template == 'immutable-release-tags': - item['conditions']['repository_name']['exclude'] = ['foreign-repository'] - if scenario == 'pr-all-scope' and template == 'pull-request-gate': - item['conditions']['repository_name']['include'] = ['~ALL'] - if scenario == 'default-extra-exclude' and template == 'default-branch-integrity': - item['conditions']['repository_name']['exclude'].append('foreign-repository') - # Keep inherited names while making actual targeting ineffective. - if scenario == 'wrong-pr-scope' and repository == '.github' and template == 'pull-request-gate': - item['conditions']['repository_name']['include'] = ['client'] - if scenario == 'pending-wrong-dependency-scope' and repository == 'observatory' and template == 'dependency-review': - item['conditions']['repository_name'] = {'include': ['observatory'], 'exclude': ['observatory'], 'protected': False} - if scenario == 'missing-tag-scope' and repository == 'service-updater' and template == 'immutable-release-tags': - item['conditions']['repository_name']['exclude'] = ['service-updater'] - if scenario == 'tag-ref-drift' and repository == 'service-updater' and template == 'immutable-release-tags': - item['conditions']['ref_name']['include'] = ['refs/tags/unrelated*'] - if scenario == 'integrity-bypass' and repository == 'observatory' and template == 'default-branch-integrity': - item['bypass_actors'] = [{'actor_type': 'OrganizationAdmin', 'actor_id': 1, 'bypass_mode': 'always'}] - if scenario == 'pr-bypass' and repository == 'observatory' and template == 'pull-request-gate': - item['bypass_actors'][0]['bypass_mode'] = 'always' - if scenario == 'codeql-threshold' and repository == 'observatory' and template == 'code-scanning': - item['rules'][0]['parameters']['code_scanning_tools'][0]['security_alerts_threshold'] = 'critical' - if scenario == 'codeql-tool' and repository == 'observatory' and template == 'code-scanning': - item['rules'][0]['parameters']['code_scanning_tools'][0]['tool'] = 'other-scanner' - if scenario == 'codeql-quality' and repository == 'observatory' and template == 'code-scanning': - item['rules'][0]['parameters']['code_scanning_tools'][0]['alerts_threshold'] = 'errors' - if template == retained_template: - if scenario.endswith(('-disabled', '-foreign-name', '-duplicate')): - item['enforcement'] = 'disabled' - if scenario.endswith('-moved'): - item['conditions']['ref_name']['include'] = ['refs/heads/other'] - if scenario.endswith('-modified'): - item['rules'] = [{'type': 'creation'}] - item['enforcement'] = 'disabled' - if scenario.endswith('-foreign-owner'): - item['source_type'] = 'Organization' - item['enforcement'] = 'disabled' - if scenario.endswith('-foreign-name'): - item['name'] = 'Foreign security policy' - result.append(item) - return result - - -payload = None -if endpoint == 'graphql': - variant = scenario.removeprefix('legacy-maintenance-').removeprefix('legacy-').removeprefix('disabled-') - repository = {'databaseId': active.index('observatory') + 1, 'nameWithOwner': 'atrinik/observatory', - 'isArchived': False, 'ref': {'name': fields['qualifiedName'].removeprefix('refs/heads/'), - 'branchProtectionRule': None}} - payload = {'data': {'repository': repository}} - if variant == 'present': - repository['ref']['branchProtectionRule'] = {'id': 'BPR_fixture'} - elif variant == 'wrong-id': - repository['databaseId'] += 100 - elif variant == 'wrong-owner': - repository['nameWithOwner'] = 'foreign/observatory' - elif variant == 'wrong-name': - repository['ref']['name'] = 'master' - elif variant == 'archived': - repository['isArchived'] = True - elif variant == 'missing-field': - del repository['ref']['branchProtectionRule'] - elif variant == 'null-ref': - repository['ref'] = None - elif variant == 'null-repository': - payload['data']['repository'] = None - elif variant == 'missing-data': - del payload['data'] - elif variant == 'malformed-rule': - repository['ref']['branchProtectionRule'] = False - elif variant == 'errors': - payload['errors'] = [{'message': 'read denied'}] - elif variant == 'unreadable': - reject('GraphQL request denied') - elif variant == 'non-json': - print('unavailable') - sys.exit(0) -elif endpoint.startswith('orgs/atrinik/repos?'): - if scenario == 'inventory-unreadable': - reject('inventory read denied') - payload = [dict(name=name, id=active.index(name) + 1 if name in active else 1000, - archived=value['lifecycle'] == 'archived', private=False, - visibility='public', disabled=False, fork=False, has_issues=True, - has_projects=True, has_wiki=True) - for name, value in properties['repositories'].items()] - if scenario == 'legacy-disabled-inventory-id': - next(item for item in payload if item['name'] == 'observatory')['id'] += 100 - if scenario == 'unmanaged': - payload.append(dict(name='unmanaged', archived=False, private=False, visibility='public', - disabled=False, fork=False, has_issues=True, has_projects=True, has_wiki=True)) - if scenario == 'temporary': - payload.append(dict(name='classic-ghsa-8533-3vg8-r287', archived=False, private=True, - visibility='private', disabled=False, fork=False, - has_issues=False, has_projects=False, has_wiki=False)) -elif endpoint == 'orgs/atrinik/properties/schema': - payload = properties['definitions'] - if scenario == 'schema-drift': - payload[0]['description'] = 'drift' -elif endpoint.startswith('orgs/atrinik/actions/permissions'): - suffix = endpoint.removeprefix('orgs/atrinik/actions/permissions') - filename = {'': 'actions-permissions.json', '/workflow': 'actions-workflow.json', - '/selected-actions': 'actions-selected.json'}[suffix] - if scenario == 'actions-unreadable': - reject('Actions read denied') - payload = config(filename) - if filename == 'actions-permissions.json': - payload['sha_pinning_required'] = scenario not in ('pending', 'sha-enforced-off', 'phase-unreadable') - if scenario == 'sha-invalid-type': - payload['sha_pinning_required'] = 'false' - if scenario == 'sha-unreadable': - del payload['sha_pinning_required'] - if filename == 'actions-workflow.json': - if scenario == 'actions-write-token': - payload['default_workflow_permissions'] = 'write' - if scenario == 'actions-approval': - payload['can_approve_pull_request_reviews'] = True - if filename == 'actions-selected.json' and scenario == 'actions-allowlist': - payload['patterns_allowed'].append('*') -elif endpoint.startswith('orgs/atrinik/rulesets/'): - identifier = int(endpoint.rsplit('/', 1)[1]) - payload = next((item for repository in active for item in rulesets(repository) - if item['id'] == identifier), None) - if payload is None or scenario == 'ruleset-unreadable': - reject('ruleset read denied') -elif endpoint.startswith('repos/atrinik/'): - repository, _, path = endpoint.removeprefix('repos/atrinik/').partition('/') - if repository not in active: - reject('audit attempted to inspect archived or foreign repository') - target = repository == 'observatory' - if path == 'actions/permissions/workflow': - if scenario == 'repository-actions-unreadable' and target: - reject('repository workflow permissions read denied') - payload = config('actions-workflow.json') - if scenario == 'repository-write-token' and target: - payload['default_workflow_permissions'] = 'write' - if scenario == 'repository-approval' and target: - payload['can_approve_pull_request_reviews'] = True - elif path.startswith('branches/') and path.endswith('/protection'): - if not include: - reject('legacy protection requires an observable HTTP status') - branch = path.removeprefix('branches/').removesuffix('/protection') - if branch not in ('main', 'release%2F2.x', 'release%2Fnext%23candidate'): - reject('unexpected or unencoded branch: ' + branch) - code, payload, result = 404, {'message': 'Branch not protected', 'status': '404'}, 1 - selected = target and branch == 'main' - if scenario.startswith('legacy-maintenance-'): - selected = target and branch == 'release%2Fnext%23candidate' - if selected: - variant = scenario.removeprefix('legacy-maintenance-').removeprefix('legacy-') - policies = { - 'extra-context': {'required_status_checks': {'checks': [ - {'context': 'Unconfigured check', 'app_id': 15368}]}}, - 'wrong-app': {'required_status_checks': {'checks': [ - {'context': 'Conventional PR title', 'app_id': 99}]}}, - 'approval': {'required_pull_request_reviews': {'required_approving_review_count': 1}}, - 'force-push': {'allow_force_pushes': {'enabled': True}}, - 'matching': {'required_status_checks': {'checks': [ - {'context': context, 'app_id': 15368} - for context in repositories['required_ci'].get(repository, [])]}}, - 'empty': {}, - } - if variant.startswith('disabled-'): - payload['message'] = 'Branch protection has been disabled on this repository.' - elif variant in policies: - code, payload, result = 200, policies[variant], 0 - elif variant == 'forbidden': - code, payload = 403, {'message': 'Resource not accessible by integration', 'status': '403'} - elif variant == 'not-found': - payload['message'] = 'Not Found' - elif variant == 'wrong-status': - payload['status'] = '403' - elif variant == 'mismatched-http': - code = 403 - elif variant == 'transport-error': - reject('connection failed') - elif variant == 'wrong-exit': - result = 2 - elif variant == 'success-error': - code, result = 200, 0 - elif variant == 'non-json': - payload = 'service unavailable' - elif variant == 'success-non-json': - code, payload, result = 200, 'service unavailable', 0 - elif variant == 'null': - payload = None - elif variant == 'array': - payload = [payload] - print(f'HTTP/2.0 {code} Fixture\r\nContent-Type: application/json\r\n\r') - print(payload if isinstance(payload, str) else json.dumps(payload)) - sys.exit(result) - elif path == 'properties/values': - payload = [{'property_name': key, 'value': value} - for key, value in properties['repositories'][repository].items()] - if scenario == 'properties-drift' and target: - payload[0]['value'] = 'drift' - elif path.startswith('rulesets?'): - if scenario == 'retained-list-unreadable': - reject('ruleset list read denied') - if scenario == 'retained-list-non-json': - print('unavailable') - sys.exit(0) - payload = [{'name': item['name'], 'id': item['id'], 'source_type': item['source_type']} - for item in rulesets(repository)] - if scenario == 'retained-list-object': - payload = {'message': 'unreadable'} - elif scenario == 'retained-list-missing-name': - payload.append({'id': 999, 'source_type': 'Repository'}) - elif scenario == 'retained-list-null-item': - payload.append(None) - elif scenario == 'retained-list-partial-page': - print(json.dumps([payload, None])) - sys.exit(0) - elif path.startswith('rulesets/'): - identifier = int(path.rsplit('/', 1)[1]) - payload = next((item for item in rulesets(repository) if item['id'] == identifier), None) - if payload is None: - reject('repository ruleset missing') - elif path.startswith('rules/branches/'): - branch = unquote(path.removeprefix('rules/branches/').partition('?')[0]) - if scenario == 'effective-unreadable' and target: - reject('effective branch read denied') - payload = [] - for item in rulesets(repository): - scope = item['conditions'].get('repository_name', {'include': [repository], 'exclude': []}) - included = any(pattern == '~ALL' or fnmatch.fnmatchcase(repository, pattern) for pattern in scope['include']) - excluded = any(pattern == '~ALL' or fnmatch.fnmatchcase(repository, pattern) for pattern in scope['exclude']) - refs = item['conditions']['ref_name'] - branch_included = any((pattern == '~DEFAULT_BRANCH' and branch == 'main') or - fnmatch.fnmatchcase('refs/heads/' + branch, pattern) for pattern in refs['include']) - branch_excluded = any((pattern == '~DEFAULT_BRANCH' and branch == 'main') or - fnmatch.fnmatchcase('refs/heads/' + branch, pattern) for pattern in refs['exclude']) - if (item['target'] == 'branch' and item['enforcement'] == 'active' - and included and not excluded and branch_included and not branch_excluded): - payload.extend(copy.deepcopy(item['rules'])) - for maintenance in repositories['maintenance_branches']: - if maintenance['repository'] == repository and maintenance['branch'] == branch: - rules = config('rulesets/maintenance-branch.json')['rules'] - for rule in rules: - if rule['type'] == 'required_status_checks': - if not maintenance['required_ci']: - continue - rule['parameters']['required_status_checks'] = [ - {'context': context, 'integration_id': 15368} - for context in maintenance['required_ci']] - payload.append(rule) - for rule in payload: - if target and rule['type'] == 'required_status_checks': - if scenario == 'wrong-app': - rule['parameters']['required_status_checks'][0]['integration_id'] = 9 - if scenario == 'wrong-context': - rule['parameters']['required_status_checks'][0]['context'] += ' drift' - if scenario == 'strict-ci': - rule['parameters']['strict_required_status_checks_policy'] = False - if target and rule['type'] == 'pull_request': - if scenario == 'approval-count': - rule['parameters']['required_approving_review_count'] = 1 - if scenario == 'thread-resolution': - rule['parameters']['required_review_thread_resolution'] = False - if scenario == 'effective-integrity' and target: - payload = [item for item in payload if item['type'] != 'deletion'] - if scenario == 'unexpected-codeql' and repository == '.github': - payload.extend(config('rulesets/code-scanning.json')['rules']) - if scenario == 'unexpected-pr' and repository == 'web-platform': - payload.append(config('rulesets/pull-request-gate.json')['rules'][0]) - if scenario.startswith('closure-'): - _, selected_branch, variant = scenario.split('-', 2) - selected = (selected_branch == 'default' and branch == 'main') or ( - selected_branch == 'maintenance' and branch == 'release/next#candidate') - if selected: - extra = { - 'signatures': {'type': 'required_signatures'}, - 'deployments': {'type': 'required_deployments', 'parameters': {'required_deployment_environments': ['production']}}, - 'update': {'type': 'update', 'parameters': {'update_allows_fetch_and_merge': False}}, - 'unknown': {'type': 'future_unconfigured_rule', 'parameters': {'enabled': True}}, - } - if variant in extra: - payload.append(extra[variant]) - elif variant == 'integrity-parameter': - next(rule for rule in payload if rule['type'] == 'deletion')['parameters'] = {'unexpected': True} - elif variant == 'status-parameter': - next(rule for rule in payload if rule['type'] == 'required_status_checks')['parameters']['unexpected'] = True - elif variant == 'top-field': - payload[0]['unknown_policy_field'] = True - elif variant == 'missing-type': - payload.append({'parameters': {}}) - elif variant == 'null-item': - payload.append(None) - elif variant == 'malformed-parameters': - next(rule for rule in payload if rule['type'] == 'deletion')['parameters'] = [] - elif variant == 'null-page': - print(json.dumps([payload, None])) - sys.exit(0) - elif variant == 'unreadable': - reject('effective branch read denied') - elif variant == 'non-json': - print('unavailable') - sys.exit(0) - elif variant in ('metadata-organization', 'metadata-repository'): - for rule in payload: - rule.update(ruleset_id=99, ruleset_source='atrinik' if variant.endswith('organization') else 'atrinik/observatory', - ruleset_source_type='Organization' if variant.endswith('organization') else 'Repository') - elif variant == 'signatures-inherited': - payload.append({'type': 'required_signatures', 'ruleset_id': 99, - 'ruleset_source': 'atrinik', 'ruleset_source_type': 'Organization'}) - elif path == 'code-security-configuration': - advanced = repository in config('codeql-advanced-setup.json')['repositories'] - if scenario == 'configuration-unreadable' and target: - reject('configuration read denied') - payload = {'status': 'enforced', 'configuration': config( - 'code-security-advanced.json' if advanced else 'code-security.json')} - if scenario == 'legacy-security': - payload['configuration'].pop('code_security') - payload['configuration'].pop('secret_protection') - payload['configuration']['advanced_security'] = 'enabled' - if scenario == 'configuration-detached' and target: - payload['status'] = 'attached' - if scenario == 'dependency-graph' and target: - payload['configuration']['dependency_graph'] = 'disabled' - if scenario == 'advanced-config' and repository == 'classic': - payload['configuration'] = config('code-security.json') - elif path == 'code-scanning/default-setup': - advanced = repository in config('codeql-advanced-setup.json')['repositories'] - if scenario == 'setup-unreadable' and target: - reject('setup read denied') - payload = config('codeql-default-setup-advanced.json' if advanced else 'codeql-default-setup.json') - payload['languages'] = policy['codeql_required_languages'].get(repository, []) - if target: - malformed_languages = { - 'languages-null': None, - 'languages-scalar': 'javascript-typescript', - 'languages-object': {'language': 'javascript-typescript'}, - 'languages-number': [7], - 'languages-mixed': ['javascript-typescript', None], - } - if scenario in malformed_languages: - payload['languages'] = malformed_languages[scenario] - elif scenario == 'languages-missing': - del payload['languages'] - elif scenario == 'languages-readable': - payload['languages'] = ['javascript-typescript', 'future-language'] - elif scenario == 'languages-empty': - payload['languages'] = [] - if scenario == 'advanced-null-languages' and repository == 'classic': - payload['languages'] = None - if scenario == 'missing-rust' and repository == 'content-toolkit': - payload['languages'] = ['javascript-typescript'] - if scenario == 'advanced-setup' and repository == 'classic': - payload['state'] = 'configured' - if scenario == 'default-setup' and target: - payload['state'] = 'not-configured' - elif path == 'vulnerability-alerts': - if scenario == 'dependabot-alerts' and target: - reject('alerts disabled') - sys.exit(0) # GitHub's enabled response is HTTP 204, without JSON. - elif path == 'private-vulnerability-reporting': - payload = {'enabled': not (scenario == 'private-reporting' and target)} - elif path == '': - payload = dict(config('repository-defaults.json'), id=active.index(repository) + 1, - name=repository, full_name='atrinik/' + repository, archived=False, security_and_analysis={ - name: {'status': 'enabled'} for name in ( - 'secret_scanning', 'secret_scanning_push_protection', - 'secret_scanning_validity_checks', 'dependabot_security_updates')}) - if scenario == 'legacy-disabled-metadata-name' and target: - payload['full_name'] = 'foreign/observatory' - if scenario == 'merge-drift' and target: - payload['allow_merge_commit'] = True - if scenario == 'secret-baseline' and target: - payload['security_and_analysis']['secret_scanning']['status'] = 'disabled' - else: - reject('unexpected repository endpoint: ' + endpoint) -else: - reject('unexpected endpoint: ' + endpoint) -print(json.dumps([payload] if slurp else payload)) diff --git a/tests/audit.sh b/tests/audit.sh deleted file mode 100755 index 36b7ea1..0000000 --- a/tests/audit.sh +++ /dev/null @@ -1,361 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir -p "${temporary}/mock" "${temporary}/full/bin" -cp -R "${root}/config" "${temporary}/full/config" -cp -R "${root}/lib" "${temporary}/full/lib" -cp "${root}/bin/audit" "${temporary}/full/bin/audit" -# Schema validation has its own policy tests; these isolate live API evidence. -printf '#!/usr/bin/env bash\nexit 0\n' >"${temporary}/full/bin/validate" -cat >"${temporary}/full/bin/security-readiness" <<'EOF' -#!/usr/bin/env bash -printf '%s\n' "$1" >>"${AUDIT_READINESS_LOG}" -case ${GH_TEST_SCENARIO:-pass} in - pending|pending-codeql|pending-wrong-dependency-scope|enforced-missing-dependency|enforced-missing-codeql) exit 1 ;; - readiness-unreadable|dependency-readiness-unreadable|codeql-readiness-unreadable|enforced-unreadable-dependency|enforced-unreadable-codeql) exit 2 ;; - *) exit 0 ;; -esac -EOF -chmod +x "${temporary}/full/bin/validate" "${temporary}/full/bin/security-readiness" -cp "${root}/tests/audit-fixtures.py" "${temporary}/mock/gh" -chmod +x "${temporary}/mock/gh" -# Exercise both reviewed rollout phases using test-owned desired state. -printf '%s\n' '{"phase":"pending","canary":null}' \ - >"${temporary}/full/config/actions-sha-pinning.json" -jq '.sha_pinning_required = true' "${temporary}/full/config/actions-permissions.json" \ - >"${temporary}/actions.json" -mv "${temporary}/actions.json" "${temporary}/full/config/actions-permissions.json" -jq '.pull_request_gate |= ((. + [".github"]) | unique)' "${temporary}/full/config/repositories.json" \ - >"${temporary}/repositories.json" -mv "${temporary}/repositories.json" "${temporary}/full/config/repositories.json" -for repository in .github classic observatory content-toolkit playtester service-updater web-platform; do - fixture="${temporary}/fixture-${repository}" - cp -R "${temporary}/full" "${fixture}" - jq --arg repository "${repository}" \ - '.repositories |= with_entries(select(.key == $repository))' \ - "${temporary}/full/config/repository-properties.json" >"${fixture}/config/repository-properties.json" -done - -cp -R "${temporary}/fixture-observatory" "${temporary}/fixture-legacy-branches" -jq '.maintenance_branches = [ - {repository: "observatory", branch: "release/2.x", required_ci: []}, - {repository: "observatory", branch: "release/next#candidate", required_ci: []}, - {repository: "classic", branch: "foreign/maintenance", required_ci: []} -]' "${temporary}/full/config/repositories.json" \ - >"${temporary}/fixture-legacy-branches/config/repositories.json" - -cp -R "${temporary}/fixture-observatory" "${temporary}/fixture-retired-observatory" -jq 'del(.required_ci.observatory)' "${temporary}/full/config/repositories.json" \ - >"${temporary}/fixture-retired-observatory/config/repositories.json" - -cp -R "${temporary}/fixture-legacy-branches" "${temporary}/fixture-effective-branches" -jq '(.maintenance_branches[] | select(.branch == "release/next#candidate") | .required_ci) = ["Conventional PR title"]' \ - "${temporary}/fixture-legacy-branches/config/repositories.json" \ - >"${temporary}/fixture-effective-branches/config/repositories.json" - -run_audit() { - local scenario=$1 fixture=${2:-focused} repository=observatory - if [[ ${fixture} == focused ]]; then - case ${scenario} in - closure-*) repository=effective-branches ;; - retained-*) repository=.github ;; - retired-*) repository=retired-observatory ;; - legacy-maintenance-*|legacy-multiple) repository=legacy-branches ;; - wrong-pr-scope|unexpected-codeql|tag-extra-nonrelease|tag-all-nonrelease|tag-repository-nonrelease|inherited-tag-unaffected|foreign-tag) repository=.github ;; - advanced-config|advanced-setup|advanced-null-languages) repository=classic ;; - missing-rust) repository=content-toolkit ;; - missing-tag-scope|tag-ref-drift|tag-all-scope|tag-extra-repo|tag-extra-exclude) repository=service-updater ;; - unexpected-pr) repository=web-platform ;; - queue-retained) repository=observatory ;; - queue-*) repository=playtester ;; - esac - fixture="fixture-${repository}" - fi - case ${scenario} in - sha-enforced-off|sha-enforced-on) - printf '%s\n' '{"phase":"enforced","canary":"atrinik/observatory/1"}' \ - >"${temporary}/${fixture}/config/actions-sha-pinning.json" - ;; - phase-unreadable) - printf '%s\n' '{}' >"${temporary}/${fixture}/config/actions-sha-pinning.json" - ;; - *) - printf '%s\n' '{"phase":"pending","canary":null}' \ - >"${temporary}/${fixture}/config/actions-sha-pinning.json" - ;; - esac - # Preserve required-gate audit scenarios independently of advisory production. - if [[ ${scenario} == production-advisory ]]; then - cp "${root}/config/security-merge-protection.json" "${temporary}/${fixture}/config/security-merge-protection.json" - else - # Dependency review never reports on merge groups, so queued repositories - # cannot carry its required gate. - jq --slurpfile repositories "${root}/config/repositories.json" ' - $repositories[0].merge_queue as $queued | - .dependency_review = (.code_scanning - $queued) | - .activation.dependency_review = (.activation.code_scanning | - with_entries(select(.key as $repository | $queued | index($repository) | not))) - ' "${root}/config/security-merge-protection.json" >"${temporary}/${fixture}/config/security-merge-protection.json" - fi - case ${scenario} in - retired-*) - jq '.dependency_review -= ["observatory"] | .code_scanning -= ["observatory"] | - del(.activation.dependency_review.observatory, .activation.code_scanning.observatory)' \ - "${temporary}/${fixture}/config/security-merge-protection.json" >"${temporary}/activation.json" - mv "${temporary}/activation.json" "${temporary}/${fixture}/config/security-merge-protection.json" - ;; - enforced-missing-dependency|enforced-unreadable-dependency) - jq '.activation.dependency_review.observatory = "enforced"' \ - "${temporary}/${fixture}/config/security-merge-protection.json" >"${temporary}/activation.json" - mv "${temporary}/activation.json" "${temporary}/${fixture}/config/security-merge-protection.json" - ;; - enforced-missing-codeql|enforced-unreadable-codeql) - jq '.activation.code_scanning.observatory = "enforced"' \ - "${temporary}/${fixture}/config/security-merge-protection.json" >"${temporary}/activation.json" - mv "${temporary}/activation.json" "${temporary}/${fixture}/config/security-merge-protection.json" - ;; - esac - : >"${temporary}/${scenario}.readiness-log" - GH_TEST_SCENARIO=${scenario} \ - AUDIT_READINESS_LOG="${temporary}/${scenario}.readiness-log" \ - PATH="${temporary}/mock:${PATH}" \ - AUDIT_CONFIG_ROOT="${temporary}/${fixture}" \ - AUDIT_API_LOG="${temporary}/api.log" \ - "${temporary}/${fixture}/bin/audit" -} - -output=$(run_audit production-advisory full) -grep -Fxq 'Governance audit passed: 22 active repositories checked.' <<<"${output}" -if grep -Fq 'Dependency review merge protection' <<<"${output}"; then - echo 'advisory production must not require dependency merge protection' >&2 - exit 1 -fi -output=$(run_audit pass full) -grep -Fxq 'Governance audit passed: 22 active repositories checked.' <<<"${output}" -output=$(run_audit temporary full) -grep -Fxq 'Governance audit passed: 22 active repositories checked.' <<<"${output}" -output=$(run_audit legacy-security) -grep -Fq 'Governance audit passed:' <<<"${output}" -output=$(run_audit repository-rulesets) -grep -Fq 'Governance audit passed:' <<<"${output}" -for scenario in owner-id-ignored api-defaults-omitted api-default-order scope-order inherited-tag-unaffected foreign-tag sha-enforced-on languages-readable languages-empty advanced-null-languages; do - output=$(run_audit "${scenario}") - grep -Fq 'Governance audit passed:' <<<"${output}" -done -output=$(run_audit pending) -grep -Fq 'PENDING Actions SHA pinning deferred pending canary proof' <<<"${output}" -grep -Fq 'PENDING Dependency review merge protection awaits landed successful producer' <<<"${output}" -grep -Fq 'Governance audit baseline passed with' <<<"${output}" -if grep -Fq 'Governance audit passed:' <<<"${output}"; then - echo 'pending policy must not report full governance enforcement' >&2 - exit 1 -fi - -assert_drift() { - local scenario=$1 message=$2 - if run_audit "${scenario}" >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "expected ${scenario} audit to fail" >&2 - exit 1 - fi - if ! grep -Fq "${message}" "${temporary}/${scenario}.out" "${temporary}/${scenario}.err"; then - cat "${temporary}/${scenario}.out" "${temporary}/${scenario}.err" >&2 - echo "missing expected ${scenario} diagnostic: ${message}" >&2 - exit 1 - fi -} - -# Only the precise GitHub absence response is accepted; legacy policies are -# manual drift even when their contexts match the declared ruleset contract. -for scenario in extra-context wrong-app approval force-push matching empty success-error; do - assert_drift "legacy-${scenario}" 'unexpected legacy branch protection requires manual review: atrinik/observatory/main' -done -for scenario in forbidden not-found wrong-status mismatched-http transport-error wrong-exit non-json success-non-json null array; do - assert_drift "legacy-${scenario}" 'legacy branch protection could not be read: atrinik/observatory/main' -done -for scenario in extra-context approval; do - assert_drift "legacy-maintenance-${scenario}" 'unexpected legacy branch protection requires manual review: atrinik/observatory/release/next#candidate' -done -assert_drift legacy-maintenance-forbidden 'legacy branch protection could not be read: atrinik/observatory/release/next#candidate' -: >"${temporary}/api.log" -output=$(run_audit legacy-multiple) -grep -Fq 'Governance audit passed:' <<<"${output}" -for branch in main release%2F2.x release%2Fnext%23candidate; do - [[ $(grep -Fxc "repos/atrinik/observatory/branches/${branch}/protection" "${temporary}/api.log") == 1 ]] -done -if grep -Fq 'foreign' "${temporary}/api.log"; then - echo 'maintenance protection must remain scoped to its repository' >&2 - exit 1 -fi - -# GitHub's disabled-protection response requires independent exact-ref proof; -# historical rules on another branch must neither create drift nor prove absence. -for scenario in legacy-disabled-absent legacy-maintenance-disabled-absent; do - output=$(run_audit "${scenario}") - grep -Fq 'Governance audit passed:' <<<"${output}" -done -assert_drift legacy-disabled-present 'unexpected legacy branch protection requires manual review: atrinik/observatory/main' -assert_drift legacy-maintenance-disabled-present 'unexpected legacy branch protection requires manual review: atrinik/observatory/release/next#candidate' -for scenario in wrong-id wrong-owner wrong-name archived missing-field null-ref null-repository missing-data malformed-rule errors unreadable non-json inventory-id metadata-name; do - assert_drift "legacy-disabled-${scenario}" 'legacy branch protection could not be read: atrinik/observatory/main' -done -assert_drift legacy-maintenance-disabled-wrong-name 'legacy branch protection could not be read: atrinik/observatory/release/next#candidate' - -# Retained named rules remain drift after target removal, regardless of whether -# their current rules apply to main. Unrelated names remain outside ownership. -for scope in retained retired; do - for kind in codeql dependency; do - case ${kind} in - codeql) name='06 - CodeQL security' ;; - dependency) name='07 - Dependency review' ;; - esac - for variant in disabled moved modified duplicate foreign-owner; do - assert_drift "${scope}-${kind}-${variant}" "unexpected retained security ruleset '${name}' requires manual review" - done - output=$(run_audit "${scope}-${kind}-foreign-name") - grep -Fq 'Governance audit passed:' <<<"${output}" - done - output=$(run_audit "${scope}-absent") - grep -Fq 'Governance audit passed:' <<<"${output}" -done -for variant in unreadable non-json object missing-name null-item partial-page; do - assert_drift "retained-list-${variant}" 'inherited rulesets could not be read' -done - -# Check the entire effective policy on main and exact maintenance refs. Desired -# CI, Dependency review and CodeQL coexist; API provenance is metadata only. -for branch in default maintenance; do - for variant in baseline metadata-organization metadata-repository; do - output=$(run_audit "closure-${branch}-${variant}") - grep -Fq 'Governance audit passed:' <<<"${output}" - done - for variant in signatures deployments update unknown integrity-parameter status-parameter top-field malformed-parameters signatures-inherited; do - assert_drift "closure-${branch}-${variant}" 'effective branch policy drift requires manual review' - done - for variant in missing-type null-item null-page unreadable non-json; do - assert_drift "closure-${branch}-${variant}" "effective ${branch}-branch rules could not be read" - done -done - -assert_drift unmanaged 'active repository is not in the desired-state inventory' -assert_drift merge-drift 'repository merge policy drift' -assert_drift properties-drift 'repository custom-property drift' -assert_drift schema-drift 'organization custom-property schema drift' -assert_drift inventory-unreadable 'organization repository inventory could not be read' -assert_drift wrong-pr-scope 'effective pull-request policy drift: atrinik/.github' -assert_drift missing-tag-scope "ruleset scope or policy drift '04 - Immutable release tags': atrinik/service-updater" -assert_drift tag-ref-drift "ruleset scope or policy drift '04 - Immutable release tags'" -for scenario in tag-all-scope tag-extra-repo tag-extra-exclude tag-all-nonrelease tag-extra-nonrelease; do - assert_drift "${scenario}" "ruleset scope or policy drift '04 - Immutable release tags'" -done -assert_drift tag-repository-nonrelease 'unexpected managed release-tag protection: atrinik/.github' -for scenario in api-required-reviewers api-extra-approval api-restricted-merges api-duplicate-merges \ - api-malformed-reviewers api-malformed-approval api-malformed-merges api-unknown-pr-field; do - assert_drift "${scenario}" "ruleset scope or policy drift '02 - Changes through pull requests'" -done -for scenario in api-create-exemption api-malformed-create-exemption; do - assert_drift "${scenario}" "ruleset scope or policy drift '03 - Required CI - observatory'" -done -assert_drift pr-all-scope "ruleset scope or policy drift '02 - Changes through pull requests'" -assert_drift default-extra-exclude "ruleset scope or policy drift '01 - Default branch integrity'" -assert_drift repository-scope-extra "ruleset scope or policy drift '07 - Dependency review'" -assert_drift organization-codeql-owner "managed security ruleset must be repository-owned '06 - CodeQL security'" -assert_drift organization-dependency-owner "managed security ruleset must be repository-owned '07 - Dependency review'" -assert_drift integrity-bypass "ruleset scope or policy drift '01 - Default branch integrity'" -assert_drift pr-bypass "ruleset scope or policy drift '02 - Changes through pull requests'" -assert_drift pending-wrong-dependency-scope "ruleset scope or policy drift '07 - Dependency review'" -for scenario in wrong-app wrong-context strict-ci; do - assert_drift "${scenario}" 'effective required CI contexts or app drift' -done -for scenario in approval-count thread-resolution; do - assert_drift "${scenario}" 'effective pull-request policy drift' -done - -# A queued repository needs its repository-owned queue, the exact queue -# parameters, and required CI that no longer demands a current branch. -output=$(run_audit queue-pass) -grep -Fq 'Governance audit passed:' <<<"${output}" -assert_drift queue-missing "missing or duplicate inherited ruleset '08 - Merge queue': atrinik/playtester" -assert_drift queue-missing 'effective merge queue drift: atrinik/playtester' -assert_drift queue-parameter "ruleset scope or policy drift '08 - Merge queue': atrinik/playtester" -assert_drift queue-parameter 'effective merge queue drift: atrinik/playtester' -assert_drift queue-organization-owner 'managed merge-queue ruleset must be repository-owned: atrinik/playtester' -assert_drift queue-strict 'effective required CI contexts or app drift: atrinik/playtester' -assert_drift queue-strict "ruleset scope or policy drift '03 - Required CI - playtester'" -assert_drift queue-retained 'unexpected retained merge-queue ruleset requires manual review: atrinik/observatory' -assert_drift queue-retained 'effective branch policy drift requires manual review: atrinik/observatory/main' -assert_drift effective-integrity 'effective default-branch integrity drift' -assert_drift unexpected-pr 'effective pull-request policy drift: atrinik/web-platform' -assert_drift unexpected-codeql 'unexpected effective CodeQL merge protection: atrinik/.github' -for scenario in codeql-threshold codeql-tool codeql-quality; do - assert_drift "${scenario}" 'effective CodeQL merge protection drift' -done -for scenario in actions-write-token actions-approval; do - assert_drift "${scenario}" 'organization Actions workflow drift' -done -for scenario in repository-write-token repository-approval; do - assert_drift "${scenario}" 'repository Actions workflow permissions drift' -done -assert_drift repository-actions-unreadable 'repository Actions workflow permissions could not be read' -assert_drift actions-allowlist 'organization Actions selected-actions drift' -assert_drift actions-unreadable 'organization Actions permissions could not be read' -assert_drift sha-unreadable 'Actions SHA pinning state could not be read' -assert_drift sha-invalid-type 'Actions SHA pinning state could not be read' -assert_drift sha-enforced-off 'Actions SHA pinning enforcement drift' -assert_drift phase-unreadable 'Actions SHA pinning rollout phase could not be read' -assert_drift missing-rust 'CodeQL setup or required language drift: atrinik/content-toolkit' -for scenario in languages-missing languages-null languages-scalar languages-object languages-number languages-mixed; do - assert_drift "${scenario}" 'CodeQL setup or required language drift: atrinik/observatory' -done -for scenario in advanced-setup default-setup; do - assert_drift "${scenario}" 'CodeQL setup or required language drift' -done -for scenario in configuration-detached dependency-graph advanced-config; do - assert_drift "${scenario}" 'security configuration attachment or baseline drift' -done -assert_drift configuration-unreadable 'security configuration could not be read' -assert_drift setup-unreadable 'CodeQL setup could not be read' -assert_drift dependabot-alerts 'Dependabot alerts disabled or unreadable' -assert_drift private-reporting 'private vulnerability reporting disabled or unreadable' -assert_drift secret-baseline 'exposed security baseline drift' -assert_drift effective-unreadable 'effective default-branch rules could not be read' -assert_drift ruleset-unreadable 'ruleset contents could not be read' -for scenario in enforced-missing-dependency enforced-unreadable-dependency; do - assert_drift "${scenario}" 'effective required CI contexts or app drift' - [[ ! -s ${temporary}/${scenario}.readiness-log ]] - if grep -Fq 'PENDING Dependency review' "${temporary}/${scenario}.out"; then - echo 'enforced dependency protection must never fall back to pending' >&2 - exit 1 - fi -done -for scenario in enforced-missing-codeql enforced-unreadable-codeql; do - assert_drift "${scenario}" 'effective CodeQL merge protection drift' - [[ ! -s ${temporary}/${scenario}.readiness-log ]] - if grep -Fq 'PENDING CodeQL' "${temporary}/${scenario}.out"; then - echo 'enforced CodeQL protection must never fall back to pending' >&2 - exit 1 - fi -done -for scenario in ready-missing ready-missing-codeql; do - output=$(run_audit "${scenario}") - grep -Fq 'merge protection awaits reviewed activation intent' <<<"${output}" - grep -Fq 'Governance audit baseline passed with' <<<"${output}" -done -assert_drift dependency-readiness-unreadable 'Dependency review readiness could not be read' -assert_drift codeql-readiness-unreadable 'CodeQL readiness could not be read' -output=$(run_audit pending-codeql) -grep -Fq 'PENDING CodeQL merge protection awaits successful analysis' <<<"${output}" -grep -Fq 'Governance audit baseline passed with' <<<"${output}" -# An existing dependency gate survives a temporarily unreadable producer readiness -# API; read readiness is required only when first installing the context. -output=$(run_audit readiness-unreadable) -grep -Fq 'Governance audit passed:' <<<"${output}" - -if grep -Eq '^repos/atrinik/(legacy-|nawerhals)' "${temporary}/api.log"; then - echo 'audit must not inspect archived repositories' >&2 - exit 1 -fi -echo 'Governance effective-policy audit tests passed.' diff --git a/tests/check-project-health.sh b/tests/check-project-health.sh deleted file mode 100755 index 5e37c06..0000000 --- a/tests/check-project-health.sh +++ /dev/null @@ -1,810 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -method=GET -endpoint= -declare -a field_names=() -while (($#)); do - case $1 in - -H) - shift 2 - ;; - --method) - method=$2 - shift 2 - ;; - -f) - field_names+=("${2%%=*}") - if [[ ${2%%=*} == body ]]; then - printf '%s\n' "${2#*=}" >"${FAKE_GH_BODY}" - fi - shift 2 - ;; - *) - endpoint=$1 - shift - ;; - esac -done -printf '%s\t%s\t%s\n' "${method}" "${endpoint}" "${field_names[*]:-}" \ - >>"${FAKE_GH_LOG}" - -if [[ ${FAKE_GH_SCENARIO} == runs-api-failure && \ - ${endpoint} == *'runs?per_page=100' ]]; then - echo "gh: workflow runs request failed" >&2 - exit 45 -elif [[ ${FAKE_GH_SCENARIO} == incident-api-failure && \ - ${endpoint} == *'issues?state=all'* ]]; then - echo "gh: incident listing failed" >&2 - exit 46 -elif [[ ${FAKE_GH_SCENARIO} == alert-api-failure && \ - ${method} == POST ]]; then - echo "gh: incident creation failed" >&2 - exit 47 -fi - -case ${endpoint} in -"repos/atrinik/github-settings/actions/workflows/sync-project.yml/runs?per_page=100") - case ${FAKE_GH_SCENARIO} in - large-healthy) - jq -n --argjson size "${FAKE_LARGE_RESPONSE_BYTES}" '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:49:00Z", - updated_at: "2026-08-10T04:50:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS", - log: ("x" * $size) - }]}' - ;; - large-repeated-failure) - jq -n --argjson size "${FAKE_LARGE_RESPONSE_BYTES}" '{workflow_runs: [ - { - status: "completed", conclusion: "failure", - updated_at: "2026-08-10T04:59:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/102", - head_sha: "FAIL2", - log: ("x" * $size) - }, - { - status: "completed", conclusion: "failure", - updated_at: "2026-08-10T04:49:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/101", - head_sha: "FAIL1" - }, - { - status: "completed", conclusion: "success", - updated_at: "2026-08-10T04:40:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS" - } - ]}' - ;; - large-invalid-response) - jq -nr --argjson size "${FAKE_LARGE_RESPONSE_BYTES}" \ - '"{\"workflow_runs\":[" + ("x" * $size)' - ;; - runs-malformed) - printf '{' - ;; - runs-empty) - : - ;; - runs-whitespace) - printf ' \n\t' - ;; - runs-null) - jq -n 'null' - ;; - runs-false) - jq -n 'false' - ;; - runs-object) - jq -n '{}' - ;; - runs-wrong-type) - jq -n '{workflow_runs: {}}' - ;; - multi-document-runs) - jq -n '{workflow_runs: []}' - jq -n '{workflow_runs: []}' - ;; - healthy | missing-settings | recovery | recurrence-before | reopen | \ - incident-api-failure | filtered-stale | filtered-empty | filtered-newer | \ - filtered-recovery | filtered-before-episode | filtered-pending | future-success | \ - multi-document-success | success-malformed | success-empty | \ - success-whitespace | success-null | success-false | success-object | \ - success-wrong-type) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:49:00Z", - updated_at: "2026-08-10T04:50:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS" - }]}' - ;; - unordered-successes) - jq -n '{workflow_runs: [ - { - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:39:00Z", - updated_at: "2026-08-10T04:40:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "EARLIER-SUCCESS" - }, - { - status: "completed", conclusion: "success", - created_at: "2026-08-09T04:39:00Z", - updated_at: "2026-08-10T04:50:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/90", - head_sha: "RERUN-SUCCESS" - }, - { - status: "completed", conclusion: "failure", - updated_at: "2026-08-10T04:59:00Z" - }, - { - status: "in_progress", conclusion: null, - updated_at: "2026-08-10T05:00:00Z" - } - ]}' - ;; - repeated-failure) - jq -n '{workflow_runs: [ - { - status: "completed", conclusion: "failure", - created_at: "2026-08-10T04:58:00Z", - updated_at: "2026-08-10T04:59:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/102", - head_sha: "FAIL2" - }, - { - status: "completed", conclusion: "failure", - created_at: "2026-08-10T04:48:00Z", - updated_at: "2026-08-10T04:49:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/101", - head_sha: "FAIL1" - }, - { - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:39:00Z", - updated_at: "2026-08-10T04:40:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS" - } - ]}' - ;; - stale | sync-failure | foreign | multiple-managed | alert-api-failure | \ - alert-malformed-response | alert-empty-response | alert-null-response | \ - alert-false-response) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T01:59:00Z", - updated_at: "2026-08-10T02:00:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/90", - head_sha: "STALE" - }]}' - ;; - no-success) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "failure", - created_at: "2026-08-10T04:58:00Z", - updated_at: "2026-08-10T04:59:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/103", - head_sha: "FAIL" - }]}' - ;; - never-ran) - jq -n '{workflow_runs: []}' - ;; - recurrence-after) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:57:00Z", - updated_at: "2026-08-10T04:58:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/104", - head_sha: "NEW-SUCCESS" - }]}' - ;; - old-success) - jq -n '{workflow_runs: [range(0; 100) | { - status: "completed", conclusion: "failure", - created_at: "2026-08-10T04:00:00Z", - updated_at: "2026-08-10T04:01:00Z", - html_url: ("https://github.com/atrinik/github-settings/actions/runs/" + tostring), - head_sha: "FAIL" - }]}' - ;; - *) exit 1 ;; - esac - ;; -"repos/atrinik/github-settings/actions/workflows/sync-project.yml/runs?status=success&per_page=1") - case ${FAKE_GH_SCENARIO} in - large-healthy | large-repeated-failure) - jq -n --argjson size "${FAKE_LARGE_RESPONSE_BYTES}" '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:39:00Z", - updated_at: "2026-08-10T04:40:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS", - log: ("x" * $size) - }]}' - ;; - multi-document-success) - jq -n '{workflow_runs: []}' - jq -n '{workflow_runs: []}' - ;; - success-malformed) - printf '{' - ;; - success-empty) - : - ;; - success-whitespace) - printf ' \n\t' - ;; - success-null) - jq -n 'null' - ;; - success-false) - jq -n 'false' - ;; - success-object) - jq -n '{}' - ;; - success-wrong-type) - jq -n '{workflow_runs: {}}' - ;; - healthy | missing-settings | recovery | recurrence-before | reopen | \ - incident-api-failure | multi-document-runs | runs-object | runs-wrong-type) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:49:00Z", - updated_at: "2026-08-10T04:50:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS" - }]}' - ;; - repeated-failure) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:39:00Z", - updated_at: "2026-08-10T04:40:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/100", - head_sha: "SUCCESS" - }]}' - ;; - stale | sync-failure | foreign | multiple-managed | alert-api-failure | \ - alert-malformed-response | alert-empty-response | alert-null-response | \ - alert-false-response | \ - filtered-stale | filtered-recovery | filtered-before-episode | filtered-pending) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T01:59:00Z", - updated_at: "2026-08-10T02:00:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/90", - head_sha: "STALE" - }]}' - ;; - recurrence-after) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:57:00Z", - updated_at: "2026-08-10T04:58:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/104", - head_sha: "NEW-SUCCESS" - }]}' - ;; - old-success) - jq -n '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-07T00:59:00Z", - updated_at: "2026-08-07T01:00:00Z", - html_url: "https://github.com/atrinik/github-settings/actions/runs/1", - head_sha: "OLD-SUCCESS" - }]}' - ;; - filtered-newer | future-success) - timestamp=2026-08-10T04:58:00Z - [[ ${FAKE_GH_SCENARIO} == future-success ]] && timestamp=2026-08-10T05:01:00Z - jq -n --arg timestamp "${timestamp}" '{workflow_runs: [{ - status: "completed", conclusion: "success", - created_at: "2026-08-10T04:57:00Z", - updated_at: $timestamp, - html_url: "https://github.com/atrinik/github-settings/actions/runs/104", - head_sha: "NEW-SUCCESS" - }]}' - ;; - no-success | never-ran | filtered-empty | unordered-successes) jq -n '{workflow_runs: []}' ;; - *) exit 1 ;; - esac - ;; -"repos/atrinik/github-settings/issues?state=all&per_page=100&page=1") - case ${FAKE_GH_SCENARIO} in - recovery | stale | recurrence-before | recurrence-after | filtered-recovery | \ - filtered-before-episode | filtered-pending) - jq -n '[range(0; 100) | { - number: (. + 1000), - state: "closed", - created_at: "2026-08-09T04:00:00Z", - body: "unmanaged", - user: {login: "someone"} - }]' - ;; - reopen) - jq -n '[{ - number: 70, - state: "closed", - created_at: "2026-08-01T04:00:00Z", - body: "\n", - user: {login: "github-actions[bot]"} - }]' - ;; - foreign) - jq -n '[range(0; 2) | { - number: (. + 80), - state: "open", - created_at: "2026-08-10T04:00:00Z", - body: "", - user: {login: ("attacker-" + tostring)} - }]' - ;; - multiple-managed) - jq -n '[range(0; 2) | { - number: (. + 90), - state: "open", - created_at: "2026-08-10T04:00:00Z", - body: "\n", - user: {login: "github-actions[bot]"} - }]' - ;; - *) jq -n '[]' ;; - esac - ;; -"repos/atrinik/github-settings/issues?state=all&per_page=100&page=2") - case ${FAKE_GH_SCENARIO} in - recovery | stale | recurrence-before | recurrence-after | filtered-recovery | \ - filtered-before-episode | filtered-pending) - episode="2026-08-10T04:00:00Z" - [[ ${FAKE_GH_SCENARIO} == recurrence-before || \ - ${FAKE_GH_SCENARIO} == recurrence-after || \ - ${FAKE_GH_SCENARIO} == filtered-before-episode ]] && \ - episode="2026-08-10T04:55:00Z" - jq -n --arg episode "${episode}" '{ - number: 70, - state: "open", - created_at: "2026-08-10T04:00:00Z", - body: ("\n"), - user: {login: "github-actions[bot]"} - } | [.]' - ;; - *) jq -n '[]' ;; - esac - ;; -repos/atrinik/github-settings/issues) - [[ ${method} == POST ]] - case ${FAKE_GH_SCENARIO} in - alert-malformed-response) printf '{' ;; - alert-empty-response) : ;; - alert-null-response) jq -n 'null' ;; - alert-false-response) jq -n 'false' ;; - *) jq -n '{number: 70, state: "open"}' ;; - esac - ;; -repos/atrinik/github-settings/issues/70) - [[ ${method} == PATCH ]] - jq -n '{number: 70}' - ;; -*) exit 1 ;; -esac -EOF -chmod +x "${temporary}/bin/gh" - -cat >"${temporary}/bin/env" <<'EOF' -#!/usr/bin/env bash - -echo "error: health check exposed the settings token through env arguments" >&2 -exit 99 -EOF -chmod +x "${temporary}/bin/env" - -cat >"${temporary}/bin/sync-plan" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${GH_TOKEN:-} == settings-token ]] -printf '%s\n' "${FAKE_SYNC_SCENARIO}" >>"${FAKE_SYNC_LOG}" -if [[ ${FAKE_SYNC_SCENARIO} == failure ]]; then - echo "error: Project authorization denied" >&2 - exit 1 -fi -mutations=0 -[[ ${FAKE_SYNC_SCENARIO} == pending ]] && mutations=6 -cat <"${temporary}/gh.log" -: >"${temporary}/sync.log" -: >"${temporary}/step-summary" -output=$(run_health healthy zero) -grep -Fq 'State: **healthy**' <<<"${output}" -grep -Fq 'Convergence: converged; mutations 0' <<<"${output}" -grep -Fq 'State: **healthy**' "${temporary}/step-summary" -[[ $(wc -l <"${temporary}/gh.log") == 2 ]] - -# Both workflow-run endpoints can exceed the host's entire command argument -# limit when run metadata contains large logs. The monitor must parse those -# responses without placing either JSON document on a child-process argv. -: >"${temporary}/gh.log" -output=$(run_health large-healthy zero) -grep -Fq 'State: **healthy**' <<<"${output}" -grep -Fq 'Last successful run: [2026-08-10T04:50:00Z]' <<<"${output}" - -: >"${temporary}/gh.log" -if run_health large-repeated-failure zero --apply \ - >"${temporary}/large-failure.out" 2>"${temporary}/large-failure.err"; then - echo "error: health check accepted large repeated synchronization failures" >&2 - exit 1 -fi -grep -Fq '2 consecutive synchronization runs failed' \ - "${temporary}/large-failure.out" -grep -Fq 'ALERT created managed Project health incident' \ - "${temporary}/large-failure.out" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health large-invalid-response zero \ - >"${temporary}/large-invalid.out" 2>"${temporary}/large-invalid.err"; then - echo "error: health check accepted a large invalid API response" >&2 - exit 1 -fi -grep -Fq 'GitHub API operation returned invalid JSON' \ - "${temporary}/large-invalid.err" -[[ ! -s ${temporary}/sync.log ]] - -for scenario in runs-malformed runs-empty runs-whitespace runs-null runs-false \ - success-malformed success-empty success-whitespace success-null success-false; do - : >"${temporary}/gh.log" - : >"${temporary}/sync.log" - if run_health "${scenario}" zero \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: health check accepted ${scenario} API response" >&2 - exit 1 - fi - grep -Fq 'GitHub API operation returned invalid JSON' \ - "${temporary}/${scenario}.err" - [[ ! -s ${temporary}/sync.log ]] -done - -for scenario in multi-document-runs runs-object runs-wrong-type \ - multi-document-success success-object success-wrong-type; do - : >"${temporary}/gh.log" - : >"${temporary}/sync.log" - if run_health "${scenario}" zero \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: health check accepted ${scenario} workflow response" >&2 - exit 1 - fi - expected_error='workflow-runs response omitted workflow_runs' - if [[ ${scenario} == *success* ]]; then - expected_error='successful workflow-runs response omitted workflow_runs' - fi - grep -Fq "${expected_error}" "${temporary}/${scenario}.err" - [[ ! -s ${temporary}/sync.log ]] -done - -# Recent successful runs must win over stale or empty filtered history, while -# a newer filtered response must still win if the run completed between reads. -for scenario in filtered-stale filtered-empty filtered-newer unordered-successes; do - : >"${temporary}/gh.log" - output=$(run_health "${scenario}" zero) - grep -Fq 'State: **healthy**' <<<"${output}" - expected_time=2026-08-10T04:50:00Z - [[ ${scenario} == filtered-newer ]] && expected_time=2026-08-10T04:58:00Z - grep -Fq "Last successful run: [${expected_time}]" <<<"${output}" - if grep -Eq '^(POST|PATCH)' "${temporary}/gh.log"; then - echo "error: plan-only health check wrote an incident" >&2 - exit 1 - fi -done - -: >"${temporary}/gh.log" -output=$(run_health filtered-recovery zero --apply) -grep -Fq 'RECOVERED managed Project health incident #70' <<<"${output}" -grep -Fq 'Last successful run: [2026-08-10T04:50:00Z]' <<<"${output}" - -# The combined evidence must still respect both outage and convergence fences. -for scenario in filtered-before-episode filtered-pending; do - : >"${temporary}/gh.log" - sync_scenario=zero - [[ ${scenario} == filtered-pending ]] && sync_scenario=pending - if run_health "${scenario}" "${sync_scenario}" --apply \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: ${scenario} resolved an unproven recovery" >&2 - exit 1 - fi - grep -Fq 'remains open until a newer successful run' "${temporary}/${scenario}.out" - if grep -Fq 'state_reason' "${temporary}/gh.log"; then - echo "error: unproven recovery closed an incident" >&2 - exit 1 - fi -done - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health future-success zero --apply \ - >"${temporary}/future-success.out" 2>"${temporary}/future-success.err"; then - echo "error: health check accepted success newer than its clock" >&2 - exit 1 -fi -grep -Fq 'newer than the health-check clock' "${temporary}/future-success.err" -[[ ! -s ${temporary}/sync.log ]] -if grep -Eq '^(POST|PATCH)' "${temporary}/gh.log"; then - echo "error: invalid success timestamp allowed an incident write" >&2 - exit 1 -fi - -for failure in runs-api-failure:45:plan \ - incident-api-failure:46:apply alert-api-failure:47:apply; do - scenario=${failure%%:*} - remainder=${failure#*:} - expected_status=${remainder%%:*} - mode=${remainder#*:} - arguments=() - [[ ${mode} == apply ]] && arguments=(--apply) - : >"${temporary}/gh.log" - : >"${temporary}/sync.log" - set +e - run_health "${scenario}" pending "${arguments[@]}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err" - status=$? - set -e - if ((status != expected_status)); then - echo "error: ${scenario} exited ${status}, expected ${expected_status}" >&2 - exit 1 - fi - grep -Fq 'GitHub API operation failed' "${temporary}/${scenario}.err" -done -grep -Fq 'read sync-project.yml workflow runs' \ - "${temporary}/runs-api-failure.err" -grep -Fq 'list Project health incidents (page 1)' \ - "${temporary}/incident-api-failure.err" -grep -Fq 'create Project health incident' \ - "${temporary}/alert-api-failure.err" - -for scenario in alert-malformed-response alert-empty-response \ - alert-null-response alert-false-response; do - : >"${temporary}/gh.log" - if run_health "${scenario}" zero --apply \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: health check accepted ${scenario} from incident creation" >&2 - exit 1 - fi - grep -Fq 'GitHub API operation returned invalid JSON: create Project health incident' \ - "${temporary}/${scenario}.err" -done - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health repeated-failure zero --apply \ - >"${temporary}/failure.out" 2>"${temporary}/failure.err"; then - echo "error: health check accepted repeated synchronization failures" >&2 - exit 1 -fi -grep -Fq '2 consecutive synchronization runs failed' \ - "${temporary}/failure.out" -grep -Fq 'ALERT created managed Project health incident' \ - "${temporary}/failure.out" -grep -Fq $'POST\trepos/atrinik/github-settings/issues\t' \ - "${temporary}/gh.log" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health stale pending --apply \ - >"${temporary}/stale.out" 2>"${temporary}/stale.err"; then - echo "error: health check accepted stale synchronization" >&2 - exit 1 -fi -grep -Fq 'The last successful synchronization is 180 minutes old' \ - "${temporary}/stale.out" -grep -Fq 'ALERT updated managed Project health incident #70' \ - "${temporary}/stale.out" -grep -Fq $'PATCH\trepos/atrinik/github-settings/issues/70\t' \ - "${temporary}/gh.log" -! grep -Fq $'POST\trepos/atrinik/github-settings/issues\t' \ - "${temporary}/gh.log" || { - echo "error: stale check created a duplicate incident" >&2 - exit 1 -} - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" FAKE_GH_SCENARIO=missing-settings \ - FAKE_GH_BODY="${temporary}/gh-body" \ - FAKE_SYNC_LOG="${temporary}/sync.log" FAKE_SYNC_SCENARIO=zero \ - GITHUB_ACTIONS=true GITHUB_REPOSITORY=atrinik/github-settings \ - GH_TOKEN=health-token ATRINIK_SETTINGS_TOKEN='' \ - ATRINIK_PROJECT_HEALTH_NOW=2026-08-10T05:00:00Z \ - ATRINIK_PROJECT_HEALTH_SYNC_COMMAND="${temporary}/bin/sync-plan" \ - ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${root}/bin/check-project-health" --apply \ - >"${temporary}/missing.out" 2>"${temporary}/missing.err"; then - echo "error: health check accepted a missing settings credential" >&2 - exit 1 -fi -grep -Fq 'ATRINIK_SETTINGS_TOKEN is unavailable to the health workflow' \ - "${temporary}/missing.out" -grep -Fq 'ALERT created managed Project health incident' \ - "${temporary}/missing.out" -[[ ! -s ${temporary}/sync.log ]] - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -output=$(run_health recovery zero --apply) -grep -Fq 'State: **healthy**' <<<"${output}" -grep -Fq 'RECOVERED managed Project health incident #70' <<<"${output}" -grep -Fq $'PATCH\trepos/atrinik/github-settings/issues/70\tbody state state_reason' \ - "${temporary}/gh.log" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health recurrence-before zero --apply \ - >"${temporary}/recurrence-before.out" \ - 2>"${temporary}/recurrence-before.err"; then - echo "error: health check resolved an incident with a pre-episode success" >&2 - exit 1 -fi -grep -Fq 'remains open until a newer successful run' \ - "${temporary}/recurrence-before.out" -grep -Fq 'ALERT updated managed Project health incident #70' \ - "${temporary}/recurrence-before.out" -if grep -Fq 'RECOVERED' "${temporary}/recurrence-before.out"; then - echo "error: pre-episode success produced a recovery message" >&2 - exit 1 -fi - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -output=$(run_health recurrence-after zero --apply) -grep -Fq 'RECOVERED managed Project health incident #70' <<<"${output}" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health foreign pending --apply \ - >"${temporary}/foreign.out" 2>"${temporary}/foreign.err"; then - echo "error: health check accepted stale synchronization" >&2 - exit 1 -fi -grep -Fq 'ALERT created managed Project health incident' \ - "${temporary}/foreign.out" -grep -Fq $'POST\trepos/atrinik/github-settings/issues\t' \ - "${temporary}/gh.log" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health multiple-managed pending --apply \ - >"${temporary}/multiple.out" 2>"${temporary}/multiple.err"; then - echo "error: health check accepted multiple genuine managed incidents" >&2 - exit 1 -fi -grep -Fq 'multiple managed Project health incidents exist' \ - "${temporary}/multiple.err" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -: >"${temporary}/gh-body" -if PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" FAKE_GH_SCENARIO=reopen \ - FAKE_GH_BODY="${temporary}/gh-body" \ - FAKE_SYNC_LOG="${temporary}/sync.log" FAKE_SYNC_SCENARIO=zero \ - GITHUB_ACTIONS=true GITHUB_REPOSITORY=atrinik/github-settings \ - GH_TOKEN=health-token ATRINIK_SETTINGS_TOKEN='' \ - ATRINIK_PROJECT_HEALTH_NOW=2026-08-10T05:00:00Z \ - ATRINIK_PROJECT_HEALTH_SYNC_COMMAND="${temporary}/bin/sync-plan" \ - ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${root}/bin/check-project-health" --apply \ - >"${temporary}/reopen.out" 2>"${temporary}/reopen.err"; then - echo "error: health check accepted a missing credential during recurrence" >&2 - exit 1 -fi -grep -Fq '' \ - "${temporary}/gh-body" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health sync-failure failure --apply \ - >"${temporary}/sync-failure.out" 2>"${temporary}/sync-failure.err"; then - echo "error: health check accepted a failed convergence preflight" >&2 - exit 1 -fi -grep -Fq 'could not produce a read-only Project convergence plan' \ - "${temporary}/sync-failure.out" -grep -Fq 'sync preflight: error: Project authorization denied' \ - "${temporary}/sync-failure.err" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health no-success zero \ - >"${temporary}/no-success.out" 2>"${temporary}/no-success.err"; then - echo "error: health check accepted missing successful run history" >&2 - exit 1 -fi -grep -Fq 'No successful sync-project.yml run exists' \ - "${temporary}/no-success.out" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health never-ran zero \ - >"${temporary}/never-ran.out" 2>"${temporary}/never-ran.err"; then - echo "error: health check accepted a workflow that never ran" >&2 - exit 1 -fi -grep -Fq 'No successful sync-project.yml run exists' \ - "${temporary}/never-ran.out" - -: >"${temporary}/gh.log" -: >"${temporary}/sync.log" -if run_health old-success zero \ - >"${temporary}/old-success.out" 2>"${temporary}/old-success.err"; then - echo "error: health check accepted more than 100 failures" >&2 - exit 1 -fi -grep -Fq '2026-08-07T01:00:00Z' "${temporary}/old-success.out" -grep -Fq 'actions/runs/1' "${temporary}/old-success.out" - -if grep -En 'health-token|settings-token' "${temporary}"/*.out \ - "${temporary}"/*.err "${temporary}/step-summary" >/dev/null; then - echo "error: health output exposed credential material" >&2 - exit 1 -fi - -echo "Project health checks cover freshness, failures, missing credentials, deduplication, and recovery." diff --git a/tests/fixtures/crate-publication.yml b/tests/fixtures/crate-publication.yml deleted file mode 100644 index ef3352d..0000000 --- a/tests/fixtures/crate-publication.yml +++ /dev/null @@ -1,57 +0,0 @@ -on: - workflow_dispatch: - inputs: - operation: - type: choice - options: [automatic] -permissions: - contents: read -jobs: - automatic-verify: - if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'automatic' - runs-on: ubuntu-24.04 - permissions: - contents: read - actions: read - checks: read - attestations: read - env: - GH_READ_TOKEN: ${{ github.token }} - SOURCE_RELEASE_ID: ${{ inputs.source_release_id }} - SOURCE_REVISION: ${{ inputs.source_revision }} - MANIFEST_SHA256: ${{ inputs.manifest_sha256 }} - steps: - - uses: actions/checkout@1111111111111111111111111111111111111111 - with: - ref: ${{ github.sha }} - persist-credentials: false - - run: python3 tools/crate_release.py verify --release-id "$SOURCE_RELEASE_ID" --revision "$SOURCE_REVISION" --manifest-sha256 "$MANIFEST_SHA256" - automatic-publish: - needs: automatic-verify - if: github.repository == 'atrinik/protocol' && github.repository_id == '1327106950' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.operation == 'automatic' - environment: crates-io-release - runs-on: ubuntu-24.04 - permissions: - contents: write - actions: read - checks: read - attestations: read - id-token: write - env: - GH_READ_TOKEN: ${{ github.token }} - SOURCE_RELEASE_ID: ${{ inputs.source_release_id }} - SOURCE_REVISION: ${{ inputs.source_revision }} - MANIFEST_SHA256: ${{ inputs.manifest_sha256 }} - steps: - - uses: actions/checkout@1111111111111111111111111111111111111111 - with: - ref: ${{ github.sha }} - persist-credentials: false - - run: python3 tools/crate_release.py verify --release-id "$SOURCE_RELEASE_ID" --revision "$SOURCE_REVISION" --manifest-sha256 "$MANIFEST_SHA256" - - id: auth - uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 - - id: upload - env: - CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} - GH_INTENT_TOKEN: ${{ github.token }} - run: python3 tools/crate_release.py upload --release-id "$SOURCE_RELEASE_ID" --revision "$SOURCE_REVISION" --manifest-sha256 "$MANIFEST_SHA256" diff --git a/tests/fixtures/crate-source-release.yml b/tests/fixtures/crate-source-release.yml deleted file mode 100644 index 36e6553..0000000 --- a/tests/fixtures/crate-source-release.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Semantic Release -'on': - workflow_dispatch: null - push: - branches: - - main - - '[0-9]+.[0-9]+.x' -permissions: - contents: read -concurrency: - group: protocol-semantic-release - cancel-in-progress: 'false' -jobs: - package: - runs-on: ubuntu-24.04 - outputs: - version: ${{ steps.plan.outputs.version }} - revision: ${{ steps.plan.outputs.revision }} - steps: - - run: cargo build --locked - attest: - name: Attest verified source release manifest - needs: package - if: needs.package.outputs.version != '' - runs-on: ubuntu-24.04 - timeout-minutes: 10 - permissions: - contents: read - id-token: write - attestations: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - ref: ${{ needs.package.outputs.revision }} - persist-credentials: 'false' - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c - with: - name: source-release-${{ github.sha }} - path: build/release/ - - name: Verify complete inert payload before attestation - env: - ATRINIK_RELEASE_BRANCH: ${{ github.ref_name }} - EXPECTED_SOURCE_REVISION: ${{ needs.package.outputs.revision }} - EXPECTED_SOURCE_VERSION: ${{ needs.package.outputs.version }} - run: python3 tools/crate_release.py finalize --source-tag "v${EXPECTED_SOURCE_VERSION}" - --archives build/release - - name: Bind manifest bytes to this exact source workflow invocation - uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 - with: - subject-path: build/release/crate-release.json - push-to-registry: 'false' - release: - name: Release protocol contracts - needs: - - package - - attest - if: needs.package.outputs.version != '' - runs-on: ubuntu-24.04 - timeout-minutes: 15 - permissions: - actions: write - contents: write - issues: write - pull-requests: write - steps: - - run: npm run semantic-release diff --git a/tests/publish-community-health.sh b/tests/publish-community-health.sh deleted file mode 100755 index d1bf26c..0000000 --- a/tests/publish-community-health.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -while (($#)); do - case $1 in - -H) - shift 2 - ;; - repos/atrinik/.github) - exit 1 - ;; - *) - echo "unexpected gh argument: $1" >&2 - exit 1 - ;; - esac -done -EOF -chmod +x "${temporary}/bin/gh" - -output=$(PATH="${temporary}/bin:${PATH}" \ - "${root}/bin/publish-community-health") - -[[ $(grep -c '^PLAN POST /orgs/atrinik/repos ' <<<"${output}") == 1 ]] -expected_files=$(jq '.files | length' "${root}/config/community-health.json") -[[ $(grep -c '^PLAN PUT /repos/atrinik/.github/contents/' <<<"${output}") == "${expected_files}" ]] -grep -Fq \ - 'PLAN PUT /repos/atrinik/.github/contents/profile/README.md' \ - <<<"${output}" - -grep -Fq \ - 'PLAN PUT /repos/atrinik/.github/contents/.github/workflows/dependency-review.yml' \ - <<<"${output}" - -# A matching generated workflow must be kept, just like every other mapped file. -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -while (($#)); do - case $1 in - -H) - shift 2 - ;; - repos/atrinik/.github) - jq '.repository' "${COMMUNITY_TEST_ROOT}/config/community-health.json" - exit - ;; - repos/atrinik/.github/contents/*\?ref=main) - target=${1#repos/atrinik/.github/contents/} - target=${target%\?ref=main} - source=$(jq -er --arg target "${target}" \ - '.files[] | select(.target == $target) | .source' \ - "${COMMUNITY_TEST_ROOT}/config/community-health.json") - content=$(base64 -w 0 "${COMMUNITY_TEST_ROOT}/community-health/${source}") - jq -n --arg content "${content}" '{sha: "fixture-sha", content: $content}' - exit - ;; - *) - echo "unexpected gh argument: $1" >&2 - exit 1 - ;; - esac -done -EOF - -output=$(PATH="${temporary}/bin:${PATH}" COMMUNITY_TEST_ROOT="${root}" \ - "${root}/bin/publish-community-health") -[[ $(grep -c '^KEEP /repos/atrinik/.github/contents/' <<<"${output}") == "${expected_files}" ]] -if grep -q '^PLAN ' <<<"${output}"; then - echo "error: publisher planned mutations for matching generated files" >&2 - exit 1 -fi -grep -Fxq \ - 'KEEP /repos/atrinik/.github/contents/.github/workflows/dependency-review.yml' \ - <<<"${output}" - -echo "Community-health publisher plans every default file and keeps matching content." diff --git a/tests/publish-maintenance-branch.sh b/tests/publish-maintenance-branch.sh deleted file mode 100755 index addeaf3..0000000 --- a/tests/publish-maintenance-branch.sh +++ /dev/null @@ -1,1868 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# This harness supplies a fake `gh` on PATH for every publisher invocation. -# Keep its CI credential synthetic even when the surrounding test runner -# deliberately clears GH_TOKEN to exercise other scripts' production gate. -export GH_TOKEN=test-token - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -source_root=${root} -# Retain the original Classic rollout/recovery scenarios as a bounded fixture. -root=${temporary}/classic-policy -mkdir -p "${root}/bin" -cp "${source_root}/bin/publish" "${source_root}/bin/validate" \ - "${source_root}/bin/security-readiness" "${root}/bin/" -cp -R "${source_root}/lib" "${root}/lib" -cp -R "${source_root}/config" "${source_root}/community-health" "${source_root}/.github" "${root}/" -jq '.repositories |= map(select(.name == "classic"))' \ - "${source_root}/config/immutable-releases.json" >"${root}/config/immutable-releases.json" -mkdir "${temporary}/bin" -export GH_SELECTED_ACTIONS_POLICY=${root}/config/actions-selected.json - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -if [[ ${1:-} != api ]]; then - echo "unexpected gh command" >&2 - exit 1 -fi -shift - -method=GET -endpoint= -input= -jq_filter= -while (($#)); do - case $1 in - -H | --header) - shift 2 - ;; - --method) - method=$2 - shift 2 - ;; - --input) - input=$2 - shift 2 - ;; - --jq) - jq_filter=$2 - shift 2 - ;; - --paginate) - shift - ;; - *) - if [[ -n ${endpoint} ]]; then - echo "unexpected gh api argument: $1" >&2 - exit 1 - fi - endpoint=$1 - shift - ;; - esac -done - -payload=null -if [[ -n ${input} ]]; then - payload=$(jq -c . "${input}") -fi -jq -cn \ - --arg method "${method}" \ - --arg endpoint "${endpoint}" \ - --argjson payload "${payload}" \ - '{method: $method, endpoint: $endpoint, payload: $payload}' \ - >>"${GH_API_LOG}" - -security_scenario=${GH_SECURITY_SCENARIO:-converged} - -crate_repository_id() { - case $1 in - protocol) printf '%s\n' 1327106950 ;; - content-toolkit) printf '%s\n' 1327107043 ;; - *) return 1 ;; - esac -} - -crate_workflow_content() { - local repository=$1 - local workflow=$2 - local fixture=${GH_CRATE_FIXTURE_ROOT:?}/tests/fixtures - local identifier - - identifier=$(crate_repository_id "${repository}") - if [[ ${GH_CRATE_SETUP_SCENARIO:-qualified} == malformed-workflow ]] && - [[ ${workflow} == publish-crate.yml ]]; then - printf 'not: [a reviewed workflow\n' - return - fi - if [[ ${workflow} == publish-crate.yml ]]; then - sed -e "s|atrinik/protocol|atrinik/${repository}|g" \ - -e "s/1327106950/${identifier}/g" "${fixture}/crate-publication.yml" - else - cat "${fixture}/crate-source-release.yml" - fi -} - -crate_environment() { - local bypass=false - if [[ ${GH_CRATE_SETUP_SCENARIO:-qualified} == environment-drift ]]; then - bypass=true - fi - jq -cn --argjson bypass "${bypass}" '{ - name: "crates-io-release", - deployment_branch_policy: {protected_branches: false, custom_branch_policies: true}, - protection_rules: [{type: "branch_policy"}], - can_admins_bypass: $bypass - }' -} - -immutable_release_snapshot() { - if [[ ${GH_CRATE_SNAPSHOT_DRIFT:-false} == true ]] && - (( $(jq -s '[.[] | select(.method == "GET" and .endpoint == "orgs/atrinik/settings/immutable-releases")] | length' "${GH_API_LOG}") >= 2 )); then - printf '{"enforced_repositories":"none"}\n' - else - jq '{enforced_repositories}' "${GH_IMMUTABLE_STATE}" - fi -} - -if [[ ${method} == PUT ]] && - [[ ${endpoint} == orgs/atrinik/settings/immutable-releases ]]; then - jq -c . "${input}" >"${GH_IMMUTABLE_STATE}" - printf '{}\n' - exit 0 -fi - -attachment_was_requested() { - local configuration_id=$1 - local repository_id=$2 - - jq -s -e \ - --arg endpoint \ - "orgs/atrinik/code-security/configurations/${configuration_id}/attach" \ - --argjson repository_id "${repository_id}" ' - any( - .[]; - .method == "POST" and - .endpoint == $endpoint and - (.payload.selected_repository_ids | index($repository_id)) != null - ) - ' "${GH_API_LOG}" >/dev/null -} - -print_attachment_progress() { - local configuration_id=$1 - local repository_id=$2 - local repository=$3 - local checks - - checks=$(jq -s \ - --arg attach_endpoint \ - "orgs/atrinik/code-security/configurations/${configuration_id}/attach" \ - --arg repository_endpoint \ - "repos/atrinik/${repository}/code-security-configuration" \ - --argjson repository_id "${repository_id}" ' - . as $events | - ( - [ - $events | to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $attach_endpoint and - ( - .value.payload.selected_repository_ids | - index($repository_id) - ) != null - ) | - .key - ] | last - ) as $attach | - [ - $events | to_entries[] | - select( - .key > $attach and - .value.method == "GET" and - .value.endpoint == $repository_endpoint - ) - ] | length - ' "${GH_API_LOG}") - - if ((checks == 1)); then - printf '{"status":"attached","configuration":{"id":%s}}\n' \ - "${configuration_id}" - else - printf '{"status":"enforced","configuration":{"id":%s}}\n' \ - "${configuration_id}" - fi -} - -print_existing_attachment_progress() { - local configuration_id=$1 - local repository=$2 - local checks - - checks=$(jq -s \ - --arg endpoint \ - "repos/atrinik/${repository}/code-security-configuration" ' - [ - .[] | - select(.method == "GET" and .endpoint == $endpoint) - ] | length - ' "${GH_API_LOG}") - - if ((checks == 1)); then - printf '{"status":"attached","configuration":{"id":%s}}\n' \ - "${configuration_id}" - else - printf '{"status":"enforced","configuration":{"id":%s}}\n' \ - "${configuration_id}" - fi -} - -print_security_configuration() { - local id=$1 - local advanced=$2 - local name description allow_advanced push_protection - - name="Atrinik security baseline" - description="Required security features for all Atrinik repositories." - allow_advanced=false - if [[ ${advanced} == true ]]; then - name="Atrinik advanced CodeQL baseline" - description="Atrinik security baseline for repositories with governed CodeQL advanced setup." - allow_advanced=true - fi - - push_protection=enabled - if [[ ${security_scenario} == drifted ]]; then - push_protection=disabled - fi - - jq -cn \ - --argjson id "${id}" \ - --arg name "${name}" \ - --arg description "${description}" \ - --argjson allow_advanced "${allow_advanced}" \ - --arg push_protection "${push_protection}" ' - { - id: $id, - name: $name, - description: $description, - advanced_security: "enabled", - dependency_graph: "enabled", - dependabot_alerts: "enabled", - dependabot_security_updates: "enabled", - code_scanning_default_setup: "enabled", - code_scanning_options: {allow_advanced: $allow_advanced}, - secret_scanning: "enabled", - secret_scanning_push_protection: $push_protection, - secret_scanning_validity_checks: "enabled", - private_vulnerability_reporting: "enabled", - enforcement: "enforced" - } - ' -} - -if [[ ${method} != GET ]]; then - if [[ ${security_scenario} == converged ]] && - [[ ${method} == POST ]] && - [[ ${endpoint} == orgs/atrinik/code-security/configurations/*/attach ]]; then - : >"${GH_ENABLEMENT_EVENT_FILE:?}" - fi - if [[ ${security_scenario} == converged ]] && - [[ ${method} == PATCH ]] && - [[ ${endpoint} == orgs/atrinik/code-security/configurations/* ]] && - [[ -f ${GH_ENABLEMENT_EVENT_FILE:-} ]]; then - echo "Another enablement event is in progress" >&2 - exit 1 - fi - if [[ ${method} == POST ]] && - [[ ${endpoint} == orgs/atrinik/code-security/configurations ]]; then - printf '{"id":265377}\n' - else - printf '{}\n' - fi - exit 0 -fi - -case "${endpoint}|${jq_filter}" in -repos/atrinik/*/actions/permissions/workflow\|* | orgs/atrinik/actions/permissions/workflow\|*) - printf '{"default_workflow_permissions":"read","can_approve_pull_request_reviews":false}\n' - ;; -"orgs/atrinik/actions/permissions/selected-actions|") - cat "${GH_SELECTED_ACTIONS_POLICY}" - ;; -"orgs/atrinik/actions/permissions|") - printf '{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":false}\n' - ;; -"orgs/atrinik|") - if [[ ${GH_ORGANIZATION_SCENARIO:-converged} == drifted ]]; then - jq -n '{ - plan: {name: "team"}, - description: "", - blog: "https://atrinik.org", - default_repository_permission: "none", - members_can_create_repositories: false, - members_can_create_public_repositories: false, - members_can_create_private_repositories: false, - members_can_create_teams: false - }' - else - jq -n '{ - plan: {name: "team"}, - description: "A cooperative, open-source fantasy world founded by Zoey Seraphina Rose (https://zoeysr.com). Playable in Classic and rebuilding for the future.", - blog: "https://atrinik.org", - default_repository_permission: "none", - members_can_create_repositories: false, - members_can_create_public_repositories: false, - members_can_create_private_repositories: false, - members_can_create_teams: false - }' - fi - ;; -"orgs/atrinik/repos?per_page=100&type=all|"*) - printf 'classic\t%s\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' \ - "${GH_CLASSIC_REPOSITORY_ID:-1327289971}" - printf 'content\t101\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' - if [[ ${GH_CRATE_IMMUTABLE_INVENTORY:-false} == true ]]; then - printf 'metaserver-worker\t1324297032\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' - printf 'protocol\t%s\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' "${GH_PROTOCOL_REPOSITORY_ID:-1327106950}" - printf 'content-toolkit\t1327107043\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' - fi - printf 'classic-ghsa-8533-3vg8-r287\t999\ttrue\tprivate\tfalse\tfalse\tfalse\tfalse\tfalse\n' - ;; -"orgs/atrinik/settings/immutable-releases|"*) - immutable_release_snapshot - ;; -"orgs/atrinik/settings/immutable-releases/repositories?per_page=100|"*) - jq ' - { - total_count: (.selected_repository_ids | length), - repositories: [.selected_repository_ids[]? | {id: .}] - } - ' "${GH_IMMUTABLE_STATE}" | jq -r "${jq_filter}" - ;; -"repos/atrinik/metaserver-worker/immutable-releases|"* | "repos/atrinik/protocol/immutable-releases|"* | "repos/atrinik/content-toolkit/immutable-releases|"*) - case ${endpoint} in - */metaserver-worker/*) repository_id=1324297032 ;; - */protocol/*) repository_id=1327106950 ;; - */content-toolkit/*) repository_id=1327107043 ;; - esac - if [[ ${GH_CRATE_IMMUTABLE_VERIFY_FAILURE:-false} == true && ${repository_id} == 1327107043 ]]; then - printf '{"enabled":false,"enforced_by_owner":false}\n' - elif jq -e --argjson id "${repository_id}" '.enforced_repositories == "selected" and (.selected_repository_ids | index($id)) != null' "${GH_IMMUTABLE_STATE}" >/dev/null; then - printf '{"enabled":true,"enforced_by_owner":true}\n' - else - printf '{"enabled":false,"enforced_by_owner":false}\n' - fi - ;; -"repos/atrinik/metaserver-worker/code-security-configuration|"* | "repos/atrinik/protocol/code-security-configuration|"* | "repos/atrinik/content-toolkit/code-security-configuration|"*) - printf '{"status":"enforced","configuration":{"id":265376}}\n' - ;; -"repos/atrinik/metaserver-worker/code-scanning/default-setup|"*) - printf '{"state":"configured","query_suite":"default","languages":["javascript-typescript","python","actions"]}\n' - ;; -"repos/atrinik/protocol/code-scanning/default-setup|"* | "repos/atrinik/content-toolkit/code-scanning/default-setup|"*) - printf '{"state":"configured","query_suite":"default","languages":["rust"]}\n' - ;; -"repos/atrinik/classic/immutable-releases|"*) - if [[ ${GH_IMMUTABLE_VERIFY_FAILURE:-false} == true ]]; then - printf '{"enabled":false,"enforced_by_owner":false}\n' - elif jq -e ' - .enforced_repositories == "all" or - ( - .enforced_repositories == "selected" and - (.selected_repository_ids | index(1327289971)) != null - ) - ' "${GH_IMMUTABLE_STATE}" >/dev/null; then - printf '{"enabled":true,"enforced_by_owner":true}\n' - else - printf '{"enabled":false,"enforced_by_owner":false}\n' - fi - ;; -repos/atrinik/protocol\| | repos/atrinik/content-toolkit\|) - repository=${endpoint#repos/atrinik/} - jq -cn --arg repository "${repository}" --argjson id "$(crate_repository_id "${repository}")" \ - '{id: $id, full_name: ("atrinik/" + $repository), archived: false, default_branch: "main"}' - ;; -repos/atrinik/protocol/branches/main\| | repos/atrinik/content-toolkit/branches/main\|) - printf '{"name":"main","protected":true,"commit":{"sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}\n' - ;; -repos/atrinik/metaserver-worker/git/ref/heads/main\|) - if [[ ${GH_METASERVER_SOURCE_SCENARIO:-valid} == late-main-drift ]] && - jq -se 'any(.[]; .endpoint == "repos/atrinik/protocol/git/ref/heads/main")' "${GH_API_LOG}" >/dev/null; then - printf '%s\n' '{"ref":"refs/heads/main","object":{"type":"commit","sha":"2222222222222222222222222222222222222222"}}' - exit 0 - fi - printf '%s\n' '{"ref":"refs/heads/main","object":{"type":"commit","sha":"1111111111111111111111111111111111111111"}}' - ;; -repos/atrinik/metaserver-worker/contents/.releaserc.json*\|) - if [[ ${GH_METASERVER_SOURCE_SCENARIO:-valid} == partial-producer ]]; then - source='{"plugins":[["@semantic-release/github",{"draftRelease":false}]]}' - else - source='{"plugins":[["@semantic-release/github",{"draftRelease":true}],"./scripts/release/publish-complete-release.cjs"]}' - fi - encoded=$(printf '%s' "${source}" | base64 -w 0) - jq -n --arg content "${encoded}" '{type:"file",encoding:"base64",content:$content}' - ;; -repos/atrinik/metaserver-worker/contents/scripts/release/publish-complete-release.*\|) - jq -n '{type:"file",encoding:"base64",size:1,content:"eA=="}' - ;; -repos/atrinik/metaserver-worker/actions/workflows/check.yml/runs*\|) - conclusion=success - if [[ ${GH_METASERVER_SOURCE_SCENARIO:-valid} == failed-source-check ]]; then conclusion=failure; fi - jq -n --arg conclusion "${conclusion}" '{workflow_runs:[{ - head_sha:"1111111111111111111111111111111111111111",head_branch:"main",event:"push", - head_repository:{full_name:"atrinik/metaserver-worker"},status:"completed",conclusion:$conclusion - }]}' - ;; -repos/atrinik/protocol/git/ref/heads/main\| | repos/atrinik/content-toolkit/git/ref/heads/main\|) - printf '{"ref":"refs/heads/main","object":{"type":"commit","sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}\n' - ;; -repos/atrinik/*/contents/.github/workflows/publish-crate.yml*\|) - repository=${endpoint#repos/atrinik/} - repository=${repository%%/*} - crate_workflow_content "${repository}" publish-crate.yml | base64 | tr -d '\n' | \ - jq -R '{type: "file", encoding: "base64", content: .}' - ;; -repos/atrinik/*/contents/.github/workflows/release.yml*\|) - repository=${endpoint#repos/atrinik/} - repository=${repository%%/*} - crate_workflow_content "${repository}" release.yml | base64 | tr -d '\n' | \ - jq -R '{type: "file", encoding: "base64", content: .}' - ;; -repos/atrinik/*/environments/crates-io-release\|) - crate_environment - ;; -repos/atrinik/*/environments/crates-io-release/deployment-branch-policies\?per_page=100\&page=1\|) - printf '{"total_count":1,"branch_policies":[{"name":"main","type":"branch"}]}\n' - ;; -repos/atrinik/*/environments/crates-io-release/secrets\?per_page=100\&page=1\|) - printf '{"total_count":0,"secrets":[]}\n' - ;; -repos/atrinik/*/environments/crates-io-release/variables\?per_page=100\&page=1\|) - printf '{"total_count":0,"variables":[]}\n' - ;; -"orgs/atrinik/rulesets|"*) - if [[ ${GH_ADVISORY_RULESETS_PRESENT:-false} == true ]]; then - printf '%s\n' '[{"id":900,"name":"05 - Maintenance branch - content - retired"},{"id":901,"name":"01 - Default branch linear history - classic"},{"id":902,"name":"02 - Changes through pull requests - classic"},{"id":903,"name":"01 - Default branch integrity - classic"}]' - else - printf '[{"id":900,"name":"05 - Maintenance branch - content - retired"}]\n' - fi - ;; -"orgs/atrinik/code-security/configurations|"*) - if [[ ${GH_ADVANCED_CONFIG_MISSING:-false} == true ]]; then - printf '[{"id":265376,"name":"Atrinik security baseline"}]\n' - else - printf '[{"id":265376,"name":"Atrinik security baseline"},{"id":265377,"name":"Atrinik advanced CodeQL baseline"}]\n' - fi - ;; -"orgs/atrinik/code-security/configurations/265376|"*) - print_security_configuration 265376 false - ;; -"orgs/atrinik/code-security/configurations/265377|"*) - print_security_configuration 265377 true - ;; -"orgs/atrinik/code-security/configurations/defaults|"*) - if [[ ${security_scenario} == drifted ]]; then - printf '[]\n' - else - printf '[{"default_for_new_repos":"all","configuration":{"id":265376}}]\n' - fi - ;; -"repos/atrinik/classic/code-security-configuration|"*) - if [[ ${GH_EMPTY_ADVANCED_INVENTORY:-false} == true ]]; then - if attachment_was_requested 265376 1327289971; then - print_attachment_progress 265376 1327289971 classic - else - printf '{"status":"enforced","configuration":{"id":265377}}\n' - fi - elif [[ ${security_scenario} == drifted || - ${security_scenario} == create ]]; then - if attachment_was_requested 265377 1327289971; then - print_attachment_progress 265377 1327289971 classic - else - printf '{"status":"enforced","configuration":{"id":265376}}\n' - fi - elif [[ ${security_scenario} == pending ]]; then - print_existing_attachment_progress 265377 classic - else - printf '{"status":"enforced","configuration":{"id":265377}}\n' - fi - ;; -"repos/atrinik/content/code-security-configuration|"*) - if [[ ${security_scenario} == drifted ]]; then - if attachment_was_requested 265376 101; then - print_attachment_progress 265376 101 content - else - printf '{"status":"enforced","configuration":{"id":265377}}\n' - fi - else - printf '{"status":"enforced","configuration":{"id":265376}}\n' - fi - ;; -"repos/atrinik/classic/code-scanning/default-setup|"*) - if [[ ${security_scenario} == drifted || - ${security_scenario} == create || - ${GH_EMPTY_ADVANCED_INVENTORY:-false} == true ]]; then - printf '{"state":"configured","query_suite":"default","languages":["c-cpp"]}\n' - else - printf '{"state":"not-configured","query_suite":"default","languages":null}\n' - fi - ;; -"repos/atrinik/content/code-scanning/default-setup|"*) - if [[ ${security_scenario} == drifted || - ${security_scenario} == create ]]; then - printf '{"state":"not-configured","languages":null}\n' - else - printf '{"state":"configured","query_suite":"default","languages":["python"]}\n' - fi - ;; -"repos/atrinik/nawerhals|.archived") - printf 'true\n' - ;; -"repos/atrinik/legacy-client|.archived" | \ -"repos/atrinik/legacy-editor|.archived" | \ -"repos/atrinik/legacy-libatrinik|.archived" | \ -"repos/atrinik/legacy-protocol|.archived" | \ -"repos/atrinik/legacy-server|.archived") - printf 'false\n' - ;; -repos/atrinik/*/rulesets\?includes_parents=false\|*) - if [[ ${GH_ADVISORY_RULESETS_PRESENT:-false} == true ]]; then - printf '%s\n' '[{"id":900,"name":"05 - Maintenance branch - content - retired"},{"id":901,"name":"01 - Default branch linear history - classic"},{"id":902,"name":"02 - Changes through pull requests - classic"},{"id":903,"name":"01 - Default branch integrity - classic"}]' - elif [[ ${GH_SHARED_RULESETS_PRESENT:-false} == true && - ${endpoint} == repos/atrinik/classic/* ]]; then - printf '%s\n' '[{"id":904,"name":"01 - Default branch integrity"},{"id":905,"name":"01 - Default branch linear history"},{"id":906,"name":"02 - Changes through pull requests"}]' - else - printf '[{"id":900,"name":"05 - Maintenance branch - content - retired"}]\n' - fi - ;; -repos/atrinik/*\|) - # Default-settings reads added by the delta-aware publisher. Other metadata - # endpoints with identity-specific contracts are handled above. - printf '{"default_branch":"main","allow_merge_commit":false,"allow_rebase_merge":false,"allow_squash_merge":true,"delete_branch_on_merge":true,"squash_merge_commit_title":"PR_TITLE","squash_merge_commit_message":"PR_BODY"}\n' - ;; -*) - printf '[]\n' - ;; -esac -EOF -chmod +x "${temporary}/bin/gh" - -cat >"${temporary}/bin/sleep" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -if (($# != 1)) || [[ $1 != 2 ]]; then - echo "unexpected security publisher sleep: $*" >&2 - exit 1 -fi -EOF -chmod +x "${temporary}/bin/sleep" - -assert_maintenance_payload() { - local log=$1 - local endpoint=$2 - local organization_scope=$3 - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --argjson organization_scope "${organization_scope}" ' - [ - .[] | - select( - .method == "POST" and - .endpoint == $endpoint and - .payload.name == "05 - Maintenance branch - content - 1.x" - ) - ] as $matches | - ($matches | length) == 1 and - ($matches[0].payload.target == "branch") and - ($matches[0].payload.enforcement == "active") and - ($matches[0].payload.conditions.ref_name.include == ["refs/heads/1.x"]) and - ( - ($matches[0].payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($organization_scope | not) or - ($matches[0].payload.conditions.repository_name.include == ["content"]) - ) and - ( - [$matches[0].payload.rules[].type] == [ - "deletion", - "non_fast_forward", - "required_linear_history", - "pull_request", - "required_status_checks" - ] - ) and - ( - [ - $matches[0].payload.rules[] | - select(.type == "required_status_checks") | - .parameters.required_status_checks[] - ] == [ - {context: "Content validation", integration_id: 15368}, - {context: "Conventional PR title", integration_id: 15368} - ] - ) - ' "${log}" >/dev/null -} - -assert_default_branch_policy_payloads() { - local log=$1 - local endpoint=$2 - local organization_scope=$3 - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --argjson organization_scope "${organization_scope}" ' - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "01 - Default branch linear history" - ) - ] as $linear | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "01 - Default branch integrity" - ) - ] as $integrity | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "02 - Changes through pull requests" - ) - ] as $pull_request | - ($linear | length) == 1 and - ($integrity | length) == 1 and - ($pull_request | length) == 1 and - $linear[0].key < $integrity[0].key and - ($linear[0].value.payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }]) and - ($linear[0].value.payload.rules == [{ - type: "required_linear_history" - }]) and - ($integrity[0].value.payload.bypass_actors == []) and - ([$integrity[0].value.payload.rules[].type] == [ - "deletion", - "non_fast_forward" - ]) and - ($pull_request[0].value.payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }]) and - ([$pull_request[0].value.payload.rules[].type] == ["pull_request"]) and - ( - ($linear[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($integrity[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($pull_request[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($organization_scope | not) or - ( - $linear[0].value.payload.conditions.repository_name.include == - ["~ALL"] and - $linear[0].value.payload.conditions.repository_name.exclude == - ["classic"] and - $integrity[0].value.payload.conditions.repository_name.include == - ["~ALL"] and - $integrity[0].value.payload.conditions.repository_name.exclude == - ["classic"] and - ( - $pull_request[0].value.payload.conditions.repository_name.include | - index("classic") - ) == null - ) - ) - ' "${log}" >/dev/null -} - -assert_classic_advisory_bypass_payloads() { - local log=$1 - local endpoint=$2 - local organization_scope=$3 - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --argjson organization_scope "${organization_scope}" ' - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == - "01 - Default branch linear history - classic" - ) - ] as $linear | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == - "02 - Changes through pull requests - classic" - ) - ] as $pull_request | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == - "01 - Default branch integrity - classic" - ) - ] as $integrity | - ($linear | length) == 1 and - ($pull_request | length) == 1 and - ($integrity | length) == 1 and - ($integrity[0].value.payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }]) and - ([$integrity[0].value.payload.rules[].type] == [ - "deletion", - "non_fast_forward" - ]) and - ($linear[0].value.payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }]) and - ($linear[0].value.payload.rules == [{ - type: "required_linear_history" - }]) and - ($pull_request[0].value.payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }]) and - ([$pull_request[0].value.payload.rules[].type] == ["pull_request"]) and - ( - ($integrity[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($linear[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - ($pull_request[0].value.payload.conditions | has("repository_name")) == - $organization_scope - ) and - ( - if $organization_scope then - $integrity[0].value.payload.conditions.repository_name.include == - ["classic"] and - $integrity[0].value.payload.conditions.repository_name.exclude == - [] and - $linear[0].value.payload.conditions.repository_name.include == - ["classic"] and - $linear[0].value.payload.conditions.repository_name.exclude == [] and - $pull_request[0].value.payload.conditions.repository_name.include == - ["classic"] and - $pull_request[0].value.payload.conditions.repository_name.exclude == - [] and - $integrity[0].key < ([ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "01 - Default branch integrity" - ) | - .key - ][0]) and - $linear[0].key < ([ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "01 - Default branch linear history" - ) | - .key - ][0]) and - $pull_request[0].key < ([ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "02 - Changes through pull requests" - ) | - .key - ][0]) - else true end - ) - ' "${log}" >/dev/null -} - -assert_advisory_window_closed() { - local log=$1 - local endpoint=$2 - local delete_prefix=$3 - local organization_scope=$4 - local ci_name="03 - Required CI" - - if [[ ${organization_scope} == true ]]; then - ci_name="03 - Required CI - classic" - fi - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --arg delete_prefix "${delete_prefix}" \ - --arg ci_name "${ci_name}" \ - --argjson organization_scope "${organization_scope}" ' - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "01 - Default branch linear history" - ) - ] as $linear | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == "02 - Changes through pull requests" - ) - ] as $pull_request | - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == $endpoint and - .value.payload.name == $ci_name - ) - ] as $ci | - [ - to_entries[] | - select( - .value.method == "DELETE" and - ( - .value.endpoint == "\($delete_prefix)/901" or - .value.endpoint == "\($delete_prefix)/902" or - .value.endpoint == "\($delete_prefix)/903" - ) - ) - ] as $deletes | - ($linear | length) == 1 and - ($pull_request | length) == 1 and - ($ci | length) == 1 and - ($deletes | length) == 3 and - ($linear[0].value.payload.bypass_actors[0].bypass_mode == - "pull_request") and - ($pull_request[0].value.payload.bypass_actors[0].bypass_mode == - "pull_request") and - ($ci[0].value.payload.bypass_actors[0].bypass_mode == "pull_request") and - ( - if $organization_scope then - $linear[0].value.payload.conditions.repository_name.exclude == [] and - ( - $pull_request[0].value.payload.conditions.repository_name.include | - index("classic") - ) != null - else - ($linear[0].value.payload.conditions | has("repository_name") | not) and - ( - $pull_request[0].value.payload.conditions | - has("repository_name") | - not - ) - end - ) and - all( - $deletes[]; - .key > $linear[0].key and - .key > $pull_request[0].key and - .key > $ci[0].key - ) - ' "${log}" >/dev/null -} - -assert_replacement_required_ci_payload() { - local log=$1 - local endpoint=$2 - local organization_scope=$3 - local repository=$4 - local validation_context=$5 - local ruleset_name="03 - Required CI" - - if [[ ${organization_scope} == true ]]; then - ruleset_name="03 - Required CI - ${repository}" - fi - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --arg ruleset_name "${ruleset_name}" \ - --arg repository "${repository}" \ - --arg validation_context "${validation_context}" \ - --argjson organization_scope "${organization_scope}" ' - [ - .[] | - select( - .method == "POST" and - .endpoint == $endpoint and - .payload.name == $ruleset_name - ) - ] as $matches | - ($matches | length) == 1 and - ( - ($matches[0].payload.conditions | has("repository_name")) == - $organization_scope - ) and - ($matches[0].payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }]) and - ( - ($organization_scope | not) or - ($matches[0].payload.conditions.repository_name.include == [$repository]) - ) and - ( - $matches[0].payload.rules[0].parameters.required_status_checks == [ - {context: $validation_context, integration_id: 15368}, - {context: "Conventional PR title", integration_id: 15368} - ] - ) - ' "${log}" >/dev/null -} - -assert_classic_required_ci_payload() { - local log=$1 - local endpoint=$2 - local organization_scope=$3 - local ruleset_name="03 - Required CI" - - if [[ ${organization_scope} == true ]]; then - ruleset_name="03 - Required CI - classic" - fi - - jq -s -e \ - --arg endpoint "${endpoint}" \ - --arg ruleset_name "${ruleset_name}" \ - --argjson organization_scope "${organization_scope}" ' - [ - .[] | - select( - .method == "POST" and - .endpoint == $endpoint and - .payload.name == $ruleset_name - ) - ] as $matches | - ($matches | length) == 1 and - ( - ($matches[0].payload.conditions | has("repository_name")) == - $organization_scope - ) and - ($matches[0].payload.bypass_actors == [{ - actor_id: 1, - actor_type: "OrganizationAdmin", - bypass_mode: "always" - }]) and - ( - ($organization_scope | not) or - ($matches[0].payload.conditions.repository_name.include == ["classic"]) - ) and - ( - $matches[0].payload.rules[0].parameters.required_status_checks == [ - {context: "Classic validation", integration_id: 15368}, - {context: "CodeQL validation", integration_id: 15368}, - {context: "Conventional PR title", integration_id: 15368} - ] - ) - ' "${log}" >/dev/null -} - -assert_codeql_default_setup() { - local log=$1 - - jq -s -e ' - any( - .[]; - .method == "PATCH" and - .endpoint == "repos/atrinik/classic/code-scanning/default-setup" and - .payload == {state: "not-configured"} - ) and - any( - .[]; - .method == "PATCH" and - .endpoint == "repos/atrinik/content/code-scanning/default-setup" and - .payload == {state: "configured", query_suite: "default"} - ) - ' "${log}" >/dev/null -} - -assert_organization_codeql_configurations() { - local log=$1 - - jq -s -e ' - any( - .[]; - .method == "PATCH" and - .endpoint == - "orgs/atrinik/code-security/configurations/265377" and - .payload.name == "Atrinik advanced CodeQL baseline" and - .payload.code_scanning_default_setup == "enabled" and - .payload.code_scanning_options == {allow_advanced: true} and - .payload.enforcement == "enforced" - ) and - any( - .[]; - .method == "POST" and - .endpoint == - "orgs/atrinik/code-security/configurations/265377/attach" and - .payload == { - scope: "selected", - selected_repository_ids: [1327289971] - } - ) and - any( - .[]; - .method == "PATCH" and - .endpoint == - "orgs/atrinik/code-security/configurations/265376" and - .payload.name == "Atrinik security baseline" and - .payload.code_scanning_default_setup == "enabled" and - .payload.code_scanning_options == {allow_advanced: false} and - .payload.enforcement == "enforced" - ) and - any( - .[]; - .method == "PUT" and - .endpoint == - "orgs/atrinik/code-security/configurations/265376/defaults" and - .payload == {default_for_new_repos: "all"} - ) and - any( - .[]; - .method == "POST" and - .endpoint == - "orgs/atrinik/code-security/configurations/265376/attach" and - .payload == {scope: "selected", selected_repository_ids: [101]} - ) and - ( - [ - to_entries[] | - select( - .value.method == "POST" and - .value.endpoint == - "orgs/atrinik/code-security/configurations/265377/attach" - ) | - .key - ][0] as $attach | - [ - to_entries[] | - select( - .value.method == "GET" and - .value.endpoint == - "repos/atrinik/classic/code-security-configuration" - ) | - .key - ] as $attachment_checks | - [ - to_entries[] | - select( - .value.method == "PATCH" and - .value.endpoint == - "repos/atrinik/classic/code-scanning/default-setup" - ) | - .key - ][0] as $disable | - ($attachment_checks | length) >= 3 and - $attachment_checks[0] < $attach and - $attach < $attachment_checks[-1] and - $attachment_checks[-1] < $disable - ) - ' "${log}" >/dev/null -} - -assert_repository_security_preserved() { - local log=$1 - - jq -s -e ' - any( - .[]; - .method == "PATCH" and - .endpoint == "repos/atrinik/classic" and - .payload.security_and_analysis.secret_scanning.status == "enabled" and - .payload.security_and_analysis.secret_scanning_push_protection.status == - "enabled" and - .payload.security_and_analysis.secret_scanning_validity_checks.status == - "enabled" - ) and - any( - .[]; - .method == "PUT" and - .endpoint == "repos/atrinik/classic/vulnerability-alerts" - ) and - any( - .[]; - .method == "PUT" and - .endpoint == "repos/atrinik/classic/automated-security-fixes" - ) and - any( - .[]; - .method == "PUT" and - .endpoint == "repos/atrinik/classic/private-vulnerability-reporting" - ) - ' "${log}" >/dev/null -} - -assert_advanced_configuration_created() { - local log=$1 - - jq -s -e ' - any( - .[]; - .method == "POST" and - .endpoint == "orgs/atrinik/code-security/configurations" and - .payload.name == "Atrinik advanced CodeQL baseline" and - .payload.code_scanning_options == {allow_advanced: true} - ) and - any( - .[]; - .method == "POST" and - .endpoint == - "orgs/atrinik/code-security/configurations/265377/attach" and - .payload == { - scope: "selected", - selected_repository_ids: [1327289971] - } - ) - ' "${log}" >/dev/null -} - -assert_empty_inventory_rollback() { - local log=$1 - - jq -s -e ' - all( - .[]; - .method != "POST" or - .endpoint != - "orgs/atrinik/code-security/configurations/265377/attach" - ) and - any( - .[]; - .method == "POST" and - .endpoint == - "orgs/atrinik/code-security/configurations/265376/attach" and - .payload == { - scope: "selected", - selected_repository_ids: [1327289971] - } - ) and - all( - .[]; - .method != "PATCH" or - .endpoint != "repos/atrinik/classic/code-scanning/default-setup" or - .payload != {state: "not-configured"} - ) - ' "${log}" >/dev/null -} - -assert_immutable_release_apply() { - local log=$1 - - jq -s -e ' - . as $calls | - [ - .[] | - select( - .method == "PUT" and - .endpoint == "orgs/atrinik/settings/immutable-releases" - ) - ] == [ - { - method: "PUT", - endpoint: "orgs/atrinik/settings/immutable-releases", - payload: { - enforced_repositories: "selected", - selected_repository_ids: [1327289971] - } - } - ] and - ( - [ - $calls | to_entries[] | - select( - .value.method == "PUT" and - .value.endpoint == - "orgs/atrinik/settings/immutable-releases" - ) | - .key - ][0] as $put | - any( - $calls | to_entries[]; - .key > $put and - .value.method == "GET" and - .value.endpoint == "repos/atrinik/classic/immutable-releases" - ) - ) - ' "${log}" >/dev/null -} - -assert_idempotent_organization_security() { - local log=$1 - - jq -s -e ' - all( - .[]; - .method == "GET" or - ( - (.endpoint | startswith( - "orgs/atrinik/code-security/configurations" - ) | not) and - ( - ( - .endpoint | startswith("repos/atrinik/") and - endswith("/code-scanning/default-setup") - ) | not - ) - ) - ) - ' "${log}" >/dev/null -} - -advisory_active_root=${temporary}/advisory-window-active -mkdir -p "${advisory_active_root}/bin" -cp "${root}/bin/publish" "${root}/bin/validate" "${root}/bin/security-readiness" \ - "${advisory_active_root}/bin/" -cp -R "${root}/lib" "${advisory_active_root}/lib" -cp -R "${root}/config" "${advisory_active_root}/config" -cp -R "${root}/community-health" \ - "${advisory_active_root}/community-health" -mkdir -p "${advisory_active_root}/.github" -cp -R "${root}/.github/workflows" "${advisory_active_root}/.github/workflows" -jq '.repositories = ["classic"]' \ - "${root}/config/advisory-merge-windows.json" \ - >"${advisory_active_root}/config/advisory-merge-windows.json" -jq '.maintenance_branches = [{ - repository: "content", - branch: "1.x", - required_ci: ["Content validation", "Conventional PR title"] -}]' "${root}/config/repositories.json" \ - >"${advisory_active_root}/config/repositories.json" -jq '.retirements = []' "${root}/config/retired-maintenance-branches.json" \ - >"${advisory_active_root}/config/retired-maintenance-branches.json" - -organization_log=${temporary}/organization.jsonl -organization_immutable_state=${temporary}/organization-immutable.json -printf '{"enforced_repositories":"none"}\n' \ - >"${organization_immutable_state}" -GH_API_LOG=${organization_log} \ - GH_IMMUTABLE_STATE=${organization_immutable_state} \ - GH_ORGANIZATION_SCENARIO=drifted \ - GH_SECURITY_SCENARIO=drifted \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${advisory_active_root}/bin/publish" --apply \ - >"${temporary}/organization.txt" -grep -F \ - 'SKIP atrinik/classic-ghsa-8533-3vg8-r287 is a temporary security-advisory workspace' \ - "${temporary}/organization.txt" >/dev/null -jq -s -e ' - all( - .[]; - (.endpoint | contains("classic-ghsa-8533-3vg8-r287") | not) - ) -' "${organization_log}" >/dev/null -assert_immutable_release_apply "${organization_log}" -jq -s -e ' - [ - .[] | - select(.method == "PATCH" and .endpoint == "orgs/atrinik") | - .payload - ] == [{ - description: "A cooperative, open-source fantasy world founded by Zoey Seraphina Rose (https://zoeysr.com). Playable in Classic and rebuilding for the future.", - blog: "https://atrinik.org", - default_repository_permission: "none", - members_can_create_repositories: false, - members_can_create_public_repositories: false, - members_can_create_private_repositories: false - }] -' "${organization_log}" >/dev/null -assert_maintenance_payload \ - "${organization_log}" "orgs/atrinik/rulesets" true -assert_default_branch_policy_payloads \ - "${organization_log}" "orgs/atrinik/rulesets" true -assert_classic_advisory_bypass_payloads \ - "${organization_log}" "orgs/atrinik/rulesets" true -assert_classic_required_ci_payload \ - "${organization_log}" "orgs/atrinik/rulesets" true -while IFS=$'\t' read -r repository validation_context; do - assert_replacement_required_ci_payload \ - "${organization_log}" "orgs/atrinik/rulesets" true \ - "${repository}" "${validation_context}" -done <<'EOF' -client Client validation -content-toolkit Content toolkit validation -protocol Protocol validation -server Server validation -website Website validation -EOF -assert_organization_codeql_configurations "${organization_log}" -assert_codeql_default_setup "${organization_log}" -jq -s -e ' - any( - .[]; - .method == "DELETE" and - .endpoint == "orgs/atrinik/rulesets/900" - ) -' "${organization_log}" >/dev/null - -idempotent_log=${temporary}/organization-idempotent.jsonl -idempotent_output=${temporary}/organization-idempotent.txt -enablement_event=${temporary}/enablement-event -GH_API_LOG=${idempotent_log} \ - GH_ENABLEMENT_EVENT_FILE=${enablement_event} \ - GH_IMMUTABLE_STATE=${organization_immutable_state} \ - GH_SECURITY_SCENARIO=converged \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" --apply >"${idempotent_output}" -assert_idempotent_organization_security "${idempotent_log}" -jq -s -e ' - all( - .[]; - .method != "PATCH" or .endpoint != "orgs/atrinik" - ) -' "${idempotent_log}" >/dev/null -[[ ! -e ${enablement_event} ]] -grep -F \ - 'KEEP /orgs/atrinik metadata and repository defaults' \ - "${idempotent_output}" >/dev/null -grep -F \ - 'KEEP /orgs/atrinik/code-security/configurations/265377 matches config/code-security-advanced.json' \ - "${idempotent_output}" >/dev/null -grep -F \ - 'KEEP /orgs/atrinik/code-security/configurations/265377/attach already covers 1 repositories' \ - "${idempotent_output}" >/dev/null -grep -F \ - 'KEEP /orgs/atrinik/code-security/configurations/265376/defaults is all' \ - "${idempotent_output}" >/dev/null - -pending_log=${temporary}/organization-pending.jsonl -GH_API_LOG=${pending_log} \ - GH_IMMUTABLE_STATE=${organization_immutable_state} \ - GH_SECURITY_SCENARIO=pending \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" --apply >/dev/null -assert_idempotent_organization_security "${pending_log}" -jq -s -e ' - ( - [ - .[] | - select( - .method == "GET" and - .endpoint == - "repos/atrinik/classic/code-security-configuration" - ) - ] | length - ) >= 2 -' "${pending_log}" >/dev/null - -creation_log=${temporary}/organization-create-codeql.jsonl -creation_immutable_state=${temporary}/organization-create-codeql-immutable.json -printf '{"enforced_repositories":"none"}\n' \ - >"${creation_immutable_state}" -GH_API_LOG=${creation_log} \ - GH_ADVANCED_CONFIG_MISSING=true \ - GH_IMMUTABLE_STATE=${creation_immutable_state} \ - GH_SECURITY_SCENARIO=create \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" --apply >/dev/null -assert_advanced_configuration_created "${creation_log}" -assert_codeql_default_setup "${creation_log}" - -rollback_root=${temporary}/empty-inventory -mkdir -p "${rollback_root}/bin" -cp "${root}/bin/publish" "${root}/bin/validate" "${root}/bin/security-readiness" "${rollback_root}/bin/" -cp -R "${root}/lib" "${rollback_root}/lib" -cp -R "${root}/config" "${rollback_root}/config" -cp -R "${root}/community-health" "${rollback_root}/community-health" -mkdir -p "${rollback_root}/.github" -cp -R "${root}/.github/workflows" "${rollback_root}/.github/workflows" -jq '.repositories = [] | .required_partitions = {}' \ - "${root}/config/codeql-advanced-setup.json" \ - >"${rollback_root}/config/codeql-advanced-setup.json" -rollback_log=${temporary}/empty-inventory.jsonl -rollback_output=${temporary}/empty-inventory.txt -empty_inventory_immutable_state=${temporary}/empty-inventory-immutable.json -printf '{"enforced_repositories":"none"}\n' \ - >"${empty_inventory_immutable_state}" -GH_API_LOG=${rollback_log} \ - GH_EMPTY_ADVANCED_INVENTORY=true \ - GH_IMMUTABLE_STATE=${empty_inventory_immutable_state} \ - GH_SECURITY_SCENARIO=rollback \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${rollback_root}/bin/publish" --apply >"${rollback_output}" -assert_empty_inventory_rollback "${rollback_log}" -grep -F 'SKIP advanced CodeQL attachment: inventory is empty' \ - "${rollback_output}" >/dev/null -grep -F \ - 'KEEP /repos/atrinik/classic/code-scanning/default-setup is configured' \ - "${rollback_output}" >/dev/null - -repository_log=${temporary}/repository.jsonl -repository_immutable_state=${temporary}/repository-immutable.json -printf '{"enforced_repositories":"none"}\n' \ - >"${repository_immutable_state}" -GH_API_LOG=${repository_log} \ - GH_SHARED_RULESETS_PRESENT=true \ - GH_IMMUTABLE_STATE=${repository_immutable_state} \ - GH_SECURITY_SCENARIO=drifted \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=repository \ - "${advisory_active_root}/bin/publish" --apply >/dev/null -assert_maintenance_payload \ - "${repository_log}" "repos/atrinik/content/rulesets" false -assert_default_branch_policy_payloads \ - "${repository_log}" "repos/atrinik/content/rulesets" false -assert_classic_advisory_bypass_payloads \ - "${repository_log}" "repos/atrinik/classic/rulesets" false -assert_classic_required_ci_payload \ - "${repository_log}" "repos/atrinik/classic/rulesets" false -jq -s -e ' - [ - .[] | - select( - .method == "DELETE" and - ( - .endpoint == "repos/atrinik/classic/rulesets/904" or - .endpoint == "repos/atrinik/classic/rulesets/905" or - .endpoint == "repos/atrinik/classic/rulesets/906" - ) - ) - ] | length == 3 -' "${repository_log}" >/dev/null -while IFS=$'\t' read -r repository validation_context; do - assert_replacement_required_ci_payload \ - "${repository_log}" "repos/atrinik/${repository}/rulesets" false \ - "${repository}" "${validation_context}" -done <<'EOF' -client Client validation -content-toolkit Content toolkit validation -protocol Protocol validation -server Server validation -website Website validation -EOF -assert_repository_security_preserved "${repository_log}" -assert_codeql_default_setup "${repository_log}" -jq -s -e ' - any( - .[]; - .method == "DELETE" and - .endpoint == "repos/atrinik/content/rulesets/900" - ) and - any( - .[]; - .method == "DELETE" and - .endpoint == "orgs/atrinik/rulesets/900" - ) -' "${repository_log}" >/dev/null - -advisory_rollback_root=${temporary}/advisory-window-rollback -mkdir -p "${advisory_rollback_root}/bin" -cp "${root}/bin/publish" "${root}/bin/validate" "${root}/bin/security-readiness" \ - "${advisory_rollback_root}/bin/" -cp -R "${root}/lib" "${advisory_rollback_root}/lib" -cp -R "${root}/config" "${advisory_rollback_root}/config" -cp -R "${root}/community-health" \ - "${advisory_rollback_root}/community-health" -mkdir -p "${advisory_rollback_root}/.github" -cp -R "${root}/.github/workflows" \ - "${advisory_rollback_root}/.github/workflows" -jq '.repositories = []' \ - "${root}/config/advisory-merge-windows.json" \ - >"${advisory_rollback_root}/config/advisory-merge-windows.json" - -advisory_organization_log=${temporary}/advisory-organization-rollback.jsonl -advisory_organization_state=${temporary}/advisory-organization-state.json -printf '%s\n' \ - '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' \ - >"${advisory_organization_state}" -GH_ADVISORY_RULESETS_PRESENT=true \ - GH_API_LOG=${advisory_organization_log} \ - GH_IMMUTABLE_STATE=${advisory_organization_state} \ - GH_SECURITY_SCENARIO=converged \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${advisory_rollback_root}/bin/publish" --apply >/dev/null -assert_advisory_window_closed \ - "${advisory_organization_log}" "orgs/atrinik/rulesets" \ - "orgs/atrinik/rulesets" true - -advisory_repository_log=${temporary}/advisory-repository-rollback.jsonl -advisory_repository_state=${temporary}/advisory-repository-state.json -printf '%s\n' \ - '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' \ - >"${advisory_repository_state}" -GH_ADVISORY_RULESETS_PRESENT=true \ - GH_API_LOG=${advisory_repository_log} \ - GH_IMMUTABLE_STATE=${advisory_repository_state} \ - GH_SECURITY_SCENARIO=converged \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=repository \ - "${advisory_rollback_root}/bin/publish" --apply >/dev/null -assert_advisory_window_closed \ - "${advisory_repository_log}" "repos/atrinik/classic/rulesets" \ - "repos/atrinik/classic/rulesets" false - -for repository in \ - legacy-client \ - legacy-editor \ - legacy-libatrinik \ - legacy-protocol \ - legacy-server; do - jq -s -e \ - --arg endpoint "repos/atrinik/${repository}" ' - any( - .[]; - .method == "PATCH" and - .endpoint == $endpoint and - .payload == {archived: true} - ) - ' "${organization_log}" >/dev/null -done - -plan_output=${temporary}/plan.txt -plan_immutable_state=${temporary}/plan-immutable.json -printf '{"enforced_repositories":"none"}\n' >"${plan_immutable_state}" -GH_API_LOG=${temporary}/plan.jsonl \ - GH_IMMUTABLE_STATE=${plan_immutable_state} \ - GH_ORGANIZATION_SCENARIO=drifted \ - GH_SECURITY_SCENARIO=drifted \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" >"${plan_output}" -grep -F \ - 'DRIFT /orgs/atrinik description live="" desired="A cooperative, open-source fantasy world founded by Zoey Seraphina Rose (https://zoeysr.com). Playable in Classic and rebuilding for the future."' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN PATCH /orgs/atrinik <= config/organization.json' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN POST /orgs/atrinik/code-security/configurations/265377/attach' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN WAIT /repos/atrinik/classic/code-security-configuration => 265377' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN PATCH /repos/atrinik/classic/code-scanning/default-setup <= config/codeql-default-setup-advanced.json' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN POST /orgs/atrinik/code-security/configurations/265376/attach' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN WAIT /repos/atrinik/content/code-security-configuration => 265376' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN PATCH /repos/atrinik/content/code-scanning/default-setup <= config/codeql-default-setup.json' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN PUT /orgs/atrinik/settings/immutable-releases <= {"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' \ - "${plan_output}" >/dev/null -grep -F \ - 'PLAN VERIFY /repos/atrinik/classic/immutable-releases => enabled=true,enforced_by_owner=true' \ - "${plan_output}" >/dev/null -grep -F \ - 'MANUAL cloudflare-workers-and-pages installation 152311798 selected repositories: atrinik/website, atrinik/metaserver-worker; publisher does not apply' \ - "${plan_output}" >/dev/null -jq -e '. == {enforced_repositories: "none"}' \ - "${plan_immutable_state}" >/dev/null -jq -s -e ' - all( - .[]; - .method == "GET" - ) -' "${temporary}/plan.jsonl" >/dev/null - -keep_log=${temporary}/immutable-keep.jsonl -keep_output=${temporary}/immutable-keep.txt -keep_immutable_state=${temporary}/immutable-keep-state.json -printf '%s\n' \ - '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' \ - >"${keep_immutable_state}" -GH_API_LOG=${keep_log} \ - GH_IMMUTABLE_STATE=${keep_immutable_state} \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=repository \ - "${root}/bin/publish" --apply >"${keep_output}" -grep -F \ - 'KEEP /orgs/atrinik/settings/immutable-releases is {"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' \ - "${keep_output}" >/dev/null -jq -s -e ' - all( - .[]; - .method != "PUT" or - .endpoint != "orgs/atrinik/settings/immutable-releases" - ) -' "${keep_log}" >/dev/null - -immutable_rollback_log=${temporary}/immutable-rollback.jsonl -immutable_rollback_output=${temporary}/immutable-rollback.txt -immutable_rollback_state=${temporary}/immutable-rollback-state.json -printf '%s\n' \ - '{"enforced_repositories":"selected","selected_repository_ids":[101]}' \ - >"${immutable_rollback_state}" -if GH_API_LOG=${immutable_rollback_log} \ - GH_IMMUTABLE_STATE=${immutable_rollback_state} \ - GH_IMMUTABLE_VERIFY_FAILURE=true \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" --apply \ - >"${immutable_rollback_output}" 2>&1; then - echo "expected immutable-release verification failure" >&2 - exit 1 -fi -jq -e '. == { - enforced_repositories: "selected", - selected_repository_ids: [101] -}' "${immutable_rollback_state}" >/dev/null -jq -s -e ' - [ - .[] | - select( - .method == "PUT" and - .endpoint == "orgs/atrinik/settings/immutable-releases" - ) | - .payload - ] == [ - { - enforced_repositories: "selected", - selected_repository_ids: [1327289971] - }, - { - enforced_repositories: "selected", - selected_repository_ids: [101] - } - ] -' "${immutable_rollback_log}" >/dev/null -grep -F \ - 'ROLLBACK verified the previous immutable-release policy' \ - "${immutable_rollback_output}" >/dev/null - -identity_drift_log=${temporary}/immutable-identity-drift.jsonl -identity_drift_output=${temporary}/immutable-identity-drift.txt -identity_drift_state=${temporary}/immutable-identity-drift-state.json -printf '{"enforced_repositories":"none"}\n' >"${identity_drift_state}" -if GH_API_LOG=${identity_drift_log} \ - GH_IMMUTABLE_STATE=${identity_drift_state} \ - GH_CLASSIC_REPOSITORY_ID=999 \ - PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization \ - "${root}/bin/publish" --apply >"${identity_drift_output}" 2>&1; then - echo "expected immutable-release repository identity failure" >&2 - exit 1 -fi -grep -F \ - 'error: immutable-release inventory id for classic is 1327289971, but GitHub reports 999' \ - "${identity_drift_output}" >/dev/null -jq -s -e 'all(.[]; .method == "GET")' "${identity_drift_log}" >/dev/null - -# A newly selected producer must qualify its exact workflow and environment -# before the publisher's first mutation. This fixture deliberately provides no -# source release, registry, or attestation endpoint: setup qualification is -# about reviewed protected-main configuration only. -crate_state=${temporary}/crate-immutable-state.json -crate_log=${temporary}/crate-immutable-log.jsonl -printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" -GH_API_LOG=${crate_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_SECURITY_SCENARIO=converged \ - GH_CRATE_FIXTURE_ROOT=${source_root} PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${source_root}/bin/publish" --apply >"${temporary}/crate-immutable-apply.out" -jq -e '. == {enforced_repositories:"selected",selected_repository_ids:[1324297032,1327106950,1327107043,1327289971]}' "${crate_state}" >/dev/null -jq -s -e ' - . as $calls | - ([ $calls | to_entries[] | - select(.value.method != "GET") | .key ] | first) as $first_mutation | - all( - ["protocol", "content-toolkit"][] as $repository | - ([ $calls | to_entries[] | - select(.value.endpoint == ("repos/atrinik/" + $repository + "/git/ref/heads/main")) | - .key ] | last) < $first_mutation - ) and - all(.[]; (.endpoint | test("/(releases|attestations|actions/runs)(/|$)") | not)) -' "${crate_log}" >/dev/null -for repository in classic protocol content-toolkit; do - jq -se --arg endpoint "repos/atrinik/${repository}/immutable-releases" \ - 'any(.[]; .method == "GET" and .endpoint == $endpoint)' "${crate_log}" >/dev/null -done - -crate_setup_root() { - local destination=$1 - - mkdir -p "${destination}/bin" "${destination}/lib" "${destination}/tests" - cp "${source_root}/bin/publish" "${source_root}/bin/validate" \ - "${source_root}/bin/verify-manual-settings" "${source_root}/bin/security-readiness" "${destination}/bin/" - cp "${source_root}/lib/verify_crate_workflow.py" "${source_root}/lib/security_readiness.py" \ - "${destination}/lib/" - cp -R "${source_root}/config" "${source_root}/community-health" \ - "${source_root}/.github" "${destination}/" - cp -R "${source_root}/tests/fixtures" "${destination}/tests/" -} - -assert_setup_failed_before_mutation() { - local log=$1 - - jq -s -e 'all(.[]; .method == "GET")' "${log}" >/dev/null -} - -# Metaserver draft-first and exact-main check failures stop before any write. -for scenario in partial-producer failed-source-check late-main-drift; do - scenario_log=${temporary}/metaserver-${scenario}.jsonl - printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" - if GH_API_LOG=${scenario_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_METASERVER_SOURCE_SCENARIO=${scenario} \ - GH_CRATE_FIXTURE_ROOT=${source_root} PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization "${source_root}/bin/publish" --apply \ - >"${temporary}/metaserver-${scenario}.out" 2>&1; then - echo "error: unqualified metaserver producer did not block initial selection" >&2 - exit 1 - fi - assert_setup_failed_before_mutation "${scenario_log}" -done - -# A pending or absent manual record blocks a newly selected producer before -# immutable policy or any unrelated governance setting can mutate. -pending_setup_root=${temporary}/crate-pending-setup -crate_setup_root "${pending_setup_root}" -jq '(.crates_io_trusted_publishing[] | select(.repository == "atrinik/protocol") | - .source_state) = "pending-reviewed-workflow" | - (.crates_io_trusted_publishing[] | select(.repository == "atrinik/protocol") | - .environment_state) = "pending"' \ - "${pending_setup_root}/config/manual-settings.json" >"${temporary}/pending-manual.json" -mv "${temporary}/pending-manual.json" "${pending_setup_root}/config/manual-settings.json" -pending_setup_log=${temporary}/crate-pending-setup.jsonl -printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" -if GH_API_LOG=${pending_setup_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_FIXTURE_ROOT=${source_root} \ - PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${pending_setup_root}/bin/publish" --apply >"${temporary}/crate-pending-setup.out" 2>&1; then - echo "error: pending crate setup did not block immutable selection" >&2 - exit 1 -fi -grep -F 'initial immutable selection requires observed qualified source/environment for atrinik/protocol' \ - "${temporary}/crate-pending-setup.out" >/dev/null -assert_setup_failed_before_mutation "${pending_setup_log}" - -missing_setup_root=${temporary}/crate-missing-setup -crate_setup_root "${missing_setup_root}" -jq 'del(.crates_io_trusted_publishing[] | select(.repository == "atrinik/protocol"))' \ - "${missing_setup_root}/config/manual-settings.json" >"${temporary}/missing-manual.json" -mv "${temporary}/missing-manual.json" "${missing_setup_root}/config/manual-settings.json" -missing_setup_log=${temporary}/crate-missing-setup.jsonl -printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" -if GH_API_LOG=${missing_setup_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_FIXTURE_ROOT=${source_root} \ - PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${missing_setup_root}/bin/publish" --apply >"${temporary}/crate-missing-setup.out" 2>&1; then - echo "error: missing crate setup record did not block immutable selection" >&2 - exit 1 -fi -assert_setup_failed_before_mutation "${missing_setup_log}" - -# The scoped verifier must reject malformed protected-main workflow bytes and -# environment drift before any mutation. -for scenario in malformed-workflow environment-drift; do - scenario_log=${temporary}/crate-${scenario}.jsonl - printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" - if GH_API_LOG=${scenario_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_SETUP_SCENARIO=${scenario} \ - GH_CRATE_FIXTURE_ROOT=${source_root} PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization "${source_root}/bin/publish" --apply \ - >"${temporary}/crate-${scenario}.out" 2>&1; then - echo "error: ${scenario} did not block immutable selection" >&2 - exit 1 - fi - assert_setup_failed_before_mutation "${scenario_log}" -done - -# The immutable snapshot is a fence: a changed live policy after successful -# qualification prevents the first convergence mutation. -snapshot_drift_log=${temporary}/crate-snapshot-drift.jsonl -printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1327289971]}' >"${crate_state}" -if GH_API_LOG=${snapshot_drift_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_SNAPSHOT_DRIFT=true \ - GH_CRATE_FIXTURE_ROOT=${source_root} PATH="${temporary}/bin:${PATH}" \ - ATRINIK_POLICY_SCOPE=organization "${source_root}/bin/publish" --apply \ - >"${temporary}/crate-snapshot-drift.out" 2>&1; then - echo "error: immutable snapshot drift did not block convergence" >&2 - exit 1 -fi -grep -F 'immutable-release policy changed during initial qualification' \ - "${temporary}/crate-snapshot-drift.out" >/dev/null -assert_setup_failed_before_mutation "${snapshot_drift_log}" - -# Existing selections do not requalify their pending records, and an all-mode -# snapshot does not cause avoidable source/environment verification. -for mode in selected all; do - mode_log=${temporary}/crate-${mode}-already-selected.jsonl - if [[ ${mode} == selected ]]; then - printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[1324297032,1327106950,1327107043,1327289971]}' >"${crate_state}" - else - printf '%s\n' '{"enforced_repositories":"all"}' >"${crate_state}" - fi - GH_API_LOG=${mode_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_FIXTURE_ROOT=${source_root} \ - PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${pending_setup_root}/bin/publish" --apply >"${temporary}/crate-${mode}-already-selected.out" - jq -s -e 'all(.[]; - (.endpoint | test("/contents/\\.github/workflows/(publish-crate|release)\\.yml") | not) and - (.endpoint | contains("/environments/crates-io-release") | not))' "${mode_log}" >/dev/null -done - -crate_failure_log=${temporary}/crate-immutable-failure.jsonl -printf '%s\n' '{"enforced_repositories":"selected","selected_repository_ids":[101,1327289971]}' >"${crate_state}" -if GH_API_LOG=${crate_failure_log} GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_CRATE_IMMUTABLE_VERIFY_FAILURE=true \ - GH_SECURITY_SCENARIO=converged PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${source_root}/bin/publish" --apply >"${temporary}/crate-immutable-failure.out" 2>&1; then - echo "error: crate-family immutable readback drift did not fail" >&2 - exit 1 -fi -jq -e '. == {enforced_repositories:"selected",selected_repository_ids:[101,1327289971]}' "${crate_state}" >/dev/null -if GH_API_LOG=${temporary}/crate-identity-drift.jsonl GH_IMMUTABLE_STATE=${crate_state} \ - GH_CRATE_IMMUTABLE_INVENTORY=true GH_PROTOCOL_REPOSITORY_ID=999 \ - GH_SECURITY_SCENARIO=converged PATH="${temporary}/bin:${PATH}" ATRINIK_POLICY_SCOPE=organization \ - "${source_root}/bin/publish" --apply >"${temporary}/crate-identity-drift.out" 2>&1; then - echo "error: crate-family repository identity drift did not fail" >&2 - exit 1 -fi -jq -se 'all(.[]; .method == "GET")' "${temporary}/crate-identity-drift.jsonl" >/dev/null - -echo "Publisher policy-scope tests passed." diff --git a/tests/publish-maintenance-retirement.sh b/tests/publish-maintenance-retirement.sh deleted file mode 100755 index 7b40304..0000000 --- a/tests/publish-maintenance-retirement.sh +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] -shift -method=GET -endpoint= -while (($#)); do - case $1 in - -H | --header) - shift 2 - ;; - --paginate) - shift - ;; - --method) - method=$2 - shift 2 - ;; - *) - endpoint=$1 - shift - ;; - esac -done - -jq -cn --arg method "${method}" --arg endpoint "${endpoint}" \ - '{method: $method, endpoint: $endpoint}' >>"${GH_API_LOG}" - -if [[ ${method} == DELETE ]] && - [[ ${endpoint} == orgs/atrinik/rulesets/20571870 ]]; then - printf 'false\n' >"${GH_RULESET_PRESENT}" - printf '{}\n' - exit 0 -fi -[[ ${method} == GET ]] - -rulesets() { - jq -n --argjson present "$(<"${GH_RULESET_PRESENT}")" ' - [ - {id: 20522685, name: "01 - Default branch integrity", enforcement: "active"}, - {id: 20593745, name: "01 - Default branch linear history", enforcement: "active"}, - {id: 20522686, name: "02 - Changes through pull requests", enforcement: "active"}, - {id: 20522693, name: "03 - Required CI - content", enforcement: "active"}, - {id: 20522688, name: "04 - Immutable release tags", enforcement: "active"} - ] + - (if $present then [{ - id: 20571870, - name: "05 - Maintenance branch - content - 1.x", - enforcement: "active" - }] else [] end) - ' -} - -case ${endpoint} in -repos/atrinik/content) - printf '%s\n' \ - '{"id":1325219730,"archived":false,"default_branch":"main"}' - ;; -repos/atrinik/content/git/ref/heads/1.x) - printf '%s\n' \ - '{"object":{"sha":"080a9ea41741e4e67adc7b09b3ccb51475d93d3a"}}' - ;; -repos/atrinik/content/git/ref/tags/v1.8.19) - printf '%s\n' \ - '{"object":{"sha":"566bd25f78b80b08d5f75f4b02017ab2429204db"}}' - ;; -repos/atrinik/content/releases/tags/v1.8.19) - printf '%s\n' '{ - "tag_name":"v1.8.19", - "draft":false, - "prerelease":false, - "assets":[ - {"name":"atrinik-content-1.8.19-runtime.tar.gz"}, - {"name":"atrinik-content-1.8.19.tar.gz"}, - {"name":"SHA256SUMS"} - ] - }' - ;; -'repos/atrinik/content/pulls?state=open&base=1.x&per_page=100') - if [[ ${GH_OPEN_PULL:-false} == true ]]; then - printf '[{"number":1}]\n' - else - printf '[]\n' - fi - ;; -orgs/atrinik/rulesets) - rulesets - ;; -orgs/atrinik/rulesets/20571870) - if [[ ${GH_RULESET_DRIFT:-false} == true ]]; then - branch=retired - else - branch=1.x - fi - jq -n --arg branch "${branch}" '{ - id: 20571870, - name: "05 - Maintenance branch - content - 1.x", - target: "branch", - enforcement: "active", - bypass_actors: [{ - actor_id: null, - actor_type: "OrganizationAdmin", - bypass_mode: "pull_request" - }], - conditions: { - repository_name: {include: ["content"], exclude: []}, - ref_name: {include: ["refs/heads/\($branch)"], exclude: []} - }, - rules: [ - {type: "deletion"}, - {type: "non_fast_forward"}, - {type: "required_linear_history"}, - { - type: "pull_request", - parameters: { - allowed_merge_methods: ["merge", "squash", "rebase"], - dismiss_stale_reviews_on_push: false, - require_code_owner_review: false, - require_last_push_approval: false, - required_approving_review_count: 0, - required_review_thread_resolution: true, - required_reviewers: [] - } - }, - { - type: "required_status_checks", - parameters: { - do_not_enforce_on_create: false, - required_status_checks: [ - {context: "Content validation", integration_id: 15368}, - {context: "Conventional PR title", integration_id: 15368} - ], - strict_required_status_checks_policy: true - } - } - ] - }' - ;; -*) - echo "unexpected endpoint: ${endpoint}" >&2 - exit 1 - ;; -esac -EOF -chmod +x "${temporary}/bin/gh" - -present=${temporary}/ruleset-present -printf 'true\n' >"${present}" -plan_log=${temporary}/plan.jsonl -plan_output=${temporary}/plan.txt -GH_API_LOG=${plan_log} GH_RULESET_PRESENT=${present} \ - PATH="${temporary}/bin:${PATH}" \ - "${root}/bin/publish" --retire-maintenance content/1.x >"${plan_output}" - -[[ $(grep -c '^PLAN ' "${plan_output}") == 1 ]] -grep -Fx 'PLAN DELETE /orgs/atrinik/rulesets/20571870' \ - "${plan_output}" >/dev/null -jq -s -e 'all(.[]; .method == "GET")' "${plan_log}" >/dev/null -[[ $(<"${present}") == true ]] - -apply_log=${temporary}/apply.jsonl -apply_output=${temporary}/apply.txt -GH_API_LOG=${apply_log} GH_RULESET_PRESENT=${present} \ - PATH="${temporary}/bin:${PATH}" \ - "${root}/bin/publish" --apply \ - --retire-maintenance content/1.x >"${apply_output}" -jq -s -e ' - [.[] | select(.method != "GET")] == [{ - method: "DELETE", - endpoint: "orgs/atrinik/rulesets/20571870" - }] -' "${apply_log}" >/dev/null -grep -Fx 'APPLY verified only ruleset 20571870 is absent' \ - "${apply_output}" >/dev/null -[[ $(<"${present}") == false ]] - -printf 'true\n' >"${present}" -if GH_API_LOG=${temporary}/open-pr.jsonl GH_RULESET_PRESENT=${present} \ - GH_OPEN_PULL=true PATH="${temporary}/bin:${PATH}" \ - "${root}/bin/publish" --retire-maintenance content/1.x \ - >"${temporary}/open-pr.out" 2>"${temporary}/open-pr.err"; then - echo "retirement plan accepted an open target-branch pull request" >&2 - exit 1 -fi -grep -F 'open pull requests still target the retirement branch' \ - "${temporary}/open-pr.err" >/dev/null - -if GH_API_LOG=${temporary}/drift.jsonl GH_RULESET_PRESENT=${present} \ - GH_RULESET_DRIFT=true PATH="${temporary}/bin:${PATH}" \ - "${root}/bin/publish" --retire-maintenance content/1.x \ - >"${temporary}/drift.out" 2>"${temporary}/drift.err"; then - echo "retirement plan accepted ruleset scope drift" >&2 - exit 1 -fi -grep -F 'exact retirement ruleset payload drift' \ - "${temporary}/drift.err" >/dev/null - -echo "Targeted maintenance retirement publisher tests passed." diff --git a/tests/publish-merge-queue.sh b/tests/publish-merge-queue.sh deleted file mode 100755 index 8598a25..0000000 --- a/tests/publish-merge-queue.sh +++ /dev/null @@ -1,368 +0,0 @@ -#!/usr/bin/env bash - -# Production functions consume these fixture globals. -# shellcheck disable=SC2034 -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -source_root=${ATRINIK_PUBLISH_TEST_ROOT:-${root}} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -sed -n '/^converge_organization_settings() {/,/^organization_metadata=/p' \ - "${source_root}/bin/publish" | sed '$d' >"${temporary}/functions.sh" -sed -n '/^list_rulesets() {/,/^}/p' "${source_root}/bin/publish" >>"${temporary}/functions.sh" -# shellcheck source=/dev/null -source "${temporary}/functions.sh" -root=${temporary}/fixture -mkdir -p "${root}/config" "${temporary}/captured" -cp -R "${source_root}/config/rulesets" "${root}/config/rulesets" -template=${root}/config/rulesets/merge-queue.json -organization=atrinik -organization_plan=team -repositories_config=${root}/config/repositories.json -advisory_merge_windows_config=${root}/config/advisory-merge-windows.json -temporary_files=() -log=${temporary}/api.jsonl - -# Live fixtures: playtester is queued, observatory is not. -github_api() { - jq -cn --arg endpoint "$1" '{method:"GET",endpoint:$endpoint}' >>"${log}" - case $1 in - 'repos/atrinik/playtester/rulesets?includes_parents=false' | \ - 'repos/atrinik/observatory/rulesets?includes_parents=false') - local repository=${1#repos/atrinik/} - repository=${repository%%/*} - cat "${temporary}/${repository}-list.json" ;; - repos/atrinik/playtester/rulesets/8 | repos/atrinik/observatory/rulesets/8) - local repository=${1#repos/atrinik/} reads - repository=${repository%%/*} - # A later read may observe a concurrent edit or fail. - reads=$(jq -s --arg endpoint "$1" '[.[] | select(.endpoint == $endpoint)] | length' "${log}") - if ((reads > 1)) && [[ -e ${temporary}/${repository}-later-rule.json ]]; then - cat "${temporary}/${repository}-later-rule.json" - elif ((reads > 1)) && [[ -e ${temporary}/${repository}-later-unreadable ]]; then - return 1 - else - cat "${temporary}/${repository}-rule.json" - fi ;; - repos/atrinik/playtester | repos/atrinik/observatory) - cat "${temporary}/${1#repos/atrinik/}-metadata.json" ;; - orgs/atrinik/rulesets) echo '[]' ;; - *) echo "unexpected endpoint: $1" >&2; return 99 ;; - esac -} -run_api() { - if ! ${apply}; then - echo "PLAN $1 /$2" - return - fi - jq -cn --arg method "$1" --arg endpoint "$2" \ - --argjson body "$(if [[ -n ${3:-} ]]; then cat "$3"; else echo null; fi)" \ - '{method:$method,endpoint:$endpoint,body:$body}' >>"${log}" -} -writes() { - jq -sc '[.[] | select(.method != "GET")]' "${log}" -} -# GitHub returns the owner sentinel with a null ID and the ruleset's identity. -live_rule() { - local repository=$1 - jq --arg source "atrinik/${repository}" ' - . + {id: 8, source_type: "Repository", source: $source} | - .bypass_actors[0].actor_id = null - ' "${template}" -} -reset_case() { - : >"${log}" - apply=true - active_repositories=(observatory playtester) - declare -gA active_repository_ids=([observatory]=1 [playtester]=2) - printf '{"repositories":[]}\n' >"${advisory_merge_windows_config}" - jq -n '{ - pull_request_gate: ["observatory", "playtester"], - required_ci: { - observatory: ["Validate dashboard and Workers", "Conventional PR title"], - playtester: ["Playtester validation", "Conventional PR title"] - }, - merge_queue: ["playtester"], - release_tags: [], - maintenance_branches: [], - archive: [] - }' >"${repositories_config}" - printf '[{"id":3,"name":"03 - Required CI"}]\n' >"${temporary}/playtester-list.json" - printf '[{"id":3,"name":"03 - Required CI"}]\n' >"${temporary}/observatory-list.json" - rm -f "${temporary}/"*-later-rule.json "${temporary}/"*-later-unreadable - printf '{"id":2,"full_name":"atrinik/playtester","archived":false}\n' \ - >"${temporary}/playtester-metadata.json" - printf '{"id":1,"full_name":"atrinik/observatory","archived":false}\n' \ - >"${temporary}/observatory-metadata.json" - live_rule playtester >"${temporary}/playtester-rule.json" - live_rule observatory >"${temporary}/observatory-rule.json" -} -expect_failure() { - local message=$1 - shift - if "$@" >"${temporary}/output" 2>&1; then - echo "expected failure: ${message}" >&2 - exit 1 - fi - grep -Fq "${message}" "${temporary}/output" - [[ $(writes) == '[]' ]] -} - -# The pilot template is the reviewed queue for squash-only repositories. -jq -e ' - .name == "08 - Merge queue" and - .rules == [{type: "merge_queue", parameters: { - check_response_timeout_minutes: 60, - grouping_strategy: "ALLGREEN", - max_entries_to_build: 5, - max_entries_to_merge: 5, - merge_method: "SQUASH", - min_entries_to_merge: 1, - min_entries_to_merge_wait_minutes: 0 - }}] -' "${template}" >/dev/null - -# A missing queue is created on the repository, never as an organization rule. -reset_case -publish_merge_queue_rulesets >"${temporary}/output" -jq -se --slurpfile desired "${template}" ' - [.[] | select(.method != "GET")] == - [{method: "POST", endpoint: "repos/atrinik/playtester/rulesets", body: $desired[0]}] -' "${log}" >/dev/null -if grep -q '"endpoint":"orgs/' "${log}"; then - echo 'merge queue must remain repository-owned' >&2 - exit 1 -fi - -# A converged queue is kept without a write. -reset_case -printf '[{"id":3,"name":"03 - Required CI"},{"id":8,"name":"08 - Merge queue"}]\n' \ - >"${temporary}/playtester-list.json" -publish_merge_queue_rulesets >"${temporary}/output" -[[ $(writes) == '[]' ]] -grep -Fxq 'KEEP /repos/atrinik/playtester/rulesets/8 08 - Merge queue' "${temporary}/output" - -# Parameter, enforcement or scope drift is converged in place. -for filter in \ - '.rules[0].parameters.check_response_timeout_minutes = 30' \ - '.rules[0].parameters.grouping_strategy = "HEADGREEN"' \ - '.rules[0].parameters.merge_method = "MERGE"' \ - '.enforcement = "disabled"' \ - '.conditions.ref_name.include = ["refs/heads/other"]' \ - '.bypass_actors[0].bypass_mode = "always"'; do - reset_case - printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" - jq "${filter}" "${temporary}/playtester-rule.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/playtester-rule.json" - publish_merge_queue_rulesets >"${temporary}/output" - jq -se --slurpfile desired "${template}" ' - [.[] | select(.method != "GET")] == - [{method: "PUT", endpoint: "repos/atrinik/playtester/rulesets/8", body: $desired[0]}] - ' "${log}" >/dev/null -done - -# Plan mode prints the operation and writes nothing. -reset_case -apply=false -publish_merge_queue_rulesets >"${temporary}/output" -grep -Fxq 'PLAN POST /repos/atrinik/playtester/rulesets' "${temporary}/output" -[[ $(writes) == '[]' ]] - -# A same-name rule with foreign ownership is never overwritten. -for filter in '.source_type = "Organization"' '.source = "foreign/playtester"' \ - '.id = 9' '.name = "Foreign queue"'; do - reset_case - printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" - jq "${filter}" "${temporary}/playtester-rule.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/playtester-rule.json" - expect_failure 'merge-queue ruleset ownership changed; retained: playtester' \ - publish_merge_queue_rulesets -done - -# An inactive inventory entry is skipped, as security gates are; an ambiguous -# live inventory fails closed. -reset_case -active_repository_ids=([observatory]=1) -publish_merge_queue_rulesets >"${temporary}/output" -grep -Fxq 'SKIP atrinik/playtester is not active; 08 - Merge queue' "${temporary}/output" -jq -se 'length == 0' "${log}" >/dev/null -reset_case -printf '[{"id":8,"name":"08 - Merge queue"},{"id":9,"name":"08 - Merge queue"}]\n' \ - >"${temporary}/playtester-list.json" -expect_failure 'ambiguous complete ruleset inventory' publish_merge_queue_rulesets - -# An advisory-level merge needs every reported rule bypassable. -reset_case -printf '{"repositories":["playtester"]}\n' >"${advisory_merge_windows_config}" -publish_merge_queue_rulesets >"${temporary}/output" -jq -se ' - [.[] | select(.method == "POST")][0].body.bypass_actors == - [{actor_id: 1, actor_type: "OrganizationAdmin", bypass_mode: "always"}] -' "${log}" >/dev/null - -# Retirement removes only the unmodified repository-owned managed queue. -reset_case -jq '.merge_queue = []' "${repositories_config}" >"${temporary}/retired.json" -mv "${temporary}/retired.json" "${repositories_config}" -printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" -delete_removed_merge_queue_rulesets >"${temporary}/output" -[[ $(writes) == '[{"method":"DELETE","endpoint":"repos/atrinik/playtester/rulesets/8","body":null}]' ]] -for filter in '.source_type = "Organization"' '.source = "foreign/playtester"' \ - '.id = 9' '.enforcement = "disabled"' \ - '.rules[0].parameters.check_response_timeout_minutes = 30' \ - '.rules += [{type: "deletion"}]'; do - reset_case - jq '.merge_queue = []' "${repositories_config}" >"${temporary}/retired.json" - mv "${temporary}/retired.json" "${repositories_config}" - printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" - jq "${filter}" "${temporary}/playtester-rule.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/playtester-rule.json" - delete_removed_merge_queue_rulesets >"${temporary}/output" - [[ $(writes) == '[]' ]] - grep -Fxq 'SKIP atrinik/playtester 08 - Merge queue: unrecognized ownership or payload; retained' \ - "${temporary}/output" -done -# Identity drift, a concurrent edit after the first read, or an unreadable -# final read retains the queue. -retire_playtester() { - reset_case - jq '.merge_queue = []' "${repositories_config}" >"${temporary}/retired.json" - mv "${temporary}/retired.json" "${repositories_config}" - printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" -} -for filter in '.id = 999' '.full_name = "foreign/playtester"' '.archived = true'; do - retire_playtester - jq "${filter}" "${temporary}/playtester-metadata.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/playtester-metadata.json" - delete_removed_merge_queue_rulesets >"${temporary}/output" - [[ $(writes) == '[]' ]] - grep -Fxq 'SKIP atrinik/playtester 08 - Merge queue: repository identity or archive state changed; retained' \ - "${temporary}/output" -done -for filter in '.enforcement = "disabled"' '.source_type = "Organization"' \ - '.rules[0].parameters.max_entries_to_merge = 1'; do - retire_playtester - jq "${filter}" "${temporary}/playtester-rule.json" >"${temporary}/playtester-later-rule.json" - delete_removed_merge_queue_rulesets >"${temporary}/output" - [[ $(writes) == '[]' ]] - grep -Fxq 'SKIP atrinik/playtester 08 - Merge queue: rule changed during retirement preflight; retained' \ - "${temporary}/output" - # The final read happens after the identity fence. - jq -se ' - [.[] | .endpoint] as $calls | - ($calls | index("repos/atrinik/playtester")) < - ($calls | rindex("repos/atrinik/playtester/rulesets/8")) - ' "${log}" >/dev/null -done -retire_playtester -touch "${temporary}/playtester-later-unreadable" -expect_failure 'merge-queue final retirement read failed; retained: playtester' \ - delete_removed_merge_queue_rulesets - -# Queued repositories and repositories without the rule are left alone. -reset_case -printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" -delete_removed_merge_queue_rulesets >"${temporary}/output" -[[ $(writes) == '[]' ]] -if grep -Fq 'repos/atrinik/playtester/' "${log}"; then - echo 'retirement must not inspect a queued repository' >&2 - exit 1 -fi - -# Required CI stops requiring a current branch only where the queue protects -# the branch, in both policy scopes. -upsert_repository_ruleset() { - cp "$2" "${temporary}/captured/repository-$1-$(jq -r .name "$2")" -} -upsert_organization_ruleset() { - cp "$1" "${temporary}/captured/organization-$(jq -r .name "$1")" -} -delete_retired_repository_required_ci() { :; } -delete_stale_repository_maintenance_rulesets() { :; } -delete_stale_repository_advisory_rulesets() { :; } -delete_managed_organization_rulesets() { :; } -delete_managed_repository_rulesets() { :; } -publish_required_ci() { - rm -f "${temporary}/captured/"* - publish_repository_rulesets >"${temporary}/output" - publish_organization_rulesets >>"${temporary}/output" -} -assert_playtester_strict() { - local strict=$1 scope - for scope in repository-playtester-03\ -\ Required\ CI organization-03\ -\ Required\ CI\ -\ playtester; do - jq -e --argjson strict "${strict}" ' - .rules[0].parameters.strict_required_status_checks_policy == $strict and - .rules[0].parameters.required_status_checks == - [{context: "Playtester validation", integration_id: 15368}, - {context: "Conventional PR title", integration_id: 15368}] - ' "${temporary}/captured/${scope}" >/dev/null - done - for scope in repository-observatory-03\ -\ Required\ CI organization-03\ -\ Required\ CI\ -\ observatory; do - jq -e '.rules[0].parameters.strict_required_status_checks_policy == true' \ - "${temporary}/captured/${scope}" >/dev/null - done -} -# Applying relaxes required CI only after a fresh read shows the exact queue. -reset_case -printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" -publish_required_ci -assert_playtester_strict false -for state in missing disabled scoped-away foreign modified; do - reset_case - printf '[{"id":8,"name":"08 - Merge queue"}]\n' >"${temporary}/playtester-list.json" - case ${state} in - missing) printf '[]\n' >"${temporary}/playtester-list.json" ;; - disabled) filter='.enforcement = "disabled"' ;; - scoped-away) filter='.conditions.ref_name.include = ["refs/heads/other"]' ;; - foreign) filter='.source_type = "Organization"' ;; - modified) filter='.rules[0].parameters.grouping_strategy = "HEADGREEN"' ;; - esac - if [[ ${state} != missing ]]; then - jq "${filter}" "${temporary}/playtester-rule.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/playtester-rule.json" - fi - publish_required_ci - assert_playtester_strict true - grep -Fxq 'SKIP atrinik/playtester 08 - Merge queue: queue not verified; required CI stays strict' \ - "${temporary}/output" -done -# A plan reports the queue publisher's planned installation. -reset_case -apply=false -printf '[]\n' >"${temporary}/playtester-list.json" -publish_required_ci -assert_playtester_strict false -# A listed but inactive repository gets no queue, so its required CI stays strict. -reset_case -active_repository_ids=([observatory]=1) -publish_required_ci -assert_playtester_strict true - -# Install the queue before required CI is relaxed, and retire it only after -# required CI is restored. Neither step belongs to one policy scope. -order=$(grep -nE '^(publish_merge_queue_rulesets|if \[\[ \$\{policy_scope\} == organization \]\]; then|publish_security_merge_rulesets|delete_removed_merge_queue_rulesets)$' \ - "${source_root}/bin/publish" | cut -d: -f2-) -[[ ${order} == $'publish_merge_queue_rulesets\nif [[ ${policy_scope} == organization ]]; then\npublish_security_merge_rulesets\ndelete_removed_merge_queue_rulesets' ]] - -# Team offers merge queue only for public repositories; fail before any write. -sed -n '/^# Team offers merge queue only/,/^done < <(jq -r .\.merge_queue\[\]. /p' \ - "${source_root}/bin/publish" >"${temporary}/preflight.sh" -grep -Fq 'merge queue requires a public repository' "${temporary}/preflight.sh" -run_preflight() { - ( - # shellcheck source=/dev/null - source "${temporary}/preflight.sh" - ) -} -reset_case -declare -A active_repository_visibility=([observatory]=private [playtester]=public) -run_preflight -active_repository_visibility[playtester]=private -expect_failure 'merge queue requires a public repository on the team plan: playtester' run_preflight -organization_plan=enterprise -run_preflight -organization_plan=team -active_repository_visibility[playtester]=private -active_repository_ids=([observatory]=1) -run_preflight -echo 'Merge-queue publisher tests passed.' diff --git a/tests/publish-planning.sh b/tests/publish-planning.sh deleted file mode 100755 index f9ae8e2..0000000 --- a/tests/publish-planning.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -input= -while (($#)); do - case $1 in - -H) - shift 2 - ;; - --input) - input=$2 - shift 2 - ;; - graphql) - shift - ;; - *) - echo "unexpected gh argument: $1" >&2 - exit 1 - ;; - esac -done -[[ -n ${input} ]] || exit 1 - -query=$(jq -r '.query' "${input}") -if [[ ${PLANNING_SCENARIO:-initial} == partial ]] && \ - [[ ${query} == query\(\$id:ID\!\)* ]]; then - jq -n --slurpfile config "${PLANNING_CONFIG:?}" ' - $config[0] as $config | - { - data: { - node: { - fields: { - nodes: ( - ( - [ - "Title", - "Repository", - "Milestone", - "Assignees", - "Reviewers", - "Linked pull requests" - ] | - map({id: ("PROJECT-FIELD-" + .), name: .}) - ) + [{ - id: "PROJECT-FIELD-Status", - name: "Status", - dataType: "SINGLE_SELECT", - options: [ - $config.project.statuses[] | - { - id: ("STATUS-" + .name), - name, - color, - description - } - ] - }] - ) - }, - views: { - nodes: [{ - id: "DEFAULT-VIEW", - name: "View 1", - layout: "TABLE_LAYOUT", - filter: null, - fields: {nodes: []} - }] - } - } - } - } - ' - exit -fi - -jq -n --slurpfile config "${PLANNING_CONFIG:?}" ' - $config[0] as $config | - { - data: { - organization: { - id: "ORG", - issueTypes: { - nodes: [ - $config.issue_types[] | - select(.name != "Initiative") | - { - id: ("TYPE-" + .name), - name, - description, - color, - isEnabled: .enabled - } - ] - }, - issueFields: { - nodes: [ - $config.issue_fields[] | - { - id: ("FIELD-" + .name), - name, - description, - dataType: .data_type, - visibility: "ORG_ONLY" - } + - if has("options") then - {options: [.options[] | . + {id: ("OPTION-" + .name)}]} - else - {} - end - ] - }, - projectsV2: { - nodes: ( - if env.PLANNING_SCENARIO == "partial" then - [{ - id: "PROJECT", - number: 1, - title: $config.project.title, - shortDescription: $config.project.short_description, - readme: $config.project.readme, - public: $config.project.public, - closed: false - }] - else - [] - end - ) - } - } - } - } -' -EOF -chmod +x "${temporary}/bin/gh" - -output=$( - PATH="${temporary}/bin:${PATH}" \ - PLANNING_CONFIG="${root}/config/planning.json" \ - "${root}/bin/publish-planning" -) - -grep -Fq 'PLAN create organization issue type Initiative' <<<"${output}" -grep -Fq 'PLAN update organization issue field Priority' <<<"${output}" -grep -Fq 'PLAN create organization project Atrinik work' <<<"${output}" -[[ $(grep -c '^PLAN create shared project view ' <<<"${output}") == 6 ]] - -partial_output=$( - PATH="${temporary}/bin:${PATH}" \ - PLANNING_CONFIG="${root}/config/planning.json" \ - PLANNING_SCENARIO=partial \ - "${root}/bin/publish-planning" -) - -for field in Priority Effort 'Start date' 'Target date'; do - grep -Fq "PLAN link organization issue field ${field} to Atrinik work" \ - <<<"${partial_output}" -done -grep -Fq 'PLAN update shared project view Triage' <<<"${partial_output}" -[[ $(grep -c '^PLAN create shared project view ' <<<"${partial_output}") == 5 ]] -grep -Fq 'Project planning configuration is converged (project 1).' \ - <<<"${partial_output}" - -echo "Planning publisher emits the expected initial and partial-project plans." diff --git a/tests/publish-policy-comparison.sh b/tests/publish-policy-comparison.sh deleted file mode 100755 index cfdc2ba..0000000 --- a/tests/publish-policy-comparison.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env bash - -# Production functions consume the fixture globals. -# shellcheck disable=SC2034 -set -euo pipefail -source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -sed -n '/^converge_organization_settings() {/,/^organization_metadata=/p' \ - "${source_root}/bin/publish" | sed '$d' >"${temporary}/functions.sh" -sed -n '/^list_rulesets() {/,/^}/p' "${source_root}/bin/publish" >>"${temporary}/functions.sh" -# shellcheck source=/dev/null -source "${temporary}/functions.sh" -root=${source_root} -organization=atrinik -temporary_files=() -log=${temporary}/writes -reads=${temporary}/reads -input=${temporary}/desired.json -live=${temporary}/live.json -later=${temporary}/later.json -scope=organization - -github_api() { - printf '%s\n' "$1" >>"${reads}" - case $1 in - orgs/atrinik/rulesets | 'repos/atrinik/example/rulesets?includes_parents=false') - jq '[{id:42,name:.name}]' "${input}" ;; - */rulesets/42) - if [[ -f ${later} ]] && (($(grep -c '/rulesets/42' "${reads}") > 1)); then - cat "${later}" - else cat "${live}"; fi ;; - *) cat "${live}" ;; - esac -} -run_api() { - jq -cn --arg method "$1" --arg endpoint "$2" --slurpfile body "$3" \ - '{method:$method,endpoint:$endpoint,body:$body[0]}' >>"${log}" -} -reset_case() { - : >"${log}" - : >"${reads}" - rm -f "${later}" - cp "${root}/config/rulesets/$1.json" "${input}" - local source_type=Organization source=atrinik - if [[ ${scope} == repository ]]; then source_type=Repository; source=atrinik/example; fi - jq --arg source_type "${source_type}" --arg source "${source}" ' - . + {id:42,source_type:$source_type,source:$source,updated_at:"before"} | - if $source_type == "Repository" then .current_user_can_bypass = "pull_requests_only" else . end | - .bypass_actors |= map(.actor_id = null) | - .rules |= map(if .type == "pull_request" then - .parameters += {required_reviewers:[],allowed_merge_methods:["rebase","squash","merge"], - require_extra_approval_for_unattributed_changes:true} - elif .type == "required_status_checks" then .parameters.do_not_enforce_on_create = false - else . end) - ' "${input}" >"${live}" -} -change_live() { - jq "$1" "${live}" >"${temporary}/changed" - mv "${temporary}/changed" "${live}" -} -upsert() { - if [[ ${scope} == organization ]]; then upsert_organization_ruleset "${input}" - else upsert_repository_ruleset example "${input}"; fi -} -for scope in organization repository; do - for template in pull-request-gate required-ci; do - reset_case "${template}" - upsert >"${temporary}/output" - test ! -s "${log}" - change_live '.bypass_actors |= map(.actor_id = 1) | .rules[].parameters |= del(.required_reviewers, .allowed_merge_methods, .require_extra_approval_for_unattributed_changes, .do_not_enforce_on_create)' - upsert >"${temporary}/output" - test ! -s "${log}" - reset_case "${template}" - # Real scope drift retains the exact live extension fields on the PUT. - change_live '.conditions.ref_name.include = ["refs/heads/old"]' - upsert >"${temporary}/output" - jq -se --slurpfile live "${live}" --slurpfile desired "${input}" ' - length == 1 and .[0].method == "PUT" and - .[0].body.conditions == $desired[0].conditions and - .[0].body.rules == $live[0].rules and - (.[0].body | has("id") or has("updated_at") or has("current_user_can_bypass") | not) - ' "${log}" >/dev/null - done - for mutation in \ - '.rules[0].parameters.future_gate = true' \ - '.rules[0].parameters.required_reviewers = [{reviewer:{id:42,type:"Team"},minimum_approvals:1}]' \ - '.rules[0].parameters.require_extra_approval_for_unattributed_changes = false' \ - '.rules[0].parameters.allowed_merge_methods = ["squash"]' \ - '.rules[0].parameters.required_reviewers = null' \ - '.rules += [{type:"required_deployments",parameters:{required_deployment_environments:["production"]}}]' \ - '.rules += [.rules[0]]' \ - '.conditions.repository_property = {future:true}' \ - '.bypass_actors[0].future_permission = true' \ - '.future_control = true' \ - '.source = "foreign"' \ - '.id = 99'; do - reset_case pull-request-gate - change_live "${mutation}" - if upsert >"${temporary}/output" 2>&1; then - echo "unexpectedly accepted ${scope}: ${mutation}" >&2; exit 1 - fi - test ! -s "${log}" - done - for mutation in \ - '.rules[0].parameters.do_not_enforce_on_create = true' \ - '.rules[0].parameters.required_status_checks = [{context:"Unknown", integration_id:15368, future_control:true}]'; do - reset_case required-ci - change_live "${mutation}" - if upsert >"${temporary}/output" 2>&1; then exit 1; fi - test ! -s "${log}" - done - # A concurrent restriction appears between the initial read and PUT. - reset_case pull-request-gate - change_live '.enforcement = "disabled"' - jq '.rules[0].parameters.required_reviewers = [{reviewer:{id:42,type:"Team"},minimum_approvals:1}]' \ - "${live}" >"${later}" - if upsert >"${temporary}/output" 2>&1; then exit 1; fi - test ! -s "${log}" - # Known read-only metadata remains part of the complete concurrency fence. - reset_case pull-request-gate - change_live '.enforcement = "disabled"' - jq '.current_user_can_bypass = "never"' "${live}" >"${later}" - if upsert >"${temporary}/output" 2>&1; then exit 1; fi - test ! -s "${log}" -done -# Repository defaults and org workflow permissions ignore unrelated metadata, -# avoid converged writes, and still report real drift. -for settings in repository-defaults actions-workflow; do - : >"${log}" - jq '. + {id:42, unrelated:"metadata"}' "${root}/config/${settings}.json" >"${live}" - converge_settings PATCH settings "${root}/config/${settings}.json" >"${temporary}/output" - test ! -s "${log}" - jq 'del(.[keys[0]])' "${root}/config/${settings}.json" >"${live}" - converge_settings PATCH settings "${root}/config/${settings}.json" >"${temporary}/output" - test "$(wc -l <"${log}")" = 1 -done -echo 'Policy comparison and preservation tests passed.' diff --git a/tests/publish-repository-properties.sh b/tests/publish-repository-properties.sh deleted file mode 100755 index 3d6d890..0000000 --- a/tests/publish-repository-properties.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -endpoint= -jq_filter= -scenario=${GH_TEST_SCENARIO:-pass} -while (($#)); do - case $1 in - -H) - shift 2 - ;; - --paginate) - shift - ;; - --jq) - jq_filter=$2 - shift 2 - ;; - *) - endpoint=$1 - shift - ;; - esac -done - -case ${endpoint} in -orgs/atrinik/properties/schema) - printf '[]\n' - ;; -orgs/atrinik/repos?*) - case ${jq_filter} in - '.[].name') - if [[ ${scenario} == extra-active ]]; then - jq -r '.repositories | keys[], "unmanaged"' "${PROPERTIES_CONFIG:?}" - elif [[ ${scenario} == missing-archived ]]; then - jq -r '.repositories | keys[] | select(. != "legacy-client")' \ - "${PROPERTIES_CONFIG:?}" - else - jq -r '.repositories | keys[]' "${PROPERTIES_CONFIG:?}" - fi - ;; - *'@tsv'*) - if [[ ${scenario} == extra-active ]]; then - jq -r '.repositories | to_entries[] | - [.key, (.value.lifecycle == "archived" | tostring), - "false", "public", "false", "false", "true", "true", "true"] | - @tsv' \ - "${PROPERTIES_CONFIG:?}" - printf 'unmanaged\tfalse\tfalse\tpublic\tfalse\tfalse\ttrue\ttrue\ttrue\n' - elif [[ ${scenario} == missing-archived ]]; then - jq -r '.repositories | to_entries[] | - select(.key != "legacy-client") | - [.key, (.value.lifecycle == "archived" | tostring), - "false", "public", "false", "false", "true", "true", "true"] | - @tsv' \ - "${PROPERTIES_CONFIG:?}" - elif [[ ${scenario} == temporary ]]; then - jq -r '.repositories | to_entries[] | - [.key, (.value.lifecycle == "archived" | tostring), - "false", "public", "false", "false", "true", "true", "true"] | - @tsv' \ - "${PROPERTIES_CONFIG:?}" - printf 'classic-ghsa-8533-3vg8-r287\tfalse\ttrue\tprivate\tfalse\tfalse\tfalse\tfalse\tfalse\n' - else - jq -r '.repositories | to_entries[] | - [.key, (.value.lifecycle == "archived" | tostring), - "false", "public", "false", "false", "true", "true", "true"] | - @tsv' \ - "${PROPERTIES_CONFIG:?}" - fi - ;; - *) - exit 1 - ;; - esac - ;; -repos/atrinik/*/properties/values) - printf '[]\n' - ;; -*) - echo "unexpected endpoint: ${endpoint}" >&2 - exit 1 - ;; -esac -EOF -chmod +x "${temporary}/bin/gh" - -output=$( - PATH="${temporary}/bin:${PATH}" \ - PROPERTIES_CONFIG="${root}/config/repository-properties.json" \ - "${root}/bin/publish-repository-properties" -) - -[[ $(grep -c '^PLAN PUT /orgs/atrinik/properties/schema/' <<<"${output}") == 4 ]] -expected_repositories=$(jq '.repositories | length' \ - "${root}/config/repository-properties.json") -[[ $(grep -c '^PLAN PATCH /orgs/atrinik/properties/values ' <<<"${output}") == "${expected_repositories}" ]] - -temporary_output=$( - GH_TEST_SCENARIO=temporary \ - PATH="${temporary}/bin:${PATH}" \ - PROPERTIES_CONFIG="${root}/config/repository-properties.json" \ - "${root}/bin/publish-repository-properties" -) -[[ $(grep -c '^PLAN PATCH /orgs/atrinik/properties/values ' <<<"${temporary_output}") == "${expected_repositories}" ]] - -if GH_TEST_SCENARIO=extra-active \ - PATH="${temporary}/bin:${PATH}" \ - PROPERTIES_CONFIG="${root}/config/repository-properties.json" \ - "${root}/bin/publish-repository-properties" \ - >"${temporary}/extra.out" 2>"${temporary}/extra.err"; then - echo "expected extra active repository to fail closed" >&2 - exit 1 -fi -grep -Fq \ - 'live active repository is not in the property inventory: atrinik/unmanaged' \ - "${temporary}/extra.err" - -missing_output=$( - GH_TEST_SCENARIO=missing-archived \ - PATH="${temporary}/bin:${PATH}" \ - PROPERTIES_CONFIG="${root}/config/repository-properties.json" \ - "${root}/bin/publish-repository-properties" -) -grep -Fq 'SKIP atrinik/legacy-client is an absent archived repository' \ - <<<"${missing_output}" -[[ $(grep -c '^PLAN PATCH /orgs/atrinik/properties/values ' <<<"${missing_output}") == $((expected_repositories - 1)) ]] - -echo "Repository-property publisher plans every definition and repository value." diff --git a/tests/publish-retired-required-ci.sh b/tests/publish-retired-required-ci.sh deleted file mode 100755 index bc128d4..0000000 --- a/tests/publish-retired-required-ci.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env bash - -# Production functions consume these fixture globals. -# shellcheck disable=SC2034 -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -source_root=${ATRINIK_PUBLISH_TEST_ROOT:-${root}} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -sed -n '/^converge_organization_settings() {/,/^organization_metadata=/p' \ - "${source_root}/bin/publish" | sed '$d' >"${temporary}/functions.sh" -sed -n '/^list_rulesets() {/,/^}/p' "${source_root}/bin/publish" >>"${temporary}/functions.sh" -# shellcheck source=/dev/null -source "${temporary}/functions.sh" -root=${temporary}/fixture -mkdir -p "${root}/config" -cp -R "${source_root}/config/rulesets" "${root}/config/rulesets" -organization=atrinik -organization_plan=free -repositories_config=${root}/config/repositories.json -advisory_merge_windows_config=${root}/config/advisory-merge-windows.json -printf '{"repositories":[]}\n' >"${advisory_merge_windows_config}" -active_repositories=(web-platform) -declare -A active_repository_ids=([web-platform]=123) -temporary_files=() -log=${temporary}/api.jsonl -repository_has_advisory_merge_window() { return 1; } -upsert_repository_ruleset() { :; } -delete_stale_repository_maintenance_rulesets() { :; } -delete_stale_repository_advisory_rulesets() { :; } -github_api() { - jq -cn --arg endpoint "$1" '{method:"GET",endpoint:$endpoint}' >>"${log}" - case $1 in - 'repos/atrinik/web-platform/rulesets?includes_parents=false') - if [[ -e ${temporary}/deleted ]]; then echo '[]'; else cat "${temporary}/list.json"; fi ;; - repos/atrinik/web-platform) - cat "${temporary}/metadata.json" ;; - repos/atrinik/web-platform/rulesets/3) - if [[ -e ${temporary}/read-once && -e ${temporary}/changed.json ]]; then - cat "${temporary}/changed.json" - else - cat "${temporary}/rule.json" - fi - touch "${temporary}/read-once" ;; - *) echo "unexpected endpoint: $1" >&2; return 99 ;; - esac -} -run_api() { - [[ $1 == DELETE && $2 == repos/atrinik/web-platform/rulesets/3 ]] - if ${apply}; then - jq -cn --arg endpoint "$2" '{method:"DELETE",endpoint:$endpoint}' >>"${log}" - touch "${temporary}/deleted" - else - jq -cn --arg endpoint "$2" '{method:"PLAN",endpoint:$endpoint}' >>"${log}" - fi -} -reset_case() { - : >"${log}" - rm -f "${temporary}/deleted" "${temporary}/read-once" "${temporary}/changed.json" - apply=true - active_repository_ids=([web-platform]=123) - printf '{"pull_request_gate":["web-platform"],"required_ci":{},"release_tags":[],"maintenance_branches":[]}\n' >"${repositories_config}" - printf '{"retirements":[{"repository":"web-platform","repository_id":123,"ruleset_id":3,"required_ci":["Platform validation","Conventional PR title"]}]}\n' >"${root}/config/retired-required-ci.json" - printf '[{"id":1,"name":"01 - Default branch integrity"},{"id":3,"name":"03 - Required CI"},{"id":5,"name":"Foreign CI"}]\n' >"${temporary}/list.json" - printf '{"id":123,"full_name":"atrinik/web-platform","archived":false}\n' >"${temporary}/metadata.json" - jq '. + {id:3,source_type:"Repository",source:"atrinik/web-platform"} | - .bypass_actors[0].actor_id = null | - .rules[0].parameters += {do_not_enforce_on_create:false, - required_status_checks:[{context:"Conventional PR title",integration_id:15368}, - {context:"Platform validation",integration_id:15368}]}' \ - "${root}/config/rulesets/required-ci.json" >"${temporary}/rule.json" -} -assert_retained() { - publish_repository_rulesets >"${temporary}/output" - jq -se 'all(.[]; .method == "GET")' "${log}" >/dev/null - grep -Fq 'retained' "${temporary}/output" -} -reset_case -publish_repository_rulesets >"${temporary}/output" -jq -se '[.[] | select(.method == "DELETE")] == [{method:"DELETE",endpoint:"repos/atrinik/web-platform/rulesets/3"}]' "${log}" >/dev/null -# Converged retirement makes no second deletion. -: >"${log}" -publish_repository_rulesets >"${temporary}/output" -jq -se 'all(.[]; .method == "GET")' "${log}" >/dev/null -reset_case -jq 'del(.rules[0].parameters.do_not_enforce_on_create)' \ - "${temporary}/rule.json" >"${temporary}/implicit-default.json" -mv "${temporary}/implicit-default.json" "${temporary}/rule.json" -publish_repository_rulesets >"${temporary}/output" -jq -se 'any(.[]; .method == "DELETE")' "${log}" >/dev/null -reset_case -apply=false -publish_repository_rulesets >"${temporary}/output" -jq -se '[.[] | select(.method != "GET")] == [{method:"PLAN",endpoint:"repos/atrinik/web-platform/rulesets/3"}]' "${log}" >/dev/null -[[ ! -e ${temporary}/deleted ]] -for filter in \ - '.id = 999' '.source_type = "Organization"' '.source = "foreign/web-platform"' \ - '.name = "Foreign CI"' '.target = "tag"' '.enforcement = "disabled"' \ - '.bypass_actors[0].bypass_mode = "always"' '.bypass_actors[0].actor_id = 2' \ - '.conditions.ref_name.include = ["refs/heads/other"]' \ - '.rules[0].parameters.required_status_checks[0].integration_id = 9' \ - '.rules[0].parameters.required_status_checks[0].context = "Unknown check"' \ - '.rules[0].parameters.strict_required_status_checks_policy = false' \ - '.rules[0].parameters.do_not_enforce_on_create = true' \ - '.rules[0].parameters.do_not_enforce_on_create = null' \ - '.rules[0].parameters.unknown_option = false' '.rules += [{type:"deletion"}]'; do - reset_case - jq "${filter}" "${temporary}/rule.json" >"${temporary}/changed-rule.json" - mv "${temporary}/changed-rule.json" "${temporary}/rule.json" - assert_retained -done -for filter in '.id = 999' '.full_name = "foreign/web-platform"' '.archived = true'; do - reset_case - jq "${filter}" "${temporary}/metadata.json" >"${temporary}/changed-metadata.json" - mv "${temporary}/changed-metadata.json" "${temporary}/metadata.json" - assert_retained -done -reset_case -jq '.rules[0].parameters.required_status_checks[0].context = "Concurrent change"' \ - "${temporary}/rule.json" >"${temporary}/changed.json" -assert_retained -reset_case -jq '.retirements[0].repository_id = 999' "${root}/config/retired-required-ci.json" >"${temporary}/wrong-record.json" -mv "${temporary}/wrong-record.json" "${root}/config/retired-required-ci.json" -assert_retained -reset_case -printf '{"retirements":[]}\n' >"${root}/config/retired-required-ci.json" -assert_retained -grep -Fq 'config/retired-required-ci.json' "${temporary}/output" -reset_case -printf '[{"id":3,"name":"03 - Required CI"},{"id":4,"name":"03 - Required CI"}]\n' >"${temporary}/list.json" -if publish_repository_rulesets >"${temporary}/output" 2>&1; then - echo 'expected ambiguous live ruleset inventory to fail' >&2 - exit 1 -fi -jq -se 'all(.[]; .method == "GET")' "${log}" >/dev/null -grep -Fq 'ambiguous complete ruleset inventory' "${temporary}/output" -reset_case -printf '[{"id":4,"name":"03 - Required CI"}]\n' >"${temporary}/list.json" -assert_retained -# Still-active CI and repositories excluded from the active identity map are untouched. -reset_case -jq '.required_ci["web-platform"] = ["Platform validation"]' "${repositories_config}" >"${temporary}/active.json" -mv "${temporary}/active.json" "${repositories_config}" -publish_repository_rulesets >"${temporary}/output" -[[ ! -s ${log} ]] -reset_case -active_repository_ids=() -publish_repository_rulesets >"${temporary}/output" -[[ ! -s ${log} ]] -echo 'Required-CI retirement publisher tests passed.' diff --git a/tests/publish-ruleset-pagination.sh b/tests/publish-ruleset-pagination.sh deleted file mode 100755 index 9e49a31..0000000 --- a/tests/publish-ruleset-pagination.sh +++ /dev/null @@ -1,270 +0,0 @@ -#!/usr/bin/env bash - -# Sourced production functions consume these fixture globals. -# shellcheck disable=SC2034 -set -euo pipefail -source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -source_root=${ATRINIK_PUBLISH_TEST_ROOT:-${source_root}} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -root=${temporary}/fixture -mkdir -p "${root}/config" -cp -R "${source_root}/config/." "${root}/config/" -cp -R "${source_root}/lib" "${root}/lib" -sed -n '/^converge_organization_settings() {/,/^organization_metadata=/p' \ - "${source_root}/bin/publish" | sed '$d' >"${temporary}/functions.sh" -sed -n '/^list_rulesets() {/,/^}/p' "${source_root}/bin/publish" >>"${temporary}/functions.sh" -# shellcheck source=/dev/null -source "${temporary}/functions.sh" -organization=atrinik -organization_plan=free -apply=true -temporary_files=() -repositories_config=${root}/config/repositories.json -security_merge_config=${root}/config/security-merge-protection.json -advisory_merge_windows_config=${root}/config/advisory-merge-windows.json -api_log=${temporary}/api.jsonl -active_repositories=(content-toolkit) -declare -A active_repository_ids=([content-toolkit]=123) -# The first 30 entries are foreign policies. Managed entries occur only on the -# next page, matching GitHub's default page size and the reported duplicate bug. -jq -cn '[range(100;130) | {id:.,name:("Foreign policy " + tostring)}]' >"${temporary}/first-page.json" -github_api() { - local endpoint=$1 - shift - jq -cn --arg endpoint "${endpoint}" '{method:"GET",endpoint:$endpoint}' >>"${api_log}" - case ${endpoint} in - orgs/atrinik/rulesets | 'repos/atrinik/content-toolkit/rulesets?includes_parents=false') - [[ $# == 1 && $1 == --paginate ]] || { - echo 'inventory must use supported --paginate without --slurp' >&2 - return 99 - } - [[ ${page_state} != empty ]] || return 0 - cat "${temporary}/first-page.json" - case ${page_state} in - valid) cat "${temporary}/second-page.json" ;; - failed) echo 'gh: later ruleset page failed (HTTP 503)' >&2; return 1 ;; - malformed) echo '{' ;; - object) echo '{"message":"API error"}' ;; - null) echo 'null' ;; - nested) echo '[[{"id":8,"name":"Nested"}]]' ;; - invalid-id) echo '[{"id":null,"name":"Invalid"}]' ;; - fractional-id) echo '[{"id":8.5,"name":"Invalid"}]' ;; - invalid-name) echo '[{"id":8,"name":null}]' ;; - duplicate-id) echo '[{"id":100,"name":"Changed name"}]' ;; - duplicate-name) echo '[{"id":8,"name":"Foreign policy 100"}]' ;; - *) return 99 ;; - esac - ;; - orgs/atrinik/rulesets/1 | orgs/atrinik/rulesets/2 | orgs/atrinik/rulesets/4 | orgs/atrinik/rulesets/5) - local template - case ${endpoint##*/} in - 1) template=default-branch-integrity ;; - 2) template=default-branch-linear-history ;; - 4) template=pull-request-gate ;; - 5) template=immutable-release-tags ;; - esac - jq --argjson id "${endpoint##*/}" ' - . + {id:$id,source_type:"Organization",source:"atrinik",enforcement:"disabled"} | - .conditions.repository_name = {include:[],exclude:[],protected:false} - ' "${root}/config/rulesets/${template}.json" ;; - orgs/atrinik/rulesets/31 | repos/atrinik/content-toolkit/rulesets/31) - local source_type=Repository source=atrinik/content-toolkit - if [[ ${endpoint} == orgs/* ]]; then source_type=Organization; source=atrinik; fi - jq --arg source_type "${source_type}" --arg source "${source}" ' - . + {id:31,source_type:$source_type,source:$source,enforcement:"disabled"} - ' "${root}/config/rulesets/default-branch-integrity.json" ;; - repos/atrinik/content-toolkit) - echo '{"id":123,"full_name":"atrinik/content-toolkit","archived":false,"default_branch":"main"}' ;; - repos/atrinik/content-toolkit/rulesets/3 | \ - repos/atrinik/content-toolkit/rulesets/6 | repos/atrinik/content-toolkit/rulesets/7) - cat "${temporary}/rule-${endpoint##*/}.json" ;; - *) echo "unexpected API endpoint: ${endpoint}" >&2; return 99 ;; - esac -} -run_api() { - local payload=null - [[ -z ${3:-} ]] || payload=$(cat "$3") - jq -cn --arg method "$1" --arg endpoint "$2" --argjson payload "${payload}" \ - '{method:$method,endpoint:$endpoint,payload:$payload}' >>"${api_log}" - [[ ${write_failed} != true ]] -} -reset_case() { - : >"${api_log}" - page_state=valid - write_failed=false - active_repositories=(content-toolkit) - active_repository_ids=([content-toolkit]=123) - echo '[]' >"${temporary}/second-page.json" - echo '{"repositories":[]}' >"${advisory_merge_windows_config}" - echo '{"pull_request_gate":["content-toolkit"],"required_ci":{"content-toolkit":["Toolkit validation"]},"release_tags":[],"maintenance_branches":[]}' >"${repositories_config}" - echo '{"dependency_review":["content-toolkit"],"code_scanning":["content-toolkit"],"activation":{"dependency_review":{"content-toolkit":"enforced"},"code_scanning":{"content-toolkit":"enforced"}}}' >"${security_merge_config}" - echo '{"retirements":[{"repository":"content-toolkit","repository_id":123,"ruleset_id":3,"required_ci":["Toolkit validation"]}]}' >"${root}/config/retired-required-ci.json" - for pair in '3 required-ci' '6 code-scanning' '7 dependency-review'; do - read -r id template <<<"${pair}" - jq --argjson id "${id}" '. + {id:$id,source_type:"Repository",source:"atrinik/content-toolkit"} | - if $id == 3 then .rules[0].parameters.required_status_checks = [{context:"Toolkit validation",integration_id:15368}] else . end' \ - "${root}/config/rulesets/${template}.json" >"${temporary}/rule-${id}.json" - done -} -assert_no_writes() { - jq -se 'all(.[]; .method == "GET")' "${api_log}" >/dev/null -} -# Ordinary repository/org upserts must update the existing off-page identity; -# complete absence alone permits POST. -for scope in repository organization; do - for found in true false; do - reset_case - if ${found}; then - echo '[{"id":31,"name":"01 - Default branch integrity"}]' >"${temporary}/second-page.json" - fi - if [[ ${scope} == repository ]]; then - upsert_repository_ruleset content-toolkit "${root}/config/rulesets/default-branch-integrity.json" - endpoint=repos/atrinik/content-toolkit/rulesets - else - upsert_organization_ruleset "${root}/config/rulesets/default-branch-integrity.json" - endpoint=orgs/atrinik/rulesets - fi - method=POST - if ${found}; then method=PUT; endpoint+=/31; fi - jq -se --arg method "${method}" --arg endpoint "${endpoint}" ' - [.[] | select(.method != "GET")] | length == 1 and .[0].method == $method and .[0].endpoint == $endpoint' "${api_log}" >/dev/null - done -done -# Security gate convergence, restoration, and retirement share full discovery -# in both scopes. Foreign same-name detail remains retained after discovery. -for policy_scope in organization repository; do - for state in converged disabled retired foreign; do - reset_case - echo '[{"id":6,"name":"06 - CodeQL security"},{"id":7,"name":"07 - Dependency review"}]' >"${temporary}/second-page.json" - if [[ ${state} == disabled ]]; then - for id in 6 7; do - jq '.enforcement = "disabled"' "${temporary}/rule-${id}.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/rule-${id}.json" - done - elif [[ ${state} == retired || ${state} == foreign ]]; then - echo '{"dependency_review":[],"code_scanning":[],"activation":{"dependency_review":{},"code_scanning":{}}}' >"${security_merge_config}" - if [[ ${state} == foreign ]]; then - for id in 6 7; do - jq '.source = "foreign/content-toolkit"' "${temporary}/rule-${id}.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/rule-${id}.json" - done - fi - fi - publish_security_merge_rulesets >"${temporary}/output" - case ${state} in - converged | foreign) assert_no_writes ;; - disabled | retired) - method=PUT - [[ ${state} != retired ]] || method=DELETE - jq -se --arg method "${method}" ' - [.[] | select(.method != "GET")] | length == 2 and - all(.[]; .method == $method) and - ([.[].endpoint] | sort) == ["repos/atrinik/content-toolkit/rulesets/6","repos/atrinik/content-toolkit/rulesets/7"]' "${api_log}" >/dev/null ;; - esac - done -done -# A recorded aggregate on a later page is retired only when its exact payload -# and repository provenance still match, leaving all foreign policies intact. -for state in owned foreign; do - reset_case - echo '[{"id":3,"name":"03 - Required CI"}]' >"${temporary}/second-page.json" - echo '{"pull_request_gate":[],"required_ci":{},"release_tags":[],"maintenance_branches":[]}' >"${repositories_config}" - if [[ ${state} == foreign ]]; then - jq '.source = "foreign/content-toolkit"' "${temporary}/rule-3.json" >"${temporary}/changed.json" - mv "${temporary}/changed.json" "${temporary}/rule-3.json" - fi - delete_retired_repository_required_ci >"${temporary}/output" - if [[ ${state} == foreign ]]; then assert_no_writes; else - jq -se '[.[] | select(.method != "GET")] | length == 1 and .[0].method == "DELETE" and .[0].endpoint == "repos/atrinik/content-toolkit/rulesets/3"' "${api_log}" >/dev/null - fi -done -# Scope migration and stale maintenance/advisory removal also see later pages. -for consumer in delete_managed_repository_rulesets delete_managed_organization_rulesets \ - delete_stale_repository_maintenance_rulesets delete_stale_repository_advisory_rulesets; do - reset_case - case ${consumer} in - delete_stale_repository_maintenance_rulesets) name='05 - Maintenance branch - content-toolkit - old' ;; - delete_stale_repository_advisory_rulesets) name='02 - Changes through pull requests - content-toolkit' ;; - *) name='01 - Default branch integrity' ;; - esac - jq -cn --arg name "${name}" '[{id:31,name:$name}]' >"${temporary}/second-page.json" - "${consumer}" content-toolkit - jq -se '[.[] | select(.method != "GET")] | length == 1 and .[0].method == "DELETE" and (.[0].endpoint | endswith("/31"))' "${api_log}" >/dev/null -done -# Propagating inventory failures through parent functions must also preserve -# API write failures instead of continuing a loop after a failed deletion. -for consumer in delete_managed_repository_rulesets delete_managed_organization_rulesets \ - delete_stale_repository_maintenance_rulesets delete_stale_repository_advisory_rulesets \ - delete_retired_repository_required_ci; do - reset_case - write_failed=true - case ${consumer} in - delete_stale_repository_maintenance_rulesets) name='05 - Maintenance branch - content-toolkit - old' ;; - delete_stale_repository_advisory_rulesets) name='02 - Changes through pull requests - content-toolkit' ;; - delete_retired_repository_required_ci) - name='03 - Required CI' - echo '{"required_ci":{}}' >"${repositories_config}" ;; - *) name='01 - Default branch integrity' ;; - esac - jq -cn --arg name "${name}" '[{id:3,name:$name},{id:32,name:"05 - Maintenance branch - content-toolkit - older"}]' >"${temporary}/second-page.json" - if "${consumer}" content-toolkit >"${temporary}/failure" 2>&1; then - echo "expected ${consumer} to propagate the failed DELETE" >&2 - exit 1 - fi - jq -se '[.[] | select(.method != "GET")] | length == 1 and .[0].method == "DELETE"' "${api_log}" >/dev/null -done -# The organization publisher's final stale-policy scan must not miss an -# off-page aggregate, nor mistake off-page desired rules for missing rules. -reset_case -active_repositories=() -echo '{"pull_request_gate":[],"required_ci":{},"release_tags":[],"maintenance_branches":[]}' >"${repositories_config}" -echo '[{"id":1,"name":"01 - Default branch integrity"},{"id":2,"name":"01 - Default branch linear history"},{"id":4,"name":"02 - Changes through pull requests"},{"id":5,"name":"04 - Immutable release tags"},{"id":31,"name":"03 - Required CI - retired"}]' >"${temporary}/second-page.json" -publish_organization_rulesets -jq -se 'all(.[]; .method != "POST") and - ([.[] | select(.method == "DELETE") | .endpoint] == ["orgs/atrinik/rulesets/31"])' "${api_log}" >/dev/null -# No inventory consumer may use an incomplete, malformed or ambiguous page -# stream as proof of absence, even when called from a shell conditional. -for invalid in failed malformed object null nested invalid-id fractional-id invalid-name duplicate-id duplicate-name empty; do - for consumer in upsert_repository_ruleset upsert_organization_ruleset \ - publish_repository_rulesets publish_organization_rulesets publish_security_merge_rulesets \ - delete_retired_repository_required_ci delete_removed_security_merge_rulesets \ - delete_managed_repository_rulesets delete_managed_organization_rulesets \ - delete_stale_repository_maintenance_rulesets delete_stale_repository_advisory_rulesets; do - reset_case - page_state=${invalid} - case ${consumer} in - upsert_repository_ruleset) arguments=(content-toolkit "${root}/config/rulesets/default-branch-integrity.json") ;; - upsert_organization_ruleset) arguments=("${root}/config/rulesets/default-branch-integrity.json") ;; - delete_retired_repository_required_ci) - arguments=() - echo '{"required_ci":{}}' >"${repositories_config}" ;; - delete_removed_security_merge_rulesets) - arguments=() - echo '{"code_scanning":[],"dependency_review":[]}' >"${security_merge_config}" ;; - *) arguments=(content-toolkit) ;; - esac - if "${consumer}" "${arguments[@]}" >"${temporary}/failure" 2>&1; then - echo "expected ${consumer} to reject ${invalid} later-page evidence" >&2 - exit 1 - fi - assert_no_writes - grep -Eq 'cannot read complete ruleset inventory|invalid or ambiguous complete ruleset inventory' "${temporary}/failure" - done -done -# Even an actionable first-page gate cannot be deleted while a later page is -# unreadable: pagination is a complete preflight, not a streaming mutation loop. -cp "${temporary}/first-page.json" "${temporary}/foreign-page.json" -for invalid in failed malformed; do - reset_case - page_state=${invalid} - jq '. + [{id:6,name:"06 - CodeQL security"},{id:7,name:"07 - Dependency review"}]' \ - "${temporary}/foreign-page.json" >"${temporary}/first-page.json" - echo '{"code_scanning":[],"dependency_review":[]}' >"${security_merge_config}" - if delete_removed_security_merge_rulesets >"${temporary}/failure" 2>&1; then - echo 'expected failed full enumeration to prevent first-page retirement' >&2 - exit 1 - fi - assert_no_writes -done -printf 'Ruleset pagination publisher tests passed.\n' diff --git a/tests/publish-security-merge.sh b/tests/publish-security-merge.sh deleted file mode 100755 index 26d2d27..0000000 --- a/tests/publish-security-merge.sh +++ /dev/null @@ -1,1173 +0,0 @@ -#!/usr/bin/env bash - -# Sourced production functions consume the globals below. -# shellcheck disable=SC2034 -set -euo pipefail - -source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -# An override permits testing the integrated candidate from an isolated worktree. -source_root=${ATRINIK_PUBLISH_TEST_ROOT:-${source_root}} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -root=${temporary}/fixture -mkdir -p "${root}/bin" "${root}/config/rulesets" -cp "${source_root}/config/"*.json "${root}/config/" -cp -R "${source_root}/lib" "${root}/lib" -cp "${source_root}/config/rulesets/"*.json "${root}/config/rulesets/" - -# Source production functions without executing validation, authentication or -# live publication. Every API call is replaced below by a fail-closed mock. -sed -n '/^converge_organization_settings() {/,/^organization_metadata=/p' \ - "${source_root}/bin/publish" | sed '$d' >"${temporary}/functions.sh" -sed -n '/^list_rulesets() {/,/^}/p' "${source_root}/bin/publish" >>"${temporary}/functions.sh" -# shellcheck source=/dev/null -source "${temporary}/functions.sh" -# Exercise the production scope dispatch, including its following gate call. -awk ' - /^if \[\[ \$\{policy_scope\} == organization \]\]; then$/ { capture = 1 } - capture { print } - capture && /^publish_security_merge_rulesets$/ { exit } -' "${source_root}/bin/publish" >"${temporary}/dispatch.sh" -[[ -s ${temporary}/dispatch.sh ]] - -organization=atrinik -apply=true -temporary_files=() -security_merge_config=${root}/config/security-merge-protection.json -codeql_advanced_config=${root}/config/codeql-advanced-setup.json -actions_sha_pinning_config=${root}/config/actions-sha-pinning.json -active_repositories=(content-toolkit) -declare -A active_repository_ids=([content-toolkit]=123) -api_log=${temporary}/api.jsonl -readiness_log=${temporary}/readiness.jsonl -export READINESS_LOG=${readiness_log} -export MOCK_API_LOG=${api_log} -export MOCK_ACTIONS_POLICY=${temporary}/actions-policy.json -export MOCK_ACTIONS_SELECTED=${root}/config/actions-selected.json -cat >"${root}/bin/security-readiness" <<'MOCK' -#!/usr/bin/env bash -set -euo pipefail -jq -cn --arg mode "$1" --arg repository "$2" \ - '{mode: $mode, repository: $repository}' >>"${READINESS_LOG}" -if [[ $1 == sha ]]; then - jq -cn '{method: "PROOF", endpoint: "sha"}' >>"${MOCK_API_LOG}" - if [[ ${CHECK_POLICY_STAGED:-false} == true ]]; then - jq -e --slurpfile selected "${MOCK_ACTIONS_SELECTED}" ' - .permissions.allowed_actions == "selected" and - .permissions.enabled_repositories == "all" and - .selected == $selected[0] - ' "${MOCK_ACTIONS_POLICY}" >/dev/null || exit 98 - fi -fi -case ${READINESS_STATUS:-ready} in -ready) echo 'producer evidence ready'; exit 0 ;; -missing) echo 'producer is missing'; exit 1 ;; -failed) echo 'producer failed'; exit 1 ;; -stale) echo 'canary base changed during preflight'; exit 1 ;; -unreadable) echo 'producer evidence unreadable'; exit 2 ;; -*) exit 99 ;; -esac -MOCK -chmod +x "${root}/bin/security-readiness" - -# Minimal live response fixtures preserve the API shapes used by the publisher. -github_api() { - local endpoint=$1 - jq -cn --arg endpoint "${endpoint}" \ - '{method: "GET", endpoint: $endpoint}' >>"${api_log}" - case ${endpoint} in - repos/atrinik/content-toolkit) - if [[ -n ${gate_metadata_after_proof_filter} ]] && - jq -se 'any(.[]; .endpoint | contains("/rules/branches/"))' "${api_log}" >/dev/null; then - [[ ${gate_metadata_after_proof_filter} != unreadable ]] || return 1 - jq "${gate_metadata_after_proof_filter}" <<<"${repository_state}" - elif [[ -n ${gate_metadata_filter} ]]; then - [[ ${gate_metadata_filter} != unreadable ]] || return 1 - jq "${gate_metadata_filter}" <<<"${repository_state}" - else - printf '%s\n' "${repository_state}" - fi - ;; - repos/atrinik/content-toolkit/rules/branches/main | repos/atrinik/content-toolkit/rules/branches/release%2Fcurrent) - if [[ ${effective_state} == covering ]]; then - jq -n --slurpfile codeql "${root}/config/rulesets/code-scanning.json" \ - --slurpfile dependency "${root}/config/rulesets/dependency-review.json" ' - [$codeql[0].rules[] + {ruleset_id: 6}, - $dependency[0].rules[] + {ruleset_id: 7}]' - elif [[ ${effective_state} == different-id ]]; then - jq -n --slurpfile codeql "${root}/config/rulesets/code-scanning.json" \ - --slurpfile dependency "${root}/config/rulesets/dependency-review.json" ' - [$codeql[0].rules[] + {ruleset_id: 600}, - $dependency[0].rules[] + {ruleset_id: 700}]' - else - echo '[]' - fi - ;; - repos/atrinik/content-toolkit/actions/permissions/workflow) - [[ ${workflow_state} != unreadable ]] || return 1 - printf '%s\n' "${workflow_state}" - ;; - repos/atrinik/content-toolkit/code-scanning/default-setup) - if [[ ${codeql_state} == http-* ]]; then - echo "gh: default-setup read failed (HTTP ${codeql_state#http-})" >&2 - return 1 - fi - [[ ${codeql_state} != unreadable ]] || return 1 - printf '%s\n' "${codeql_state}" - ;; - 'repos/atrinik/content-toolkit/rulesets?includes_parents=false') - if [[ ${ruleset_state} == missing ]]; then - echo '[]' - else - jq -n --slurpfile codeql "${root}/config/rulesets/code-scanning.json" \ - --slurpfile dependency "${root}/config/rulesets/dependency-review.json" ' - [{id: 1, name: "01 - Default branch integrity"}, - {id: 3, name: "03 - Required CI"}, - {id: 6, name: $codeql[0].name}, {id: 7, name: $dependency[0].name}]' - fi - ;; - repos/atrinik/content-toolkit/rulesets/6 | repos/atrinik/content-toolkit/rulesets/7) - local template=code-scanning - [[ ${endpoint##*/} != 7 ]] || template=dependency-review - if [[ ${ruleset_state} == pending-branch-race ]]; then - local pending_filter=. pending_initial_filter=. - [[ ${endpoint##*/} != "${gate_update_id}" ]] || pending_initial_filter=${gate_initial_filter} - if [[ ${endpoint##*/} == "${gate_update_id}" ]] && - (( $(jq -s --arg endpoint "${endpoint}" '[.[] | select(.endpoint == $endpoint)] | length' "${api_log}") >= 2 )); then - [[ ${gate_update_filter} != unreadable ]] || return 1 - pending_filter=${gate_update_filter} - fi - jq --argjson id "${endpoint##*/}" --argjson target "${gate_update_id}" \ - --arg branch "$(jq -r '.default_branch' <<<"${repository_state}")" ' - . + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} | - if $id == $target then .conditions.ref_name.include = [("refs/heads/" + $branch)] else . end' \ - "${root}/config/rulesets/${template}.json" | jq "${pending_initial_filter}" | jq "${pending_filter}" - return - elif [[ ${ruleset_state} == restoration-race || ${ruleset_state} == retirement-race ]]; then - local filter=. - if [[ ${endpoint##*/} == "${gate_update_id}" ]] && - (( $(jq -s --arg endpoint "${endpoint}" '[.[] | select(.endpoint == $endpoint)] | length' "${api_log}") >= 2 )); then - [[ ${gate_update_filter} != unreadable ]] || return 1 - filter=${gate_update_filter} - fi - jq --argjson id "${endpoint##*/}" --argjson target "${gate_update_id}" --arg state "${ruleset_state}" ' - . + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} | - if $id == $target and $state == "restoration-race" then .enforcement = "disabled" else . end' \ - "${root}/config/rulesets/${template}.json" | jq "${filter}" - return - elif [[ ${ruleset_state} == api-default-* ]]; then - jq --argjson id "${endpoint##*/}" --arg state "${ruleset_state}" ' - . + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} | - .bypass_actors[0].actor_id = null | - if $id == 7 then - .rules[0].parameters.do_not_enforce_on_create = - (if $state == "api-default-false" then false - elif $state == "api-default-true" then true else null end) | - if $state == "api-default-unknown" then - .rules[0].parameters.do_not_enforce_on_create = false | - .rules[0].parameters.unknown_future_control = false - else . end - else . end' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == exact || ${ruleset_state} == removal-owned ]]; then - jq --argjson id "${endpoint##*/}" \ - '. + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"}' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == removal-owner-null ]]; then - jq --argjson id "${endpoint##*/}" \ - '. + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} | - .bypass_actors[0].actor_id = null' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == removal-foreign ]]; then - jq --argjson id "${endpoint##*/}" \ - '. + {id: $id, source_type: "Organization", source: "atrinik"}' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == removal-id-drift ]]; then - jq '. + {id: 999, source_type: "Repository", source: "atrinik/content-toolkit"}' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == removal-name-collision ]]; then - jq --argjson id "${endpoint##*/}" \ - '. + {id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} | - .rules = [{type: "deletion"}, {type: "non_fast_forward"}]' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == owner-null ]]; then - jq '.bypass_actors[0].actor_id = null' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == foreign-repository-source ]]; then - jq '.source = "foreign/content-toolkit"' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == extra-rule ]]; then - jq '.rules += [{type: "deletion"}]' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == unknown-rule-parameter ]]; then - jq '.rules[0].parameters.unknown_future_control = true' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == unknown-condition ]]; then - jq '.conditions.unknown_future_scope = {}' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == active-wrong-ref ]]; then - jq '.conditions.ref_name.include = ["refs/heads/feature"]' \ - "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == active-drift ]]; then - jq '.conditions.ref_name.include = ["refs/heads/main"]' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == active-bypass-drift ]]; then - jq '.bypass_actors = []' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == unknown-ref-condition ]]; then - jq '.conditions.ref_name.unknown_future_scope = true' "${root}/config/rulesets/${template}.json" - elif [[ ${ruleset_state} == changed-severity ]]; then - if [[ ${template} == code-scanning ]]; then - jq '.rules[0].parameters.code_scanning_tools[0].security_alerts_threshold = "critical"' \ - "${root}/config/rulesets/${template}.json" - else - cat "${root}/config/rulesets/${template}.json" - fi - elif [[ ${ruleset_state} == active-unrelated-gate ]]; then - if [[ ${template} == code-scanning ]]; then - jq '.rules[0].parameters.code_scanning_tools[0].tool = "Another scanner"' \ - "${root}/config/rulesets/${template}.json" - else - jq '.rules[0].parameters.required_status_checks[0].integration_id = 999' \ - "${root}/config/rulesets/${template}.json" - fi - elif [[ ${ruleset_state} == active-without-gate ]]; then - jq '.rules = []' "${root}/config/rulesets/${template}.json" - else - jq '.enforcement = "disabled"' "${root}/config/rulesets/${template}.json" - fi | jq --argjson id "${endpoint##*/}" \ - '{id: $id, source_type: "Repository", source: "atrinik/content-toolkit"} + .' - ;; - orgs/atrinik/actions/permissions) printf '%s\n' "${actions_state}" ;; - orgs/atrinik/actions/permissions/selected-actions) - # Model the API prerequisite: the dormant list cannot be read or changed - # until the publisher has staged conservative selected mode. - [[ $(jq -r '.allowed_actions' <<<"${actions_state}") == selected ]] || return 1 - [[ ${selected_state} != unreadable ]] || return 1 - printf '%s\n' "${selected_state}" - ;; - *) echo "unexpected mock API: ${endpoint}" >&2; return 99 ;; - esac -} - -run_api() { - if [[ $1 == DELETE ]]; then - jq -cn --arg endpoint "$2" '{method: "DELETE", endpoint: $endpoint}' >>"${api_log}" - return - fi - jq -cn --arg method "$1" --arg endpoint "$2" --slurpfile payload "$3" \ - '{method: $method, endpoint: $endpoint, payload: $payload[0]}' >>"${api_log}" - if ${apply}; then - case $2 in - orgs/atrinik/actions/permissions) - actions_state=$(jq --slurpfile payload "$3" '. * $payload[0]' <<<"${actions_state}") - ;; - orgs/atrinik/actions/permissions/selected-actions) - [[ $(jq -r '.allowed_actions' <<<"${actions_state}") == selected ]] || return 1 - selected_state=$(cat "$3") - case ${staging_race} in - disable | replace-repository) - actions_state=$(jq '.sha_pinning_required = false' <<<"${actions_state}") - if [[ ${staging_race} == replace-repository ]]; then - repository_state=$(jq '.id = 999' <<<"${repository_state}") - fi - ;; - malformed) - actions_state=$(jq '.sha_pinning_required = "false"' <<<"${actions_state}") - ;; - esac - ;; - esac - if [[ ${selected_state} != unreadable ]]; then - jq -n --argjson permissions "${actions_state}" --argjson selected "${selected_state}" \ - '{permissions:$permissions, selected:$selected}' >"${MOCK_ACTIONS_POLICY}" - fi - fi -} -reset_case() { - : >"${api_log}" - : >"${readiness_log}" - codeql_state='{"state":"configured","query_suite":"default","languages":["python","javascript-typescript"]}' - ruleset_state=missing - gate_update_id=6 - gate_update_filter=. - gate_initial_filter=. - gate_metadata_filter= - gate_metadata_after_proof_filter= - effective_state=covering - repository_state='{"id":123,"full_name":"atrinik/content-toolkit","archived":false,"default_branch":"main"}' - workflow_state='{"default_workflow_permissions":"write","can_approve_pull_request_reviews":true}' - # Exercise dormant required-gate tooling with explicit test-owned intent. - jq '.dependency_review = .code_scanning | .activation.dependency_review = .activation.code_scanning' \ - "${source_root}/config/security-merge-protection.json" >"${security_merge_config}" - cp "${source_root}/config/codeql-advanced-setup.json" "${codeql_advanced_config}" - echo '{"phase":"pending","canary":null}' >"${actions_sha_pinning_config}" - actions_state='{"enabled_repositories":"selected","allowed_actions":"all","sha_pinning_required":false}' - selected_state=$(cat "${root}/config/actions-selected.json") - sha_pinning_canary= - staging_race= - apply=true - export CHECK_POLICY_STAGED=false - export READINESS_STATUS=ready -} -assert_no_writes() { - jq -se 'all(.[]; .method == "GET")' "${api_log}" >/dev/null -} - -# Production dependency advice cannot install a required gate in either scope; -# old exact owned gates retire without changing the existing CodeQL gate. -for policy_scope in organization repository; do - for state in missing exact api-default-false api-default-true; do - reset_case - cp "${source_root}/config/security-merge-protection.json" "${security_merge_config}" - ruleset_state=${state} - publish_security_merge_rulesets >"${temporary}/production-advisory.txt" - if [[ ${state} == exact || ${state} == api-default-false ]]; then - jq -se '[.[] | select(.method != "GET")] | length == 1 and - .[0].method == "DELETE" and .[0].endpoint == "repos/atrinik/content-toolkit/rulesets/7"' "${api_log}" >/dev/null - else - assert_no_writes - fi - if [[ -s ${readiness_log} ]]; then - jq -se 'all(.[]; .mode != "dependency")' "${readiness_log}" >/dev/null - fi - done -done - -reset_case -converge_codeql_default_setup >"${temporary}/languages.txt" -jq -se ' - [.[] | select(.method == "PATCH")] == [{ - method: "PATCH", - endpoint: "repos/atrinik/content-toolkit/code-scanning/default-setup", - payload: {state: "configured", query_suite: "default", - languages: ["javascript-typescript", "python", "rust"]} - }]' "${api_log}" >/dev/null -reset_case -codeql_state='{"state":"configured","query_suite":"default","languages":["actions","javascript","javascript-typescript","python","typescript"]}' -converge_codeql_default_setup >"${temporary}/languages-aliases.txt" -jq -se '[.[] | select(.method == "PATCH")][0].payload.languages == - ["actions", "javascript-typescript", "python", "rust"]' "${api_log}" >/dev/null -reset_case -codeql_state='{"state":"configured","query_suite":"default","languages":["rust","python"]}' -converge_codeql_default_setup >"${temporary}/languages-keep.txt" -assert_no_writes -reset_case -codeql_state=unreadable -if converge_codeql_default_setup >"${temporary}/languages-error.txt" 2>&1; then - echo 'expected unreadable language inventory to fail closed' >&2 - exit 1 -fi -assert_no_writes -reset_case -codeql_state='{"state":"configured","query_suite":"default","languages":null}' -if converge_codeql_default_setup >"${temporary}/languages-malformed.txt" 2>&1; then - echo 'expected malformed language inventory to fail closed' >&2 - exit 1 -fi -assert_no_writes - -# Read failures are fatal even without a language minimum, in both setup modes. -for setup_kind in default advanced; do - for http_status in 403 404 500; do - reset_case - jq '.codeql_required_languages = {}' "${security_merge_config}" >"${temporary}/no-minima.json" - cp "${temporary}/no-minima.json" "${security_merge_config}" - if [[ ${setup_kind} == advanced ]]; then - echo '{"repositories":["content-toolkit"]}' >"${codeql_advanced_config}" - fi - codeql_state=http-${http_status} - if converge_codeql_default_setup >"${temporary}/languages-${setup_kind}-${http_status}.txt" 2>&1; then - echo 'expected unreadable default setup to fail publication without a language minimum' >&2 - exit 1 - fi - grep -q 'cannot read existing CodeQL languages' "${temporary}/languages-${setup_kind}-${http_status}.txt" - assert_no_writes - done -done -reset_case -jq '.codeql_required_languages = {}' "${security_merge_config}" >"${temporary}/no-minima.json" -cp "${temporary}/no-minima.json" "${security_merge_config}" -codeql_state='{"state":"configured","query_suite":"default","languages":["python"]}' -converge_codeql_default_setup >"${temporary}/languages-readable-no-minimum.txt" -assert_no_writes -echo '{"repositories":["content-toolkit"]}' >"${codeql_advanced_config}" -codeql_state='{"state":"not-configured","languages":null}' -converge_codeql_default_setup >"${temporary}/languages-readable-advanced-null.txt" -assert_no_writes - -# Use the actual dispatch: security producer readiness follows base convergence -# for both scopes, and these Team-compatible gates always target repositories. -publish_organization_rulesets() { echo organization-rules >>"${temporary}/order"; } -publish_organization_security() { echo organization-security >>"${temporary}/order"; } -publish_repository_rulesets() { echo repository-rules >>"${temporary}/order"; } -publish_repository_security() { echo repository-security >>"${temporary}/order"; } -for policy_scope in organization repository; do - for producer in missing failed unreadable ready; do - reset_case - export READINESS_STATUS=${producer} - : >"${temporary}/order" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/${policy_scope}-${producer}.txt" - [[ $(cat "${temporary}/order") == "${policy_scope}-rules"$'\n'"${policy_scope}-security" ]] - assert_no_writes - if [[ ${producer} == ready ]]; then - [[ $(grep -c '^READY ' "${temporary}/${policy_scope}-${producer}.txt") == 2 ]] - fi - jq -se '[.[].mode] == ["codeql", "dependency"] and - all(.[]; .repository == "atrinik/content-toolkit")' "${readiness_log}" >/dev/null - jq -se 'all(.[]; .endpoint | startswith("repos/atrinik/content-toolkit/"))' \ - "${api_log}" >/dev/null - done -done - -# Reviewed enforced intent precedes initial installation and survives deletion, -# disablement, and ref drift independently of current producer health. -for policy_scope in organization repository; do - for producer in failed unreadable; do - for state in missing disabled active-wrong-ref; do - reset_case - ruleset_state=${state} - effective_state=absent - export READINESS_STATUS=${producer} - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/enforced-${policy_scope}-${producer}-${state}.txt" - method=PUT - [[ ${state} != missing ]] || method=POST - jq -se --arg method "${method}" \ - --slurpfile codeql "${root}/config/rulesets/code-scanning.json" \ - --slurpfile dependency "${root}/config/rulesets/dependency-review.json" ' - [.[] | select(.method != "GET")] | - [.[].payload] == [$codeql[0], $dependency[0]] and - all(.[]; .method == $method)' "${api_log}" >/dev/null - [[ ! -s ${readiness_log} ]] - done - done -done - -# Changes made after the initial GET cannot be erased by restoration PUT. -for policy_scope in organization repository; do - for gate_update_target in 6 7; do - common_filters=( - '.id = 999' '.source_type = "Organization"' '.source = "foreign/content-toolkit"' - '.name = "Renamed gate"' '.target = "tag"' '.enforcement = "unknown"' - '.bypass_actors[0].bypass_mode = "always"' '.bypass_actors = []' - '.rules[0].parameters.unknown_future_control = true' - '.conditions.ref_name.unknown_future_scope = true' '.rules += [{type:"deletion"}]' - 'unreadable' - ) - if [[ ${gate_update_target} == 6 ]]; then - common_filters+=( - '.rules[0].parameters.code_scanning_tools[0].tool = "Other tool"' - '.rules[0].parameters.code_scanning_tools[0].security_alerts_threshold = "critical"' - ) - else - common_filters+=( - '.rules[0].parameters.required_status_checks[0].context = "Unrelated context"' - '.rules[0].parameters.required_status_checks[0].integration_id = 9' - '.rules[0].parameters.do_not_enforce_on_create = true' - '.rules[0].parameters.do_not_enforce_on_create = null' - ) - fi - for filter in "${common_filters[@]}"; do - reset_case - ruleset_state=restoration-race - gate_update_id=${gate_update_target} - gate_update_filter=${filter} - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - # shellcheck source=/dev/null - if source "${temporary}/dispatch.sh" >"${temporary}/concurrent-gate.txt" 2>&1; then - echo "expected concurrent gate change to be retained: ${filter}" >&2 - exit 1 - fi - assert_no_writes - grep -Fq 'retained:' "${temporary}/concurrent-gate.txt" - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${gate_update_id}" \ - '[.[] | select(.endpoint == $endpoint)] | length == 2' "${api_log}" >/dev/null - done - # Unchanged ownership, explicit API defaults, and allowed enforcement/ref - # restoration still converge; a concurrent completed repair causes KEEP. - for filter in '.' \ - '.current_user_can_bypass = "pull_requests_only"' \ - '.bypass_actors[0].actor_id = null | if .rules[0].type == "required_status_checks" then .rules[0].parameters.do_not_enforce_on_create = false else . end' \ - '.enforcement = "evaluate" | .conditions.ref_name.include = ["refs/heads/other"]' \ - '.enforcement = "active"'; do - reset_case - ruleset_state=restoration-race - gate_update_id=${gate_update_target} - gate_update_filter=${filter} - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/safe-concurrent-gate.txt" - if [[ ${filter} == '.enforcement = "active"' ]]; then - assert_no_writes - else - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${gate_update_id}" ' - [.[] | select(.method != "GET")] | length == 1 and - .[0].method == "PUT" and .[0].endpoint == $endpoint' "${api_log}" >/dev/null - jq -se '[.[] | select(.method == "PUT")][0].payload | - has("current_user_can_bypass") | not' "${api_log}" >/dev/null - if [[ ${gate_update_id} == 7 && ${filter} == *do_not_enforce_on_create* ]]; then - jq -se '[.[] | select(.method == "PUT")][0].payload.rules[0].parameters | - has("do_not_enforce_on_create") and .do_not_enforce_on_create == false' \ - "${api_log}" >/dev/null - fi - fi - done - for filter in '.archived = true' '.id = 999' '.full_name = "foreign/content-toolkit"' unreadable; do - reset_case - ruleset_state=restoration-race - gate_update_id=${gate_update_target} - gate_metadata_filter=${filter} - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - # shellcheck source=/dev/null - if source "${temporary}/dispatch.sh" >"${temporary}/fresh-repository.txt" 2>&1; then - echo 'expected fresh repository identity/archive/read failure to block PUT' >&2 - exit 1 - fi - assert_no_writes - done - done -done - -# Pending existing-gate restoration is authorized only for the exact default -# branch whose effective protection was checked, even if another branch is valid. -for policy_scope in organization repository; do - for pending_gate_id in 6 7; do - for filter in '.default_branch = "new-main"' '.default_branch = "release/next"' \ - '.default_branch = null' 'del(.default_branch)' unreadable '.'; do - reset_case - ruleset_state=pending-branch-race - gate_update_id=${pending_gate_id} - gate_metadata_after_proof_filter=${filter} - export READINESS_STATUS=failed - jq '.activation |= with_entries(.value |= with_entries(.value = "pending"))' \ - "${security_merge_config}" >"${temporary}/pending.json" - cp "${temporary}/pending.json" "${security_merge_config}" - status=0 - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/pending-branch-fence.txt" 2>&1 || status=$? - if [[ ${filter} == '.' ]]; then - [[ ${status} == 0 ]] - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${pending_gate_id}" ' - [.[] | select(.method != "GET")] | length == 1 and - .[0].method == "PUT" and .[0].endpoint == $endpoint' "${api_log}" >/dev/null - else - [[ ${status} != 0 ]] - assert_no_writes - if [[ ${filter} == '.default_branch = "'* ]]; then - grep -Fq 'default branch changed after existing security gate proof; retained' \ - "${temporary}/pending-branch-fence.txt" - fi - fi - jq -se 'any(.[]; .endpoint == "repos/atrinik/content-toolkit/rules/branches/main")' \ - "${api_log}" >/dev/null - [[ ! -s ${readiness_log} ]] - cmp "${temporary}/pending.json" "${security_merge_config}" - done - done - # Durable enforced intent still restores missing gates on the current default. - reset_case - ruleset_state=missing - gate_metadata_filter='.default_branch = "new-main"' - export READINESS_STATUS=failed - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/enforced-current-default.txt" - jq -se '[.[] | select(.method != "GET")] | length == 2 and all(.[]; .method == "POST")' \ - "${api_log}" >/dev/null - [[ ! -s ${readiness_log} ]] -done - -# Pending grandfathering cannot restore a gate revoked after its effective -# proof. Enforced intent deliberately permits the same restoration changes. -for policy_scope in organization repository; do - for pending_gate_id in 6 7; do - for phase in pending enforced; do - for filter in '.enforcement = "disabled"' '.enforcement = "evaluate"' \ - '.conditions.ref_name.include = ["refs/heads/other"]' \ - '.conditions.ref_name.exclude = ["refs/heads/main"]' \ - 'unreadable' '.' \ - '.bypass_actors[0].actor_id = null | if .rules[0].type == "required_status_checks" then .rules[0].parameters.do_not_enforce_on_create = false else . end' \ - '.conditions.ref_name.include |= reverse | .conditions.ref_name.exclude |= reverse'; do - reset_case - ruleset_state=pending-branch-race - gate_update_id=${pending_gate_id} - gate_update_filter=${filter} - if [[ ${filter} == *'|= reverse'* ]]; then - gate_initial_filter='.conditions.ref_name.include += ["refs/heads/release/*"] | .conditions.ref_name.exclude = ["refs/heads/excluded-a", "refs/heads/excluded-b"]' - fi - export READINESS_STATUS=failed - jq --arg phase "${phase}" '.activation |= with_entries(.value |= with_entries(.value = $phase))' \ - "${security_merge_config}" >"${temporary}/proof-phase.json" - cp "${temporary}/proof-phase.json" "${security_merge_config}" - status=0 - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/pending-proof-fence.txt" 2>&1 || status=$? - if [[ ${filter} == unreadable ]] || { [[ ${phase} == pending ]] && - [[ ${filter} == '.enforcement ='* || ${filter} == '.conditions.ref_name.include ='* || - ${filter} == '.conditions.ref_name.exclude ='* ]]; }; then - [[ ${status} != 0 ]] - assert_no_writes - if [[ ${filter} != unreadable ]]; then - grep -Fq 'existing security gate protection changed after effective proof; retained' \ - "${temporary}/pending-proof-fence.txt" - fi - else - [[ ${status} == 0 ]] - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${pending_gate_id}" ' - [.[] | select(.method != "GET")] | length == 1 and - .[0].method == "PUT" and .[0].endpoint == $endpoint' "${api_log}" >/dev/null - fi - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${pending_gate_id}" ' - [.[] | select(.endpoint == $endpoint and .method == "GET")] | length == 2' "${api_log}" >/dev/null - if [[ ${phase} == pending ]]; then - jq -se 'any(.[]; .endpoint == "repos/atrinik/content-toolkit/rules/branches/main")' \ - "${api_log}" >/dev/null - fi - [[ ! -s ${readiness_log} ]] - cmp "${temporary}/proof-phase.json" "${security_merge_config}" - done - done - done -done - -# The two gate phases are independent; qualification does not mutate source. -reset_case -export READINESS_STATUS=failed -jq '.activation.code_scanning["content-toolkit"] = "enforced"' \ - "${security_merge_config}" >"${temporary}/mixed.json" -cp "${temporary}/mixed.json" "${security_merge_config}" -publish_security_merge_rulesets >"${temporary}/mixed.txt" -jq -se '[.[] | select(.method != "GET")] | length == 1 and - .[0].payload.name == "06 - CodeQL security"' "${api_log}" >/dev/null -jq -se '[.[].mode] == ["dependency"]' "${readiness_log}" >/dev/null -cmp "${temporary}/mixed.json" "${security_merge_config}" - -# Enforced restoration preserves foreign/ambiguous same-name rules and rejects -# archived or replaced repositories at the point of mutation. -for state in removal-foreign removal-id-drift removal-name-collision active-unrelated-gate active-without-gate unknown-rule-parameter unknown-condition unknown-ref-condition active-bypass-drift changed-severity foreign-repository-source extra-rule; do - reset_case - ruleset_state=${state} - jq '.activation |= with_entries(.value |= with_entries(.value = "enforced"))' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - if publish_security_merge_rulesets >"${temporary}/enforced-collision-${state}.txt" 2>&1; then - echo 'expected enforced gate ownership collision to fail closed' >&2 - exit 1 - fi - assert_no_writes - [[ ! -s ${readiness_log} ]] -done -for kind in code_scanning dependency_review; do - for metadata in \ - '{"id":123,"full_name":"atrinik/content-toolkit","archived":true,"default_branch":"main"}' \ - '{"id":999,"full_name":"atrinik/content-toolkit","archived":false,"default_branch":"main"}' \ - '{"id":123,"full_name":"atrinik/renamed-toolkit","archived":false,"default_branch":"main"}' \ - '{"id":123,"full_name":"foreign/content-toolkit","archived":false,"default_branch":"main"}'; do - reset_case - export READINESS_STATUS=failed - repository_state=${metadata} - jq --arg kind "${kind}" '.activation[$kind]["content-toolkit"] = "enforced"' \ - "${security_merge_config}" >"${temporary}/enforced.json" - cp "${temporary}/enforced.json" "${security_merge_config}" - if publish_security_merge_rulesets >"${temporary}/enforced-metadata-${kind}.txt" 2>&1; then - echo 'expected enforced repository identity fence to fail closed' >&2 - exit 1 - fi - assert_no_writes - jq -se --arg mode "$([[ ${kind} == code_scanning ]] && echo codeql || echo dependency)" \ - 'all(.[]; .mode != $mode)' "${readiness_log}" >/dev/null - done -done - -reset_case -ruleset_state=exact -export READINESS_STATUS=failed -publish_security_merge_rulesets >"${temporary}/exact.txt" -assert_no_writes -[[ ! -s ${readiness_log} ]] -reset_case -ruleset_state=owner-null -export READINESS_STATUS=failed -publish_security_merge_rulesets >"${temporary}/owner-null.txt" -assert_no_writes -[[ ! -s ${readiness_log} ]] -reset_case -ruleset_state=active-drift -export READINESS_STATUS=failed -publish_security_merge_rulesets >"${temporary}/active-drift.txt" -jq -se '[.[] | select(.method != "GET")] | length == 2 and - all(.[]; .method == "PUT" and .payload.enforcement == "active")' \ - "${api_log}" >/dev/null -[[ ! -s ${readiness_log} ]] -ruleset_state=disabled -effective_state=absent -: >"${api_log}" -: >"${readiness_log}" -export READINESS_STATUS=failed -publish_security_merge_rulesets >"${temporary}/${ruleset_state}.txt" -assert_no_writes -jq -se '[.[].mode] == ["codeql", "dependency"]' "${readiness_log}" >/dev/null - -# An active rule on another ref does not grandfather a new default-branch gate. -for effective_state in absent different-id; do - : >"${api_log}" - : >"${readiness_log}" - ruleset_state=active-wrong-ref - export READINESS_STATUS=missing - publish_security_merge_rulesets >"${temporary}/wrong-ref-${effective_state}.txt" - assert_no_writes - jq -se '[.[].mode] == ["codeql", "dependency"]' "${readiness_log}" >/dev/null -done -reset_case -ruleset_state=active-drift -repository_state='{"id":123,"full_name":"atrinik/content-toolkit","archived":false,"default_branch":"release/current"}' -export READINESS_STATUS=failed -publish_security_merge_rulesets >"${temporary}/encoded-ref.txt" -jq -se 'any(.[]; .endpoint == "repos/atrinik/content-toolkit/rules/branches/release%2Fcurrent") and - ([.[] | select(.method == "PUT")] | length == 2)' "${api_log}" >/dev/null -[[ ! -s ${readiness_log} ]] - -# Stale identities and archived metadata cannot grandfather a gate. -for repository_state in '{"id":999,"archived":false,"default_branch":"main"}' '{"id":123,"archived":true,"default_branch":"main"}'; do - : >"${api_log}" - : >"${readiness_log}" - ruleset_state=active-drift - effective_state=covering - export READINESS_STATUS=missing - publish_security_merge_rulesets >"${temporary}/metadata-drift.txt" - assert_no_writes - jq -se '[.[].mode] == ["codeql", "dependency"]' "${readiness_log}" >/dev/null -done - -# Exact repository-owned retired targets are removed; foreign collisions stay. -for removal in removal-owned removal-owner-null removal-foreign removal-id-drift removal-name-collision; do - reset_case - ruleset_state=${removal} - jq '.code_scanning -= ["content-toolkit"] | .dependency_review -= ["content-toolkit"] | del(.activation.code_scanning["content-toolkit"], .activation.dependency_review["content-toolkit"])' \ - "${security_merge_config}" >"${temporary}/removed.json" - cp "${temporary}/removed.json" "${security_merge_config}" - publish_security_merge_rulesets >"${temporary}/${removal}.txt" - if [[ ${removal} == removal-owned || ${removal} == removal-owner-null ]]; then - jq -se '[.[] | select(.method != "GET")] == [ - {method: "DELETE", endpoint: "repos/atrinik/content-toolkit/rulesets/6"}, - {method: "DELETE", endpoint: "repos/atrinik/content-toolkit/rulesets/7"} - ]' "${api_log}" >/dev/null - else - assert_no_writes - grep -q '^SKIP ' "${temporary}/${removal}.txt" - fi - [[ ! -s ${readiness_log} ]] -done - -# GitHub expands an omitted create-exemption flag to false. Both publisher -# scopes must keep exact active API payloads and retire only exact owned gates. -for policy_scope in organization repository; do - reset_case - ruleset_state=api-default-false - export READINESS_STATUS=failed - : >"${temporary}/order" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/${policy_scope}-api-default-keep.txt" - assert_no_writes - [[ ! -s ${readiness_log} ]] - grep -Fq 'KEEP /repos/atrinik/content-toolkit/rulesets/7 07 - Dependency review' \ - "${temporary}/${policy_scope}-api-default-keep.txt" - for default_state in false true null unknown; do - reset_case - ruleset_state=api-default-${default_state} - jq '.dependency_review -= ["content-toolkit"] | del(.activation.dependency_review["content-toolkit"])' \ - "${security_merge_config}" >"${temporary}/removed.json" - cp "${temporary}/removed.json" "${security_merge_config}" - : >"${temporary}/order" - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/${policy_scope}-api-default-${default_state}.txt" - if [[ ${default_state} == false ]]; then - jq -se '[.[] | select(.method != "GET")] == [ - {method: "DELETE", endpoint: "repos/atrinik/content-toolkit/rulesets/7"} - ]' "${api_log}" >/dev/null - else - assert_no_writes - grep -Fq '07 - Dependency review: unrecognized ownership or payload; retained' \ - "${temporary}/${policy_scope}-api-default-${default_state}.txt" - fi - [[ ! -s ${readiness_log} ]] - done -done - -# The final retirement GET must still prove exact managed ownership/payload -# after the repository fence, including for changes that PUT may restore. -for policy_scope in organization repository; do - for retired_gate_id in 6 7; do - retired_kind=code_scanning - [[ ${retired_gate_id} != 7 ]] || retired_kind=dependency_review - retirement_filters=( - '.id = 999' '.source_type = "Organization"' '.source = "foreign/content-toolkit"' - '.name = "Renamed gate"' '.enforcement = "disabled"' '.enforcement = "evaluate"' - '.conditions.ref_name.include = ["refs/heads/other"]' - '.conditions.ref_name.exclude = ["~DEFAULT_BRANCH"]' - '.bypass_actors[0].bypass_mode = "always"' '.bypass_actors = []' - '.rules[0].parameters.unknown_future_control = true' '.rules += [{type:"deletion"}]' - 'unreadable' - ) - if [[ ${retired_gate_id} == 6 ]]; then - retirement_filters+=( - '.rules[0].parameters.code_scanning_tools[0].tool = "Other tool"' - '.rules[0].parameters.code_scanning_tools[0].security_alerts_threshold = "critical"' - ) - else - retirement_filters+=( - '.rules[0].parameters.required_status_checks[0].context = "Changed context"' - '.rules[0].parameters.required_status_checks[0].integration_id = 9' - '.rules[0].parameters.do_not_enforce_on_create = true' - '.rules[0].parameters.do_not_enforce_on_create = null' - ) - fi - for filter in "${retirement_filters[@]}" '.' \ - '.bypass_actors[0].actor_id = null | if .rules[0].type == "required_status_checks" then .rules[0].parameters.do_not_enforce_on_create = false else . end'; do - reset_case - ruleset_state=retirement-race - gate_update_id=${retired_gate_id} - gate_update_filter=${filter} - jq --arg kind "${retired_kind}" '.[$kind] -= ["content-toolkit"] | - del(.activation[$kind]["content-toolkit"])' "${security_merge_config}" >"${temporary}/removed.json" - cp "${temporary}/removed.json" "${security_merge_config}" - status=0 - # shellcheck source=/dev/null - source "${temporary}/dispatch.sh" >"${temporary}/retirement-race.txt" 2>&1 || status=$? - if [[ ${filter} == unreadable ]]; then - [[ ${status} != 0 ]] - assert_no_writes - grep -Fq 'final retirement read failed; retained' "${temporary}/retirement-race.txt" - elif [[ ${filter} == '.' || ${filter} == '.bypass_actors[0].actor_id = null |'* ]]; then - [[ ${status} == 0 ]] - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${retired_gate_id}" ' - [.[] | select(.method != "GET")] == [{method:"DELETE",endpoint:$endpoint}]' "${api_log}" >/dev/null - else - [[ ${status} == 0 ]] - assert_no_writes - grep -Fq 'rule changed during retirement preflight; retained' "${temporary}/retirement-race.txt" - fi - jq -se --arg endpoint "repos/atrinik/content-toolkit/rulesets/${retired_gate_id}" ' - [to_entries[] | select(.value.endpoint == $endpoint and .value.method == "GET") | .key] as $reads | - ($reads | length) == 2 and - any(to_entries[]; .key > $reads[0] and .key < $reads[1] and - .value.endpoint == "repos/atrinik/content-toolkit")' "${api_log}" >/dev/null - [[ ! -s ${readiness_log} ]] - done - done -done - -# Retirements also fence a repository archived or replaced after enumeration. -for retired_state in '{"id":123,"archived":true}' '{"id":999,"archived":false}' \ - '{"id":123,"full_name":"foreign/content-toolkit","archived":false}'; do - reset_case - repository_state=${retired_state} - ruleset_state="removal-owned" - jq '.code_scanning -= ["content-toolkit"] | .dependency_review -= ["content-toolkit"] | del(.activation.code_scanning["content-toolkit"], .activation.dependency_review["content-toolkit"])' \ - "${security_merge_config}" >"${temporary}/removed.json" - cp "${temporary}/removed.json" "${security_merge_config}" - publish_security_merge_rulesets >"${temporary}/removed-state-changed.txt" - assert_no_writes - [[ ! -s ${readiness_log} ]] -done - -# Read errors must propagate even when publication is called conditionally. -reset_case -ruleset_state="removal-owned" -gate_metadata_filter=unreadable -jq '.code_scanning -= ["content-toolkit"] | .dependency_review -= ["content-toolkit"] | - del(.activation.code_scanning["content-toolkit"], .activation.dependency_review["content-toolkit"])' \ - "${security_merge_config}" >"${temporary}/removed.json" -cp "${temporary}/removed.json" "${security_merge_config}" -if publish_security_merge_rulesets >"${temporary}/retirement-metadata-unreadable.txt" 2>&1; then - echo 'expected unreadable retirement repository metadata to fail closed' >&2 - exit 1 -fi -assert_no_writes - -# An archived or missing repository is absent from the active identity map. -reset_case -active_repository_ids=() -publish_security_merge_rulesets >"${temporary}/inactive.txt" -[[ ! -s ${api_log} && ! -s ${readiness_log} ]] -active_repository_ids=([content-toolkit]=123) - -reset_case -converge_actions_permissions >"${temporary}/sha-deferred.txt" -jq -se '[.[] | select(.method == "PUT")][0].payload == - {enabled_repositories: "all", allowed_actions: "selected"}' "${api_log}" >/dev/null -[[ ! -s ${readiness_log} ]] -reset_case -actions_state='{"enabled_repositories":"selected","allowed_actions":"all","sha_pinning_required":true}' -converge_actions_permissions >"${temporary}/sha-retained.txt" -jq -se '[.[] | select(.method == "PUT")][0].payload | has("sha_pinning_required") | not' \ - "${api_log}" >/dev/null -[[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == true ]] -[[ ! -s ${readiness_log} ]] -for producer in failed ready; do - reset_case - sha_pinning_canary=atrinik/content-toolkit/99 - export READINESS_STATUS=${producer} - converge_actions_permissions >"${temporary}/sha-pending-${producer}.txt" - jq -se '[.[] | select(.method == "PUT")][0].payload | has("sha_pinning_required") | not' \ - "${api_log}" >/dev/null -done -reset_case -echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" -converge_actions_permissions >"${temporary}/sha-enforced-ready.txt" -jq -se --slurpfile desired "${root}/config/actions-permissions.json" ' - [.[] | select(.method == "PUT")][-1].payload == $desired[0]' "${api_log}" >/dev/null -jq -se '. == [{mode: "sha", repository: "atrinik/content-toolkit/99"}]' \ - "${readiness_log}" >/dev/null -for producer in failed unreadable; do - reset_case - echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" - export READINESS_STATUS=${producer} - if converge_actions_permissions >"${temporary}/sha-enforced-${producer}.txt" 2>&1; then - echo "expected enforced SHA evidence failure to fail closed: ${producer}" >&2 - exit 1 - fi - jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null -done -reset_case -echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" -actions_state=$(cat "${root}/config/actions-permissions.json") -export READINESS_STATUS=failed -converge_actions_permissions >"${temporary}/sha-keep.txt" -assert_no_writes -[[ ! -s ${readiness_log} ]] - -# Explicit pending canary probes still run when SHA is already enabled. -for producer in ready failed unreadable stale; do - reset_case - actions_state=$(cat "${root}/config/actions-permissions.json") - sha_pinning_canary=atrinik/content-toolkit/99 - export READINESS_STATUS=${producer} - converge_actions_permissions >"${temporary}/sha-enabled-probe-${producer}.txt" - jq -se '. == [{mode:"sha", repository:"atrinik/content-toolkit/99"}]' "${readiness_log}" >/dev/null - jq -se 'all(.[]; .method == "GET" or .method == "PROOF")' "${api_log}" >/dev/null - [[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == true ]] - if [[ ${producer} == ready ]]; then - grep -q '^READY canary evidence:' "${temporary}/sha-enabled-probe-${producer}.txt" - else - grep -q '^PENDING canary evidence:' "${temporary}/sha-enabled-probe-${producer}.txt" - fi -done -for invalid in foreign/content-toolkit/99 atrinik/unregistered/99 replaced; do - reset_case - actions_state=$(cat "${root}/config/actions-permissions.json") - sha_pinning_canary=${invalid} - if [[ ${invalid} == replaced ]]; then - sha_pinning_canary=atrinik/content-toolkit/99 - repository_state=$(jq '.id = 999' <<<"${repository_state}") - fi - if converge_actions_permissions >"${temporary}/sha-enabled-probe-invalid.txt" 2>&1; then - echo 'expected invalid requested canary identity to fail with SHA already enabled' >&2 - exit 1 - fi - assert_no_writes - [[ ! -s ${readiness_log} ]] - [[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == true ]] -done - -# Simultaneous mode, patterns and SHA drift repairs conservative policy first. -for producer in ready failed unreadable; do - reset_case - echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" - selected_state='{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":["old/action@*"]}' - export CHECK_POLICY_STAGED=true - export READINESS_STATUS=${producer} - if converge_actions_permissions >"${temporary}/sha-staged-${producer}.txt" 2>&1; then - [[ ${producer} == ready ]] - else - [[ ${producer} != ready ]] - fi - jq -se ' - [.[] | select(.method == "PUT" or .method == "PROOF")] as $events | - $events[0].endpoint == "orgs/atrinik/actions/permissions" and - ($events[0].payload | has("sha_pinning_required") | not) and - $events[1].endpoint == "orgs/atrinik/actions/permissions/selected-actions" and - $events[2].method == "PROOF" - ' "${api_log}" >/dev/null - if [[ ${producer} == ready ]]; then - jq -se '[.[] | select(.method == "PUT" or .method == "PROOF")] | - length == 4 and .[3].payload.sha_pinning_required == true' "${api_log}" >/dev/null - # A second converged publication neither mutates nor re-proves retained SHA. - : >"${api_log}" - : >"${readiness_log}" - converge_actions_permissions >"${temporary}/sha-staged-converged.txt" - assert_no_writes - [[ ! -s ${readiness_log} ]] - else - jq -se '[.[] | select(.method == "PUT" or .method == "PROOF")] | length == 3' "${api_log}" >/dev/null - [[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == false ]] - fi -done - -# A disable concurrent with pattern staging must not reuse the initial true. -for producer in ready failed unreadable; do - reset_case - echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" - actions_state='{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":true}' - selected_state='{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":[]}' - staging_race=disable - export READINESS_STATUS=${producer} - if converge_actions_permissions >"${temporary}/sha-concurrent-disable-${producer}.txt" 2>&1; then - [[ ${producer} == ready ]] - else - [[ ${producer} != ready ]] - fi - jq -se ' - to_entries as $events | - ([$events[] | select(.value.method == "PUT" and - .value.endpoint == "orgs/atrinik/actions/permissions/selected-actions")][0].key) as $staged | - ([$events[] | select(.key > $staged and .value.method == "GET" and - .value.endpoint == "orgs/atrinik/actions/permissions")][0].key) as $read | - ([$events[] | select(.key > $read and .value.method == "GET" and - .value.endpoint == "repos/atrinik/content-toolkit")][0].key) as $identity | - ([$events[] | select(.value.method == "PROOF")][0].key) as $proof | - $staged < $read and $read < $identity and $identity < $proof and - all($events[] | select(.key < $proof and .value.method == "PUT"); - .value.payload.sha_pinning_required != true) - ' "${api_log}" >/dev/null - if [[ ${producer} == ready ]]; then - [[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == true ]] - jq -se '.[-1].method == "PUT" and .[-1].payload.sha_pinning_required == true' "${api_log}" >/dev/null - else - [[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == false ]] - jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null - fi -done -for race in malformed replace-repository; do - reset_case - echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" - actions_state='{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":true}' - selected_state='{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":[]}' - staging_race=${race} - if converge_actions_permissions >"${temporary}/sha-concurrent-${race}.txt" 2>&1; then - echo 'expected changed post-staging evidence to fail closed' >&2 - exit 1 - fi - [[ ! -s ${readiness_log} ]] - jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null -done -reset_case -actions_state='{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":true}' -selected_state='{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":[]}' -staging_race=disable -converge_actions_permissions >"${temporary}/sha-concurrent-disable-pending.txt" -[[ $(jq -r '.sha_pinning_required' <<<"${actions_state}") == false ]] -[[ ! -s ${readiness_log} ]] -jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null - -reset_case -echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" -apply=false -converge_actions_permissions >"${temporary}/sha-stage-plan.txt" 2>&1 -grep -q 'PLAN SHA pinning proof' "${temporary}/sha-stage-plan.txt" -if grep -Eq 'jq:|error:' "${temporary}/sha-stage-plan.txt"; then - echo 'unexpected error in SHA staging dry run' >&2 - exit 1 -fi -[[ ! -s ${readiness_log} ]] -jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null -[[ $(jq -r '.allowed_actions' <<<"${actions_state}") == all ]] - -# An unreadable staged allowlist never reaches the canary or writes SHA. -reset_case -echo '{"phase":"enforced","canary":"atrinik/content-toolkit/99"}' >"${actions_sha_pinning_config}" -selected_state=unreadable -if converge_actions_permissions >"${temporary}/sha-staged-unreadable-policy.txt" 2>&1; then - echo 'expected unreadable staged Actions policy to fail closed' >&2 - exit 1 -fi -[[ ! -s ${readiness_log} ]] -jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null - -# Pending rollout may repair policy and probe, but never enables SHA pinning. -reset_case -selected_state='{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":[]}' -sha_pinning_canary=atrinik/content-toolkit/99 -export CHECK_POLICY_STAGED=true -converge_actions_permissions >"${temporary}/sha-pending-staged.txt" -jq -se 'all(.[] | select(.method == "PUT"); .payload.sha_pinning_required != true)' "${api_log}" >/dev/null - -# Malformed configured languages are unreadable for ordinary repositories too. -for languages in null '{}' '[false]' '[""]' '"rust"'; do - reset_case - jq '.codeql_required_languages = {}' "${security_merge_config}" >"${temporary}/no-minima.json" - cp "${temporary}/no-minima.json" "${security_merge_config}" - codeql_state=$(jq -cn --argjson languages "${languages}" \ - '{state:"configured", query_suite:"default", languages:$languages}') - if converge_codeql_default_setup >"${temporary}/malformed-languages.txt" 2>&1; then - echo 'expected malformed configured CodeQL languages to fail closed without minima' >&2 - exit 1 - fi - assert_no_writes -done -reset_case -jq '.codeql_required_languages = {}' "${security_merge_config}" >"${temporary}/no-minima.json" -cp "${temporary}/no-minima.json" "${security_merge_config}" -codeql_state='{"state":"configured","query_suite":"default","languages":[]}' -converge_codeql_default_setup >"${temporary}/readable-empty-languages.txt" -assert_no_writes -reset_case -codeql_state='{"state":"not-configured","languages":null}' -converge_codeql_default_setup >"${temporary}/unconfigured-languages.txt" -jq -se '[.[] | select(.method == "PATCH")][0].payload.languages == ["rust"]' "${api_log}" >/dev/null - -# Neither a foreign owner nor an unregistered repository can lend canary proof. -for phase in pending enforced; do - for rejected_canary in foreign/content-toolkit/99 atrinik/unregistered/99; do - reset_case - if [[ ${phase} == enforced ]]; then - jq -n --arg canary "${rejected_canary}" '{phase:"enforced", canary:$canary}' \ - >"${actions_sha_pinning_config}" - else - sha_pinning_canary=${rejected_canary} - fi - if converge_actions_permissions >"${temporary}/sha-identity-rejected.txt" 2>&1; then - echo 'expected foreign or unregistered canary to be rejected' >&2 - exit 1 - fi - assert_no_writes - [[ ! -s ${readiness_log} ]] - done -done -reset_case -repository_state='{"id":999,"full_name":"atrinik/content-toolkit","archived":false}' -sha_pinning_canary=atrinik/content-toolkit/99 -if converge_actions_permissions >"${temporary}/sha-replaced-repository.txt" 2>&1; then - echo 'expected a replaced canary repository to be rejected' >&2 - exit 1 -fi -assert_no_writes -[[ ! -s ${readiness_log} ]] - -reset_case -converge_repository_workflow_permissions >"${temporary}/workflow-drift.txt" -jq -se --slurpfile desired "${root}/config/actions-workflow.json" ' - [.[] | select(.method != "GET")] == [{method: "PUT", - endpoint: "repos/atrinik/content-toolkit/actions/permissions/workflow", payload: $desired[0]}] -' "${api_log}" >/dev/null -reset_case -workflow_state=$(cat "${root}/config/actions-workflow.json") -converge_repository_workflow_permissions >"${temporary}/workflow-noop.txt" -assert_no_writes -for workflow_state in unreadable '{}' '{"default_workflow_permissions":"read","can_approve_pull_request_reviews":"false"}'; do - : >"${api_log}" - if converge_repository_workflow_permissions >"${temporary}/workflow-error.txt" 2>&1; then - echo 'expected unreadable or malformed workflow permissions to fail closed' >&2 - exit 1 - fi - assert_no_writes -done - -rm -f "${temporary_files[@]}" -echo 'Security merge publisher tests passed.' diff --git a/tests/security-readiness.py b/tests/security-readiness.py deleted file mode 100644 index b24953b..0000000 --- a/tests/security-readiness.py +++ /dev/null @@ -1,2073 +0,0 @@ -#!/usr/bin/env python3 -"""Deterministic, read-only security readiness contract tests.""" - -import base64 -import copy -import importlib.util -import io -import json -import os -from pathlib import Path -import subprocess -import sys -import tempfile -import unittest -from unittest.mock import patch -from urllib.parse import parse_qs, quote, urlparse - - -ROOT = Path(__file__).resolve().parent.parent -sys.dont_write_bytecode = True -SPEC = importlib.util.spec_from_file_location("security_readiness", ROOT / "lib/security_readiness.py") -readiness = importlib.util.module_from_spec(SPEC) -SPEC.loader.exec_module(readiness) -HEAD, BASE, MERGE = "a" * 40, "b" * 40, "c" * 40 -OLD, NEW = "d" * 40, "e" * 40 -WORKFLOW = ("name: Dependency review\n\non:\n pull_request:\n branches: [main]\n" - " types: [opened, synchronize, reopened, edited]\n" - " merge_group:\n types: [checks_requested]\n" - "permissions:\n contents: read\njobs:\n dependency-review:\n" - " name: Dependency review\n runs-on: ubuntu-24.04\n steps:\n" - f" - uses: actions/dependency-review-action@{OLD} # v5.0.0\n" - " with:\n fail-on-severity: high\n warn-only: false\n").encode() -# Snapshot of the actual content-toolkit producer, including its types-first -# mapping, block branch filter, named step, and complete enforcement settings. -# Immutable action versions remain producer-owned and are normalized by policy. -COMPONENT_WORKFLOW = b"""name: Dependency review - -on: - pull_request: - types: [opened, synchronize, reopened, edited] - branches: - - main - merge_group: - types: [checks_requested] - -permissions: - contents: read - -jobs: - dependency-review: - name: Dependency review - runs-on: ubuntu-24.04 - timeout-minutes: 10 - steps: - - name: Review dependency changes - uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 - with: - fail-on-severity: high - fail-on-scopes: runtime,development,unknown - warn-only: false - comment-summary-in-pr: never - show-openssf-scorecard: false - retry-on-snapshot-warnings: true - retry-on-snapshot-warnings-timeout: 120 -""" -SELECTED = {"github_owned_allowed": True, "verified_allowed": False, - "patterns_allowed": ["rust-lang/crates-io-auth-action@*", "docker/setup-buildx-action@*"]} -# Executable Classic workflow snapshot; action pins remain producer-owned. -CODEQL_WORKFLOW = b"""name: CodeQL - -on: - push: - branches: - - main - pull_request: - branches: - - main - merge_group: - workflow_dispatch: - schedule: - - cron: "17 4 * * 2" - -permissions: - actions: read - contents: read - security-events: write - -concurrency: - group: classic-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - classify: - name: CodeQL classification - runs-on: ubuntu-24.04 - timeout-minutes: 5 - outputs: - matrix: ${{ steps.classify.outputs.codeql_matrix }} - run: ${{ steps.classify.outputs.codeql_run }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - id: classify - name: Select analysis languages and paths - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - EVENT_NAME: ${{ github.event_name }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 tools/ci/classify_changes.py \\ - --event "${EVENT_NAME}" \\ - --base "${BASE_SHA}" \\ - --head "${HEAD_SHA}" \\ - --github-output "${GITHUB_OUTPUT}" \\ - --codeql-config build/codeql-config.yml - - analyze: - name: CodeQL analysis (${{ matrix.display }}) - needs: classify - if: needs.classify.outputs.run == 'true' - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.classify.outputs.matrix) }} - runs-on: ubuntu-24.04 - timeout-minutes: 30 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - id: classify - name: Recreate the trusted path configuration - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - EVENT_NAME: ${{ github.event_name }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 tools/ci/classify_changes.py \\ - --event "${EVENT_NAME}" \\ - --base "${BASE_SHA}" \\ - --head "${HEAD_SHA}" \\ - --github-output "${GITHUB_OUTPUT}" \\ - --codeql-config build/codeql-config.yml \\ - --codeql-scope "${{ matrix.scope }}" - - name: Initialize CodeQL - if: matrix.run == true - uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2 - with: - build-mode: none - config-file: ${{ steps.classify.outputs.codeql_config }} - languages: ${{ matrix.language }} - - name: Analyze - if: matrix.run == true - uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2 - with: - category: ${{ matrix.category }} - - codeql-validation: - name: CodeQL validation - if: always() - needs: - - classify - - analyze - runs-on: ubuntu-24.04 - timeout-minutes: 2 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - name: Require every selected analysis - run: | - python3 tools/ci/require_checks.py optional \\ - --label CodeQL \\ - --classifier-result '${{ needs.classify.result }}' \\ - --required '${{ needs.classify.outputs.run }}' \\ - --result '${{ needs.analyze.result }}' -""" -PARTITIONS = [ - {"display": "C/C++ client", "scope": "client", "language": "c-cpp", - "category": "/partition:client/language:c-cpp", "run": True}, - {"display": "C/C++ server", "scope": "server", "language": "c-cpp", - "category": "/partition:server/language:c-cpp", "run": True}, - {"display": "C/C++ core", "scope": "core-cpp", "language": "c-cpp", - "category": "/partition:core/language:c-cpp", "run": True}, - {"display": "Python", "scope": "python", "language": "python", - "category": "/partition:core/language:python", "run": True}, - {"display": "GitHub Actions", "scope": "actions", "language": "actions", - "category": "/partition:core/language:actions", "run": True}, -] - - -def classifier_source(partitions): - source = """FULL_EVENTS = {'push', 'schedule', 'workflow_dispatch', 'merge_group'} -def main(): - if arguments.event in FULL_EVENTS: - full = True - paths = [] -def write_outputs(path, result, config): - entries = [] -""" - for item in partitions: - source += f" if result[{item['scope']!r}]:\n entries.append({item!r})\n" - source += " matrix = {'include': entries or [{'run': False, 'scope': 'union'}]}\n" - return source.encode() - - -CLASSIFIER = classifier_source(PARTITIONS) - - -def content(data): - return {"type": "file", "encoding": "base64", "content": base64.b64encode(data).decode()} - - -def check(name, ref=HEAD, identifier=1, conclusion="success", status="completed"): - return {"name": name, "head_sha": ref, "id": identifier, "status": status, - "conclusion": conclusion, "started_at": "2026-10-11T12:00:00Z", - "app": {"id": 15368, "slug": "github-actions"}, "check_suite": {"id": 99}} - - -class Fixture: - def __init__(self): - self.calls = [] - self.metadata = {"id": 42, "full_name": "atrinik/example", "default_branch": "main", "archived": False} - self.pr = {"number": 12, "state": "open", "draft": False, "merged": False, - "changed_files": 1, "merge_commit_sha": MERGE, - "base": {"ref": "main", "sha": BASE, "repo": {"full_name": "atrinik/example"}}, - "head": {"sha": HEAD, "repo": {"full_name": "atrinik/example"}}} - self.run = {"id": 9, "run_attempt": 2, "event": "pull_request", "status": "completed", - "conclusion": "success", "head_sha": HEAD, "check_suite_id": 99, - "path": ".github/workflows/dependency-review.yml", - "head_repository": {"full_name": "atrinik/example"}, - "pull_requests": [{"number": 12, "head": {"sha": HEAD}, - "base": {"sha": BASE, "ref": "main"}}]} - self.suite_runs = {} - self.associated_pulls = [{"number": 12}] - self.suite = {"id": 99, "head_sha": MERGE, "status": "completed", "conclusion": "success", - "app": {"id": 15368}, "pull_requests": copy.deepcopy(self.run["pull_requests"])} - self.jobs = [{"name": "Dependency review", "status": "completed", "conclusion": "success"}] - self.files = [{"filename": ".github/workflows/check.yml", "status": "modified"}] - self.before = f"name: Check\nsteps:\n - uses: rust-lang/crates-io-auth-action@{OLD} # v1\n".encode() - self.after = f"name: Check\nsteps:\n - uses: rust-lang/crates-io-auth-action@{NEW} # v2\n".encode() - self.checks = {HEAD: [check("Required checks"), check("Conventional PR title", identifier=2)], MERGE: []} - self.live = copy.deepcopy(SELECTED) - self.actions_policy = {"enabled_repositories": "all", "allowed_actions": "selected"} - self.repository_actions = {"enabled": True, "allowed_actions": "all"} - self.enabled_repositories = [{"id": 42, "full_name": "atrinik/example"}] - self.effective_rules = [] - self.legacy_checks = None - self.default_workflow = WORKFLOW - self.run_workflow = WORKFLOW - self.executed_workflow = WORKFLOW - self.parents = [BASE, HEAD] - self.branch_head = HEAD - self.setup = {"state": "configured", "languages": ["rust"]} - self.codeql_sources = {".github/workflows/codeql.yml": CODEQL_WORKFLOW, - "tools/ci/classify_changes.py": CLASSIFIER, - "tools/ci/require_checks.py": b"# Trusted aggregate\n"} - self.codeql_head_sources = copy.deepcopy(self.codeql_sources) - self.codeql_run = {"id": 29, "run_attempt": 1, "head_sha": HEAD, "head_branch": "main", - "event": "push", "path": ".github/workflows/codeql.yml", "check_suite_id": 777, - "status": "completed", "conclusion": "success"} - self.codeql_check = check("CodeQL validation", identifier=999) - self.codeql_check["check_suite"]["id"] = 777 - self.codeql_jobs = [] - self.analysis_reads = 0 - self.fresh_analyses = None - self.analyses = [{"id": 1, "created_at": "2026-10-11T12:00:00Z", "tool": {"name": "CodeQL"}, - "ref": "refs/heads/main", "commit_sha": HEAD, "category": "/language:rust", - "environment": '{"language":"rust"}', "error": "", "rules_count": 42}] - - def __call__(self, endpoint): - self.calls.append(endpoint) - if endpoint == "repos/atrinik/example": - return copy.deepcopy(self.metadata) - if endpoint == "repos/atrinik/example/pulls/12": - return copy.deepcopy(self.pr) - if "/contents/.github/workflows/dependency-review.yml" in endpoint: - return content(self.default_workflow if "ref=main" in endpoint else - self.executed_workflow if "ref=" + MERGE in endpoint else self.run_workflow) - if "/contents/.github/workflows/check.yml" in endpoint: - return content(self.before if "ref=" + self.pr["base"]["sha"] in endpoint else self.after) - if "/contents/" in endpoint: - path = endpoint.split("/contents/")[1].split("?")[0] - ref = parse_qs(urlparse(endpoint).query).get("ref", [None])[0] - sources = self.codeql_sources if ref == self.metadata["default_branch"] else self.codeql_head_sources - return content(sources[path]) - if "/actions/workflows/codeql.yml/runs" in endpoint: - return {"workflow_runs": [copy.deepcopy(self.codeql_run)]} - if "/actions/runs/29/attempts/1/jobs" in endpoint: - return {"total_count": len(self.codeql_jobs), "jobs": copy.deepcopy(self.codeql_jobs)} - if endpoint.endswith("/check-runs/999"): - return copy.deepcopy(self.codeql_check) - if "/check-runs/" in endpoint: - identifier = int(endpoint.rsplit("/", 1)[1]) - for checks in self.checks.values(): - for current in checks: - if current["id"] == identifier: - return copy.deepcopy(current) - raise AssertionError("Unexpected check identity: " + endpoint) - if "/actions/workflows/dependency-review.yml/runs" in endpoint: - return {"workflow_runs": [copy.deepcopy(self.run)]} - if "/attempts/2/jobs" in endpoint: - return {"total_count": len(self.jobs), "jobs": copy.deepcopy(self.jobs)} - if endpoint == "orgs/atrinik/actions/permissions": - return copy.deepcopy(self.actions_policy) - if endpoint == "repos/atrinik/example/actions/permissions": - return copy.deepcopy(self.repository_actions) - if "/actions/permissions/repositories?" in endpoint: - return {"total_count": len(self.enabled_repositories), - "repositories": copy.deepcopy(self.enabled_repositories)} - if "/rules/branches/" in endpoint: - return copy.deepcopy(self.effective_rules) - if endpoint.endswith("/protection"): - return {"required_status_checks": copy.deepcopy(self.legacy_checks)} - if "/actions/permissions/selected-actions" in endpoint: - return copy.deepcopy(self.live) - if "/pulls/12/files" in endpoint: - return copy.deepcopy(self.files) - if f"/commits/{HEAD}/pulls?" in endpoint: - return copy.deepcopy(self.associated_pulls) - if endpoint == "repos/atrinik/example/commits/" + MERGE: - return {"parents": [{"sha": value} for value in self.parents]} - if "/check-runs?" in endpoint: - values = copy.deepcopy(self.checks[endpoint.split("/commits/")[1].split("/")[0]]) - return {"total_count": len(values), "check_runs": values} - if "/actions/runs?check_suite_id=" in endpoint: - suite_id = int(parse_qs(urlparse(endpoint).query)["check_suite_id"][0]) - return {"workflow_runs": [copy.deepcopy(self.suite_runs.get(suite_id, self.run))]} - if "/actions/runs?event=pull_request&head_sha=" in endpoint: - return {"total_count": 1, "workflow_runs": [copy.deepcopy(self.run)]} - if "/check-suites/" in endpoint: - value = copy.deepcopy(self.suite) - value["id"] = int(endpoint.rsplit("/", 1)[1]) - return value - if endpoint == "repos/atrinik/example/branches/" + quote(self.metadata["default_branch"], safe=""): - return {"commit": {"sha": self.branch_head}} - if "/code-scanning/analyses?" in endpoint: - page = int(parse_qs(urlparse(endpoint).query)["page"][0]) - if page == 1: - self.analysis_reads += 1 - analyses = (self.fresh_analyses if self.analysis_reads > 1 and self.fresh_analyses is not None - else self.analyses) - return copy.deepcopy(analyses[(page - 1) * 100:page * 100]) - if endpoint.endswith("/code-scanning/default-setup"): - return copy.deepcopy(self.setup) - raise AssertionError("Unexpected read-only API endpoint: " + endpoint) - - -class ReadinessTests(unittest.TestCase): - def setUp(self): - self.temp = tempfile.TemporaryDirectory() - self.addCleanup(self.temp.cleanup) - self.root = Path(self.temp.name) - (self.root / ".github/workflows").mkdir(parents=True) - (self.root / ".github/workflows/dependency-review.yml").write_bytes(WORKFLOW) - (self.root / "config").mkdir() - (self.root / "config/actions-selected.json").write_text(json.dumps(SELECTED)) - (self.root / "config/repositories.json").write_text(json.dumps({ - "required_ci": {"example": ["Required checks", "Conventional PR title"]}})) - (self.root / "config/security-merge-protection.json").write_text(json.dumps({ - "codeql_required_languages": {"example": ["rust"]}, "dependency_review": []})) - (self.root / "config/codeql-advanced-setup.json").write_text('{"repositories": [], "required_partitions": {}}') - self.fixture = Fixture() - self.root_patch = patch.object(readiness, "ROOT", self.root) - self.api_patch = patch.object(readiness, "api", self.fixture) - self.root_patch.start() - self.api_patch.start() - self.addCleanup(self.root_patch.stop) - self.addCleanup(self.api_patch.stop) - - def invoke(self, mode): - stream = io.StringIO() - with patch("sys.stdout", stream): - result = readiness.main([mode, "atrinik/example/12" if mode == "sha" else "atrinik/example"]) - return result, stream.getvalue() - - def assert_deferred(self, mode, fragment): - code, text = self.invoke(mode) - self.assertEqual(code, 1, text) - self.assertIn(fragment, text) - - def test_dependency_ready_latest_attempt_exact_workflow(self): - self.assertEqual(self.invoke("dependency")[0], 0) - self.assertTrue(any("/attempts/2/jobs" in call for call in self.fixture.calls)) - - def merged_empty_fixture(self, run_empty=True, suite_empty=True): - fixture = Fixture() - fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - if run_empty: - fixture.run["pull_requests"] = [] - if suite_empty: - fixture.suite["pull_requests"] = [] - return fixture - - def test_merged_empty_associations_ready_for_dependency_and_stored_sha_canary(self): - for mode in ("dependency", "sha"): - for run_empty, suite_empty in ((True, False), (False, True), (True, True)): - for direct_head in (False, True): - with self.subTest(mode=mode, run_empty=run_empty, suite_empty=suite_empty, - direct_head=direct_head): - fixture = self.merged_empty_fixture(run_empty, suite_empty) - if direct_head: - fixture.suite["head_sha"] = HEAD - elif mode == "sha": - fixture.checks[MERGE] = [check("Required checks", MERGE), - check("Conventional PR title", MERGE, 2)] - fixture.checks[HEAD] = [] - with patch.object(readiness, "api", fixture): - result, output = self.invoke(mode) - self.assertEqual(result, 0, output) - self.assertGreaterEqual(sum(f"/commits/{HEAD}/pulls?" in endpoint - for endpoint in fixture.calls), 2) - - def test_merged_empty_association_newer_failed_or_queued_canary_still_blocks(self): - for status, conclusion in (("completed", "failure"), ("queued", None)): - with self.subTest(status=status): - fixture = self.merged_empty_fixture() - newer = check("Required checks", identifier=50, status=status, conclusion=conclusion) - newer["started_at"] = None - newer["check_suite"]["id"] = 100 - fixture.checks[HEAD].append(newer) - run = copy.deepcopy(fixture.run) - run.update(id=20, check_suite_id=100, status=status, conclusion=conclusion) - fixture.suite_runs[100] = run - with patch.object(readiness, "api", fixture): - self.assert_deferred("sha", "workflow run not successful") - - def test_merged_empty_associations_reject_ambiguous_or_missing_commit_pulls(self): - for mode in ("dependency", "sha"): - for entries in ([], [{"number": 12}, {"number": 13}]): - with self.subTest(mode=mode, entries=entries): - fixture = self.merged_empty_fixture() - fixture.associated_pulls = entries - with patch.object(readiness, "api", fixture): - self.assert_deferred(mode, "association missing or ambiguous") - - def test_merged_empty_associations_reject_open_pr(self): - for mode in ("dependency", "sha"): - with self.subTest(mode=mode): - fixture = self.merged_empty_fixture() - fixture.pr.update(state="open", merged=False) - fixture.pr["merge_commit_sha"] = MERGE - with patch.object(readiness, "api", fixture): - self.assert_deferred(mode, "association identity") - - def test_merged_empty_associations_reject_identity_mismatch(self): - for mode in ("dependency", "sha"): - for field in ("head", "head_repository", "base", "base_repository", "number"): - with self.subTest(mode=mode, field=field): - fixture = self.merged_empty_fixture() - # Change only the independently fetched association PR; retain - # the caller's initial canary so its own guards cannot mask this test. - count = 0 - def mismatch(endpoint): - nonlocal count - value = fixture(endpoint) - if endpoint.endswith("/pulls/12"): - count += 1 - if mode == "dependency" or count > 1: - if field == "head": - value["head"]["sha"] = OLD - elif field == "head_repository": - value["head"]["repo"]["full_name"] = "other/example" - elif field == "base": - value["base"]["ref"] = "other" - elif field == "base_repository": - value["base"]["repo"]["full_name"] = "other/example" - else: - value["number"] = 13 - return value - with patch.object(readiness, "api", mismatch): - self.assert_deferred(mode, "association identity") - - def test_merged_empty_associations_never_override_nonempty_conflict(self): - for mode in ("dependency", "sha"): - for conflicting in ("run", "suite"): - with self.subTest(mode=mode, conflicting=conflicting): - fixture = self.merged_empty_fixture(conflicting != "run", conflicting != "suite") - source = fixture.run if conflicting == "run" else fixture.suite - source["pull_requests"][0]["base"]["sha"] = OLD - with patch.object(readiness, "api", fixture): - self.assert_deferred(mode, "nonempty PR association conflicts") - - def test_merged_empty_associations_reject_non_pr_event_or_workflow_path(self): - for mode in ("dependency", "sha"): - for field, value in (("event", "push"), ("event", "workflow_dispatch"), - ("path", "untrusted.yml")): - with self.subTest(mode=mode, field=field, value=value): - fixture = self.merged_empty_fixture() - fixture.run[field] = value - with patch.object(readiness, "api", fixture): - result, output = self.invoke(mode) - self.assertEqual(result, 1, output) - - def test_merged_empty_associations_unreadable_is_error(self): - for mode in ("dependency", "sha"): - with self.subTest(mode=mode): - fixture = self.merged_empty_fixture() - def unreadable(endpoint): - if f"/commits/{HEAD}/pulls?" in endpoint: - raise readiness.APIError(endpoint, 403) - return fixture(endpoint) - with patch.object(readiness, "api", unreadable): - code, output = self.invoke(mode) - self.assertEqual(code, 2, output) - self.assertIn("HTTP 403", output) - - def test_merged_empty_association_collection_is_refenced(self): - for mode in ("dependency", "sha"): - with self.subTest(mode=mode): - fixture = self.merged_empty_fixture() - verify = readiness.verify_recovered_associations - def change_at_fence(coordinate, recovered): - fixture.associated_pulls.append({"number": 13}) - return verify(coordinate, recovered) - with patch.object(readiness, "api", fixture), patch.object( - readiness, "verify_recovered_associations", change_at_fence): - self.assert_deferred(mode, "association missing or ambiguous") - - def test_merged_empty_association_pr_identity_is_refenced(self): - for mode in ("dependency", "sha"): - with self.subTest(mode=mode): - fixture = self.merged_empty_fixture() - verify = readiness.verify_recovered_associations - def change_at_fence(coordinate, recovered): - fixture.pr["base"]["sha"] = OLD - return verify(coordinate, recovered) - with patch.object(readiness, "api", fixture), patch.object( - readiness, "verify_recovered_associations", change_at_fence): - self.assert_deferred(mode, "association changed during preflight") - - def test_merged_empty_association_preserves_workflow_and_merge_parent_proof(self): - for mode in ("dependency", "sha"): - with self.subTest(mode=mode): - fixture = self.merged_empty_fixture() - fixture.parents = [OLD, HEAD] - with patch.object(readiness, "api", fixture): - self.assert_deferred(mode, "merge") - fixture = self.merged_empty_fixture() - fixture.executed_workflow += b"# changed execution bytes\n" - with patch.object(readiness, "api", fixture): - self.assert_deferred("dependency", "different workflow bytes") - - def test_dependency_base_retarget_requires_edited_trigger(self): - # An otherwise green producer that ran before retargeting coverage was - # added cannot establish the complete default-branch PR contract. - old = WORKFLOW.replace(b"opened, synchronize, reopened, edited", - b"opened, synchronize, reopened") - self.fixture.default_workflow = old - self.fixture.run_workflow = old - self.fixture.executed_workflow = old - self.assert_deferred("dependency", "not landed") - - def test_dependency_base_retarget_activity_block_ready(self): - edited = WORKFLOW.replace( - b" types: [opened, synchronize, reopened, edited]", - b" types:\n - edited\n - opened\n - reopened\n - synchronize") - self.fixture.default_workflow = edited - self.fixture.run_workflow = edited - self.fixture.executed_workflow = edited - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_extra_activity_type_deferred(self): - self.fixture.default_workflow = WORKFLOW.replace(b"reopened, edited]", - b"reopened, edited, closed]") - self.assert_deferred("dependency", "not landed") - - def test_dependency_merge_queue_trigger_required(self): - self.fixture.default_workflow = WORKFLOW.replace( - b" merge_group:\n types: [checks_requested]\n", b"") - self.assert_deferred("dependency", "not landed") - - def test_dependency_merge_queue_activity_block_ready(self): - queue = WORKFLOW.replace(b" types: [checks_requested]", - b" types:\n - checks_requested") - self.fixture.default_workflow = queue - self.fixture.run_workflow = queue - self.fixture.executed_workflow = queue - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_merge_queue_wrong_activity_deferred(self): - self.fixture.default_workflow = WORKFLOW.replace(b"[checks_requested]", b"[destroyed]") - self.assert_deferred("dependency", "not landed") - - def test_dependency_merge_queue_run_does_not_replace_pr_evidence(self): - self.fixture.run["event"] = "merge_group" - self.assert_deferred("dependency", "latest dependency-review PR run not successful") - - def test_actual_component_workflow_key_order_matches_central_contract(self): - # Retain the historical hard-gate contract as a test-owned fixture; - # the production root workflow is now deliberately advisory. - central = COMPONENT_WORKFLOW.replace( - b" types: [opened, synchronize, reopened, edited]\n branches:\n - main", - b" branches: [main]\n types: [opened, synchronize, reopened, edited]") - self.assertEqual(readiness.dependency_contract(COMPONENT_WORKFLOW), - readiness.dependency_contract(central)) - - def test_actual_component_key_order_preserves_branch_restriction(self): - # Retain the historical hard-gate contract as a test-owned fixture; - # the production root workflow is now deliberately advisory. - central = COMPONENT_WORKFLOW.replace( - b" types: [opened, synchronize, reopened, edited]\n branches:\n - main", - b" branches: [main]\n types: [opened, synchronize, reopened, edited]") - changed = COMPONENT_WORKFLOW.replace(b" - main", b" - other") - self.assertNotEqual(readiness.dependency_contract(changed), - readiness.dependency_contract(central)) - - def test_actual_component_key_order_preserves_activity_restriction(self): - # Retain the historical hard-gate contract as a test-owned fixture; - # the production root workflow is now deliberately advisory. - central = COMPONENT_WORKFLOW.replace( - b" types: [opened, synchronize, reopened, edited]\n branches:\n - main", - b" branches: [main]\n types: [opened, synchronize, reopened, edited]") - changed = COMPONENT_WORKFLOW.replace(b", edited]", b"]") - self.assertNotEqual(readiness.dependency_contract(changed), - readiness.dependency_contract(central)) - - def test_production_advisory_reports_without_vulnerability_ci_barrier(self): - document = readiness.workflow_yaml( - (ROOT / ".github/workflows/dependency-review.yml").read_bytes(), "advisory") - self.assertEqual(document["permissions"], {"contents": "read", "pull-requests": "write"}) - self.assertEqual(set(document["on"]), {"pull_request"}) - self.assertEqual(document["on"]["pull_request"], { - "types": ["opened", "synchronize", "reopened", "edited"]}) - job = document["jobs"]["dependency-review"] - self.assertEqual(document["concurrency"], { - "group": "dependency-review-${{ github.event.pull_request.number || github.ref }}", - "cancel-in-progress": "true"}) - self.assertEqual(job["timeout-minutes"], 10) - self.assertEqual(len(job["steps"]), 2) - step = job["steps"][0] - self.assertEqual(step["id"], "dependency_review") - self.assertEqual(step["timeout-minutes"], 5) - self.assertRegex(step["uses"], r"^actions/dependency-review-action@[0-9a-f]{40}$") - self.assertEqual(step["continue-on-error"], "true") - self.assertEqual(step["with"]["warn-only"], "true") - self.assertEqual(step["with"]["fail-on-severity"], "low") - self.assertEqual(step["with"]["fail-on-scopes"], "runtime,development,unknown") - self.assertEqual(step["with"]["license-check"], "true") - self.assertEqual(step["with"]["comment-summary-in-pr"], "always") - self.assertNotIn("if", job) - self.assertNotIn("if", step) - self.assertNotIn("run", step) - self.assertNotIn("secrets", job) - self.assertNotIn("allow-ghsas", step["with"]) - - def test_advisory_failure_notice_preserves_available_report_and_is_nonblocking(self): - documents = [] - for path in (".github/workflows/dependency-review.yml", - "community-health/workflows/dependency-review.yml"): - document = readiness.workflow_yaml((ROOT / path).read_bytes(), "advisory") - documents.append(document) - notice = document["jobs"]["dependency-review"]["steps"][1] - self.assertEqual(notice["if"], "${{ !cancelled() && steps.dependency_review.outcome == 'failure' }}") - self.assertEqual(notice["continue-on-error"], "true") - self.assertNotIn("uses", notice) - self.assertEqual(notice["shell"], "python") - self.assertEqual(notice["timeout-minutes"], 2) - self.assertEqual(notice["env"], { - "GITHUB_TOKEN": "${{ github.token }}", - "PR_NUMBER": "${{ github.event.pull_request.number }}", - "PR_HEAD_SHA": "${{ github.event.pull_request.head.sha }}", - "PR_BASE_REF": "${{ github.event.pull_request.base.ref }}", - "PR_BASE_SHA": "${{ github.event.pull_request.base.sha }}"}) - summary = self.root / "failure-summary.md" - summary.write_text("Existing vulnerability and license report.\n") - # Invalid API context exercises the local fallback before any network access. - env = {"PATH": os.environ["PATH"], "GITHUB_STEP_SUMMARY": str(summary), - "GITHUB_REPOSITORY": "atrinik/example", "PR_NUMBER": "42", - "PR_HEAD_SHA": HEAD, "PR_BASE_REF": "main", "PR_BASE_SHA": BASE, - "GITHUB_RUN_ID": "123", "GITHUB_RUN_ATTEMPT": "1", - "GITHUB_API_URL": "https://invalid.example", "GITHUB_SERVER_URL": "https://github.com", - "GITHUB_EVENT_NAME": "pull_request"} - result = subprocess.run([sys.executable, "-c", notice["run"]], - capture_output=True, text=True, env=env, check=False) - self.assertEqual(result.returncode, 0, result.stderr) - self.assertIn("::warning::", result.stdout) - report = summary.read_text() - self.assertTrue(report.startswith("Existing vulnerability and license report.\n")) - self.assertIn("Dependency review needs attention", report) - self.assertIn("An absent report means the result is unknown, not clean.", report) - self.assertIn("Invalid reporting context; PR comment was not refreshed.", report) - self.assertEqual(documents[0], documents[1]) - - def test_production_advisory_never_qualifies_required_gate(self): - source = (ROOT / ".github/workflows/dependency-review.yml").read_bytes() - (self.root / ".github/workflows/dependency-review.yml").write_bytes(source) - self.fixture.default_workflow = source - self.fixture.run_workflow = source - self.fixture.executed_workflow = source - self.assert_deferred("dependency", "advisory") - - def test_advisory_inputs_and_failure_suppression_cannot_qualify(self): - for source in [WORKFLOW.replace(b"warn-only: false", b"warn-only: true"), - WORKFLOW.replace(b" with:", b" continue-on-error: true\n with:"), - WORKFLOW.replace(b" runs-on:", b" continue-on-error: true\n runs-on:"), - WORKFLOW.replace(b" with:", b" if: false\n with:")]: - with self.subTest(source=source): - (self.root / ".github/workflows/dependency-review.yml").write_bytes(source) - self.fixture.default_workflow = source - self.assert_deferred("dependency", "cannot qualify") - - def test_advisory_dependency_failure_is_not_a_desired_sha_gate(self): - self.fixture.checks[HEAD].append(check("Dependency review", identifier=30, conclusion="failure")) - self.assertEqual(self.invoke("sha")[0], 0) - - def test_dependency_not_landed(self): - self.fixture.default_workflow = WORKFLOW.replace(b"fail-on-severity: high", b"fail-on-severity: low") - self.assert_deferred("dependency", "not landed") - - def test_dependency_producer_fresh_sha_passes_without_central_update(self): - fresh = WORKFLOW.replace(OLD.encode(), NEW.encode()).replace(b"v5.0.0", b"v5.1.0") - self.fixture.default_workflow = fresh - self.fixture.run_workflow = fresh - self.fixture.executed_workflow = fresh - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_mutable_action_ref_deferred(self): - self.fixture.default_workflow = WORKFLOW.replace(OLD.encode(), b"v5") - self.assert_deferred("dependency", "full-SHA") - - def test_dependency_classic_block_branch_filter_ready(self): - fresh = WORKFLOW.replace(b" branches: [main]", b" branches:\n - main") - self.fixture.default_workflow = fresh - self.fixture.run_workflow = fresh - self.fixture.executed_workflow = fresh - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_extra_branch_filter_deferred(self): - self.fixture.default_workflow = WORKFLOW.replace(b" branches: [main]", - b" branches:\n - main\n - extra") - self.assert_deferred("dependency", "not landed") - - def test_dependency_named_official_action_step_ready(self): - fresh = WORKFLOW.replace(b" - uses:", - b" - name: Review dependency changes\n uses:") - self.fixture.default_workflow = fresh - self.fixture.run_workflow = fresh - self.fixture.executed_workflow = fresh - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_labels_do_not_lock_producer_workflow(self): - fresh = WORKFLOW.replace(b"name: Dependency review\n", b"name: Dependency safety\n", 1) - fresh = fresh.replace(b" - uses:", b" - name: Validate dependencies\n uses:") - self.fixture.default_workflow = fresh - self.fixture.run_workflow = fresh - self.fixture.executed_workflow = fresh - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_named_step_arbitrary_run_deferred(self): - fresh = WORKFLOW.replace(b" - uses:", - b" - name: Review dependency changes\n run: arbitrary\n uses:") - self.fixture.default_workflow = fresh - self.assert_deferred("dependency", "not landed") - - def test_dependency_blank_comment_trailing_whitespace_ready(self): - fresh = WORKFLOW.replace(b"permissions:\n", b"# Explanation\n\npermissions: \n") - self.fixture.default_workflow = fresh - self.fixture.run_workflow = fresh - self.fixture.executed_workflow = fresh - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_failed_latest_does_not_search_older_success(self): - self.fixture.run["conclusion"] = "failure" - self.assert_deferred("dependency", "latest") - self.assertEqual(len([call for call in self.fixture.calls if "/runs?event=" in call]), 1) - - def test_dependency_successful_run_failed_job(self): - self.fixture.jobs[0]["conclusion"] = "failure" - self.assert_deferred("dependency", "job not successful") - - def test_dependency_run_different_bytes(self): - self.fixture.executed_workflow += b"# different\n" - self.assert_deferred("dependency", "different workflow bytes") - - def test_dependency_matching_head_but_executed_merge_workflow_differs(self): - self.assertEqual(self.fixture.default_workflow, self.fixture.run_workflow) - self.fixture.executed_workflow = WORKFLOW.replace(b"warn-only: false", b"warn-only: true") - self.assert_deferred("dependency", "different workflow bytes") - - def test_dependency_direct_head_execution_bound_to_pr(self): - self.fixture.suite["head_sha"] = HEAD - self.assertEqual(self.invoke("dependency")[0], 0) - - def test_dependency_direct_head_missing_execution_pr_association(self): - self.fixture.suite.update(head_sha=HEAD, pull_requests=[]) - self.assert_deferred("dependency", "merged PR association") - - def test_dependency_executed_merge_wrong_parents_deferred(self): - self.fixture.parents = [BASE, OLD] - self.assert_deferred("dependency", "current PR head/base") - - def test_dependency_stale_execution_base_association_deferred(self): - self.fixture.suite["pull_requests"][0]["base"]["sha"] = OLD - self.assert_deferred("dependency", "execution PR association") - - def test_dependency_check_suite_drift_deferred(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if endpoint.endswith("/check-suites/99"): - calls += 1 - if calls > 1: - value["head_sha"] = OLD - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("dependency", "check suite changed") - - def test_dependency_run_association_drift_deferred(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if "/actions/workflows/dependency-review.yml/runs" in endpoint: - calls += 1 - if calls > 1: - value["workflow_runs"][0]["pull_requests"] = [] - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("dependency", "run changed") - - def test_dependency_pr_drift_deferred(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if endpoint.endswith("/pulls/12"): - calls += 1 - if calls > 1: - value["base"]["sha"] = OLD - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("dependency", "PR changed") - - def test_dependency_wrong_base(self): - self.fixture.pr["base"]["ref"] = "maintenance" - self.assert_deferred("dependency", "default branch") - - def test_dependency_stale_head(self): - self.fixture.pr["head"]["sha"] = NEW - self.assert_deferred("dependency", "head changed") - - def test_dependency_api_404_missing_is_deferred(self): - def missing(endpoint): - if "/contents/" in endpoint: - raise readiness.APIError(endpoint, 404) - return self.fixture(endpoint) - with patch.object(readiness, "api", missing): - self.assert_deferred("dependency", "missing") - - def test_api_denied_is_error_not_deferred(self): - with patch.object(readiness, "api", side_effect=readiness.APIError("repos/atrinik/example", 403)): - self.assertEqual(self.invoke("dependency")[0], 2) - - def test_sha_wildcard_accepts_fresh_rust_pin(self): - self.assertEqual(self.invoke("sha")[0], 0) - - def require_dependency_for_canary(self): - path = self.root / "config/security-merge-protection.json" - policy = json.loads(path.read_text()) - policy["dependency_review"] = ["example"] - path.write_text(json.dumps(policy)) - - def effective_check(self, context, app=15368): - return {"type": "required_status_checks", "parameters": { - "required_status_checks": [{"context": context, "integration_id": app}]}} - - def test_sha_targeted_dependency_review_missing_failed_or_queued_rejected(self): - self.require_dependency_for_canary() - self.assert_deferred("sha", "Dependency review") - self.fixture.checks[HEAD].append(check("Dependency review", identifier=30, conclusion="failure")) - self.assert_deferred("sha", "Dependency review") - self.fixture.checks[HEAD][-1].update(status="queued", conclusion=None, started_at=None) - self.assert_deferred("sha", "Dependency review") - self.fixture.checks[HEAD][-1].update(status="completed", conclusion="success") - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_effective_extra_rule_context_required_with_trusted_actions(self): - self.fixture.effective_rules = [self.effective_check("Extra validation")] - self.assert_deferred("sha", "Extra validation") - self.fixture.checks[HEAD].append(check("Extra validation", identifier=30)) - self.fixture.checks[HEAD][-1]["app"]["id"] = 999 - self.assert_deferred("sha", "Extra validation") - self.fixture.checks[HEAD][-1]["app"]["id"] = 15368 - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_effective_dependency_review_required_outside_target_inventory(self): - self.fixture.effective_rules = [self.effective_check("Dependency review")] - self.assert_deferred("sha", "Dependency review") - - def test_sha_legacy_protection_context_required(self): - self.fixture.legacy_checks = {"contexts": ["Legacy check"], "checks": []} - self.assert_deferred("sha", "Legacy check") - self.fixture.checks[HEAD].append(check("Legacy check", identifier=30)) - self.assertEqual(self.invoke("sha")[0], 0) - - def legacy_error(self, message, status="404"): - def response(endpoint): - if endpoint.endswith("/protection"): - raise readiness.APIError(endpoint, 404, {"message": message, "status": status}) - return self.fixture(endpoint) - return patch.object(readiness, "api", response) - - def disabled_legacy_response(self): - return {"data": {"repository": {"databaseId": 42, "nameWithOwner": "atrinik/example", - "isArchived": False, "ref": {"name": "main", "branchProtectionRule": None}}}} - - def test_sha_only_exact_unprotected_error_proves_absence(self): - for message, status, expected in (("Branch not protected", "404", 0), - ("Resource not found", "404", 2), ("Not Found", "404", 2), - ("Resource not accessible by integration", "404", 2), - ("Branch not protected", None, 2), ("Branch not protected", 404, 2)): - with self.subTest(message=message, status=status), self.legacy_error(message, status): - self.assertEqual(self.invoke("sha")[0], expected) - - def test_sha_missing_or_malformed_full_protection_not_absence(self): - for value in ({}, [], None, {"required_status_checks": False}, - {"required_status_checks": {}}, - {"required_status_checks": {"checks": None, "contexts": []}}, - {"required_status_checks": {"checks": [], "contexts": None}}): - def response(endpoint): - return value if endpoint.endswith("/protection") else self.fixture(endpoint) - with self.subTest(value=value), patch.object(readiness, "api", response): - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_disabled_legacy_requires_exact_readonly_identity_proof(self): - result = subprocess.CompletedProcess([], 0, stdout=json.dumps(self.disabled_legacy_response()), stderr="") - with self.legacy_error("Branch protection has been disabled on this repository."), \ - patch.object(readiness.subprocess, "run", return_value=result) as mocked: - self.assertEqual(self.invoke("sha")[0], 0) - self.assertEqual(mocked.call_count, 2) - args = mocked.call_args.args[0] - self.assertEqual(args[args.index("--method") + 1], "POST") - self.assertIn("graphql", args) - self.assertIn("owner=atrinik", args) - self.assertIn("name=example", args) - self.assertIn("qualifiedName=refs/heads/main", args) - query = next(arg for arg in args if arg.startswith("query=")) - self.assertTrue(query.startswith("query=query LegacyBranchProtection(")) - self.assertNotIn("mutation", query) - - def test_sha_disabled_legacy_ambiguous_identity_or_presence_rejected(self): - mutations = [lambda r: r.update(errors=[]), - lambda r: r["data"].update(repository=None), - lambda r: r["data"]["repository"].update(databaseId=43), - lambda r: r["data"]["repository"].update(databaseId=True), - lambda r: r["data"]["repository"].update(nameWithOwner="foreign/example"), - lambda r: r["data"]["repository"].update(isArchived=True), - lambda r: r["data"]["repository"].update(ref=None), - lambda r: r["data"]["repository"]["ref"].update(name="other"), - lambda r: r["data"]["repository"]["ref"].pop("branchProtectionRule"), - lambda r: r["data"]["repository"]["ref"].update(branchProtectionRule={"id": "rule"})] - for index, mutate in enumerate(mutations): - response = self.disabled_legacy_response() - mutate(response) - result = subprocess.CompletedProcess([], 0, stdout=json.dumps(response), stderr="") - with self.subTest(index=index), self.legacy_error("Branch protection has been disabled on this repository."), \ - patch.object(readiness.subprocess, "run", return_value=result): - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_disabled_legacy_unreadable_or_invalid_graphql_rejected(self): - for result in (subprocess.CompletedProcess([], 1, stdout="", stderr="denied"), - subprocess.CompletedProcess([], 0, stdout="not json", stderr="")): - with self.subTest(result=result), self.legacy_error("Branch protection has been disabled on this repository."), \ - patch.object(readiness.subprocess, "run", return_value=result): - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_disabled_legacy_fresh_rest_identity_required(self): - for field, value in (("id", 43), ("full_name", "foreign/example"), - ("default_branch", "other"), ("archived", True)): - count = 0 - def response(endpoint): - nonlocal count - if endpoint.endswith("/protection"): - raise readiness.APIError(endpoint, 404, { - "message": "Branch protection has been disabled on this repository.", "status": "404"}) - current = self.fixture(endpoint) - if endpoint == "repos/atrinik/example": - count += 1 - if count > 1: - current[field] = value - return current - with self.subTest(field=field), patch.object(readiness, "api", response), \ - patch.object(readiness.subprocess, "run") as mocked: - self.assertNotEqual(self.invoke("sha")[0], 0) - mocked.assert_not_called() - - def test_sha_disabled_legacy_proof_rechecked_before_acceptance(self): - initial = self.disabled_legacy_response() - changed = copy.deepcopy(initial) - changed["data"]["repository"]["ref"]["branchProtectionRule"] = {"id": "new-rule"} - results = [subprocess.CompletedProcess([], 0, stdout=json.dumps(value), stderr="") - for value in (initial, changed)] - with self.legacy_error("Branch protection has been disabled on this repository."), \ - patch.object(readiness.subprocess, "run", side_effect=results): - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_full_legacy_checks_array_requires_all_bound_contexts(self): - self.fixture.legacy_checks = {"contexts": [], "checks": [ - {"context": "Legacy check", "app_id": 15368}, - {"context": "Second legacy check", "app_id": None}]} - self.assert_deferred("sha", "Legacy check") - self.fixture.checks[HEAD].append(check("Legacy check", identifier=30)) - self.assert_deferred("sha", "Second legacy check") - self.fixture.checks[HEAD].append(check("Second legacy check", identifier=31)) - self.assertEqual(self.invoke("sha")[0], 0) - self.fixture.checks[HEAD][-1]["conclusion"] = "failure" - self.assert_deferred("sha", "Second legacy check") - - def test_sha_legacy_absence_must_remain_readable_at_final_fence(self): - count = 0 - def response(endpoint): - nonlocal count - if endpoint.endswith("/protection"): - count += 1 - if count > 1: - raise readiness.APIError(endpoint, 404, {"message": "Not Found", "status": "404"}) - return self.fixture(endpoint) - with patch.object(readiness, "api", response): - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_non_actions_app_binding_never_satisfied_by_same_named_actions_check(self): - self.fixture.effective_rules = [self.effective_check("Required checks", 999)] - self.assert_deferred("sha", "non-Actions app") - self.fixture.effective_rules = [] - self.fixture.legacy_checks = {"contexts": ["Required checks"], - "checks": [{"context": "Required checks", "app_id": 999}]} - self.assert_deferred("sha", "non-Actions app") - - def test_sha_unbound_effective_context_still_requires_trusted_actions(self): - self.fixture.effective_rules = [self.effective_check("Required checks", None)] - self.assertEqual(self.invoke("sha")[0], 0) - self.fixture.checks[HEAD][0]["app"]["slug"] = "untrusted" - self.assert_deferred("sha", "Required checks") - - def test_sha_effective_rule_or_legacy_changes_during_preflight_rejected(self): - for endpoint_part in ("/rules/branches/", "/protection"): - with self.subTest(endpoint=endpoint_part): - count = 0 - def drift(endpoint): - nonlocal count - if endpoint_part in endpoint: - count += 1 - if count > 1: - if "rules/branches" in endpoint: - return [self.effective_check("New gate")] - return {"required_status_checks": {"contexts": ["New gate"], "checks": []}} - return self.fixture(endpoint) - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "effective required checks changed") - - def test_sha_effective_rules_and_legacy_unreadable_fail_closed(self): - for endpoint_part in ("/rules/branches/", "/protection"): - with self.subTest(endpoint=endpoint_part): - def unreadable(endpoint): - if endpoint_part in endpoint: - raise readiness.APIError(endpoint, 403) - return self.fixture(endpoint) - with patch.object(readiness, "api", unreadable): - code, output = self.invoke("sha") - self.assertEqual(code, 2, output) - - def test_sha_malformed_effective_checks_rejected(self): - self.fixture.effective_rules = [self.effective_check("Required checks", "15368")] - self.assertEqual(self.invoke("sha")[0], 2) - self.fixture.effective_rules = [] - self.fixture.legacy_checks = {"contexts": "Required checks", "checks": []} - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_dormant_selected_patterns_with_all_mode_rejected(self): - self.fixture.actions_policy["allowed_actions"] = "all" - self.assert_deferred("sha", "selected policy is not active") - self.assertFalse(any("/check-runs?" in endpoint for endpoint in self.fixture.calls)) - - def test_sha_selected_repository_enablement_and_identity_required(self): - self.fixture.actions_policy["enabled_repositories"] = "selected" - self.assertEqual(self.invoke("sha")[0], 0) - self.fixture.enabled_repositories[0]["id"] = 999 - self.assert_deferred("sha", "not enabled") - self.fixture.enabled_repositories[0].update(id=42, full_name="foreign/example") - self.assert_deferred("sha", "not enabled") - - def test_sha_disabled_organization_or_repository_actions_rejected(self): - self.fixture.actions_policy["enabled_repositories"] = "none" - self.assert_deferred("sha", "disabled") - self.fixture.actions_policy["enabled_repositories"] = "all" - self.fixture.repository_actions["enabled"] = False - self.assert_deferred("sha", "does not allow external") - self.fixture.repository_actions.update(enabled=True, allowed_actions="local_only") - self.assert_deferred("sha", "does not allow external") - - def test_sha_repository_all_or_selected_cannot_relax_organization_ceiling(self): - for mode in ("all", "selected"): - self.fixture.repository_actions["allowed_actions"] = mode - self.assertEqual(self.invoke("sha")[0], 0) - self.fixture.actions_policy["allowed_actions"] = "all" - self.assert_deferred("sha", "selected policy is not active") - - def test_sha_actions_mode_or_repository_changes_during_proof_rejected(self): - for owner in ("orgs/atrinik", "repos/atrinik/example"): - with self.subTest(owner=owner): - count = 0 - def drift(endpoint): - nonlocal count - value = self.fixture(endpoint) - if endpoint == owner + "/actions/permissions": - count += 1 - if count > 1: - value["allowed_actions"] = "all" if owner.startswith("orgs") else "local_only" - return value - with patch.object(readiness, "api", drift): - self.assertEqual(self.invoke("sha")[0], 1) - - def test_sha_actions_policy_unreadable_and_malformed_fail_closed(self): - for endpoint_part in ("orgs/atrinik/actions/permissions", "repos/atrinik/example/actions/permissions"): - with self.subTest(endpoint=endpoint_part): - def unreadable(endpoint): - if endpoint == endpoint_part: - raise readiness.APIError(endpoint, 403) - return self.fixture(endpoint) - with patch.object(readiness, "api", unreadable): - self.assertEqual(self.invoke("sha")[0], 2) - self.fixture.repository_actions["enabled"] = "true" - self.assertEqual(self.invoke("sha")[0], 2) - self.fixture.repository_actions["enabled"] = True - self.fixture.actions_policy["enabled_repositories"] = "unexpected" - self.assertEqual(self.invoke("sha")[0], 2) - - def test_sha_selected_membership_change_refenced(self): - self.fixture.actions_policy["enabled_repositories"] = "selected" - count = 0 - def drift(endpoint): - nonlocal count - value = self.fixture(endpoint) - if "/actions/permissions/repositories?" in endpoint: - count += 1 - if count > 1: - value = {"total_count": 0, "repositories": []} - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "not enabled") - - def test_codeql_languages_schema_rejects_mapping_null_and_nonstrings(self): - for value in ({"rust": False}, None, "rust", [False], [""]): - with self.subTest(value=value): - self.fixture.setup["languages"] = value - code, output = self.invoke("codeql") - self.assertEqual(code, 2, output) - - def test_codeql_fresh_languages_schema_rejected(self): - count = 0 - def drift(endpoint): - nonlocal count - value = self.fixture(endpoint) - if endpoint.endswith("/code-scanning/default-setup"): - count += 1 - if count > 1: - value["languages"] = {"rust": False} - return value - with patch.object(readiness, "api", drift): - self.assertEqual(self.invoke("codeql")[0], 2) - - def test_sha_general_github_owned_pin_update(self): - self.fixture.before = f"steps:\n - uses: actions/checkout@{OLD} # v5\n".encode() - self.fixture.after = f"steps:\n - uses: actions/checkout@{NEW} # v6\n".encode() - self.assertEqual(self.invoke("sha")[0], 0) - - def allow_canary_action_family(self, pattern): - self.fixture.live["patterns_allowed"].append(pattern) - (self.root / "config/actions-selected.json").write_text(json.dumps(self.fixture.live)) - - def test_sha_reusable_workflow_update_is_not_action_enforcement_evidence(self): - self.allow_canary_action_family("atrinik/shared/*") - for suffix in ("yml", "yaml"): - with self.subTest(suffix=suffix): - workflow = ("name: Check\non: pull_request\njobs:\n validation:\n" - f" uses: atrinik/shared/.github/workflows/check.{suffix}@{{pin}}\n") - self.fixture.before = workflow.format(pin=OLD).encode() - self.fixture.after = workflow.format(pin=NEW).encode() - self.assert_deferred("sha", "reusable workflow reference") - # GitHub-owned allowances do not turn a reusable workflow into an action. - self.fixture.before = self.fixture.before.replace(b"atrinik/shared", b"github/shared") - self.fixture.after = self.fixture.after.replace(b"atrinik/shared", b"github/shared") - self.assert_deferred("sha", "reusable workflow reference") - - def test_sha_mixed_reusable_and_action_updates_rejected(self): - self.allow_canary_action_family("atrinik/shared/*") - workflow = ("name: Check\non: pull_request\njobs:\n validation:\n" - " uses: atrinik/shared/.github/workflows/check.yml@{workflow_pin}\n" - " local:\n runs-on: ubuntu-24.04\n steps:\n" - " - uses: actions/checkout@{action_pin}\n") - self.fixture.before = workflow.format(workflow_pin=OLD, action_pin=OLD).encode() - self.fixture.after = workflow.format(workflow_pin=NEW, action_pin=NEW).encode() - self.assert_deferred("sha", "reusable workflow reference") - # An unchanged reusable reference is ordinary context, not changed proof. - self.fixture.after = workflow.format(workflow_pin=OLD, action_pin=NEW).encode() - result, message = self.invoke("sha") - self.assertEqual(result, 0, message) - - def test_sha_real_action_subpath_update_remains_eligible(self): - self.allow_canary_action_family("atrinik/shared/*") - for action in ("atrinik/shared/actions/check", "atrinik/shared/.github/actions/check", - "github/codeql-action/init"): - with self.subTest(action=action): - workflow = ("name: Check\non: pull_request\njobs:\n validation:\n" - " runs-on: ubuntu-24.04\n steps:\n" - f" - uses: {action}@{{pin}}\n") - self.fixture.before = workflow.format(pin=OLD).encode() - self.fixture.after = workflow.format(pin=NEW).encode() - result, message = self.invoke("sha") - self.assertEqual(result, 0, message) - - def test_sha_live_old_exact_pin_deferred(self): - self.fixture.live["patterns_allowed"][-1] = "rust-lang/crates-io-auth-action@" + OLD - self.assert_deferred("sha", "live selected-actions") - - def test_sha_allowlist_file_update_rejected(self): - self.fixture.files = [{"filename": "config/actions-selected.json", "status": "modified"}] - self.assert_deferred("sha", "outside existing workflows") - - def test_sha_arbitrary_code_update_rejected_even_if_patch_hides_it(self): - self.fixture.files[0]["patch"] = "@@ fake pin-only partial diff" - self.fixture.after += b" - run: arbitrary-command\n" - self.assert_deferred("sha", "more than action pins") - - def test_sha_changed_action_identity_rejected(self): - self.fixture.after = self.fixture.after.replace(b"rust-lang/crates-io-auth-action", b"docker/setup-buildx-action") - self.assert_deferred("sha", "action structure") - - def test_sha_version_ref_rejected(self): - self.fixture.after = self.fixture.after.replace(NEW.encode(), b"v2") - self.assert_deferred("sha", "more than action pins") - - def test_sha_disallowed_action_update_rejected(self): - self.fixture.before = self.fixture.before.replace(b"rust-lang", b"untrusted") - self.fixture.after = self.fixture.after.replace(b"rust-lang", b"untrusted") - self.assert_deferred("sha", "outside desired") - - def test_sha_latest_failure_masks_old_success(self): - self.fixture.checks[HEAD].append(check("Required checks", identifier=10, conclusion="failure")) - self.assert_deferred("sha", "not successful") - - def test_sha_missing_context(self): - self.fixture.checks[HEAD].pop() - self.assert_deferred("sha", "missing") - - def test_sha_wrong_head_check_rejected(self): - self.fixture.checks[HEAD][0]["head_sha"] = OLD - self.assert_deferred("sha", "missing") - - def test_sha_direct_head_push_checks_rejected(self): - self.fixture.run["event"] = "push" - self.assert_deferred("sha", "missing") - - def test_sha_direct_head_workflow_dispatch_checks_rejected(self): - self.fixture.run["event"] = "workflow_dispatch" - self.assert_deferred("sha", "missing") - - def test_sha_direct_head_unrelated_pr_checks_rejected(self): - self.fixture.run["pull_requests"][0]["number"] = 100 - self.assert_deferred("sha", "missing") - - def test_sha_direct_head_wrong_suite_checks_rejected(self): - self.fixture.run["check_suite_id"] = 100 - self.assert_deferred("sha", "missing") - - def test_sha_direct_head_stale_run_checks_rejected(self): - self.fixture.run["head_sha"] = OLD - self.assert_deferred("sha", "missing") - - def advance_canary_base(self): - self.fixture.pr["base"]["sha"] = OLD - self.fixture.parents = [OLD, HEAD] - - def test_sha_open_canary_base_advance_rejects_old_direct_head_success(self): - self.advance_canary_base() - self.assert_deferred("sha", "required check missing") - - def test_sha_open_canary_base_advance_requires_both_run_and_suite_current(self): - for stale in ("run", "suite"): - with self.subTest(stale=stale): - self.advance_canary_base() - self.fixture.run["pull_requests"][0]["base"]["sha"] = BASE if stale == "run" else OLD - self.fixture.suite["pull_requests"][0]["base"]["sha"] = BASE if stale == "suite" else OLD - self.assert_deferred("sha", "required check missing") - - def test_sha_open_canary_fresh_base_associations_pass_direct_and_merge_checks(self): - self.advance_canary_base() - for source in (self.fixture.run, self.fixture.suite): - source["pull_requests"][0]["base"]["sha"] = OLD - self.assertEqual(self.invoke("sha")[0], 0) - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_open_canary_old_base_associations_reject_even_with_current_merge_parents(self): - self.advance_canary_base() - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assert_deferred("sha", "required check missing") - - def test_sha_merged_canary_keeps_recorded_historical_base_proof(self): - self.fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - self.fixture.pr["base"]["sha"] = OLD - # The historical merge and association retain their recorded BASE. - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_current_base_failure_or_queued_check_cannot_hide_behind_stale_green(self): - for status, conclusion in (("completed", "failure"), ("queued", None)): - with self.subTest(status=status): - self.advance_canary_base() - self.fixture.checks[HEAD] = [check("Required checks"), check("Conventional PR title", identifier=2)] - self.fixture.suite_runs.clear() - self.add_newer_pr_check(check_status=status, check_conclusion=conclusion, - run_status=status, run_conclusion=conclusion) - self.fixture.checks[HEAD][-1]["started_at"] = None - self.fixture.suite_runs[100]["pull_requests"][0]["base"]["sha"] = OLD - def current_suite(endpoint): - value = self.fixture(endpoint) - if endpoint.endswith("/check-suites/100"): - value["pull_requests"][0]["base"]["sha"] = OLD - return value - with patch.object(readiness, "api", current_suite): - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_merged_canary_rejects_conflicting_recorded_run_and_suite_bases(self): - self.fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - self.fixture.suite["pull_requests"][0]["base"]["sha"] = OLD - self.assert_deferred("sha", "required check missing") - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assert_deferred("sha", "required check missing") - - def test_sha_merged_canary_common_base_must_match_selected_merge_parents(self): - self.fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - # A run lists two historical associations, but the suite corroborates - # only the base absent from this merge commit's parents. - alternate = copy.deepcopy(self.fixture.run["pull_requests"][0]) - alternate["base"]["sha"] = OLD - self.fixture.run["pull_requests"].append(alternate) - self.fixture.suite["pull_requests"] = [alternate] - self.assert_deferred("sha", "required check missing") - - def test_sha_direct_head_failed_workflow_run_rejected(self): - self.fixture.run["conclusion"] = "failure" - self.assert_deferred("sha", "workflow run not successful") - - def add_newer_pr_check(self, check_status="completed", check_conclusion="success", - run_status="completed", run_conclusion="success"): - newer = check("Required checks", identifier=50, status=check_status, conclusion=check_conclusion) - newer["started_at"] = "2026-10-11T12:01:00Z" - newer["check_suite"]["id"] = 100 - self.fixture.checks[HEAD].append(newer) - run = copy.deepcopy(self.fixture.run) - run.update(id=20, check_suite_id=100, status=run_status, conclusion=run_conclusion) - self.fixture.suite_runs[100] = run - - def test_sha_newer_failing_pr_suite_does_not_hide_behind_older_green_suite(self): - self.add_newer_pr_check(check_conclusion="failure", run_conclusion="failure") - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_newer_pending_pr_suite_does_not_hide_behind_older_green_suite(self): - self.add_newer_pr_check(check_status="queued", check_conclusion=None, - run_status="queued", run_conclusion=None) - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_newer_queued_null_start_pr_suite_blocks_older_green_suite(self): - self.add_newer_pr_check(check_status="queued", check_conclusion=None, - run_status="queued", run_conclusion=None) - self.fixture.checks[HEAD][-1]["started_at"] = None - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_newer_queued_null_start_check_blocks_older_green_in_same_suite(self): - newer = check("Required checks", identifier=50, status="queued", conclusion=None) - newer["started_at"] = None - self.fixture.checks[HEAD].append(newer) - self.assert_deferred("sha", "required check not successful") - - def test_sha_older_check_starting_later_does_not_hide_newer_failure(self): - self.add_newer_pr_check(check_conclusion="failure", run_conclusion="failure") - self.fixture.checks[HEAD][0]["started_at"] = "2026-10-11T12:02:00Z" - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_newer_green_check_in_failed_pr_run_does_not_hide_behind_older_green_suite(self): - self.add_newer_pr_check(run_conclusion="failure") - self.assert_deferred("sha", "workflow run not successful") - - def test_sha_direct_head_run_drift_at_completion_deferred(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if "/actions/runs?check_suite_id=99" in endpoint: - calls += 1 - if calls > 1: - value["workflow_runs"][0]["run_attempt"] += 1 - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "workflow-run evidence changed") - - def test_sha_direct_head_check_drift_at_completion_deferred(self): - def drift(endpoint): - value = self.fixture(endpoint) - if endpoint.endswith("/check-runs/1"): - value["conclusion"] = "failure" - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "required check evidence changed") - - def test_sha_new_required_check_at_completion_deferred(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if f"/commits/{HEAD}/check-runs?" in endpoint: - calls += 1 - if calls > 1: - value["check_runs"].append(check("Required checks", identifier=50, conclusion="failure")) - value["total_count"] += 1 - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "required check collection changed") - - def test_sha_wrong_app_check_rejected(self): - self.fixture.checks[HEAD][0]["app"]["id"] = 1 - self.assert_deferred("sha", "missing") - - def test_sha_realistic_merge_sha_checks(self): - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_merged_canary_current_head_direct_checks(self): - self.fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_merged_canary_historical_merge_checks(self): - self.fixture.pr.update(state="closed", merged=True, merge_commit_sha=NEW) - self.fixture.checks[MERGE] = [check("Required checks", MERGE), check("Conventional PR title", MERGE, 2)] - self.fixture.checks[HEAD] = [] - self.assertEqual(self.invoke("sha")[0], 0) - - def test_sha_closed_unmerged_canary_deferred(self): - self.fixture.pr.update(state="closed", merged=False) - self.assert_deferred("sha", "merged or open") - - def test_sha_stale_merge_run_head(self): - self.fixture.checks[MERGE] = [check("Required checks", MERGE)] - self.fixture.checks[HEAD] = [] - self.fixture.run["head_sha"] = OLD - self.assert_deferred("sha", "missing") - - def test_sha_stale_merge_commit(self): - self.fixture.parents = [BASE, OLD] - self.assert_deferred("sha", "stale") - - def test_sha_fresh_pr_head_required_at_completion(self): - calls = 0 - def drift(endpoint): - nonlocal calls - value = self.fixture(endpoint) - if endpoint.endswith("/pulls/12"): - calls += 1 - if calls > 1: - value["head"]["sha"] = NEW - return value - with patch.object(readiness, "api", drift): - self.assert_deferred("sha", "changed during") - - def test_codeql_success_current_head_rust(self): - self.assertEqual(self.invoke("codeql")[0], 0) - - def test_codeql_large_history_stops_after_current_coverage(self): - old = copy.deepcopy(self.fixture.analyses[0]) - old.update(commit_sha=OLD, category="/partition:retired/language:rust") - self.fixture.analyses.extend([old] * 1200) - self.assertEqual(self.invoke("codeql")[0], 0) - self.assertEqual(len([call for call in self.fixture.calls if "/analyses?" in call]), 2) - - def test_codeql_retired_category_failure_does_not_gate(self): - old = copy.deepcopy(self.fixture.analyses[0]) - old.update(commit_sha=OLD, category="/partition:retired/language:rust", error="old failure") - self.fixture.analyses.insert(0, old) - self.assertEqual(self.invoke("codeql")[0], 0) - - def test_codeql_all_live_configured_languages_required(self): - self.fixture.setup["languages"].append("python") - self.assert_deferred("codeql", "configured CodeQL language") - - def test_codeql_javascript_typescript_alias_normalized(self): - self.fixture.setup["languages"] = ["rust", "javascript/typescript"] - second = copy.deepcopy(self.fixture.analyses[0]) - second.update(category="/language:javascript-typescript", environment='{"language":"javascript-typescript"}') - self.fixture.analyses.append(second) - self.assertEqual(self.invoke("codeql")[0], 0) - - def enable_advanced(self, partitions=None): - if partitions is None: - partitions = PARTITIONS - # The policy minimum remains independent of the producer declarations. - (self.root / "config/codeql-advanced-setup.json").write_text(json.dumps({ - "repositories": ["example"], "required_partitions": {"example": [ - {"scope": item["scope"], "language": item["language"]} for item in PARTITIONS]}})) - self.set_classifier_source(classifier_source(partitions)) - (self.root / "config/security-merge-protection.json").write_text('{"codeql_required_languages": {}}') - self.fixture.analyses = [] - self.fixture.codeql_jobs = [] - for index, item in enumerate(partitions): - display, category, language = item["display"], item["category"], item["language"] - job = {"id": index + 1, "name": f"CodeQL analysis ({display})", "head_sha": HEAD, - "status": "completed", "conclusion": "success", - "started_at": "2026-10-11T11:59:00Z", "completed_at": "2026-10-11T12:01:00Z"} - self.fixture.codeql_jobs.append(job) - self.fixture.analyses.append({"id": index + 1, "tool": {"name": "CodeQL"}, - "analysis_key": ".github/workflows/codeql.yml:analyze", "category": category, - "environment": json.dumps({"display": display, "category": category, "language": language, - "scope": item["scope"], "run": ""}), - "commit_sha": HEAD, "ref": "refs/heads/main", "error": "", "rules_count": 58, - "created_at": "2026-10-11T12:00:00Z"}) - for name in ("CodeQL classification", "CodeQL validation"): - job = copy.deepcopy(self.fixture.codeql_jobs[0]) - job.update(id=999, name=name, check_run_url="https://api.github.com/repos/atrinik/example/check-runs/999") - self.fixture.codeql_jobs.append(job) - - def set_classifier_source(self, source): - self.fixture.codeql_sources["tools/ci/classify_changes.py"] = source - self.fixture.codeql_head_sources["tools/ci/classify_changes.py"] = source - - def set_codeql_workflow(self, source): - self.fixture.codeql_sources[".github/workflows/codeql.yml"] = source - self.fixture.codeql_head_sources[".github/workflows/codeql.yml"] = source - - def codeql_document(self): - import yaml - # Preserve Actions' on key when constructing modified fixtures. - return yaml.safe_load(CODEQL_WORKFLOW.replace(b"\non:", b"\n'on':")) - - def set_codeql_document(self, document): - import yaml - self.set_codeql_workflow(yaml.safe_dump(document, sort_keys=False).encode()) - - def test_yaml_dependency_missing_fails_closed_for_workflow_verification(self): - self.enable_advanced() - with patch.dict(sys.modules, {"yaml": None}): - result, message = self.invoke("codeql") - self.assertEqual(result, 2, message) - self.assertIn("install requirements-validation.txt", message) - result, message = self.invoke("dependency") - self.assertEqual(result, 2, message) - self.assertIn("install requirements-validation.txt", message) - - def test_codeql_advanced_full_run_cannot_replace_pull_request_trigger(self): - for event in ('push', 'schedule', 'workflow_dispatch'): - for triggers in (None, 'push', ['push', 'workflow_dispatch'], - {'push': {'branches': ['main']}, 'schedule': [{'cron': '0 0 * * *'}], - 'workflow_dispatch': None}, {'pull_request_target': None}): - with self.subTest(event=event, triggers=triggers): - self.enable_advanced() - self.fixture.codeql_run['event'] = event - document = self.codeql_document() - if triggers is None: - del document['on'] - else: - document['on'] = triggers - self.set_codeql_document(document) - self.assert_deferred('codeql', 'pull_request trigger missing') - - def test_codeql_advanced_pull_request_filters_cannot_skip_required_producer(self): - rejected = [False, [], 'main', {'branches': ['develop']}, - {'branches': []}, {'branches': 'main'}, {'branches': None}, - {'branches': ['main', '!main']}, {'branches': ['**']}, - {'branches': ['main', 3]}, {'branches-ignore': ['main']}, - {'branches-ignore': ['unrelated']}, {'paths': ['client/**']}, - {'paths': ['**']}, {'paths-ignore': ['docs/**']}, - {'branches': ['main'], 'paths-ignore': []}, - {'tags': ['v*']}, {'types': None}, {'types': 'opened'}, - {'types': []}, {'types': ['opened', 'reopened']}, - {'types': ['synchronize', 'reopened']}, {'types': ['opened', 'synchronize']}, - {'types': ['opened', 'synchronize', 'reopened', False]}, - {'types': ['opened', 'synchronize', 'reopened', 'invented']}, - {'types': ['opened', 'synchronize', 'reopened', 'opened']}] - for trigger in rejected: - with self.subTest(trigger=trigger): - self.enable_advanced() - document = self.codeql_document() - document['on']['pull_request'] = trigger - self.set_codeql_document(document) - self.assert_deferred('codeql', 'pull_request') - - def test_codeql_advanced_pull_request_event_forms_and_additional_types_ready(self): - for triggers in ('pull_request', ['push', 'pull_request', 'workflow_dispatch'], - {'pull_request': None}, {'pull_request': {}}, - {'pull_request': {'branches': ['main', 'maintenance']}}, - {'pull_request': {'types': ['opened', 'synchronize', 'reopened']}}, - {'pull_request': {'branches': ['main'], 'types': [ - 'ready_for_review', 'edited', 'reopened', 'opened', 'synchronize']}}): - with self.subTest(triggers=triggers): - self.enable_advanced() - document = self.codeql_document() - document['on'] = triggers - self.set_codeql_document(document) - result, message = self.invoke('codeql') - self.assertEqual(result, 0, message) - - def test_codeql_advanced_pull_request_uses_fresh_default_branch(self): - self.enable_advanced() - branch = 'release/current' - self.fixture.metadata['default_branch'] = branch - self.fixture.codeql_run['head_branch'] = branch - for analysis in self.fixture.analyses: - analysis['ref'] = 'refs/heads/' + branch - self.assert_deferred('codeql', 'pull_request does not cover the default branch') - document = self.codeql_document() - document['on']['pull_request']['branches'] = [branch] - document['on']['push']['branches'] = [branch] - self.set_codeql_document(document) - result, message = self.invoke('codeql') - self.assertEqual(result, 0, message) - self.assertIn('repos/atrinik/example/branches/release%2Fcurrent', self.fixture.calls) - - def test_codeql_advanced_default_branch_change_during_preflight_deferred(self): - self.enable_advanced() - reads = 0 - - def drift(endpoint): - nonlocal reads - result = self.fixture(endpoint) - if endpoint == 'repos/atrinik/example': - reads += 1 - if reads > 1: - result = dict(result, default_branch='release/current') - return result - - with patch.object(readiness, 'api', drift): - self.assert_deferred('codeql', 'repository default branch changed') - - def test_codeql_advanced_comments_cannot_prove_executable_wiring(self): - self.enable_advanced() - source = b"name: CodeQL\njobs:\n fake:\n runs-on: ubuntu-24.04\n steps:\n - run: true\n" - source += b"\n".join(b"# " + line for line in CODEQL_WORKFLOW.splitlines()) - self.set_codeql_workflow(source) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_disconnected_wiring_rejected_despite_green_uploads(self): - changes = [ - (("classify", "outputs", "matrix"), '${{ steps.other.outputs.codeql_matrix }}'), - (("classify", "outputs", "run"), 'true'), - (("classify", "steps", 1, "id"), 'other'), - (("classify", "steps", 1, "env", "EVENT_NAME"), 'push'), - (("classify", "steps", 1, "env", "HEAD_SHA"), '${{ github.event.pull_request.base.sha }}'), - (("analyze", "needs"), 'other'), - (("analyze", "if"), 'false'), - (("analyze", "name"), 'CodeQL analysis (C/C++ client)'), - (("analyze", "strategy", "matrix"), {"include": PARTITIONS}), - (("analyze", "strategy", "matrix"), '${{ fromJSON(needs.other.outputs.matrix) }}'), - (("analyze", "steps", 2, "with", "config-file"), 'unrelated-codeql.yml'), - (("analyze", "steps", 2, "with", "config-file"), '${{ steps.other.outputs.codeql_config }}'), - (("analyze", "steps", 2, "with", "languages"), 'c-cpp'), - (("analyze", "steps", 2, "with", "build-mode"), 'autobuild'), - (("analyze", "steps", 3, "with", "category"), '/partition:client/language:c-cpp'), - (("codeql-validation", "if"), 'success()'), - (("codeql-validation", "needs"), ['classify']), - (("codeql-validation", "strategy"), {"matrix": {"fake": [1]}}), - ] - for path, value in changes: - with self.subTest(path=path, value=value): - self.enable_advanced() - document = self.codeql_document() - target = document["jobs"] - for key in path[:-1]: - target = target[key] - target[path[-1]] = value - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_classifier_and_aggregate_arguments_are_executable(self): - mutations = [ - ('classify', '--event "${EVENT_NAME}"', '--event push'), - ('classify', '--event "${EVENT_NAME}"', "--event '${EVENT_NAME}'"), - ('classify', '--event "${EVENT_NAME}"', '--event "\\${EVENT_NAME}"'), - ('classify', '--github-output "${GITHUB_OUTPUT}"', '--github-output /dev/null'), - ('analyze', '--codeql-scope "${{ matrix.scope }}"', '--codeql-scope client'), - ('analyze', 'build/codeql-config.yml', 'build/disconnected-config.yml'), - ('codeql-validation', "'${{ needs.classify.result }}'", 'success'), - ('codeql-validation', "'${{ needs.classify.outputs.run }}'", 'true'), - ('codeql-validation', "'${{ needs.analyze.result }}'", 'success'), - ] - for name, before, after in mutations: - with self.subTest(name=name, before=before): - self.enable_advanced() - document = self.codeql_document() - step = document['jobs'][name]['steps'][1] - self.assertIn(before, step['run']) - step['run'] = step['run'].replace(before, after) - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - for name in ('classify', 'analyze', 'codeql-validation'): - for mutation in ('comment-only', 'trailing-command', 'leading-command', 'substitution', 'duplicate-option'): - with self.subTest(name=name, mutation=mutation): - self.enable_advanced() - document = self.codeql_document() - step = document['jobs'][name]['steps'][1] - run = step['run'] - if mutation == 'comment-only': - step['run'] = '\n'.join('# ' + line for line in run.splitlines()) + '\ntrue\n' - elif mutation == 'trailing-command': - step['run'] = run.rstrip() + '; true\n' - elif mutation == 'leading-command': - step['run'] = 'true\n' + run - elif mutation == 'substitution': - step['run'] = run.replace('python3', '$(echo python3)', 1) - else: - step['run'] = run.rstrip() + ' --event push\n' - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_disabled_or_overridden_execution_rejected(self): - targets = [('classify', None), ('analyze', None), ('codeql-validation', None), - ('classify', 1), ('analyze', 1), ('analyze', 2), ('analyze', 3), - ('codeql-validation', 1)] - for name, index in targets: - for key, value in [('continue-on-error', True), ('if', 'false'), - ('env', {'PYTHONPATH': 'untrusted'}), - ('defaults', {'run': {'working-directory': 'elsewhere'}}), - ('shell', 'bash {0}'), ('working-directory', 'elsewhere')]: - with self.subTest(name=name, index=index, override=key): - self.enable_advanced() - document = self.codeql_document() - target = document['jobs'][name] - if index is not None: - target = target['steps'][index] - target[key] = value - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - for key, value in [('env', {'GITHUB_OUTPUT': '/dev/null'}), - ('defaults', {'run': {'shell': 'true {0}'}})]: - with self.subTest(workflow_override=key): - self.enable_advanced() - document = self.codeql_document() - document[key] = value - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - self.enable_advanced() - document = self.codeql_document() - document['jobs']['analyze'] = {'uses': 'foreign/repo/.github/workflows/codeql.yml@' + NEW} - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_current_complete_checkout_required(self): - for name in ('classify', 'analyze', 'codeql-validation'): - for key, value in [('ref', 'main'), ('ref', OLD), ('repository', 'foreign/repo'), - ('path', 'elsewhere'), ('sparse-checkout', 'only-one-file')]: - with self.subTest(name=name, key=key, value=value): - self.enable_advanced() - document = self.codeql_document() - document['jobs'][name]['steps'][0].setdefault('with', {})[key] = value - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_step_order_actions_and_duplicate_ids_rejected(self): - for mutation in ('order', 'extra', 'duplicate-id', 'mutable-init', 'foreign-analyze'): - with self.subTest(mutation=mutation): - self.enable_advanced() - document = self.codeql_document() - steps = document['jobs']['analyze']['steps'] - if mutation == 'order': - steps[2], steps[3] = steps[3], steps[2] - elif mutation == 'extra': - steps.insert(2, {'run': 'echo overwrite generated config'}) - elif mutation == 'duplicate-id': - steps[0]['id'] = 'classify' - elif mutation == 'mutable-init': - steps[2]['uses'] = 'github/codeql-action/init@v4' - else: - steps[3]['uses'] = 'foreign/codeql-action/analyze@' + NEW - self.set_codeql_document(document) - self.assert_deferred("codeql", "executable workflow contract") - - def test_codeql_advanced_duplicate_yaml_is_unreadable(self): - for source in (CODEQL_WORKFLOW + b'\njobs: {}\n', - CODEQL_WORKFLOW.replace(b' - id: classify', b' - id: classify\n id: other', 1), - CODEQL_WORKFLOW.replace(b' if: always()', b' if: false\n if: always()'), - b'jobs: [unclosed'): - with self.subTest(source=source[-50:]): - self.enable_advanced() - self.set_codeql_workflow(source) - result, message = self.invoke('codeql') - self.assertEqual(result, 2, message) - self.assertIn('YAML malformed or ambiguous', message) - - def test_codeql_advanced_formatting_and_owner_action_updates_ready(self): - self.enable_advanced() - document = self.codeql_document() - for job in document['jobs'].values(): - for step in job['steps']: - if 'uses' in step: - step['uses'] = step['uses'].split('@')[0] + '@' + NEW - job['steps'][0].setdefault('with', {}).update( - ref='${{github.sha}}', repository='${{ github.repository }}') - for name in ('classify', 'analyze'): - step = document['jobs'][name]['steps'][1] - step['run'] = ('# executable invocation follows\npython3 tools/ci/classify_changes.py ' - '--codeql-config build/new-config.yml --github-output "$GITHUB_OUTPUT" ' - '--head "$HEAD_SHA" --base "$BASE_SHA" --event "$EVENT_NAME"') - if name == 'analyze': - step['run'] += ' --codeql-scope "${{matrix.scope}}"' - document['jobs']['analyze']['if'] = "${{needs.classify.outputs.run=='true'}}" - document['jobs']['analyze']['strategy']['matrix'] = '${{ fromJSON ( needs.classify.outputs.matrix ) }}' - document['jobs']['analyze']['steps'][2]['with']['languages'] = '${{matrix.language}}' - document['jobs']['analyze']['steps'][3]['with']['category'] = '${{ matrix.category}}' - document['jobs']['codeql-validation']['if'] = '${{ always ( ) }}' - self.set_codeql_document(document) - result, message = self.invoke('codeql') - self.assertEqual(result, 0, message) - - def test_codeql_advanced_reduced_source_and_jobs_below_policy_deferred(self): - self.enable_advanced(PARTITIONS[:1]) - self.assert_deferred("codeql", "omits required partition coverage") - - def test_codeql_advanced_reduced_jobs_with_full_source_deferred(self): - self.enable_advanced() - self.fixture.codeql_jobs = self.fixture.codeql_jobs[:1] + self.fixture.codeql_jobs[-2:] - self.fixture.analyses = self.fixture.analyses[:1] - self.assert_deferred("codeql", "every declared partition") - - def test_codeql_advanced_additional_declared_partition_ready(self): - extra = {"display": "Extra C/C++", "scope": "extra", "language": "c-cpp", - "category": "/partition:extra/language:c-cpp", "run": True} - self.enable_advanced(PARTITIONS + [extra]) - self.assertEqual(self.invoke("codeql")[0], 0) - - def test_codeql_advanced_additional_declaration_requires_job(self): - extra = {"display": "Extra C/C++", "scope": "extra", "language": "c-cpp", - "category": "/partition:extra/language:c-cpp", "run": True} - self.enable_advanced(PARTITIONS + [extra]) - del self.fixture.codeql_jobs[5] - self.assert_deferred("codeql", "every declared partition") - - def test_codeql_advanced_category_rename_preserves_semantic_minimum(self): - partitions = copy.deepcopy(PARTITIONS) - partitions[0]["category"] = "/partition:client-renamed/language:c-cpp" - self.enable_advanced(partitions) - self.assertEqual(self.invoke("codeql")[0], 0) - - def test_codeql_advanced_upload_matches_declared_scope_category_and_language(self): - for field, value in (("scope", "server"), ("category", "/other/language:c-cpp"), - ("language", "python")): - with self.subTest(field=field): - self.enable_advanced() - analysis = self.fixture.analyses[0] - environment = json.loads(analysis["environment"]) - environment[field] = value - analysis["environment"] = json.dumps(environment) - if field == "category": - analysis["category"] = value - self.assert_deferred("codeql", "selected full-run job") - - def test_codeql_advanced_duplicate_declarations_rejected(self): - for field in ("display", "category", "scope"): - with self.subTest(field=field): - partitions = copy.deepcopy(PARTITIONS) - partitions[1][field] = partitions[0][field] - self.enable_advanced(partitions) - self.assert_deferred("codeql", "declarations duplicated") - - def test_codeql_advanced_nonliteral_declaration_deferred(self): - self.enable_advanced() - self.set_classifier_source(CLASSIFIER.replace(b"entries.append({", b"entries.append(dict(", 1)) - self.assertEqual(self.invoke("codeql")[0], 2) # Invalid Python is unreadable evidence. - self.set_classifier_source(CLASSIFIER + b"\n") - source = CLASSIFIER.replace(b" matrix =", b" entries.append(dynamic_partition)\n matrix =") - self.set_classifier_source(source) - self.assert_deferred("codeql", "not literal") - - def test_codeql_advanced_unsupported_matrix_mutation_deferred(self): - self.enable_advanced() - source = CLASSIFIER.replace(b" matrix =", b" entries.extend(extra)\n matrix =") - self.set_classifier_source(source) - self.assert_deferred("codeql", "shape unsupported") - - def test_codeql_advanced_missing_or_malformed_minima_unreadable(self): - for minima in (None, [], {}, [{"scope": "client"}], - [{"scope": "client", "language": "c-cpp"}] * 2): - with self.subTest(minima=minima): - self.enable_advanced() - policy = {"repositories": ["example"], "required_partitions": {"example": minima}} - (self.root / "config/codeql-advanced-setup.json").write_text(json.dumps(policy)) - self.assertEqual(self.invoke("codeql")[0], 2) - (self.root / "config/codeql-advanced-setup.json").write_text('{"repositories": ["example"]}') - self.assertEqual(self.invoke("codeql")[0], 2) - - def test_codeql_advanced_current_full_producer_all_partitions_ready(self): - self.enable_advanced() - self.assertEqual(self.invoke("codeql")[0], 0) - - def test_codeql_advanced_large_retired_history_ready(self): - self.enable_advanced() - retired = copy.deepcopy(self.fixture.analyses[0]) - retired.update(commit_sha=OLD, category="/retired/language:c-cpp", environment='{"display":"Retired"}') - self.fixture.analyses.insert(0, retired) - self.fixture.analyses.extend([retired] * 1200) - self.assertEqual(self.invoke("codeql")[0], 0) - self.assertEqual(len([call for call in self.fixture.calls if "/analyses?" in call]), 2) - - def test_codeql_advanced_partial_uploads_deferred(self): - self.enable_advanced() - self.fixture.analyses.pop() - self.assert_deferred("codeql", "partition upload missing") - - def test_codeql_advanced_latest_failed_category_masks_success(self): - self.enable_advanced() - failed = copy.deepcopy(self.fixture.analyses[0]); failed["error"] = "failed" - self.fixture.analyses.insert(0, failed) - self.assert_deferred("codeql", "failed") - - def test_codeql_advanced_wrong_producer_deferred(self): - self.enable_advanced() - self.fixture.analyses[0]["analysis_key"] = ".github/workflows/other.yml:analyze" - self.assert_deferred("codeql", "partition upload missing") - - def test_codeql_advanced_partial_pr_event_deferred(self): - self.enable_advanced() - self.fixture.codeql_run["event"] = "pull_request" - self.assert_deferred("codeql", "full-event") - - def test_codeql_advanced_wrong_app_deferred(self): - self.enable_advanced() - self.fixture.codeql_check["app"]["id"] = 1 - self.assert_deferred("codeql", "trusted current-head producer") - - def test_codeql_advanced_stale_source_deferred(self): - self.enable_advanced() - self.fixture.codeql_head_sources["tools/ci/classify_changes.py"] += b"# different\n" - self.assert_deferred("codeql", "source is stale") - - def test_codeql_advanced_upload_outside_job_window_deferred(self): - self.enable_advanced() - self.fixture.analyses[0]["created_at"] = "2026-10-11T13:00:00Z" - self.assert_deferred("codeql", "selected full-run job") - - def prepare_analysis_recheck(self, advanced): - if advanced: - self.enable_advanced() - self.fixture.analysis_reads = 0 - self.fixture.fresh_analyses = copy.deepcopy(self.fixture.analyses) - - def test_codeql_newer_failure_during_preflight_deferred(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - failed = copy.deepcopy(self.fixture.analyses[0]) - failed.update(id=1000, error="new analysis failed") - self.fixture.fresh_analyses.insert(0, failed) - self.assert_deferred("codeql", "failed") - self.assertEqual(self.fixture.analysis_reads, 2) - - def test_codeql_newer_zero_rules_during_preflight_deferred(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - empty = copy.deepcopy(self.fixture.analyses[0]) - empty.update(id=1000, rules_count=0) - self.fixture.fresh_analyses.insert(0, empty) - self.assert_deferred("codeql", "no executed rules") - - def test_codeql_deleted_selected_analysis_during_preflight_deferred(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - del self.fixture.fresh_analyses[0] - self.assert_deferred("codeql", "missing within bounded evidence") - - def test_codeql_replaced_successful_coverage_during_preflight_deferred(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - replacement = copy.deepcopy(self.fixture.analyses[0]) - replacement["id"] = 1000 - self.fixture.fresh_analyses.insert(0, replacement) - self.assert_deferred("codeql", "analysis coverage changed during preflight") - - def test_codeql_selected_analysis_mutation_during_preflight_deferred(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - self.fixture.fresh_analyses[0]["rules_count"] += 1 - self.assert_deferred("codeql", "analysis coverage changed during preflight") - - def test_codeql_new_retired_analysis_during_preflight_preserves_readiness(self): - for advanced in (False, True): - with self.subTest(advanced=advanced): - self.prepare_analysis_recheck(advanced) - retired = copy.deepcopy(self.fixture.analyses[0]) - retired.update(id=1000, commit_sha=OLD, category="/retired/language:c-cpp", - environment='{"display":"Retired"}') - self.fixture.fresh_analyses.insert(0, retired) - self.assertEqual(self.invoke("codeql")[0], 0) - self.assertEqual(self.fixture.analysis_reads, 2) - - def test_codeql_default_new_failure_with_changed_language_does_not_fallback(self): - self.prepare_analysis_recheck(False) - failed = copy.deepcopy(self.fixture.analyses[0]) - failed.update(id=1000, error="new analysis failed", environment='{"language":"python"}') - self.fixture.fresh_analyses.insert(0, failed) - self.assert_deferred("codeql", "failed") - - def test_codeql_advanced_new_failure_without_display_does_not_fallback(self): - for environment in ('{}', '{"display":"Renamed"}'): - with self.subTest(environment=environment): - self.prepare_analysis_recheck(True) - failed = copy.deepcopy(self.fixture.analyses[0]) - failed.update(id=1000, error="new analysis failed", environment=environment) - self.fixture.fresh_analyses.insert(0, failed) - self.assert_deferred("codeql", "partition upload missing") - - def test_codeql_latest_error_masks_older_success(self): - failed = copy.deepcopy(self.fixture.analyses[0]) - failed.update(id=2, error="analysis failed") - self.fixture.analyses.insert(0, failed) - self.assert_deferred("codeql", "failed") - - def test_codeql_success_old_head_deferred(self): - self.fixture.analyses[0]["commit_sha"] = OLD - self.assert_deferred("codeql", "current default head") - - def test_codeql_missing_rust_analysis_deferred(self): - self.fixture.analyses[0]["environment"] = '{"language":"python"}' - self.fixture.analyses[0]["category"] = "/language:python" - self.assert_deferred("codeql", "language") - - def test_codeql_no_executed_rules_deferred(self): - self.fixture.analyses[0]["rules_count"] = 0 - self.assert_deferred("codeql", "no executed rules") - - def test_archived_repository_deferred(self): - self.fixture.metadata["archived"] = True - self.assert_deferred("dependency", "archived") - - def test_malformed_api_evidence_error(self): - self.fixture.metadata.pop("default_branch") - self.assertEqual(self.invoke("dependency")[0], 2) - - def test_api_subprocess_uses_only_get_and_version(self): - self.api_patch.stop() - result = subprocess.CompletedProcess([], 0, stdout='{}', stderr='') - with patch.object(readiness.subprocess, "run", return_value=result) as mocked: - readiness.api("repos/atrinik/example") - args = mocked.call_args.args[0] - self.assertEqual(args[args.index("--method") + 1], "GET") - self.assertIn("X-GitHub-Api-Version: 2026-03-10", args) - - def test_api_error_retains_structured_response_without_printing_body(self): - self.api_patch.stop() - for body in ('{"message":"Branch not protected","status":"404"}', "not json", "null"): - result = subprocess.CompletedProcess([], 1, stdout=body, stderr="gh: error (HTTP 404)") - with self.subTest(body=body), patch.object(readiness.subprocess, "run", return_value=result): - with self.assertRaises(readiness.APIError) as raised: - readiness.api("repos/atrinik/example/branches/main/protection") - self.assertEqual(raised.exception.status, 404) - self.assertEqual(raised.exception.response, json.loads(body) if body != "not json" else None) - self.assertNotIn(body, str(raised.exception)) - - def test_executable_wrapper_is_bash_and_delegates_python(self): - wrapper = ROOT / "bin/security-readiness" - self.assertEqual(wrapper.read_text().splitlines()[0], "#!/usr/bin/env bash") - self.assertIn('exec python3 "${root}/lib/security_readiness.py" "$@"', wrapper.read_text()) - - -if __name__ == "__main__": - unittest.main(verbosity=2) diff --git a/tests/security-readiness.sh b/tests/security-readiness.sh deleted file mode 100755 index 900b90c..0000000 --- a/tests/security-readiness.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -exec python3 "${root}/tests/security-readiness.py" diff --git a/tests/sync-project.sh b/tests/sync-project.sh deleted file mode 100755 index 410927e..0000000 --- a/tests/sync-project.sh +++ /dev/null @@ -1,459 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -endpoint= -input= -while (($#)); do - case $1 in - --include) - shift - ;; - -H) - shift 2 - ;; - --input) - input=$2 - shift 2 - ;; - user) - endpoint=user - shift - ;; - *) - shift - ;; - esac -done - -if [[ ${endpoint} == user ]]; then - printf '%s\n' 'REST user' >>"${FAKE_GH_LOG}" - if [[ ${FAKE_GH_SCENARIO} == scope-api-failure ]]; then - echo "gh: scope metadata request failed" >&2 - exit 44 - fi - scopes='admin:org, project, repo' - [[ ${FAKE_GH_SCENARIO} == insufficient-scopes ]] && scopes=repo - printf 'HTTP/2.0 200 OK\r\nx-oauth-scopes: %s\r\n\r\n{"login":"test"}\n' \ - "${scopes}" - exit 0 -fi - -[[ -n ${input} ]] -query=$(jq -r '.query' "${input}") -variables=$(jq -c '.variables' "${input}") -cursor=$(jq -r '.endCursor // empty' <<<"${variables}") -printf '%s\n' "${query}" >>"${FAKE_GH_LOG}" - -case ${FAKE_GH_SCENARIO} in -api-failure) - echo "gh: authentication failed" >&2 - exit 42 - ;; -graphql-error) - jq -n '{errors: [{message: "Resource not accessible by personal access token"}]}' - exit 0 - ;; -invalid-response) - jq -n '{}' - exit 0 - ;; -page2-api-failure) - if [[ ${cursor} == CURSOR ]]; then - echo "gh: pagination transport failed" >&2 - exit 43 - fi - ;; -page2-graphql-error) - if [[ ${cursor} == CURSOR ]]; then - jq -n '{errors: [{message: "Pagination authorization denied"}]}' - exit 0 - fi - ;; -happy | idempotent | paginated | page2-shape-error | repeated-cursor | \ - mutation-empty-add | mutation-empty-status | mutation-empty-type | \ - project-read-only | repository-read-only | search-overflow | count-short | \ - count-change | duplicate-node) ;; -*) exit 1 ;; -esac - -if [[ ${FAKE_GH_SCENARIO} == mutation-empty-add && \ - ${query} == *'addProjectV2ItemById'* ]]; then - jq -n '{data: {addProjectV2ItemById: {item: null}}}' - exit 0 -elif [[ ${FAKE_GH_SCENARIO} == mutation-empty-status && \ - ${query} == *'updateProjectV2ItemFieldValue'* ]]; then - jq -n '{data: {updateProjectV2ItemFieldValue: {projectV2Item: null}}}' - exit 0 -elif [[ ${FAKE_GH_SCENARIO} == mutation-empty-type && \ - ${query} == *'updateIssue(input:'* ]]; then - jq -n '{data: {updateIssue: {issue: null}}}' - exit 0 -fi - -if [[ ${query} == *'addProjectV2ItemById'* ]]; then - jq -n --arg id "ITEM-$(jq -r '.input.contentId' <<<"${variables}")" \ - '{data: {addProjectV2ItemById: {item: {id: $id}}}}' -elif [[ ${query} == *'updateProjectV2ItemFieldValue'* ]]; then - jq -n --arg id "$(jq -r '.input.itemId' <<<"${variables}")" \ - '{data: {updateProjectV2ItemFieldValue: {projectV2Item: {id: $id}}}}' -elif [[ ${query} == *'updateIssue(input:'* ]]; then - jq -n --arg id "$(jq -r '.input.id' <<<"${variables}")" \ - '{data: {updateIssue: {issue: {id: $id}}}}' -elif [[ ${query} == *'organization(login:'* ]]; then - can_update=true - [[ ${FAKE_GH_SCENARIO} == project-read-only ]] && can_update=false - jq -n --argjson can_update "${can_update}" '{ - data: { - organization: { - issueTypes: { - nodes: [ - {id: "TASK", name: "Task", isEnabled: true}, - {id: "BUG", name: "Bug", isEnabled: true}, - {id: "FEATURE", name: "Feature", isEnabled: true}, - {id: "INITIATIVE", name: "Initiative", isEnabled: true} - ] - }, - projectsV2: { - nodes: [{ - id: "PROJECT", - number: 1, - title: "Atrinik work", - viewerCanUpdate: $can_update, - fields: { - nodes: [{ - id: "STATUS", - name: "Status", - options: [ - {id: "INBOX", name: "Inbox"}, - {id: "BACKLOG", name: "Backlog"}, - {id: "REVIEW", name: "Review"}, - {id: "DONE", name: "Done"} - ] - }] - } - }] - } - } - } - }' -elif [[ ${query} == *'search(query:'* ]]; then - issue_count=1 - [[ ${FAKE_GH_SCENARIO} == search-overflow ]] && issue_count=1001 - [[ ${FAKE_GH_SCENARIO} == count-short || \ - ${FAKE_GH_SCENARIO} == duplicate-node ]] && issue_count=2 - if [[ ${FAKE_GH_SCENARIO} == count-change ]]; then - issue_count=2 - [[ ${cursor} == CURSOR ]] && issue_count=1 - fi - if [[ ${cursor} == CURSOR ]]; then - case ${FAKE_GH_SCENARIO} in - page2-shape-error) - jq -n '{data: {search: null}}' - ;; - repeated-cursor) - jq -n --argjson issue_count "${issue_count}" '{data: {search: { - issueCount: $issue_count, - nodes: [], - pageInfo: {hasNextPage: true, endCursor: "CURSOR"} - }}}' - ;; - *) - jq -n --argjson issue_count "${issue_count}" '{data: {search: { - issueCount: $issue_count, - nodes: [], - pageInfo: {hasNextPage: false, endCursor: null} - }}}' - ;; - esac - exit 0 - fi - page_info='{"hasNextPage":false,"endCursor":null}' - case ${FAKE_GH_SCENARIO} in - paginated | page2-api-failure | page2-graphql-error | page2-shape-error | \ - repeated-cursor | count-change) - page_info='{"hasNextPage":true,"endCursor":"CURSOR"}' - ;; - esac - query_string=$(jq -r '.queryString' <<<"${variables}") - if [[ ${query_string} == *'is:issue'* ]]; then - issue_type=null - if [[ ${FAKE_GH_SCENARIO} == idempotent ]]; then - issue_type='{"name":"Initiative"}' - fi - viewer_permission=WRITE - copies=1 - [[ ${FAKE_GH_SCENARIO} == duplicate-node ]] && copies=2 - [[ ${FAKE_GH_SCENARIO} == repository-read-only ]] && \ - viewer_permission=READ - jq -n --argjson copies "${copies}" \ - --argjson issue_count "${issue_count}" \ - --argjson issue_type "${issue_type}" \ - --arg viewer_permission "${viewer_permission}" \ - --argjson page_info "${page_info}" ' - { - __typename: "Issue", - id: "ISSUE", - url: "https://github.com/atrinik/server/issues/1", - createdAt: "2020-01-01T00:00:00Z", - state: "OPEN", - issueType: $issue_type, - repository: { - name: "server", isArchived: false, - viewerPermission: $viewer_permission - }, - labels: {nodes: []}, - subIssues: {totalCount: 1} - } as $node | - {data: {search: { - issueCount: $issue_count, - nodes: [range(0; $copies) | $node], - pageInfo: $page_info - }} - }' - else - jq -n --argjson issue_count "${issue_count}" \ - --argjson page_info "${page_info}" '{ - data: {search: { - issueCount: $issue_count, - nodes: [{ - __typename: "PullRequest", - id: "PR", - url: "https://github.com/atrinik/server/pull/2", - createdAt: "2020-01-01T00:00:00Z", - state: "OPEN", - isDraft: false, - repository: { - name: "server", isArchived: false, viewerPermission: "WRITE" - } - }], - pageInfo: $page_info - }} - }' - fi -elif [[ ${query} == *'... on ProjectV2{items('* ]]; then - if [[ ${FAKE_GH_SCENARIO} == idempotent ]]; then - jq -n '{ - data: {node: {items: { - nodes: [ - { - id: "ITEM-ISSUE", - fieldValueByName: {name: "Inbox", optionId: "INBOX"}, - content: { - __typename: "Issue", id: "ISSUE", - url: "https://github.com/atrinik/server/issues/1", - createdAt: "2020-01-01T00:00:00Z", state: "OPEN", - issueType: {name: "Initiative"}, - repository: {name: "server", isArchived: false}, - labels: {nodes: []}, subIssues: {totalCount: 1} - } - }, - { - id: "ITEM-PR", - fieldValueByName: {name: "Review", optionId: "REVIEW"}, - content: { - __typename: "PullRequest", id: "PR", - url: "https://github.com/atrinik/server/pull/2", - createdAt: "2020-01-01T00:00:00Z", state: "OPEN", - isDraft: false, - repository: {name: "server", isArchived: false} - } - } - ], - pageInfo: {hasNextPage: false, endCursor: null} - }}} - }' - elif [[ ${FAKE_GH_SCENARIO} == paginated && -z ${cursor} ]]; then - jq -n '{ - data: {node: {items: { - nodes: [], - pageInfo: {hasNextPage: true, endCursor: "CURSOR"} - }}} - }' - else - jq -n '{ - data: {node: {items: { - nodes: [], - pageInfo: {hasNextPage: false, endCursor: null} - }}} - }' - fi -else - exit 1 -fi -EOF -chmod +x "${temporary}/bin/gh" - -run_sync() { - local scenario=$1 - shift - - PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" \ - FAKE_GH_SCENARIO="${scenario}" \ - GITHUB_ACTIONS=true \ - GH_TOKEN=test-token \ - ATRINIK_PROJECT_SYNC_PAUSE_SECONDS=0 \ - "${root}/bin/sync-project" "$@" -} - -: >"${temporary}/gh.log" -output=$(run_sync happy --apply) -grep -Fq 'APPLY project 1 (Atrinik work)' <<<"${output}" -grep -Fq 'Items to add: 2' <<<"${output}" -grep -Fq 'Open-item status changes: 2' <<<"${output}" -grep -Fq 'Issue types to set: 1 (Initiative 1, Feature 0, Bug 0, Task 0)' \ - <<<"${output}" -grep -Fq 'Total mutations: 5' <<<"${output}" -[[ $(grep -c 'addProjectV2ItemById' "${temporary}/gh.log") == 2 ]] -[[ $(grep -c 'updateProjectV2ItemFieldValue' "${temporary}/gh.log") == 2 ]] -[[ $(grep -c 'updateIssue(input:' "${temporary}/gh.log") == 1 ]] - -: >"${temporary}/gh.log" -output=$(run_sync idempotent) -grep -Fq 'PLAN project 1 (Atrinik work)' <<<"${output}" -grep -Fq 'Items to add: 0' <<<"${output}" -grep -Fq 'Open-item status changes: 0' <<<"${output}" -grep -Fq 'Issue types to set: 0' <<<"${output}" -grep -Fq 'Total mutations: 0' <<<"${output}" -if grep -Eq 'addProjectV2ItemById|updateProjectV2ItemFieldValue|updateIssue\(input:' \ - "${temporary}/gh.log"; then - echo "error: idempotent plan attempted a mutation" >&2 - exit 1 -fi - -: >"${temporary}/gh.log" -output=$(run_sync paginated --apply) -grep -Fq 'APPLY project 1 (Atrinik work)' <<<"${output}" -grep -Fq 'Total mutations: 5' <<<"${output}" -[[ $(grep -c 'search(query:' "${temporary}/gh.log") == 4 ]] -[[ $(grep -c '... on ProjectV2{items(' "${temporary}/gh.log") == 2 ]] - -: >"${temporary}/gh.log" -if PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" FAKE_GH_SCENARIO=happy \ - GITHUB_ACTIONS=true GH_TOKEN='' "${root}/bin/sync-project" \ - >"${temporary}/empty.out" 2>"${temporary}/empty.err"; then - echo "error: synchronization accepted an empty workflow credential" >&2 - exit 1 -fi -grep -Fq 'ATRINIK_SETTINGS_TOKEN is unavailable' "${temporary}/empty.err" -[[ ! -s ${temporary}/gh.log ]] - -assert_preflight_failure() { - local expected_status=$1 - local scenario=$2 - local status - - : >"${temporary}/gh.log" - set +e - run_sync "${scenario}" --apply \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err" - status=$? - set -e - if ((status != expected_status)); then - echo "error: ${scenario} exited ${status}, expected ${expected_status}" >&2 - exit 1 - fi - if grep -Fq 'project Status option is missing' \ - "${temporary}/${scenario}.err"; then - echo "error: ${scenario} fell through to a schema error" >&2 - exit 1 - fi - if grep -Fq 'APPLY project' "${temporary}/${scenario}.out"; then - echo "error: ${scenario} printed a success summary" >&2 - exit 1 - fi - if grep -Eq 'addProjectV2ItemById|updateProjectV2ItemFieldValue|updateIssue\(input:' \ - "${temporary}/gh.log"; then - echo "error: ${scenario} attempted a mutation" >&2 - exit 1 - fi -} - -assert_preflight_failure 42 api-failure -grep -Fq 'read organization planning metadata' \ - "${temporary}/api-failure.err" -assert_preflight_failure 44 scope-api-failure -grep -Fq 'gh: scope metadata request failed' \ - "${temporary}/scope-api-failure.err" -grep -Fq 'verify settings credential scopes' \ - "${temporary}/scope-api-failure.err" -assert_preflight_failure 1 insufficient-scopes -grep -Fq 'missing required classic PAT scope: admin:org' \ - "${temporary}/insufficient-scopes.err" -[[ $(wc -l <"${temporary}/gh.log") == 1 ]] -assert_preflight_failure 1 graphql-error -grep -Fq 'read organization planning metadata' \ - "${temporary}/graphql-error.err" -assert_preflight_failure 1 invalid-response -grep -Fq 'invalid response: read organization planning metadata' \ - "${temporary}/invalid-response.err" -assert_preflight_failure 43 page2-api-failure -grep -Fq 'search open is:issue work (page 2)' \ - "${temporary}/page2-api-failure.err" -assert_preflight_failure 1 page2-graphql-error -grep -Fq 'Pagination authorization denied' \ - "${temporary}/page2-graphql-error.err" -assert_preflight_failure 1 page2-shape-error -grep -Fq 'missing the expected connection: search open is:issue work' \ - "${temporary}/page2-shape-error.err" -assert_preflight_failure 1 repeated-cursor -grep -Fq 'repeated the next cursor: search open is:issue work' \ - "${temporary}/repeated-cursor.err" -assert_preflight_failure 1 project-read-only -grep -Fq 'cannot update organization project: Atrinik work' \ - "${temporary}/project-read-only.err" -assert_preflight_failure 1 repository-read-only -grep -Fq 'cannot set issue types in repositories: server' \ - "${temporary}/repository-read-only.err" -assert_preflight_failure 1 search-overflow -grep -Fq 'search exceeds the 1000-result API window' \ - "${temporary}/search-overflow.err" -assert_preflight_failure 1 count-short -grep -Fq 'search result count does not match unique nodes' \ - "${temporary}/count-short.err" -assert_preflight_failure 1 count-change -grep -Fq 'search result count changed during pagination' \ - "${temporary}/count-change.err" -assert_preflight_failure 1 duplicate-node -grep -Fq 'search result count does not match unique nodes' \ - "${temporary}/duplicate-node.err" - -grep -Fq 'gh: authentication failed' "${temporary}/api-failure.err" -grep -Fq 'Resource not accessible by personal access token' \ - "${temporary}/graphql-error.err" - -for scenario in mutation-empty-add mutation-empty-status mutation-empty-type; do - : >"${temporary}/gh.log" - if run_sync "${scenario}" --apply \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: synchronization accepted ${scenario}" >&2 - exit 1 - fi - grep -Fq 'GitHub GraphQL operation returned an invalid' \ - "${temporary}/${scenario}.err" - if grep -Fq 'APPLY project' "${temporary}/${scenario}.out"; then - echo "error: ${scenario} printed a success summary" >&2 - exit 1 - fi -done -grep -Fq 'add ISSUE to project' "${temporary}/mutation-empty-add.err" -grep -Fq 'set project item ITEM-ISSUE status to Backlog' \ - "${temporary}/mutation-empty-status.err" -grep -Fq 'set issue ISSUE type to Initiative' \ - "${temporary}/mutation-empty-type.err" - -echo "Project synchronization validates authentication, API failures, mutations, and idempotence." diff --git a/tests/validate-codeql-advanced.sh b/tests/validate-codeql-advanced.sh deleted file mode 100755 index 3fd7ddb..0000000 --- a/tests/validate-codeql-advanced.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/validate" -cp -R "${root}/config" "${temporary}/config" -cp -R "${root}/community-health" "${temporary}/community-health" -cp -R "${root}/.github" "${temporary}/.github" -"${temporary}/bin/validate" >/dev/null - -assert_invalid() { - local description=$1 - - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -rewrite_json() { - local filter=$1 - local path=$2 - local output - - output=$(mktemp) - jq "${filter}" "${path}" >"${output}" - mv "${output}" "${path}" -} - -rewrite_json '.repositories += ["classic"]' \ - "${temporary}/config/codeql-advanced-setup.json" -assert_invalid 'a duplicate advanced CodeQL inventory entry' -cp "${root}/config/codeql-advanced-setup.json" \ - "${temporary}/config/codeql-advanced-setup.json" - -rewrite_json '.repositories = ["legacy-client"]' \ - "${temporary}/config/codeql-advanced-setup.json" -assert_invalid 'an archived advanced CodeQL inventory repository' -cp "${root}/config/codeql-advanced-setup.json" \ - "${temporary}/config/codeql-advanced-setup.json" - -for filter in \ - 'del(.required_partitions)' \ - '.required_partitions = {}' \ - '.required_partitions.classic = []' \ - '.required_partitions.classic = {}' \ - '.required_partitions.classic[0].scope = null' \ - 'del(.required_partitions.classic[0].language)' \ - '.required_partitions.classic += [.required_partitions.classic[0]]' \ - '.required_partitions.other = .required_partitions.classic'; do - rewrite_json "${filter}" "${temporary}/config/codeql-advanced-setup.json" - assert_invalid "malformed or mismatched advanced partition policy: ${filter}" - cp "${root}/config/codeql-advanced-setup.json" \ - "${temporary}/config/codeql-advanced-setup.json" -done - -rewrite_json '.repositories = [] | .required_partitions = {}' \ - "${temporary}/config/codeql-advanced-setup.json" -"${temporary}/bin/validate" >/dev/null -cp "${root}/config/codeql-advanced-setup.json" \ - "${temporary}/config/codeql-advanced-setup.json" - -rewrite_json '.secret_scanning = "disabled"' \ - "${temporary}/config/code-security-advanced.json" -assert_invalid 'advanced security configuration drift from the baseline' -cp "${root}/config/code-security-advanced.json" \ - "${temporary}/config/code-security-advanced.json" - -rewrite_json '.code_scanning_options.allow_advanced = true' \ - "${temporary}/config/code-security.json" -assert_invalid 'advanced setup in the ordinary security baseline' -cp "${root}/config/code-security.json" \ - "${temporary}/config/code-security.json" - -rewrite_json '.state = "configured"' \ - "${temporary}/config/codeql-default-setup-advanced.json" -assert_invalid 'configured default setup for an advanced CodeQL repository' - -echo "Advanced CodeQL validation tests passed." diff --git a/tests/validate-community-health.sh b/tests/validate-community-health.sh deleted file mode 100755 index a445165..0000000 --- a/tests/validate-community-health.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -cp -R "${root}/." "${temporary}/repository" - -forms=${temporary}/repository/community-health/.github/ISSUE_TEMPLATE -profile=${temporary}/repository/community-health/profile/README.md - -assert_invalid() { - local description=$1 - - if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -reset_repository() { - rm -rf "${temporary}/repository" - cp -R "${root}/." "${temporary}/repository" -} - -"${temporary}/repository/bin/validate" >/dev/null - -rm "${profile}" -assert_invalid 'a missing organization profile source' -reset_repository - -sed -i 's/GPL-licensed/GPL-compatible/' "${profile}" -assert_invalid 'an organization profile without the Classic license boundary' -reset_repository - -sed -i 's/MIT by default/MIT-only/' "${profile}" -assert_invalid 'an organization profile without the tools mixed-license boundary' -reset_repository - -# shellcheck disable=SC2016 # Markdown code markers are intentionally literal. -sed -i \ - 's/GPL-2.0-or-later `map-checker-qt\/` exception/GPL-2.0-or-later `wrong-checker\/` exception/' \ - "${profile}" -printf '\nUnrelated replacement tracker: map-checker-qt/.\n' >>"${profile}" -assert_invalid 'an organization profile without the tools path-scoped exception' -reset_repository - -jq 'del(.files[] | select(.target == "profile/README.md"))' \ - "${temporary}/repository/config/community-health.json" \ - >"${temporary}/community-health.json" -mv "${temporary}/community-health.json" \ - "${temporary}/repository/config/community-health.json" -assert_invalid 'an undeclared generated organization profile' -reset_repository - -jq '.description = "Developer tools for Atrinik"' \ - "${temporary}/repository/config/organization.json" \ - >"${temporary}/organization.json" -mv "${temporary}/organization.json" \ - "${temporary}/repository/config/organization.json" -assert_invalid 'organization identity drift' -reset_repository - -jq '.organization_pins.repositories |= reverse' \ - "${temporary}/repository/config/manual-settings.json" \ - >"${temporary}/manual-settings.json" -mv "${temporary}/manual-settings.json" \ - "${temporary}/repository/config/manual-settings.json" -assert_invalid 'organization pin order drift' -reset_repository - -jq '.organization_pins.apply_path = "https://github.com/organizations/atrinik/settings/profile"' \ - "${temporary}/repository/config/manual-settings.json" \ - >"${temporary}/manual-settings.json" -mv "${temporary}/manual-settings.json" \ - "${temporary}/repository/config/manual-settings.json" -assert_invalid 'an organization pin path that omits the public profile flow' -reset_repository - -sed -i '2a title: ""' "${forms}/bug.yml" -assert_invalid 'an empty issue-form title' -reset_repository - -sed -i '2a type: Bug' "${forms}/bug.yml" -assert_invalid 'direct issue-form type metadata' -reset_repository - -sed -i 's/^labels: \["bug"\]$/labels: []/' "${forms}/bug.yml" -assert_invalid 'an empty issue-form labels array' -reset_repository - -sed -i '/^labels:/d' "${forms}/bug.yml" -assert_invalid 'a bug form without an inference label' -reset_repository - -sed -i 's/^labels: \["enhancement"\]$/labels: ["documentation"]/' \ - "${forms}/feature.yml" -assert_invalid 'a feature form label outside feature type inference' -reset_repository - -sed -i '2a labels: ["bug"]' "${forms}/task.yml" -assert_invalid 'a labeled task form that bypasses default type inference' -reset_repository - -jq '.type_inference.default = "Feature"' \ - "${temporary}/repository/config/planning.json" \ - >"${temporary}/planning.json" -mv "${temporary}/planning.json" \ - "${temporary}/repository/config/planning.json" -assert_invalid 'a non-Task default issue type' - -echo "Community-health validation rejects incompatible issue-form metadata." diff --git a/tests/validate-crate-trusted-publishing.sh b/tests/validate-crate-trusted-publishing.sh deleted file mode 100755 index 6108f83..0000000 --- a/tests/validate-crate-trusted-publishing.sh +++ /dev/null @@ -1,247 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -export ATRINIK_VALIDATION_TODAY=2026-10-18 -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/validate" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${temporary}/" - -reset_policy() { - cp "${root}/config/manual-settings.json" "${temporary}/config/manual-settings.json" - cp "${root}/config/actions-selected.json" "${temporary}/config/actions-selected.json" -} - -assert_rejected() { - local filter=$1 - jq "${filter}" "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted invalid crate publishing policy: ${filter}" >&2 - exit 1 - fi - reset_policy -} - -"${temporary}/bin/validate" >/dev/null -for filter in \ - '.crates_io_trusted_publishing[0].source_state = "active"' \ - '.crates_io_trusted_publishing[0].crates = ["other-crate"]' \ - '.crates_io_trusted_publishing[0].provider = "other-provider"' \ - '.crates_io_trusted_publishing[0].repository = "atrinik/classic"' \ - '.crates_io_trusted_publishing[0].repository_id = 1' \ - '.crates_io_trusted_publishing[0].workflow_filename = "../publish-crate.yml"' \ - '.crates_io_trusted_publishing[0].source_workflow_filename = "../release.yml"' \ - '.crates_io_trusted_publishing[0].source_evidence_policy = "release-asset-digest-only"' \ - '.crates_io_trusted_publishing[0].upload_intent_policy = "retry-on-registry-404"' \ - '.crates_io_trusted_publishing[0].workflow_ref = "refs/tags/v1.0.0"' \ - '.crates_io_trusted_publishing[0].workflow_trigger = "push"' \ - '.crates_io_trusted_publishing[0].environment_state = "active"' \ - '.crates_io_trusted_publishing[0].publisher_registration.state = "active"' \ - '.crates_io_trusted_publishing[1].publisher_registration = {state:"pending-owner-registration", observed_on:null, evidence_location:"invented"}' \ - '.crates_io_trusted_publishing[1].bootstrap_crates += ["atrinik-render"]' \ - '.crates_io_trusted_publishing[2].bootstrap_crates += ["atrinik-content"]' \ - '.crates_io_trusted_publishing[0].bootstrap_crates = ["atrinik-protocol"]' \ - '.crates_io_trusted_publishing[0].bootstrap_policy = "api-token-every-release"' \ - '.crates_io_trusted_publishing[0].release_approval = "per-release-approval"' \ - '.crates_io_trusted_publishing[0].authentication_action = "rust-lang/crates-io-auth-action@v1"' \ - '.crates_io_trusted_publishing[0].environment.name = "crates-io-bootstrap"' \ - '.crates_io_trusted_publishing[0].environment.required_reviewers = [{type: "User", id: 3865595}]' \ - '.crates_io_trusted_publishing[0].environment.wait_timer_minutes = 30' \ - '.crates_io_trusted_publishing[0].environment.required_reviewers = null' \ - '.crates_io_trusted_publishing[0].environment.prevent_self_review = true' \ - '.crates_io_trusted_publishing[0].environment.can_admins_bypass = true' \ - '.crates_io_trusted_publishing[0].environment.deployment_branch_policy.patterns[0].name = "*"' \ - '.crates_io_trusted_publishing[0].environment.deployment_branch_policy.patterns[0].type = "tag"' \ - '.crates_io_trusted_publishing[0].environment.deployment_branch_policy.patterns += [{name:"v*",type:"tag"}]' \ - '.crates_io_trusted_publishing[0].environment.secret_names = ["CARGO_REGISTRY_TOKEN"]' \ - '.crates_io_trusted_publishing[0].environment.variable_names = ["UNREVIEWED"]' \ - '.crates_io_trusted_publishing[0].token = "forbidden-value"' \ - '.crates_io_trusted_publishing[0].release_sha = "invented"' \ - '.crates_io_trusted_publishing[0].crate_sha256 = "invented"' \ - '.crates_io_trusted_publishing += [.crates_io_trusted_publishing[0]]'; do - assert_rejected "${filter}" -done - -jq '.patterns_allowed |= map(select(startswith("rust-lang/crates-io-auth-action@") | not))' \ - "${root}/config/actions-selected.json" >"${temporary}/config/actions-selected.json" -if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted planned publisher without official action allowance" >&2 - exit 1 -fi -reset_policy -jq '.patterns_allowed |= map(if startswith("rust-lang/crates-io-auth-action@") then "rust-lang/*" else . end)' \ - "${root}/config/actions-selected.json" >"${temporary}/config/actions-selected.json" -if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted an unrelated broader Rust action allowance" >&2 - exit 1 -fi -reset_policy -jq '.patterns_allowed += ["rust-lang/*"]' "${root}/config/actions-selected.json" \ - >"${temporary}/config/actions-selected.json" -if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted broader Rust action access beside the exact action" >&2 - exit 1 -fi -reset_policy -# GitHub-owned official signing actions remain permitted without central SHA locks. -jq '.github_owned_allowed = false' "${root}/config/actions-selected.json" \ - >"${temporary}/config/actions-selected.json" -if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted source provenance signing without GitHub-owned Actions access" >&2 - exit 1 -fi -reset_policy -# Dependabot can change the immutable workflow pin without a central version lock. -jq '.crates_io_trusted_publishing[0].authentication_action = "rust-lang/crates-io-auth-action@2222222222222222222222222222222222222222"' \ - "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" -"${temporary}/bin/validate" >/dev/null -reset_policy -# Observed onboarding requires coherent source/environment/external proof. -jq '.crates_io_trusted_publishing[0] |= ( - .source_state = "observed-reviewed-workflow" | .environment_state = "observed" | - .publisher_registration = {state:"owner-observed-registration", observed_on:"2026-10-11", - evidence_location:"atrinik/github-settings#owner-setup"})' "${root}/config/manual-settings.json" \ - >"${temporary}/config/manual-settings.json" -"${temporary}/bin/validate" >/dev/null -reset_policy -for filter in \ - '.crates_io_trusted_publishing[0] |= (.source_state="pending-reviewed-workflow" | .environment_state="observed")' \ - '.crates_io_trusted_publishing[0].publisher_registration = {state:"owner-observed-registration", observed_on:"2026-02-31", evidence_location:"atrinik/github-settings#owner-setup"}' \ - '.crates_io_trusted_publishing[0] |= (.source_state="observed-reviewed-workflow" | .environment_state="observed" | .publisher_registration={state:"owner-observed-registration",observed_on:"2099-01-01",evidence_location:"atrinik/github-settings#owner-setup"})'; do - assert_rejected "${filter}" -done -jq '.crate_dependency_update_app |= (.status="owner-observed" | .app_id=85500002 | - .installation_id=154000002 | .repository_scope_verification="organization_owner_ui" | - .observed_on="2026-08-31" | .evidence_location="atrinik/github-settings#owner-app" | - .repository_scope_reverification.last_readback_on="2026-08-31" | - .workflow_activation={state:"pending-reviewed-workflows", observed_on:null, evidence_location:null})' \ - "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" -"${temporary}/bin/validate" >/dev/null -reset_policy -for filter in \ - '.crate_dependency_update_app.permissions.administration = "write"' \ - '.crate_dependency_update_app.consumers += ["atrinik/classic/.github/workflows/update-content.yml"]' \ - '.crate_dependency_update_app.key_created_on = "2099-01-01"' \ - '.crate_dependency_update_app.last_verified_on = null' \ - '.crate_dependency_update_app.rotate_by = "2026-10-10"' \ - '.crate_dependency_update_app.rotate_by = "2027-01-10"' \ - '.crate_dependency_update_app.rotation_cadence_days = 365' \ - '.crate_dependency_update_app.rotation_owner = "unknown"' \ - '.crate_dependency_update_app.events = ["push"]' \ - '.crate_dependency_update_app.webhook_active = true' \ - '.crate_dependency_update_app.homepage_url = "https://example.test"' \ - '.crate_dependency_update_app.repository_selection = "all"' \ - '.crate_dependency_update_app.repositories += [{repository:"atrinik/classic", repository_id:1327289971}]' \ - '.crate_dependency_update_app.repositories[0].repository_id = 1' \ - '.crate_dependency_update_app.secret_scope = "organization"' \ - '.crate_dependency_update_app.secret_name = "CARGO_REGISTRY_TOKEN"' \ - '.crate_dependency_update_app.private_key = "forbidden"' \ - '.crate_dependency_update_app.pull_request_policy = "auto-merge"' \ - '.crate_dependency_update_app.status = "active"' \ - '.crate_dependency_update_app.workflow_activation.state = "active"' \ - '.crate_dependency_update_app.workflow_activation = {state:"observed-successful-owned-pr", observed_on:null, evidence_location:null}' \ - '.crate_dependency_update_app.workflow_activation = {state:"pending-reviewed-workflows", observed_on:null, evidence_location:"invented"}' \ - '.crate_dependency_update_app.app_id = null' \ - '.crate_dependency_update_app.observed_on = null'; do - assert_rejected "${filter}" -done - -assert_accepted() { - local filter=$1 - jq "${filter}" "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" - if ! "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: rejected valid dependency App record: ${filter}" >&2 - exit 1 - fi - reset_policy -} - -# The exposure acceptance pins the editor transfer and stays while the key -# that was current at the transfer is in use. Rotation retires it. -assert_accepted '.crate_dependency_update_app |= (.key_created_on = "2026-10-18" | - .last_verified_on = "2026-10-18" | .rotate_by = "2027-01-16" | .accepted_key_exposures = [])' -exposure='.crate_dependency_update_app.accepted_key_exposures' -for filter in \ - "${exposure} = null" \ - "${exposure} = []" \ - "${exposure}[0] |= (.former_repository = \"atrinik/classic\" | .repository = \"elsewhere/classic\" | .repository_id = 1327289971)" \ - "${exposure}[0].repository = \"seraphinastudios/other-editor\"" \ - "${exposure}[0].exposure_started_on = \"2026-10-18\"" \ - "${exposure} = {}" \ - "${exposure} += [${exposure}[0]]" \ - "${exposure}[0].private_key = \"forbidden\"" \ - "del(${exposure}[0].accepted_on)" \ - "${exposure}[0].exposure = \"accepted\"" \ - "${exposure}[0].exposed_names = [\"CRATE_DEPENDENCY_UPDATE_APP_ID\"]" \ - "${exposure}[0].exposed_names += [\"CARGO_REGISTRY_TOKEN\"]" \ - "${exposure}[0].exposed_names |= reverse" \ - "${exposure}[0].former_repository = \"atrinik/client\"" \ - "${exposure}[0].former_repository = \"seraphinastudios/tilewright-editor\"" \ - "${exposure}[0].repository = \"atrinik/editor\"" \ - "${exposure}[0].repository = \"Atrinik/editor\"" \ - "${exposure}[0].repository_id = 1327106844" \ - "${exposure}[0].repository_id = 0" \ - "${exposure}[0].exposure_started_on = \"2026-10-10\"" \ - "${exposure}[0].exposure_started_on = \"2026-02-30\"" \ - "${exposure}[0].removal_observed_on = null" \ - "${exposure}[0].removal_observed_on = \"2026-10-16\"" \ - "${exposure}[0].accepted_on = null" \ - "${exposure}[0].accepted_on = \"2026-10-17\"" \ - "${exposure}[0].accepted_on = \"2099-01-01\"" \ - "${exposure}[0].accepted_by = \"unknown\"" \ - "${exposure}[0].evidence_location = \"https://example.test/evidence?id=1\"" \ - '.crate_dependency_update_app |= (.key_created_on = "2026-10-18" | - .last_verified_on = "2026-10-18" | .rotate_by = "2027-01-16")'; do - assert_rejected "${filter}" -done - -# A readback on or before the transfer stays pending; only a later readback -# in observed_on may clear the record, and then it must be cleared. -assert_accepted '.crate_dependency_update_app |= (.repository_scope_verification = "organization_owner_ui" | - .observed_on = "2026-10-18" | .repository_scope_reverification = null)' -reverification='.crate_dependency_update_app.repository_scope_reverification' -for filter in \ - "${reverification} = null" \ - "${reverification} = \"pending\"" \ - '.crate_dependency_update_app |= (.observed_on = "2026-10-17" | .repository_scope_reverification = null)' \ - '.crate_dependency_update_app.observed_on = "2026-10-18"' \ - '.crate_dependency_update_app |= (.observed_on = "2026-10-17" | .repository_scope_reverification.last_readback_on = "2026-10-17")' \ - "${reverification}.removed_repositories = [{repository:\"atrinik/classic\", repository_id:1327289971}]" \ - "${reverification}.selection_changed_on = \"2026-10-16\"" \ - "${reverification} = {}" \ - "${reverification}.observed_on = \"2026-10-18\"" \ - "${reverification}.state = \"reverified\"" \ - "${reverification}.reason = \"unknown\"" \ - "${reverification}.last_readback_on = \"2026-10-10\"" \ - "${reverification}.last_readback_on = null" \ - "${reverification}.selection_changed_on = \"2026-10-11\"" \ - "${reverification}.selection_changed_on = \"2099-01-01\"" \ - "${reverification}.selection_changed_on = null" \ - "${reverification}.removed_repositories = []" \ - "${reverification}.removed_repositories = null" \ - "${reverification}.removed_repositories += [${reverification}.removed_repositories[0]]" \ - "${reverification}.removed_repositories[0] = {repository:\"atrinik/client\", repository_id:1327106844}" \ - "${reverification}.removed_repositories[0].repository_id = 1327106844" \ - "${reverification}.removed_repositories[0].repository = \"seraphinastudios/tilewright-editor\"" \ - "${reverification}.removed_repositories[0].visibility = \"public\"" \ - "${reverification}.evidence_location = null" \ - '.crate_dependency_update_app.observed_on = "2026-10-12"'; do - assert_rejected "${filter}" -done - -# A planned App has no observed readback or key to qualify. -planned='.crate_dependency_update_app |= (.status="planned" | .app_id=null | .installation_id=null | - .key_created_on=null | .last_verified_on=null | .rotate_by=null | - .repository_scope_verification="pending-owner-ui" | .observed_on=null | .evidence_location=null | - .credential_state="pending-name-metadata")' -assert_accepted "${planned} | .crate_dependency_update_app |= (.accepted_key_exposures=[] | .repository_scope_reverification=null)" -assert_rejected "${planned} | .crate_dependency_update_app.accepted_key_exposures=[]" -assert_rejected "${planned} | .crate_dependency_update_app.repository_scope_reverification=null" -# Removing unactivated manual intent is a valid reviewed rollback. -jq '.crates_io_trusted_publishing = []' "${root}/config/manual-settings.json" \ - >"${temporary}/config/manual-settings.json" -"${temporary}/bin/validate" >/dev/null - -echo "Automatic crates.io Trusted Publishing and dependency App validation tests passed." diff --git a/tests/validate-immutable-releases.sh b/tests/validate-immutable-releases.sh deleted file mode 100755 index b705e10..0000000 --- a/tests/validate-immutable-releases.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -make_case() { - local name=$1 - local case_root=${temporary}/${name} - - mkdir -p "${case_root}/bin" - cp "${root}/bin/validate" "${case_root}/bin/validate" - cp -R "${root}/config" "${case_root}/config" - cp -R "${root}/community-health" "${case_root}/community-health" - printf '%s\n' "${case_root}" -} - -expect_invalid() { - local name=$1 - local filter=$2 - local case_root output - - case_root=$(make_case "${name}") - output=${case_root}/config/immutable-releases.next.json - jq "${filter}" \ - "${case_root}/config/immutable-releases.json" >"${output}" - mv "${output}" "${case_root}/config/immutable-releases.json" - if "${case_root}/bin/validate" >/dev/null 2>&1; then - echo "expected immutable-release validation failure: ${name}" >&2 - exit 1 - fi -} - -"${root}/bin/validate" >/dev/null -jq -e '.enforced_repositories == "selected" and .repositories == [ - {id:1327289971,name:"classic"},{id:1327107043,name:"content-toolkit"}, - {id:1324297032,name:"metaserver-worker",activation_variable:{name:"ATRINIK_RELEASE_IMMUTABILITY_ACTIVE",scope:"repository"}}, - {id:1327106950,name:"protocol"} -]' "${root}/config/immutable-releases.json" >/dev/null -expect_invalid metaserver-identity '.repositories |= map(if .name == "metaserver-worker" then .id = 1 else . end)' -expect_invalid metaserver-activation-scope '.repositories |= map(if .name == "metaserver-worker" then .activation_variable.scope = "environment" else . end)' -expect_invalid metaserver-activation-name '.repositories |= map(if .name == "metaserver-worker" then .activation_variable.name = "OTHER_GATE" else . end)' -expect_invalid foreign-activation-variable '.repositories[0].activation_variable = {name:"ATRINIK_RELEASE_IMMUTABILITY_ACTIVE",scope:"repository"}' -expect_invalid protocol-identity '.repositories |= map(if .name == "protocol" then .id = 1 else . end)' -expect_invalid toolkit-identity '.repositories |= map(if .name == "content-toolkit" then .id = 1 else . end)' - -expect_invalid mode-all '.enforced_repositories = "all"' -expect_invalid invalid-id '.repositories[0].id = 0' -expect_invalid duplicate-id ' - .repositories += [{id: .repositories[0].id, name: "content"}] -' -expect_invalid archived-repository ' - .repositories = [{id: 1, name: "nawerhals"}] -' -expect_invalid unsorted-repositories ' - .repositories = [ - {id: 101, name: "content"}, - {id: 1327289971, name: "classic"} - ] -' - -echo "Immutable-release validation tests passed." diff --git a/tests/validate-manual-credentials.sh b/tests/validate-manual-credentials.sh deleted file mode 100755 index 8d4d545..0000000 --- a/tests/validate-manual-credentials.sh +++ /dev/null @@ -1,508 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/validate" -cp -R "${root}/config" "${temporary}/config" -cp -R "${root}/community-health" "${temporary}/community-health" -cp -R "${root}/.github" "${temporary}/.github" - -assert_invalid() { - local description=$1 - - if ATRINIK_VALIDATION_TODAY=2026-08-31 \ - "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -reset_manual_settings() { - jq '.github_actions_credentials |= map(select(.credential_type == "classic_pat")) | - .crates_io_trusted_publishing[].publisher_registration = - {state:"pending-owner-registration",observed_on:null,evidence_location:null} | - .github_packages_actions_access[] |= (.grant_state="pending-owner-ui-read-grant" | - .observed_on=null | .evidence_location=null) | - .crate_dependency_update_app |= (.status="planned" | .app_id=null | .installation_id=null | - .key_created_on=null | .last_verified_on=null | .rotate_by=null | - .repository_scope_verification="pending-owner-ui" | .observed_on=null | .evidence_location=null | - .accepted_key_exposures=[] | .repository_scope_reverification=null | - .credential_state="pending-name-metadata" | - .workflow_activation={state:"pending-reviewed-workflows", observed_on:null, evidence_location:null})' \ - "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" -} - -rewrite_manual_settings() { - local filter=$1 - local output - - output=$(mktemp) - jq "${filter}" "${temporary}/config/manual-settings.json" >"${output}" - mv "${output}" "${temporary}/config/manual-settings.json" -} - -reset_manual_settings -ATRINIK_VALIDATION_TODAY=2026-08-31 \ - "${temporary}/bin/validate" >/dev/null -jq -e ' - .external_provider_apps == [{ - app_id: 85455, - app_slug: "cloudflare-workers-and-pages", - events: ["pull_request", "push"], - evidence_location: "atrinik/metaserver-worker#56-private-provider-evidence", - exceptional_retry: { - authorization: "provider-retry-only", - long_lived_production_branches: ["main"], - source: "exact-sha-still-current-main", - stale_policy: "abandon-and-re-evaluate-without-github-bypass" - }, - installation_id: 152311798, - last_verified_on: "2026-08-15", - owner: "Atrinik organization owners", - permissions: { - administration: "write", - checks: "write", - contents: "write", - deployments: "write", - metadata: "read", - pull_requests: "write" - }, - provider: "Cloudflare Workers Builds and Pages", - purpose: "Allow the existing website Pages connection and the reviewed metaserver-worker Workers Builds connection to receive GitHub events, read source, and publish provider-owned checks and deployments without access to any other Atrinik repository.", - repositories: [ - { - purpose: "Preserve the existing Cloudflare Pages website connection.", - repository: "atrinik/website", - repository_id: 1327107093 - }, - { - purpose: "Authorize the serialized Workers Builds topology governed by atrinik/metaserver-worker issues 53-56.", - repository: "atrinik/metaserver-worker", - repository_id: 1324297032 - } - ], - repository_scope_verification: "organization_owner_ui", - repository_selection: "selected", - review_by: "2026-11-13", - review_cadence_days: 90, - review_owner: "Atrinik organization owners", - revocation: "Remove only atrinik/metaserver-worker from installation 152311798 after disconnecting its Cloudflare repository connection; preserve atrinik/website unless its separately governed Pages connection is retired.", - runbook: "README.md#cloudflare-github-app", - status: "active", - status_producer: "Cloudflare Workers and Pages GitHub App" - }, { - app_id: null, - app_slug: "atrinik-deploy-control", - control_plane_repository: { - default_branch: "main", - license: "MIT", - repository: "atrinik/deploy-control", - repository_id: 1352850539, - visibility: "public" - }, - events: ["workflow_run"], - evidence_location: "atrinik/deploy-control#3", - exceptional_retry: null, - installation_id: null, - last_verified_on: "2026-08-31", - owner: "Atrinik organization owners", - permissions: { - actions: "read", - metadata: "read" - }, - provider: "Cloudflare Workers deploy-control control plane", - purpose: "Receive only successful workflow_run events from atrinik/classic for the reviewed deploy-control staging-image handoff; do not authorize source, package, environment, metaserver, or organization-wide access.", - repositories: [{ - purpose: "Authorize only the Classic workflow-run source for the deploy-control control plane.", - repository: "atrinik/classic", - repository_id: 1327289971 - }], - repository_scope_verification: "pending_provisioning", - repository_selection: "selected", - review_by: "2026-11-29", - review_cadence_days: 90, - review_owner: "Atrinik organization owners", - revocation: "Before retiring the control plane, disable its workflow-run delivery, revoke the App keys and webhook secret, remove only the named control-plane secret/variable slots, and verify the App installation no longer selects atrinik/classic; leave the Cloudflare Workers and Pages installation and metaserver boundary unchanged.", - runbook: "README.md#deploy-control-github-app", - secret_names: [ - "DEPLOY_CONTROL_AGENT_ENROLLMENT_SECRET", - "DEPLOY_CONTROL_GITHUB_APP_PRIVATE_KEY", - "DEPLOY_CONTROL_GITHUB_WEBHOOK_SECRET" - ], - status: "planned", - status_producer: "Atrinik deploy-control control-plane owner", - variable_names: [ - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_DURABLE_OBJECT_BINDING", - "CLOUDFLARE_WORKER_NAME", - "DEPLOY_CONTROL_GITHUB_APP_ID", - "DEPLOY_CONTROL_GITHUB_INSTALLATION_ID" - ] - }] and - .github_actions_apps == [{ - app_id: 4564008, - app_slug: "atrinik-classic-dependency-updater", - consumers: [".github/workflows/update-content.yml"], - events: [], - installation_id: 153045686, - last_verified_on: "2026-08-11", - owner: "Atrinik organization owners", - permissions: { - contents: "write", - metadata: "read", - pull_requests: "write" - }, - purpose: "Authenticate the branch and pull-request operations for one reviewed Classic content-lock update without access to other Atrinik repositories.", - repository: "atrinik/classic", - repository_id: 1327289971, - repository_scope_verification: "organization_owner_ui", - repository_selection: "selected", - rotate_by: "2026-11-09", - rotation_cadence_days: 90, - rotation_owner: "Atrinik organization owners", - runbook: "README.md#classic-dependency-update-app", - secret_name: "DEPENDENCY_UPDATE_APP_PRIVATE_KEY", - secret_scope: "repository", - variable_name: "DEPENDENCY_UPDATE_APP_ID", - variable_scope: "repository" - }] -' "${root}/config/manual-settings.json" >/dev/null -jq -e ' - [.github_actions_credentials[] | select(.credential_type == "classic_pat")] == [{ - credential_type: "classic_pat", - consumers: [ - ".github/workflows/check-project-health.yml", - ".github/workflows/publish-planning.yml", - ".github/workflows/publish.yml", - ".github/workflows/sync-project.yml" - ], - last_verified_on: "2026-08-10", - owner: "Atrinik organization owners", - purpose: "Administer Atrinik organization governance and synchronize the shared organization Project from GitHub Actions.", - repository: "atrinik/github-settings", - repository_id: 1324382941, - required_scopes: ["admin:org", "project", "repo"], - rotate_by: "2026-11-08", - rotation_cadence_days: 90, - rotation_owner: "Atrinik organization owners", - runbook: "README.md#settings-automation-credential", - secret_name: "ATRINIK_SETTINGS_TOKEN", - secret_scope: "repository" - }] -' "${root}/config/manual-settings.json" >/dev/null - -jq -e ' - [.github_actions_credentials[] | select(.environment == "development")] as $credentials | - ($credentials | length) == 3 and - all($credentials[]; - .repository == "atrinik/metaserver-worker" and .repository_id == 1324297032 and - .environment == "development" and .consumers == [".github/workflows/deploy-development.yml"] and - .last_verified_on == "2026-10-11" and .rotate_by == "2027-01-09" and - .rotation_cadence_days == 90 and .owner == "Zoey Seraphina Rose (Atrinik organization owner)" - ) and - ([$credentials[].secret_name] | sort) == [ - "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", "CLOUDFLARE_API_TOKEN" - ] -' "${root}/config/manual-settings.json" >/dev/null - -jq -e ' - [.github_actions_credentials[] | select(.environment == "production")] as $credentials | - ($credentials | length) == 3 and - all($credentials[]; - .repository == "atrinik/metaserver-worker" and .repository_id == 1324297032 and - .consumers == [".github/workflows/promote-production.yml"] and - .runbook == "README.md#metaserver-production-credentials" and - .rotation_cadence_days == 90 and .owner == "Zoey Seraphina Rose (Atrinik organization owner)" and - (if .secret_name == "CLOUDFLARE_API_TOKEN" then - .last_verified_on == "2026-10-12" and .rotate_by == "2027-01-10" - else .last_verified_on == "2026-10-11" and .rotate_by == "2027-01-09" end) - ) and - ([$credentials[].secret_name] | sort) == [ - "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", "CLOUDFLARE_API_TOKEN" - ] -' "${root}/config/manual-settings.json" >/dev/null - -# Fixture records exercise the schema; they do not declare live PROD credentials. -jq '.github_actions_credentials |= map(select(.environment != "production")) | - .github_actions_credentials += [ - .github_actions_credentials[] | select(.secret_scope == "environment") | - .environment = "production" | - .consumers = [".github/workflows/promote-production.yml"] | - .runbook = "README.md#metaserver-production-credentials" -]' "${root}/config/manual-settings.json" >"${temporary}/production-credentials.json" -cp "${temporary}/production-credentials.json" "${temporary}/config/manual-settings.json" -ATRINIK_VALIDATION_TODAY=2026-10-18 "${temporary}/bin/validate" >/dev/null - -for invalid in \ - '.github_actions_credentials += [.github_actions_credentials[-1]]' \ - '.github_actions_credentials[-1].environment = "staging"' \ - '.github_actions_credentials[-1].consumers = [".github/workflows/deploy-development.yml"]' \ - '.github_actions_credentials[-1].runbook = "README.md#metaserver-development-credentials"' \ - '.github_actions_credentials[-1].required_scopes += ["Workers Scripts Edit"]' \ - '.github_actions_credentials[-1].credential_type = "cloudflare_account_token"'; do - jq "$invalid" "${temporary}/production-credentials.json" >"${temporary}/config/manual-settings.json" - if ATRINIK_VALIDATION_TODAY=2026-10-18 "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted malformed PROD credential lifecycle: ${invalid}" >&2 - exit 1 - fi -done - -for invalid in \ - '.github_actions_credentials[1].required_scopes = ["Workers Scripts Read"]' \ - '.github_actions_credentials[2].credential_type = "cloudflare_user_token"' \ - '.github_actions_credentials[3].environment = "production"' \ - '.github_actions_credentials[1].repository_id = 1' \ - '.github_actions_credentials[1].consumers = [".github/workflows/publish.yml"]' \ - '.github_actions_credentials[1].credential_value = "secret"'; do - jq "$invalid" "${root}/config/manual-settings.json" >"${temporary}/config/manual-settings.json" - if ATRINIK_VALIDATION_TODAY=2026-10-18 "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted malformed DEV credential lifecycle: ${invalid}" >&2 - exit 1 - fi -done -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].repository_selection = "all"' -assert_invalid 'an external provider App installed on all repositories' -reset_manual_settings - -rewrite_manual_settings 'del(.external_provider_apps[0].repositories[0])' -assert_invalid 'an external provider App that drops website access' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].repositories += [{purpose: "unrelated", repository: "atrinik/classic", repository_id: 1327289971}]' -assert_invalid 'an external provider App with unrelated repository access' -reset_manual_settings - -rewrite_manual_settings 'del(.external_provider_apps[0].repositories[1])' -assert_invalid 'an external provider App without metaserver-worker access' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].permissions.contents = "read"' -assert_invalid 'external provider App permission drift' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].events = ["push"]' -assert_invalid 'external provider App event drift' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].evidence_location = ""' -assert_invalid 'an external provider App without its owner evidence location' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].exceptional_retry.source = "branch"' -assert_invalid 'an external provider App retry not pinned to exact current main' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[0].installation_token = "secret"' -assert_invalid 'external provider App credential material' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].app_id = 123' -assert_invalid 'a planned external provider App with a fabricated App ID' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].installation_id = 123' -assert_invalid 'a planned external provider App with a fabricated installation ID' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].permissions.actions = "write"' -assert_invalid 'a planned external provider App with write Actions permission' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].events = ["push"]' -assert_invalid 'a planned external provider App with an unexpected event' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].repositories[0].repository_id = 1' -assert_invalid 'a planned external provider App with a wrong selected repository ID' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].secret_names[0] = "private-key"' -assert_invalid 'a planned external provider App with a malformed secret name' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].secret_names[0] = "DEPLOY_CONTROL_AGENT_TOKEN"' -assert_invalid 'a planned external provider App with an unexpected secret name' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].variable_names[0] = "CLOUDFLARE_ACCOUNT"' -assert_invalid 'a planned external provider App with an unexpected variable name' -reset_manual_settings - -rewrite_manual_settings '.external_provider_apps[1].private_key = "secret"' -assert_invalid 'a planned external provider App with credential material' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps += [.github_actions_apps[0]]' -assert_invalid 'a duplicate GitHub App record' -reset_manual_settings - -rewrite_manual_settings \ - 'del(.github_actions_apps[0].installation_id)' -assert_invalid 'a GitHub App without an installation ID' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].permissions.actions = "write"' -assert_invalid 'a GitHub App with Actions permission' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].permissions.contents = "read"' -assert_invalid 'a GitHub App without contents write permission' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].events = ["push"]' -assert_invalid 'a GitHub App with webhook events' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].repository_selection = "all"' -assert_invalid 'a GitHub App installed on all repositories' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].repository_scope_verification = "unverified"' -assert_invalid 'a GitHub App without owner-verified repository scope' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].repository = "atrinik/unknown"' -assert_invalid 'a GitHub App for an ungoverned repository' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].secret_name = "private-key"' -assert_invalid 'a malformed GitHub App Actions secret name' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].variable_name = "app-id"' -assert_invalid 'a malformed GitHub App Actions variable name' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].rotate_by = "2026-08-10"' -assert_invalid 'a stale GitHub App rotate-by date' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_apps[0].private_key = "secret"' -assert_invalid 'GitHub App private-key material' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials += [.github_actions_credentials[0]]' -assert_invalid 'a duplicate repository credential' -reset_manual_settings - -rewrite_manual_settings \ - 'del(.github_actions_credentials[0].repository_id)' -assert_invalid 'a credential without a stable repository ID' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].repository = "atrinik/unknown"' -assert_invalid 'a credential for an ungoverned repository' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].credential_type = "fine_grained_pat"' -assert_invalid 'an unsupported credential type' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].required_scopes += ["delete:packages"]' -assert_invalid 'an unsupported credential scope' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].required_scopes += ["project"]' -assert_invalid 'a duplicate credential scope' -reset_manual_settings - -for scope in admin:org project repo; do - rewrite_manual_settings \ - ".github_actions_credentials[0].required_scopes -= [\"${scope}\"]" - assert_invalid "a credential missing the required ${scope} scope" - reset_manual_settings -done - -rewrite_manual_settings \ - '.github_actions_credentials[0].secret_name = "settings-token"' -assert_invalid 'a malformed Actions secret name' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].owner = ""' -assert_invalid 'a credential without accountable ownership' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].rotate_by = "2026-08-09"' -assert_invalid 'a stale rotate-by date' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].rotate_by = "2026-02-30"' -assert_invalid 'an impossible calendar day' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].last_verified_on = "2025-02-29"' -assert_invalid 'a non-leap-year February 29' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].last_verified_on = "2026-09-01"' -assert_invalid 'a future verification date' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].rotate_by = "2026-12-31"' -assert_invalid 'a rotate-by date beyond the declared cadence' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].consumers = [".github/workflows/missing.yml"]' -assert_invalid 'a missing credential consumer workflow' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credentials[0].credential_value = "secret"' -assert_invalid 'a credential-value field' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_credential_values = {ATRINIK_SETTINGS_TOKEN: "secret"}' -assert_invalid 'a top-level credential-value field' - -reset_manual_settings -rewrite_manual_settings ' - .external_provider_apps[0].last_verified_on = "2028-02-29" | - .external_provider_apps[0].review_by = "2028-05-29" | - .external_provider_apps[1].last_verified_on = "2028-02-29" | - .external_provider_apps[1].review_by = "2028-05-29" | - .github_actions_apps[0].last_verified_on = "2028-02-29" | - .github_actions_apps[0].rotate_by = "2028-05-29" | - .github_actions_credentials[0].last_verified_on = "2028-02-29" | - .github_actions_credentials[0].rotate_by = "2028-05-29" -' -ATRINIK_VALIDATION_TODAY=2028-02-29 \ - "${temporary}/bin/validate" >/dev/null - -if ATRINIK_VALIDATION_TODAY=2026-02-30 \ - "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted an impossible validation date" >&2 - exit 1 -fi - -echo "Manual GitHub Actions credential validation tests passed." diff --git a/tests/validate-manual-environments.sh b/tests/validate-manual-environments.sh deleted file mode 100755 index a41a0e4..0000000 --- a/tests/validate-manual-environments.sh +++ /dev/null @@ -1,289 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/validate" -cp -R "${root}/config" "${temporary}/config" -cp -R "${root}/community-health" "${temporary}/community-health" -cp -R "${root}/.github" "${temporary}/.github" - -assert_invalid() { - local description=$1 - - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -reset_manual_settings() { - jq ' - .github_pages_sites = [] | - .github_actions_environments = [ - { - deployment_branch_policy: { - custom_branch_policies: true, - patterns: [ - {name: "main", type: "branch"}, - {name: "v*", type: "tag"} - ], - protected_branches: false - }, - environment: "test-deployment", - repository: "atrinik/classic", - repository_id: 1327289971, - required_reviewers: [], - secret_names: ["EXTERNAL_TOKEN"], - variable_names: ["EXTERNAL_ACCOUNT_ID"] - } - ] - ' "${root}/config/manual-settings.json" \ - >"${temporary}/config/manual-settings.json" -} - -rewrite_manual_settings() { - local filter=$1 - local output - - output=$(mktemp) - jq "${filter}" \ - "${temporary}/config/manual-settings.json" >"${output}" - mv "${output}" "${temporary}/config/manual-settings.json" -} - -jq -e ' - (.github_actions_environments | length) == 4 and - any(.github_actions_environments[]; . == { - deployment_branch_policy: { - custom_branch_policies: true, - patterns: [ - {name: "main", type: "branch"}, - {name: "v*", type: "tag"} - ], - protected_branches: false - }, - environment: "discord-release", - repository: "atrinik/classic", - repository_id: 1327289971, - required_reviewers: [], - secret_names: ["DISCORD_APPLICATION_ID"], - variable_names: [] - }) and - any(.github_actions_environments[]; . == { - deployment_branch_policy: { - custom_branch_policies: true, - patterns: [{name: "main", type: "branch"}], - protected_branches: false - }, - environment: "github-pages", - repository: "atrinik/classic", - repository_id: 1327289971, - required_reviewers: [], - secret_names: [], - variable_names: [] - }) and - any(.github_actions_environments[]; . == { - deployment_branch_policy: { - custom_branch_policies: false, - patterns: [], - protected_branches: true - }, - environment: "development", - repository: "atrinik/metaserver-worker", - repository_id: 1324297032, - required_reviewers: [], - secret_names: [ - "ATRINIK_DELIVERY_RESOURCE_POLICY", - "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "ATRINIK_DEVELOPMENT_CORE_CONFIG", - "ATRINIK_DEVELOPMENT_PUBLISHER_CONFIG", - "ATRINIK_DEVELOPMENT_RENDEZVOUS_CONFIG", - "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", - "CLOUDFLARE_ACCOUNT_ID", - "CLOUDFLARE_API_TOKEN" - ], - variable_names: ["ATRINIK_PRODUCTION_WRITER_FENCE_POLICY"] - }) and - any(.github_actions_environments[]; . == { - deployment_branch_policy: {custom_branch_policies: false, patterns: [], protected_branches: true}, - environment: "production", - repository: "atrinik/metaserver-worker", - repository_id: 1324297032, - required_reviewers: [], - secret_names: [ - "ATRINIK_DELIVERY_RESOURCE_POLICY", "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN", - "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN", "ATRINIK_PRODUCTION_CORE_CONFIG", - "ATRINIK_PRODUCTION_PUBLISHER_CONFIG", "ATRINIK_PRODUCTION_RENDEZVOUS_CONFIG", - "CLOUDFLARE_ACCOUNT_ID", "CLOUDFLARE_API_TOKEN" - ], - variable_names: ["ATRINIK_PRODUCTION_RECOVERY_PUBLIC_KEY", "ATRINIK_PRODUCTION_WRITER_FENCE_POLICY"] - }) and - .github_pages_sites == [{ - activation_marker: "actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e", - build_type: "workflow", - environment: "github-pages", - https_enforced: true, - repository: "atrinik/classic", - repository_id: 1327289971, - site_url: "https://atrinik.github.io/classic/", - workflow_path: ".github/workflows/daily-client-performance.yml" - }] -' "${root}/config/manual-settings.json" >/dev/null - -"${temporary}/bin/validate" >/dev/null -reset_manual_settings -"${temporary}/bin/validate" >/dev/null - -rewrite_manual_settings \ - '.github_actions_environments[0].variable_names = []' -"${temporary}/bin/validate" >/dev/null -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments += [.github_actions_environments[0]]' -assert_invalid 'a duplicate repository environment' -reset_manual_settings - -rewrite_manual_settings \ - 'del(.github_actions_environments[0].repository_id)' -assert_invalid 'an environment without a stable repository ID' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].repository = "atrinik/unknown"' -assert_invalid 'an environment for an ungoverned repository' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].required_reviewers = [{type: "User", id: 1}]' -assert_invalid 'a required reviewer outside the declared empty set' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].deployment_branch_policy = { - custom_branch_policies: false, - patterns: [], - protected_branches: true - } -' -"${temporary}/bin/validate" >/dev/null -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns = [{name: "main", type: "branch"}]' -assert_invalid 'custom patterns combined with protected-branches mode' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].deployment_branch_policy.custom_branch_policies = true | - .github_actions_environments[0].deployment_branch_policy.protected_branches = true -' -assert_invalid 'both deployment branch policy modes enabled' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].deployment_branch_policy = { - custom_branch_policies: false, patterns: [], protected_branches: false - } -' -assert_invalid 'both deployment branch policy modes disabled' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns = []' -assert_invalid 'custom branch policy mode with no exact patterns' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns[0].name = "*"' -assert_invalid 'a wildcard deployment branch policy' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns[1].name = "*"' -assert_invalid 'an unrestricted tag deployment policy' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns[1].name = "release-*"' -assert_invalid 'a noncanonical release tag deployment policy' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].deployment_branch_policy.patterns[1].type = "environment"' -assert_invalid 'an unsupported deployment policy type' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].secret_values = {}' -assert_invalid 'an environment secret-value field' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environment_secret_values = {EXTERNAL_TOKEN: "secret"}' -assert_invalid 'a top-level environment secret-value field' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].variable_names += - [.github_actions_environments[0].variable_names[0]] -' -assert_invalid 'a duplicate environment variable name' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].variable_names = ["external_account_id"]' -assert_invalid 'a malformed environment variable name' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].secret_names += - [.github_actions_environments[0].secret_names[0]] -' -assert_invalid 'a duplicate environment secret name' -reset_manual_settings - -rewrite_manual_settings ' - .github_actions_environments[0].secret_names = - [.github_actions_environments[0].variable_names[0]] -' -assert_invalid 'a name declared as both a variable and a secret' -reset_manual_settings - -rewrite_manual_settings \ - '.github_actions_environments[0].secret_names = ["external_token"]' -assert_invalid 'a malformed environment secret name' - -reset_manual_settings -rewrite_manual_settings \ - '.github_actions_environments[0].secret_names = []' -assert_invalid 'an empty secret contract outside github-pages' - -cp "${root}/config/manual-settings.json" \ - "${temporary}/config/manual-settings.json" -rewrite_manual_settings \ - '.github_pages_sites[0].build_type = "legacy"' -assert_invalid 'a non-workflow desired Pages source' - -cp "${root}/config/manual-settings.json" \ - "${temporary}/config/manual-settings.json" -rewrite_manual_settings \ - '.github_pages_sites[0].site_url = "https://example.test/classic/"' -assert_invalid 'a Pages URL outside the repository identity' - -cp "${root}/config/manual-settings.json" \ - "${temporary}/config/manual-settings.json" -rewrite_manual_settings \ - '.github_pages_sites[0].activation_marker = "actions/deploy-pages@v4"' -assert_invalid 'a mutable Pages activation marker' - -cp "${root}/config/manual-settings.json" \ - "${temporary}/config/manual-settings.json" -rewrite_manual_settings \ - '.github_pages_sites[0].environment = "production"' -assert_invalid 'a Pages site without its exact environment' - -echo "Manual GitHub Actions environment validation tests passed." diff --git a/tests/validate-manual-package-access.sh b/tests/validate-manual-package-access.sh deleted file mode 100755 index fe55a22..0000000 --- a/tests/validate-manual-package-access.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/validate" -cp -R "${root}/.github" "${temporary}/.github" -cp -R "${root}/config" "${temporary}/config" -cp -R "${root}/community-health" "${temporary}/community-health" - -assert_invalid() { - local description=$1 - - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -rewrite_manual_settings() { - local filter=$1 - local output - - output=$(mktemp) - jq "${filter}" \ - "${temporary}/config/manual-settings.json" >"${output}" - mv "${output}" "${temporary}/config/manual-settings.json" -} - -jq -e ' - [.github_packages_actions_access[] | select(.package_name != "linux-build")] == [] and - [.github_packages_actions_access[].actions_repository] == ["atrinik/client"] and - all(.github_packages_actions_access[]; .package_id == 14205615 and .preserve_visibility == "private" and - .source_repository == "atrinik/devcontainer" and .source_repository_id == 1322185908 and - .role == "read" and .grant_state == "owner-observed-read-grant" and - .observed_on == "2026-10-11" and .evidence_location == "README.md#private-linux-updater-build-image") -' "${root}/config/manual-settings.json" >/dev/null - -reset_valid_access() { - cp "${root}/config/manual-settings.json" \ - "${temporary}/config/manual-settings.json" - rewrite_manual_settings ' - .github_packages_actions_access = [ - { - package_owner: "atrinik", - package_type: "container", - package_name: "classic-build", - package_id: 14345002, - preserve_visibility: "private", - actions_repository: "atrinik/classic", - actions_repository_id: 1327289971, - role: "read" - } - ]' - "${temporary}/bin/validate" >/dev/null -} - -reset_valid_access -rewrite_manual_settings \ - '.github_packages_actions_access += [.github_packages_actions_access[0]]' -assert_invalid 'a duplicate package Actions-access grant' - -reset_valid_access -rewrite_manual_settings \ - '.github_packages_actions_access[0].role = "write"' -assert_invalid 'a write-capable package Actions-access grant' - -reset_valid_access -rewrite_manual_settings \ - 'del(.github_packages_actions_access[0].actions_repository_id)' -assert_invalid 'a package grant without a stable repository ID' - -reset_valid_access -rewrite_manual_settings \ - '.github_packages_actions_access[0].package_id = 0' -assert_invalid 'a package grant without a positive package ID' - -reset_valid_access -rewrite_manual_settings \ - '.github_packages_actions_access[0].actions_repository = "classic"' -assert_invalid 'a package grant without a full repository name' - -# Preserve the legacy schema for unrelated owners/types sharing this package name. -for filter in \ - '.github_packages_actions_access[0] |= (.package_owner="another-owner" | .package_name="linux-build")' \ - '.github_packages_actions_access[0] |= (.package_type="npm" | .package_name="linux-build")'; do - reset_valid_access - rewrite_manual_settings "${filter}" - "${temporary}/bin/validate" >/dev/null -done - -for filter in \ - '.github_packages_actions_access[0].source_repository_id = 1' \ - '.github_packages_actions_access[0].preserve_visibility = "public"' \ - '.github_packages_actions_access[0].actions_repository_id = 1' \ - '.github_packages_actions_access[0].grant_state = "active"' \ - '.github_packages_actions_access[0].grant_state = "pending-owner-ui-read-grant"' \ - '.github_packages_actions_access[0].evidence_location = null'; do - cp "${root}/config/manual-settings.json" "${temporary}/config/manual-settings.json" - rewrite_manual_settings "${filter}" - assert_invalid "${filter}" -done -cp "${root}/config/manual-settings.json" "${temporary}/config/manual-settings.json" -rewrite_manual_settings '.github_packages_actions_access[] |= (.grant_state="owner-observed-read-grant" | - .observed_on="2026-10-11" | .evidence_location="README.md#private-linux-updater-build-image")' -"${temporary}/bin/validate" >/dev/null -rewrite_manual_settings '.github_packages_actions_access[] |= (.grant_state="pending-owner-ui-read-grant" | - .observed_on=null | .evidence_location=null)' -"${temporary}/bin/validate" >/dev/null - -echo "Manual package Actions-access validation tests passed." diff --git a/tests/validate-merge-queue.sh b/tests/validate-merge-queue.sh deleted file mode 100755 index a45eef2..0000000 --- a/tests/validate-merge-queue.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${temporary}/" -config=${temporary}/config -"${temporary}/bin/validate" >/dev/null -cp "${config}/repositories.json" "${temporary}/repositories.json" -cp "${config}/rulesets/merge-queue.json" "${temporary}/merge-queue.json" -cp "${config}/rulesets/required-ci.json" "${temporary}/required-ci.json" -cp "${config}/security-merge-protection.json" "${temporary}/security.json" - -expect_invalid() { - local file=$1 source=$2 filter=$3 - jq "${filter}" "${source}" >"${file}" - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted invalid merge-queue policy: ${filter}" >&2 - exit 1 - fi - cp "${source}" "${file}" -} - -# Queued repositories need required CI for the queue to run on each merge result. -for filter in \ - 'del(.merge_queue)' '.merge_queue = "playtester"' '.merge_queue = [null]' \ - '.merge_queue = [""]' '.merge_queue = ["playtester", "playtester"]' \ - '.merge_queue = ["web-platform"]' '.merge_queue = ["legacy-client"]' \ - '.merge_queue = ["unknown"]'; do - expect_invalid "${config}/repositories.json" "${temporary}/repositories.json" "${filter}" -done - -# Parameters stay within GitHub's API ranges and the organization's merge method. -for filter in \ - '.name = "Merge queue"' '.target = "tag"' '.enforcement = "disabled"' \ - '.conditions.ref_name.include = ["refs/heads/*"]' \ - '.bypass_actors[0].bypass_mode = "always"' '.bypass_actors = []' \ - '.rules += [{type: "deletion"}]' '.rules[0].type = "pull_request"' \ - '.rules[0].parameters.merge_method = "MERGE"' \ - '.rules[0].parameters.merge_method = "REBASE"' \ - '.rules[0].parameters.merge_method = "squash"' \ - '.rules[0].parameters.grouping_strategy = "ANYGREEN"' \ - '.rules[0].parameters.check_response_timeout_minutes = 0' \ - '.rules[0].parameters.check_response_timeout_minutes = 361' \ - '.rules[0].parameters.check_response_timeout_minutes = 1.5' \ - '.rules[0].parameters.check_response_timeout_minutes = "60"' \ - '.rules[0].parameters.max_entries_to_build = 0' \ - '.rules[0].parameters.max_entries_to_build = 101' \ - '.rules[0].parameters.max_entries_to_merge = 0' \ - '.rules[0].parameters.min_entries_to_merge = 0' \ - '.rules[0].parameters.min_entries_to_merge = 6' \ - '.rules[0].parameters.min_entries_to_merge_wait_minutes = 361' \ - '.rules[0].parameters.min_entries_to_merge_wait_minutes = 5' \ - 'del(.rules[0].parameters.grouping_strategy)' \ - '.rules[0].parameters.unknown_option = true'; do - expect_invalid "${config}/rulesets/merge-queue.json" "${temporary}/merge-queue.json" "${filter}" -done -# A wait applies only while a group is below a minimum above one. -jq '.rules[0].parameters.min_entries_to_merge = 2 | - .rules[0].parameters.min_entries_to_merge_wait_minutes = 5' \ - "${temporary}/merge-queue.json" >"${config}/rulesets/merge-queue.json" -"${temporary}/bin/validate" >/dev/null -cp "${temporary}/merge-queue.json" "${config}/rulesets/merge-queue.json" - -# The publisher relaxes only a strict template, and only for queued repositories. -for filter in \ - '.rules[0].parameters.strict_required_status_checks_policy = false' \ - '.rules[0].parameters.required_status_checks = [{context: "Extra", integration_id: 15368}]' \ - '.name = "Required CI"'; do - expect_invalid "${config}/rulesets/required-ci.json" "${temporary}/required-ci.json" "${filter}" -done - -# Dependency review never reports on merge groups, so it cannot gate a queue. -expect_invalid "${config}/security-merge-protection.json" "${temporary}/security.json" \ - '.dependency_review = ["playtester"] | .activation.dependency_review = {playtester: "pending"}' -"${temporary}/bin/validate" >/dev/null -echo 'Merge-queue schema tests passed.' diff --git a/tests/validate-planning-health.sh b/tests/validate-planning-health.sh deleted file mode 100755 index b0f815b..0000000 --- a/tests/validate-planning-health.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -cp -R "${root}/." "${temporary}/repository" - -assert_invalid() { - local filter=$1 - local description=$2 - - jq "${filter}" "${root}/config/planning-health.json" \ - >"${temporary}/repository/config/planning-health.json" - if ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: validator accepted ${description}" >&2 - exit 1 - fi -} - -ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${temporary}/repository/bin/validate" >/dev/null - -assert_invalid '.freshness_threshold_minutes = 30' \ - 'a freshness threshold below the best-effort schedule tolerance' -assert_invalid '.consecutive_failure_threshold = 1' \ - 'an alert on the first synchronization failure' -assert_invalid '.incident_marker = ""' \ - 'an unstable managed-incident marker' -assert_invalid '.incident_actor = "untrusted-user"' \ - 'an untrusted managed-incident actor' -assert_invalid '.monitoring_owner = ""' \ - 'planning health without an accountable owner' -assert_invalid '.monitor_workflow = "missing.yml"' \ - 'a missing monitoring workflow' -assert_invalid '.credential_value = "secret"' \ - 'an unexpected planning-health field' - -echo "Planning health validation tests passed." diff --git a/tests/validate-planning.sh b/tests/validate-planning.sh deleted file mode 100755 index 4992b3f..0000000 --- a/tests/validate-planning.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -cp -R "${root}/." "${temporary}/repository" - -"${temporary}/repository/bin/validate" >/dev/null - -jq '.release_tags += ["observatory"]' \ - "${root}/config/repositories.json" \ - >"${temporary}/repository/config/repositories.json" -if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: a no-release repository in release_tags was accepted" >&2 - exit 1 -fi - -cp "${root}/config/repositories.json" \ - "${temporary}/repository/config/repositories.json" -jq '.repositories.observatory.release_policy = "semantic-release"' \ - "${root}/config/repository-properties.json" \ - >"${temporary}/repository/config/repository-properties.json" -if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: a release-policy repository omitted from release_tags was accepted" >&2 - exit 1 -fi - -cp "${root}/config/repository-properties.json" \ - "${temporary}/repository/config/repository-properties.json" - -jq '.project.views += [.project.views[0]]' \ - "${root}/config/planning.json" \ - >"${temporary}/repository/config/planning.json" -if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: duplicate project view was accepted" >&2 - exit 1 -fi - -jq '.project.builtin_fields[0].name = .issue_fields[0].name' \ - "${root}/config/planning.json" \ - >"${temporary}/repository/config/planning.json" -if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: ambiguous project field name was accepted" >&2 - exit 1 -fi - -cp "${root}/config/planning.json" \ - "${temporary}/repository/config/planning.json" -jq '.repositories.server.lifecycle = "unknown"' \ - "${root}/config/repository-properties.json" \ - >"${temporary}/repository/config/repository-properties.json" -if "${temporary}/repository/bin/validate" >/dev/null 2>&1; then - echo "error: invalid repository lifecycle was accepted" >&2 - exit 1 -fi - -echo "Planning validation rejects invalid desired state." diff --git a/tests/validate-retired-maintenance.sh b/tests/validate-retired-maintenance.sh deleted file mode 100755 index 866c901..0000000 --- a/tests/validate-retired-maintenance.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT - -make_case() { - local name=$1 - local case_root=${temporary}/${name} - - mkdir -p "${case_root}/bin" - cp "${root}/bin/validate" "${case_root}/bin/validate" - cp -R "${root}/config" "${case_root}/config" - cp -R "${root}/community-health" "${case_root}/community-health" - printf '%s\n' "${case_root}" -} - -expect_invalid_retirement() { - local name=$1 - local filter=$2 - local case_root output - - case_root=$(make_case "${name}") - output=${case_root}/config/retired-maintenance-branches.next.json - jq "${filter}" \ - "${case_root}/config/retired-maintenance-branches.json" >"${output}" - mv "${output}" "${case_root}/config/retired-maintenance-branches.json" - if "${case_root}/bin/validate" >/dev/null 2>&1; then - echo "expected retired-maintenance validation failure: ${name}" >&2 - exit 1 - fi -} - -"${root}/bin/validate" >/dev/null - -expect_invalid_retirement invalid-commit \ - '.retirements[0].final_branch_commit = "not-a-commit"' -expect_invalid_retirement duplicate-asset \ - '.retirements[0].final_release.assets += ["SHA256SUMS"]' -expect_invalid_retirement duplicate-ci \ - '.retirements[0].ruleset.required_ci += ["Content validation"]' -expect_invalid_retirement duplicate-preserved-id ' - .retirements[0].preserved_rulesets += - [{id: 20522685, name: "duplicate identity"}] -' -expect_invalid_retirement duplicate-coordinate ' - .retirements += [ - .retirements[0] | - .ruleset.id = 99999999 - ] -' -expect_invalid_retirement duplicate-ruleset-id ' - .retirements += [ - .retirements[0] | - .repository = "other" | - .repository_id = 99999999 | - .ruleset.name = "05 - Maintenance branch - other - 1.x" - ] -' - -overlap_root=$(make_case active-overlap) -jq '.maintenance_branches = [{ - repository: "content", - branch: "1.x", - required_ci: ["Content validation", "Conventional PR title"] -}]' "${overlap_root}/config/repositories.json" \ - >"${overlap_root}/config/repositories.next.json" -mv "${overlap_root}/config/repositories.next.json" \ - "${overlap_root}/config/repositories.json" -if "${overlap_root}/bin/validate" >/dev/null 2>&1; then - echo "expected active and retired maintenance overlap to fail" >&2 - exit 1 -fi - -echo "Retired-maintenance validation tests passed." diff --git a/tests/validate-retired-required-ci.sh b/tests/validate-retired-required-ci.sh deleted file mode 100755 index 8bfcc2e..0000000 --- a/tests/validate-retired-required-ci.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir -p "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${temporary}/" -"${temporary}/bin/validate" >/dev/null -printf '{"retirements":[{"repository":"web-platform","repository_id":123,"ruleset_id":3,"required_ci":["Platform validation","Conventional PR title"]}]}\n' >"${temporary}/valid.json" -cp "${temporary}/valid.json" "${temporary}/config/retired-required-ci.json" -"${temporary}/bin/validate" >/dev/null -for filter in \ - '.retirements[0].repository = "client"' '.retirements[0].repository = "legacy-client"' \ - '.retirements[0].repository = "unknown"' '.retirements[0].required_ci = []' \ - '.retirements[0].required_ci = [""]' '.retirements[0].required_ci = [" "]' \ - '.retirements[0].required_ci = ["Duplicate", "Duplicate"]' \ - '.retirements[0].required_ci = [null]' '.retirements[0].repository_id = 0' \ - '.retirements[0].ruleset_id = -1' '.retirements[0].ruleset_id = "3"' \ - '.retirements[0].repository_id = 1.5' '.retirements += [.retirements[0]]' \ - '.retirements[0].unknown_field = true' 'del(.retirements[0].ruleset_id)'; do - jq "${filter}" "${temporary}/valid.json" >"${temporary}/config/retired-required-ci.json" - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted invalid required-CI retirement: ${filter}" >&2 - exit 1 - fi -done -echo 'Required-CI retirement schema tests passed.' diff --git a/tests/validate-security-merge.sh b/tests/validate-security-merge.sh deleted file mode 100755 index c766c08..0000000 --- a/tests/validate-security-merge.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -root=${ATRINIK_PUBLISH_TEST_ROOT:-${root}} -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" -cp "${root}/bin/validate" "${temporary}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${temporary}/" - -reject() { - local file=$1 filter=$2 - jq "${filter}" "${root}/config/${file}" >"${temporary}/config/${file}" - if "${temporary}/bin/validate" >/dev/null 2>&1; then - echo "error: accepted invalid security policy ${file}: ${filter}" >&2 - exit 1 - fi - cp "${root}/config/${file}" "${temporary}/config/${file}" -} - -"${temporary}/bin/validate" >/dev/null -reject security-merge-protection.json '.dependency_review += ["legacy-client"]' -reject security-merge-protection.json '.code_scanning -= ["service-updater"]' -reject security-merge-protection.json '.dependency_review += ["web-platform"]' -reject security-merge-protection.json '.codeql_required_languages["content-toolkit"] = []' -reject security-merge-protection.json '.codeql_required_languages.classic = ["rust"]' -reject security-merge-protection.json '.codeql_required_languages.server = ["invented"]' -for filter in 'del(.activation)' '.activation = null' '.activation = []' \ - '.activation.unexpected = {}' 'del(.activation.code_scanning)' \ - '.activation.code_scanning = []' '.activation.code_scanning = null' \ - 'del(.activation.code_scanning.classic)' '.activation.code_scanning.classic = null' \ - '.activation.code_scanning.classic = "unknown"' '.activation.code_scanning.classic = true' \ - '.activation.dependency_review.classic = {}' '.activation.dependency_review.classic = "ready"' \ - '.activation.dependency_review.nawerhals = "enforced"'; do - reject security-merge-protection.json "${filter}" -done -reject rulesets/code-scanning.json '.bypass_actors[0].bypass_mode = "always"' -reject rulesets/code-scanning.json '.rules[0].parameters.code_scanning_tools[0].security_alerts_threshold = "critical"' -reject rulesets/code-scanning.json '.rules[0].parameters.code_scanning_tools[0].alerts_threshold = "errors"' -reject rulesets/dependency-review.json '.rules[0].parameters.required_status_checks[0].integration_id = null' -reject actions-permissions.json '.sha_pinning_required = false' -reject actions-sha-pinning.json '.phase = "pending" | .canary = "atrinik/github-settings/99"' -reject actions-sha-pinning.json '.phase = "enforced" | .canary = null' -reject actions-sha-pinning.json '.phase = "enforced" | .canary = "atrinik/unregistered/99"' -reject actions-sha-pinning.json '.phase = "enforced" | .canary = "foreign/github-settings/99"' -reject actions-sha-pinning.json '.phase = "enforced" | .canary = "atrinik/github-settings/0"' -reject actions-sha-pinning.json '.phase = "unknown"' -reject actions-sha-pinning.json '.phase = null' -reject actions-sha-pinning.json '.unexpected = true' - -# Reviewed enforced source binds its canary to a repository with required CI. -jq '.phase = "enforced" | .canary = "atrinik/github-settings/99"' \ - "${root}/config/actions-sha-pinning.json" >"${temporary}/config/actions-sha-pinning.json" -"${temporary}/bin/validate" >/dev/null -cp "${root}/config/actions-sha-pinning.json" "${temporary}/config/actions-sha-pinning.json" - -# Source review can promote CodeQL without making dependency advice a gate. -reject security-merge-protection.json '.dependency_review = ["atrinik"] | .activation.dependency_review.atrinik = "enforced"' -jq '.activation.code_scanning.classic = "enforced"' \ - "${root}/config/security-merge-protection.json" >"${temporary}/config/security-merge-protection.json" -"${temporary}/bin/validate" >/dev/null -cp "${root}/config/security-merge-protection.json" "${temporary}/config/security-merge-protection.json" - -# A coordinated target retirement is valid; unrelated governed policies stay. -jq 'del(.required_ci["service-updater"])' "${root}/config/repositories.json" \ - >"${temporary}/config/repositories.json" -jq '.code_scanning -= ["service-updater"] | .dependency_review -= ["service-updater"] | del(.activation.code_scanning["service-updater"], .activation.dependency_review["service-updater"])' \ - "${root}/config/security-merge-protection.json" >"${temporary}/config/security-merge-protection.json" -"${temporary}/bin/validate" >/dev/null - -echo 'Security merge policy validation tests passed.' diff --git a/tests/verify-crate-workflow.sh b/tests/verify-crate-workflow.sh deleted file mode 100755 index f185dfa..0000000 --- a/tests/verify-crate-workflow.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -python3 "${root}/tests/verify_crate_workflow.py" diff --git a/tests/verify-manual-settings.sh b/tests/verify-manual-settings.sh deleted file mode 100755 index 1411aa6..0000000 --- a/tests/verify-manual-settings.sh +++ /dev/null @@ -1,1259 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) -temporary=$(mktemp -d) -trap 'rm -rf "${temporary}"' EXIT -mkdir "${temporary}/bin" -fixture_root=${temporary}/pending-fixture -mkdir -p "${fixture_root}/bin" -cp "${root}/bin/validate" "${root}/bin/verify-manual-settings" "${fixture_root}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${root}/lib" "${fixture_root}/" -jq '.crates_io_trusted_publishing[] |= (.source_state="pending-reviewed-workflow" | .environment_state="pending")' \ - "${root}/config/manual-settings.json" >"${fixture_root}/config/manual-settings.json" - -cat >"${temporary}/bin/gh" <<'EOF' -#!/usr/bin/env bash - -set -euo pipefail - -[[ ${1:-} == api ]] || exit 1 -shift -endpoint= -while (($#)); do - case $1 in - -H) - shift 2 - ;; - -f | -F) - shift 2 - ;; - *) - if [[ -n ${endpoint} ]]; then - echo "unexpected gh api argument: $1" >&2 - exit 1 - fi - endpoint=$1 - shift - ;; - esac -done -printf '%s\n' "${endpoint}" >>"${FAKE_GH_LOG}" - -if [[ ${FAKE_GH_SCENARIO} == api-failure ]]; then - echo "gh: repository administration denied" >&2 - exit 41 -fi -case ${endpoint} in -graphql) - if [[ ${FAKE_GH_SCENARIO} == malformed-pins ]]; then - jq -n '{data: {organization: {login: "atrinik", pinnedItems: {nodes: []}}}}' - elif [[ ${FAKE_GH_SCENARIO} == pin-drift ]]; then - jq -n '{data: {organization: { - login: "atrinik", - pinnedItems: { - totalCount: 2, - nodes: [ - {name: "atrinik", databaseId: 15810595, nameWithOwner: "atrinik/atrinik", isArchived: false, visibility: "PUBLIC"}, - {name: "classic", databaseId: 1327289971, nameWithOwner: "atrinik/classic", isArchived: false, visibility: "PUBLIC"} - ] - } - }}}' - else - jq -n '{data: {organization: { - login: "atrinik", - pinnedItems: { - totalCount: 6, - nodes: [ - {name: "classic", databaseId: 1327289971, nameWithOwner: "atrinik/classic", isArchived: false, visibility: "PUBLIC"}, - {name: "atrinik", databaseId: 15810595, nameWithOwner: "atrinik/atrinik", isArchived: false, visibility: "PUBLIC"}, - {name: "website", databaseId: 1327107093, nameWithOwner: "atrinik/website", isArchived: false, visibility: "PUBLIC"}, - {name: "content", databaseId: 1325219730, nameWithOwner: "atrinik/content", isArchived: false, visibility: "PUBLIC"}, - {name: "protocol", databaseId: 1327106950, nameWithOwner: "atrinik/protocol", isArchived: false, visibility: "PUBLIC"}, - {name: "playtester", databaseId: 1329284051, nameWithOwner: "atrinik/playtester", isArchived: false, visibility: "PUBLIC"} - ] - } - }}}' - fi - ;; -repos/atrinik/protocol) - repository_id=1327106950 - if [[ ${FAKE_GH_SCENARIO} == crate-repository-drift ]]; then - repository_id=1 - fi - jq -n --argjson id "${repository_id}" \ - '{id: $id, full_name: "atrinik/protocol", archived: false, default_branch: "main"}' - ;; -repos/atrinik/content-toolkit | repos/atrinik/client) - name=${endpoint##*/} - case ${name} in - content-toolkit) id=1327107043 ;; - client) id=1327106844 ;; - esac - jq -n --arg name "${name}" --argjson id "${id}" \ - '{id:$id, full_name:("atrinik/"+$name), archived:false, default_branch:"main"}' - ;; -repos/atrinik/devcontainer) - jq -n '{id:1322185908,full_name:"atrinik/devcontainer",archived:false,default_branch:"main"}' - ;; -orgs/atrinik/packages/container/linux-build) - id=14205615 - visibility=private - source_id=1322185908 - [[ ${FAKE_GH_SCENARIO} != crate-image-identity-drift ]] || id=1 - [[ ${FAKE_GH_SCENARIO} != crate-image-visibility-drift ]] || visibility=public - [[ ${FAKE_GH_SCENARIO} != crate-image-source-drift ]] || source_id=1 - jq -n --argjson id "${id}" --arg visibility "${visibility}" --argjson source_id "${source_id}" \ - '{id:$id,name:"linux-build",package_type:"container",visibility:$visibility, - repository:{id:$source_id,full_name:"atrinik/devcontainer"}}' - ;; -repos/atrinik/*/branches/main) - protected=true - [[ ${FAKE_GH_SCENARIO} != crate-unprotected ]] || protected=false - jq -n --argjson protected "${protected}" \ - '{name:"main",protected:$protected,commit:{sha:"1111111111111111111111111111111111111111"}}' - ;; -repos/atrinik/*/git/ref/heads/main) - sha=1111111111111111111111111111111111111111 - [[ ${FAKE_GH_SCENARIO} != crate-ref-drift ]] || sha=2222222222222222222222222222222222222222 - jq -n --arg sha "${sha}" '{ref:"refs/heads/main",object:{type:"commit",sha:$sha}}' - ;; -repos/atrinik/protocol/contents/.github/workflows/publish-crate.yml\?ref=*) - source=$(cat "${FAKE_CRATE_FIXTURES}/crate-publication.yml") - case ${FAKE_GH_SCENARIO} in - crate-workflow-drift) source=${source//rust-lang\/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18/rust-lang\/crates-io-auth-action@v1} ;; - crate-workflow-future-pin) source=${source//c6f97d42243bad5fab37ca0427f495c86d5b1a18/2222222222222222222222222222222222222222} ;; - crate-workflow-plaintext) source='crates-io-release refs/heads/main automatic rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18' ;; - crate-workflow-comments) source="# crates-io-release refs/heads/main automatic rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18" ;; - crate-workflow-disabled) source=${source//inputs.operation == \'automatic\'/false} ;; - crate-workflow-no-oidc) source=${source//id-token: write/id-token: none} ;; - crate-workflow-shell) source=$(sed '/- run: python3 tools\/crate_release.py verify/a\ shell: echo {0}' <<<"${source}") ;; - crate-workflow-ignored-step-failure) source=$(sed '/- run: python3 tools\/crate_release.py verify/a\ continue-on-error: true' <<<"${source}") ;; - crate-workflow-ignored-job-failure) source=$(sed '/ runs-on: ubuntu-24.04/a\ continue-on-error: true' <<<"${source}") ;; - crate-workflow-default-shell) source=$(printf 'defaults:\n run:\n shell: echo {0}\n%s\n' "${source}") ;; - crate-workflow-job-default-shell) source=$(sed '/ runs-on: ubuntu-24.04/a\ defaults:\n run:\n shell: echo {0}' <<<"${source}") ;; - crate-workflow-comment-run) source=${source//run: python3/run: \"# python3}; source=${source//\"\$DIGEST\"/\"\$DIGEST\"\"} ;; - esac - jq -n --arg content "$(printf '%s' "${source}" | base64)" \ - '{type:"file",encoding:"base64",content:$content}' - ;; -repos/atrinik/protocol/contents/.github/workflows/release.yml\?ref=*) - source=$(cat "${FAKE_CRATE_FIXTURES}/crate-source-release.yml") - case ${FAKE_GH_SCENARIO} in - crate-source-workflow-comments) source="# id-token: write actions/attest-build-provenance@1111111111111111111111111111111111111111" ;; - crate-source-workflow-oidc-build) source=$(sed '/ package:/a\ permissions: {contents: read, id-token: write}' <<<"${source}") ;; - crate-source-workflow-build-signer) source=${source//python3 tools\/crate_release.py finalize/npm install} ;; - crate-source-workflow-bypass-signer) source=$(sed '/ - attest/d' <<<"${source}") ;; - esac - jq -n --arg content "$(printf '%s' "${source}" | base64)" \ - '{type:"file",encoding:"base64",content:$content}' - ;; -repos/atrinik/protocol/environments/crates-io-release) - rules='[{"type":"branch_policy"}]' - bypass=false - [[ ${FAKE_GH_SCENARIO} != crate-env-wait ]] || rules='[{"type":"branch_policy"},{"type":"wait_timer","wait_timer":1}]' - [[ ${FAKE_GH_SCENARIO} != crate-env-reviewer ]] || rules='[{"type":"branch_policy"},{"type":"required_reviewers","reviewers":[{"type":"User","reviewer":{"id":3865595}}]}]' - [[ ${FAKE_GH_SCENARIO} != crate-env-bypass ]] || bypass=true - jq -n --argjson rules "${rules}" --argjson bypass "${bypass}" \ - '{name:"crates-io-release",can_admins_bypass:$bypass,protection_rules:$rules, - deployment_branch_policy:{protected_branches:false,custom_branch_policies:true}}' - ;; -"repos/atrinik/protocol/environments/crates-io-release/deployment-branch-policies?per_page=100&page=1") - name=main - [[ ${FAKE_GH_SCENARIO} != crate-env-branch ]] || name='*' - jq -n --arg name "${name}" '{total_count:1,branch_policies:[{name:$name,type:"branch"}]}' - ;; -"repos/atrinik/protocol/environments/crates-io-release/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == crate-env-secret ]]; then - jq -n '{total_count:1,secrets:[{name:"CARGO_REGISTRY_TOKEN"}]}' - else - jq -n '{total_count:0,secrets:[]}' - fi - ;; -"repos/atrinik/protocol/environments/crates-io-release/variables?per_page=100&page=1") - jq -n '{total_count:0,variables:[]}' - ;; -"repos/atrinik/client/actions/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == updater-missing-secret ]]; then - jq -n '{total_count:0,secrets:[]}' - else - jq -n '{total_count:1,secrets:[{name:"CRATE_DEPENDENCY_UPDATE_APP_PRIVATE_KEY",updated_at:"2026-08-31T00:00:00Z"}]}' - fi - ;; -"repos/atrinik/client/actions/variables?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == updater-missing-variable ]]; then - jq -n '{total_count:0,variables:[]}' - else - jq -n '{total_count:1,variables:[{name:"CRATE_DEPENDENCY_UPDATE_APP_ID",created_at:"2026-08-31T00:00:00Z",updated_at:"2026-08-31T00:00:00Z"}]}' - fi - ;; -repos/atrinik/github-settings) - if [[ ${FAKE_GH_SCENARIO} == identity-drift ]]; then - jq -n '{ - id: 1, - full_name: "atrinik/github-settings", - archived: false, - default_branch: "main" - }' - else - jq -n '{ - id: 1324382941, - full_name: "atrinik/github-settings", - archived: false, - default_branch: "main" - }' - fi - ;; -repos/atrinik/deploy-control) - repository_id=1352850539 - repository_visibility=public - repository_license=MIT - if [[ ${FAKE_GH_SCENARIO} == planned-control-identity-drift ]]; then - repository_id=1 - fi - if [[ ${FAKE_GH_SCENARIO} == planned-control-license-drift ]]; then - repository_license=GPL-2.0 - fi - jq -n \ - --argjson repository_id "${repository_id}" \ - --arg repository_visibility "${repository_visibility}" \ - --arg repository_license "${repository_license}" '{ - id: $repository_id, - full_name: "atrinik/deploy-control", - archived: false, - default_branch: "main", - visibility: $repository_visibility, - license: {spdx_id: $repository_license} - }' - ;; -repos/atrinik/website) - repository_id=1327107093 - if [[ ${FAKE_GH_SCENARIO} == external-website-identity-drift ]]; then - repository_id=1 - fi - jq -n --argjson repository_id "${repository_id}" '{ - id: $repository_id, - full_name: "atrinik/website", - archived: false, - default_branch: "main" - }' - ;; -repos/atrinik/metaserver-worker) - repository_id=1324297032 - if [[ ${FAKE_GH_SCENARIO} == external-metaserver-identity-drift ]]; then - repository_id=1 - fi - jq -n --argjson repository_id "${repository_id}" '{ - id: $repository_id, - full_name: "atrinik/metaserver-worker", - archived: false, - default_branch: "main" - }' - ;; -repos/atrinik/classic) - if [[ ${FAKE_GH_SCENARIO} == environment-identity-drift ]]; then - jq -n '{ - id: 1, - full_name: "atrinik/classic", - archived: false, - default_branch: "main" - }' - elif [[ ${FAKE_GH_SCENARIO} == environment-repository-name-drift ]]; then - jq -n '{ - id: 1327289971, - full_name: "atrinik/renamed-classic", - archived: false, - default_branch: "main" - }' - elif [[ ${FAKE_GH_SCENARIO} == environment-archived ]]; then - jq -n '{ - id: 1327289971, - full_name: "atrinik/classic", - archived: true, - default_branch: "main" - }' - elif [[ ${FAKE_GH_SCENARIO} == environment-default-branch-drift ]]; then - jq -n '{ - id: 1327289971, - full_name: "atrinik/classic", - archived: false, - default_branch: "trunk" - }' - else - jq -n '{ - id: 1327289971, - full_name: "atrinik/classic", - archived: false, - default_branch: "main" - }' - fi - ;; -repos/atrinik/classic/pages) - build_type=legacy - html_url=https://atrinik.github.io/classic/ - source='{"branch":"main","path":"/"}' - if [[ ${FAKE_GH_SCENARIO} == pages-active ]]; then - build_type=workflow - source=null - elif [[ ${FAKE_GH_SCENARIO} == pages-source-drift ]]; then - source='{"branch":"development","path":"/"}' - elif [[ ${FAKE_GH_SCENARIO} == pages-identity-drift ]]; then - html_url=https://example.test/classic/ - fi - jq -n \ - --arg build_type "${build_type}" \ - --arg html_url "${html_url}" \ - --argjson source "${source}" \ - '{html_url: $html_url, build_type: $build_type, source: $source, - public: true, https_enforced: true, cname: null}' - ;; -"repos/atrinik/classic/contents/.github/workflows/daily-client-performance.yml?ref=main") - workflow='name: Daily Classic client performance' - if [[ ${FAKE_GH_SCENARIO} == pages-active || - ${FAKE_GH_SCENARIO} == pages-activation-missing ]]; then - workflow='uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e' - fi - if [[ ${FAKE_GH_SCENARIO} == pages-workflow-metadata-drift ]]; then - jq -n '{type: "dir", encoding: "none", content: null}' - else - content=$(printf '%s\n' "${workflow}" | base64 -w0) - jq -n --arg content "${content}" \ - '{type: "file", encoding: "base64", content: $content}' - fi - ;; -"orgs/atrinik/installations?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == app-api-failure ]]; then - echo "gh: organization installation administration denied" >&2 - exit 45 - elif [[ ${FAKE_GH_SCENARIO} == malformed-app-installations ]]; then - jq -n '{total_count: 1, installation: []}' - elif [[ ${FAKE_GH_SCENARIO} == app-installations-page2 || \ - ${FAKE_GH_SCENARIO} == app-installations-page2-failure ]]; then - jq -n '{ - total_count: 103, - installations: [range(0; 100) | { - id: (1000 + .), - app_id: (2000 + .), - app_slug: ("unrelated-" + tostring), - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: "selected", - permissions: {metadata: "read"}, - events: [], - suspended_at: null - }] - }' - elif [[ ${FAKE_GH_SCENARIO} == missing-app ]]; then - jq -n '{ - total_count: 1, - installations: [{ - id: 152311798, - app_id: 85455, - app_slug: "cloudflare-workers-and-pages", - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: "selected", - permissions: { - administration: "write", - checks: "write", - contents: "write", - deployments: "write", - metadata: "read", - pull_requests: "write" - }, - events: ["pull_request", "push"], - suspended_at: null - }] - }' - elif [[ ${FAKE_GH_SCENARIO} == missing-external-app ]]; then - jq -n '{total_count: 0, installations: []}' - else - app_id=4564008 - installation_id=153045686 - app_slug=atrinik-classic-dependency-updater - repository_selection=selected - account_login=atrinik - events='[]' - permissions='{"contents":"write","metadata":"read","pull_requests":"write"}' - suspended_at=null - case ${FAKE_GH_SCENARIO} in - app-id-drift) app_id=1 ;; - app-installation-id-drift) installation_id=1 ;; - app-slug-drift) app_slug=other-app ;; - app-selection-drift) repository_selection=all ;; - app-account-drift) account_login=other ;; - app-events-drift) events='["push"]' ;; - app-permission-drift) permissions='{"actions":"write","contents":"write","metadata":"read","pull_requests":"write"}' ;; - app-suspended) suspended_at='"2026-08-11T00:00:00Z"' ;; - esac - external_app_id=85455 - external_installation_id=152311798 - external_app_slug=cloudflare-workers-and-pages - external_repository_selection=selected - external_events='["pull_request","push"]' - external_permissions='{"administration":"write","checks":"write","contents":"write","deployments":"write","metadata":"read","pull_requests":"write"}' - external_suspended_at=null - case ${FAKE_GH_SCENARIO} in - external-app-id-drift) external_app_id=1 ;; - external-app-installation-id-drift) external_installation_id=1 ;; - external-app-slug-drift) external_app_slug=other-app ;; - external-app-selection-drift) external_repository_selection=all ;; - external-app-events-drift) external_events='["push"]' ;; - external-app-permission-drift) external_permissions='{"checks":"write","contents":"write","deployments":"write","metadata":"read","pull_requests":"write"}' ;; - external-app-suspended) external_suspended_at='"2026-08-15T00:00:00Z"' ;; - esac - updater_installed=true - [[ ${FAKE_GH_SCENARIO} != updater-missing ]] || updater_installed=false - updater_permissions='{"contents":"write","metadata":"read","pull_requests":"write"}' - [[ ${FAKE_GH_SCENARIO} != updater-permissions ]] || updater_permissions='{"contents":"write","metadata":"read","pull_requests":"write","administration":"write"}' - updater_selection=selected - [[ ${FAKE_GH_SCENARIO} != updater-selection ]] || updater_selection=all - planned_control=false - [[ ${FAKE_GH_SCENARIO} == planned-control-installed ]] && planned_control=true - jq -n \ - --argjson app_id "${app_id}" \ - --argjson installation_id "${installation_id}" \ - --arg app_slug "${app_slug}" \ - --arg repository_selection "${repository_selection}" \ - --arg account_login "${account_login}" \ - --argjson events "${events}" \ - --argjson permissions "${permissions}" \ - --argjson suspended_at "${suspended_at}" \ - --argjson external_app_id "${external_app_id}" \ - --argjson external_installation_id "${external_installation_id}" \ - --arg external_app_slug "${external_app_slug}" \ - --arg external_repository_selection "${external_repository_selection}" \ - --argjson external_events "${external_events}" \ - --argjson external_permissions "${external_permissions}" \ - --argjson external_suspended_at "${external_suspended_at}" \ - --argjson updater_installed "${updater_installed}" \ - --argjson updater_permissions "${updater_permissions}" \ - --arg updater_selection "${updater_selection}" \ - --argjson planned_control "${planned_control}" '( - [{ - id: $installation_id, - app_id: $app_id, - app_slug: $app_slug, - target_type: "Organization", - account: {login: $account_login, type: "Organization"}, - repository_selection: $repository_selection, - permissions: $permissions, - events: $events, - suspended_at: $suspended_at - }, { - id: $external_installation_id, - app_id: $external_app_id, - app_slug: $external_app_slug, - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: $external_repository_selection, - permissions: $external_permissions, - events: $external_events, - suspended_at: $external_suspended_at - }] + (if $planned_control then [{ - id: 154000001, - app_id: 85500001, - app_slug: "atrinik-deploy-control", - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: "selected", - permissions: {actions: "read", metadata: "read"}, - events: ["workflow_run"], - suspended_at: null - }] else [] end) - + (if $updater_installed then [{ - id:170332148, app_id:5276152, app_slug:"atrinik-crate-dependency-update", - target_type:"Organization",account:{login:"atrinik",type:"Organization"}, - repository_selection:$updater_selection,permissions:$updater_permissions, - events:[],suspended_at:null - }] else [] end) - ) as $installations | - {total_count: ($installations | length), installations: $installations}' - fi - ;; -"orgs/atrinik/installations?per_page=100&page=2") - if [[ ${FAKE_GH_SCENARIO} == app-installations-page2-failure ]]; then - echo "gh: second installation page failed" >&2 - exit 47 - fi - [[ ${FAKE_GH_SCENARIO} == app-installations-page2 ]] - jq -n '{ - total_count: 103, - installations: [{ - id: 153045686, - app_id: 4564008, - app_slug: "atrinik-classic-dependency-updater", - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: "selected", - permissions: { - contents: "write", - metadata: "read", - pull_requests: "write" - }, - events: [], - suspended_at: null - }, { - id: 152311798, - app_id: 85455, - app_slug: "cloudflare-workers-and-pages", - target_type: "Organization", - account: {login: "atrinik", type: "Organization"}, - repository_selection: "selected", - permissions: { - administration: "write", - checks: "write", - contents: "write", - deployments: "write", - metadata: "read", - pull_requests: "write" - }, - events: ["pull_request", "push"], - suspended_at: null - }, { - id:170332148, app_id:5276152, app_slug:"atrinik-crate-dependency-update", - target_type:"Organization",account:{login:"atrinik",type:"Organization"}, - repository_selection:"selected", - permissions:{contents:"write",metadata:"read",pull_requests:"write"}, - events:[],suspended_at:null - }] - }' - ;; -"repos/atrinik/classic/actions/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == missing-app-secret ]]; then - jq -n '{total_count: 0, secrets: []}' - else - jq -n '{ - total_count: 1, - secrets: [{ - name: "DEPENDENCY_UPDATE_APP_PRIVATE_KEY", - created_at: "2026-08-11T23:47:15Z", - updated_at: "2026-08-11T23:47:15Z" - }] - }' - fi - ;; -"repos/atrinik/classic/actions/variables?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == app-variable-api-failure ]]; then - echo "gh: Actions variable administration denied" >&2 - exit 46 - elif [[ ${FAKE_GH_SCENARIO} == malformed-app-variables ]]; then - jq -n '{total_count: 1, variable: []}' - elif [[ ${FAKE_GH_SCENARIO} == missing-app-variable ]]; then - jq -n '{total_count: 0, variables: []}' - else - jq -n '{ - total_count: 1, - variables: [{ - name: "DEPENDENCY_UPDATE_APP_ID", - value: "not-inspected-by-the-verifier", - created_at: "2026-08-11T23:47:00Z", - updated_at: "2026-08-11T23:47:00Z" - }] - }' - fi - ;; -"repos/atrinik/github-settings/actions/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == missing ]]; then - jq -n '{total_count: 0, secrets: []}' - elif [[ ${FAKE_GH_SCENARIO} == page2 || \ - ${FAKE_GH_SCENARIO} == page2-failure ]]; then - jq -n '{ - total_count: 101, - secrets: [range(0; 100) | { - name: ("UNRELATED_" + tostring), - created_at: "2026-08-01T00:00:00Z", - updated_at: "2026-08-01T00:00:00Z" - }] - }' - elif [[ ${FAKE_GH_SCENARIO} == shared-repository ]]; then - jq -n '{ - total_count: 2, - secrets: [ - { - name: "ATRINIK_SETTINGS_TOKEN", - created_at: "2026-08-10T02:13:48Z", - updated_at: "2026-08-10T02:13:48Z" - }, - { - name: "SECOND_SETTINGS_TOKEN", - created_at: "2026-08-10T02:13:48Z", - updated_at: "2026-08-10T02:13:48Z" - } - ] - }' - else - jq -n '{ - total_count: 1, - secrets: [{ - name: "ATRINIK_SETTINGS_TOKEN", - created_at: "2026-08-10T02:13:48Z", - updated_at: "2026-08-10T02:13:48Z" - }] - }' - fi - ;; -"repos/atrinik/github-settings/actions/secrets?per_page=100&page=2") - if [[ ${FAKE_GH_SCENARIO} == page2-failure ]]; then - echo "gh: second secret page failed" >&2 - exit 42 - fi - [[ ${FAKE_GH_SCENARIO} == page2 ]] - jq -n '{ - total_count: 101, - secrets: [{ - name: "ATRINIK_SETTINGS_TOKEN", - created_at: "2026-08-10T02:13:48Z", - updated_at: "2026-08-10T02:13:48Z" - }] - }' - ;; -repos/atrinik/metaserver-worker/environments/production) - jq -n '{name: "production", deployment_branch_policy: { - protected_branches: true, custom_branch_policies: false - }, protection_rules: [{type: "branch_policy"}]}' - ;; -"repos/atrinik/metaserver-worker/environments/production/deployment-branch-policies?per_page=100&page=1") - echo "error: protected production environment must not request custom policies" >&2 - exit 79 - ;; -"repos/atrinik/metaserver-worker/environments/production/secrets?per_page=100&page=1") - jq -n '{total_count: 8, secrets: [ - {name: "ATRINIK_DELIVERY_RESOURCE_POLICY"}, {name: "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN"}, - {name: "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN"}, {name: "ATRINIK_PRODUCTION_CORE_CONFIG"}, - {name: "ATRINIK_PRODUCTION_PUBLISHER_CONFIG"}, {name: "ATRINIK_PRODUCTION_RENDEZVOUS_CONFIG"}, - {name: "CLOUDFLARE_ACCOUNT_ID"}, {name: "CLOUDFLARE_API_TOKEN"} - ]}' - ;; -"repos/atrinik/metaserver-worker/environments/production/variables?per_page=100&page=1") - jq -n '{total_count: 2, variables: [ - {name: "ATRINIK_PRODUCTION_RECOVERY_PUBLIC_KEY"}, - {name: "ATRINIK_PRODUCTION_WRITER_FENCE_POLICY"} - ]}' - ;; -repos/atrinik/metaserver-worker/environments/development) - jq -n '{ - name: "development", - deployment_branch_policy: {protected_branches: true, custom_branch_policies: false}, - protection_rules: [{type: "branch_policy"}] - }' - ;; -"repos/atrinik/metaserver-worker/environments/development/deployment-branch-policies?per_page=100&page=1") - echo "error: protected-branch environment must not request custom policies" >&2 - exit 79 - ;; -"repos/atrinik/metaserver-worker/environments/development/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == development-credential-api-failure ]]; then - echo "gh: development credential metadata denied" >&2 - exit 81 - fi - if [[ ${FAKE_GH_SCENARIO} == missing-development-credential ]]; then - jq -n '{total_count: 0, secrets: []}' - exit 0 - fi - jq -n '{total_count: 8, secrets: [ - {name: "ATRINIK_DELIVERY_RESOURCE_POLICY"}, - {name: "ATRINIK_DELIVERY_RESOURCE_READ_TOKEN"}, - {name: "ATRINIK_DEVELOPMENT_CORE_CONFIG"}, - {name: "ATRINIK_DEVELOPMENT_PUBLISHER_CONFIG"}, - {name: "ATRINIK_DEVELOPMENT_RENDEZVOUS_CONFIG"}, - {name: "ATRINIK_PRODUCTION_BUILDS_READ_TOKEN"}, - {name: "CLOUDFLARE_ACCOUNT_ID"}, - {name: "CLOUDFLARE_API_TOKEN"} - ] | map(. + {updated_at: "2026-10-11T00:00:00Z"})}' - ;; -"repos/atrinik/metaserver-worker/environments/development/variables?per_page=100&page=1") - jq -n '{total_count: 1, variables: [{name: "ATRINIK_PRODUCTION_WRITER_FENCE_POLICY"}]}' - ;; -repos/atrinik/classic/environments/discord-release) - if [[ ${FAKE_GH_SCENARIO} == missing-environment ]]; then - echo "gh: environment not found" >&2 - exit 43 - elif [[ ${FAKE_GH_SCENARIO} == environment-name-drift ]]; then - jq -n '{ - name: "other-environment", - deployment_branch_policy: { - protected_branches: false, - custom_branch_policies: true - }, - protection_rules: [{type: "branch_policy"}] - }' - elif [[ ${FAKE_GH_SCENARIO} == branch-mode-drift ]]; then - jq -n '{ - name: "discord-release", - deployment_branch_policy: { - protected_branches: true, - custom_branch_policies: false - }, - protection_rules: [{type: "branch_policy"}] - }' - elif [[ ${FAKE_GH_SCENARIO} == extra-reviewer ]]; then - jq -n '{ - name: "discord-release", - deployment_branch_policy: { - protected_branches: false, - custom_branch_policies: true - }, - protection_rules: [{ - type: "required_reviewers", - reviewers: [{type: "User", reviewer: {id: 1, login: "reviewer"}}] - }, {type: "branch_policy"}] - }' - elif [[ ${FAKE_GH_SCENARIO} == wait-timer || - ${FAKE_GH_SCENARIO} == custom-protection-rule ]]; then - rule_type=wait_timer - if [[ ${FAKE_GH_SCENARIO} == custom-protection-rule ]]; then - rule_type=custom_deployment_protection_rule - fi - jq -n --arg rule_type "${rule_type}" '{ - name: "discord-release", - deployment_branch_policy: { - protected_branches: false, - custom_branch_policies: true - }, - protection_rules: [{type: "branch_policy"}, {type: $rule_type}] - }' - else - jq -n '{ - name: "discord-release", - deployment_branch_policy: { - protected_branches: false, - custom_branch_policies: true - }, - protection_rules: [{type: "branch_policy"}] - }' - fi - ;; -repos/atrinik/classic/environments/github-pages) - jq -n '{ - name: "github-pages", - deployment_branch_policy: { - protected_branches: false, - custom_branch_policies: true - }, - protection_rules: [{type: "branch_policy"}] - }' - ;; -"repos/atrinik/classic/environments/discord-release/deployment-branch-policies?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == branch-policy-drift ]]; then - jq -n '{ - total_count: 1, - branch_policies: [{id: 1, name: "release", type: "branch"}] - }' - elif [[ ${FAKE_GH_SCENARIO} == environment-page2 || - ${FAKE_GH_SCENARIO} == environment-page2-failure ]]; then - jq -n '{ - total_count: 101, - branch_policies: [range(0; 100) | { - id: ., name: ("branch-" + tostring), type: "branch" - }] - }' - elif [[ ${FAKE_GH_SCENARIO} == malformed-branch-policy-response ]]; then - jq -n '{total_count: 1, branch_policy: []}' - else - jq -n '{ - total_count: 2, - branch_policies: [ - {id: 1, name: "main", type: "branch"}, - {id: 2, name: "v*", type: "tag"} - ] - }' - fi - ;; -"repos/atrinik/classic/environments/discord-release/deployment-branch-policies?per_page=100&page=2") - if [[ ${FAKE_GH_SCENARIO} == environment-page2-failure ]]; then - echo "gh: second environment branch-policy page failed" >&2 - exit 44 - fi - [[ ${FAKE_GH_SCENARIO} == environment-page2 ]] - jq -n '{ - total_count: 101, - branch_policies: [{id: 101, name: "main", type: "branch"}] - }' - ;; -"repos/atrinik/classic/environments/discord-release/secrets?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == missing-environment-secret ]]; then - jq -n '{total_count: 0, secrets: []}' - else - jq -n '{ - total_count: 1, - secrets: [{ - name: "DISCORD_APPLICATION_ID", - created_at: "2026-08-10T00:00:00Z", - updated_at: "2026-08-10T00:00:00Z" - }] - }' - fi - ;; -"repos/atrinik/classic/environments/discord-release/variables?per_page=100&page=1") - if [[ ${FAKE_GH_SCENARIO} == extra-environment-variable ]]; then - jq -n '{ - total_count: 1, - variables: [{name: "UNEXPECTED", created_at: "2026-08-10T00:00:00Z"}] - }' - else - jq -n '{total_count: 0, variables: []}' - fi - ;; -"repos/atrinik/classic/environments/github-pages/deployment-branch-policies?per_page=100&page=1") - jq -n '{ - total_count: 1, - branch_policies: [{id: 3, name: "main", type: "branch"}] - }' - ;; -"repos/atrinik/classic/environments/github-pages/secrets?per_page=100&page=1") - jq -n '{total_count: 0, secrets: []}' - ;; -"repos/atrinik/classic/environments/github-pages/variables?per_page=100&page=1") - jq -n '{total_count: 0, variables: []}' - ;; -*) exit 1 ;; -esac -EOF -chmod +x "${temporary}/bin/gh" - -run_verify() { - local scenario=$1 - local verification_root=${2:-${fixture_root}} - - PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" \ - FAKE_GH_SCENARIO="${scenario}" \ - FAKE_CRATE_FIXTURES="${root}/tests/fixtures" \ - GITHUB_ACTIONS=true GH_TOKEN=test-token \ - ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${verification_root}/bin/verify-manual-settings" -} - -: >"${temporary}/gh.log" -output=$(run_verify present) -grep -Fq 'KEEP atrinik/metaserver-worker environment development metadata' <<<"${output}" -grep -Fq 'KEEP atrinik/metaserver-worker environment production metadata' <<<"${output}" -if grep -Fq 'metaserver-worker/environments/development/deployment-branch-policies' "${temporary}/gh.log"; then - echo "error: protected-branch mode queried custom branch policies" >&2 - exit 1 -fi -grep -Fq 'OWNER-OBSERVED atrinik/client read-only Actions access to private atrinik/linux-build' <<<"${output}" -grep -Fq 'PENDING atrinik/protocol crates.io atrinik-protocol via publish-crate.yml / crates-io-release' <<<"${output}" -if grep -Eq 'protocol/environments|crates.io|/trusted-publishers' "${temporary}/gh.log"; then - echo "error: planned crate contract inspected or mutated unprovisioned state" >&2 - exit 1 -fi -for scenario in crate-repository-drift crate-unprotected crate-ref-drift \ - crate-image-identity-drift crate-image-visibility-drift crate-image-source-drift; do - if run_verify "${scenario}" >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: verifier accepted ${scenario}" >&2 - exit 1 - fi -done -observed_root=${temporary}/observed-crate -mkdir -p "${observed_root}/bin" -cp "${root}/bin/validate" "${fixture_root}/bin/verify-manual-settings" "${observed_root}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${root}/lib" "${observed_root}/" -jq '.crates_io_trusted_publishing[0] |= ( - .source_state = "observed-reviewed-workflow" | .environment_state = "observed" | - .publisher_registration = {state:"owner-observed-registration",observed_on:"2026-08-31", - evidence_location:"atrinik/github-settings#owner-setup"})' "${fixture_root}/config/manual-settings.json" \ - >"${observed_root}/config/manual-settings.json" -observed_output=$(run_verify present "${observed_root}") -future_output=$(run_verify crate-workflow-future-pin "${observed_root}") -grep -Fq "immutable actions rust-lang/crates-io-auth-action@2222222222222222222222222222222222222222" <<<"${future_output}" -grep -Fq 'KEEP atrinik/protocol environment crates-io-release metadata' <<<"${observed_output}" -grep -Fq 'GitHub metadata does not verify external registration' <<<"${observed_output}" -for scenario in crate-workflow-drift crate-env-wait crate-env-reviewer crate-env-bypass \ - crate-env-branch crate-env-secret crate-workflow-comments crate-workflow-plaintext \ - crate-workflow-disabled crate-workflow-no-oidc crate-workflow-shell \ - crate-workflow-ignored-step-failure crate-workflow-ignored-job-failure \ - crate-workflow-default-shell crate-workflow-job-default-shell \ - crate-source-workflow-comments crate-source-workflow-oidc-build \ - crate-source-workflow-build-signer crate-source-workflow-bypass-signer; do - if run_verify "${scenario}" "${observed_root}" >"${temporary}/${scenario}.out" \ - 2>"${temporary}/${scenario}.err"; then - echo "error: verifier accepted ${scenario}" >&2 - exit 1 - fi -done - -planned_updater_root=${temporary}/planned-updater -mkdir -p "${planned_updater_root}/bin" -cp "${root}/bin/validate" "${fixture_root}/bin/verify-manual-settings" "${planned_updater_root}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${planned_updater_root}/" -jq '.crate_dependency_update_app |= (.status="planned" | .app_id=null | .installation_id=null | - .key_created_on=null | .last_verified_on=null | .rotate_by=null | - .repository_scope_verification="pending-owner-ui" | .observed_on=null | .evidence_location=null | - .accepted_key_exposures=[] | .repository_scope_reverification=null | - .credential_state="pending-name-metadata" | - .workflow_activation={state:"pending-reviewed-workflows", observed_on:null, evidence_location:null})' "${fixture_root}/config/manual-settings.json" \ - >"${planned_updater_root}/config/manual-settings.json" -ATRINIK_VALIDATION_TODAY=2026-10-18 "${planned_updater_root}/bin/validate" >/dev/null -if run_verify updater-present "${planned_updater_root}" >"${temporary}/updater-planned.out" 2>"${temporary}/updater-planned.err"; then - echo "error: pending App accepted an unrecorded live installation" >&2 - exit 1 -fi -grep -Fq 'planned crate dependency App has a live installation' "${temporary}/updater-planned.err" -updater_root=${temporary}/observed-updater -mkdir -p "${updater_root}/bin" -cp "${root}/bin/validate" "${fixture_root}/bin/verify-manual-settings" "${updater_root}/bin/" -cp -R "${root}/config" "${root}/community-health" "${root}/.github" "${updater_root}/" -jq '.crate_dependency_update_app |= (.status="owner-observed" | .app_id=5276152 | - .installation_id=170332148 | .repository_scope_verification="organization_owner_ui" | - .observed_on="2026-10-18" | .evidence_location="atrinik/github-settings#owner-app" | - .repository_scope_reverification=null | - .workflow_activation={state:"pending-reviewed-workflows", observed_on:null, evidence_location:null})' \ - "${fixture_root}/config/manual-settings.json" >"${updater_root}/config/manual-settings.json" -updater_output=$(run_verify updater-present "${updater_root}") -grep -Fq 'KEEP atrinik/client crate dependency App credential name metadata' <<<"${updater_output}" -grep -Fq 'MANUAL atrinik-crate-dependency-update selected repositories require current owner UI or App-authenticated API proof: atrinik/client only' <<<"${updater_output}" -if grep -Fq 'await re-verification' <<<"${updater_output}"; then - echo "error: verifier reported pending re-verification after a fresh selected-set readback" >&2 - exit 1 -fi -for scenario in updater-missing updater-permissions updater-selection updater-missing-secret updater-missing-variable; do - if run_verify "${scenario}" "${updater_root}" >"${temporary}/updater-${scenario}.out" \ - 2>"${temporary}/updater-${scenario}.err"; then - echo "error: verifier accepted observed updater ${scenario}" >&2 - exit 1 - fi -done - -grep -Fq 'KEEP atrinik/github-settings repository Actions secret ATRINIK_SETTINGS_TOKEN' \ - <<<"${output}" -grep -Fq 'KEEP atrinik/classic environment discord-release metadata' <<<"${output}" -grep -Fq 'PENDING atrinik/classic Pages remains on the exact legacy main-root source' \ - <<<"${output}" -grep -Fq 'KEEP atrinik/classic environment github-pages metadata' <<<"${output}" -grep -Fq 'KEEP cloudflare-workers-and-pages installation metadata and exact permissions/events' \ - <<<"${output}" -grep -Fq 'MANUAL cloudflare-workers-and-pages selected repositories require owner UI proof: atrinik/website and atrinik/metaserver-worker only' \ - <<<"${output}" -grep -Fq 'PENDING atrinik-deploy-control GitHub App installation and credentials; owner UI proof is required for atrinik/deploy-control and selected repository atrinik/classic only' \ - <<<"${output}" -grep -Fq 'KEEP atrinik-classic-dependency-updater installation metadata and exact permissions' \ - <<<"${output}" -grep -Fq 'KEEP atrinik/classic repository Actions secret DEPENDENCY_UPDATE_APP_PRIVATE_KEY' \ - <<<"${output}" -grep -Fq 'KEEP atrinik/classic repository Actions variable DEPENDENCY_UPDATE_APP_ID' \ - <<<"${output}" -# The recorded transfer leaves the crate App's client-only set pending. -grep -Fq 'PENDING atrinik-crate-dependency-update selected repositories await re-verification: a 2026-10-17 repository transfer removed atrinik/editor after the 2026-10-11 readback; fresh owner UI or App-authenticated API proof is required: atrinik/client only' \ - <<<"${output}" -if grep -Fq 'MANUAL atrinik-crate-dependency-update selected repositories' <<<"${output}"; then - echo "error: verifier treated a stale selected-set readback as current" >&2 - exit 1 -fi -grep -Fq 'PENDING atrinik-crate-dependency-update owning workflow activation evidence: pending-reviewed-workflows' \ - <<<"${output}" -grep -Fq 'KEEP atrinik organization pins match the exact governed order' <<<"${output}" -grep -Fq 'Manual settings live credential, GitHub App, external provider App, Pages, environment, and organization pin metadata is present; planned integrations are recorded without live provisioning.' \ - <<<"${output}" - -for scenario in missing-development-credential development-credential-api-failure; do - if run_verify "${scenario}" >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: verifier accepted DEV credential metadata failure: ${scenario}" >&2 - exit 1 - fi -done -grep -Fq 'MISSING atrinik/metaserver-worker environment Actions secret CLOUDFLARE_API_TOKEN' \ - "${temporary}/missing-development-credential.err" -grep -Fq 'development credential metadata denied' "${temporary}/development-credential-api-failure.err" - -: >"${temporary}/gh.log" -output=$(run_verify pages-active) -grep -Fq 'KEEP atrinik/classic Pages uses the reviewed Actions workflow source' \ - <<<"${output}" - -for scenario in pages-source-drift pages-identity-drift \ - pages-activation-missing pages-workflow-metadata-drift; do - : >"${temporary}/gh.log" - if run_verify "${scenario}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: manual-settings verifier accepted ${scenario}" >&2 - exit 1 - fi -done -grep -Fq 'pending Pages activation has unexpected live source' \ - "${temporary}/pages-source-drift.err" -grep -Fq 'Pages identity or HTTPS drift' \ - "${temporary}/pages-identity-drift.err" -grep -Fq 'Pages Actions source is not active' \ - "${temporary}/pages-activation-missing.err" -grep -Fq 'Pages workflow metadata is invalid' \ - "${temporary}/pages-workflow-metadata-drift.err" - -: >"${temporary}/gh.log" -output=$(run_verify page2) -grep -Fq 'KEEP atrinik/github-settings repository Actions secret ATRINIK_SETTINGS_TOKEN' \ - <<<"${output}" -grep -Fq 'page=2' "${temporary}/gh.log" - -environment_page_root=${temporary}/environment-page -mkdir -p "${environment_page_root}/bin" -cp "${root}/bin/validate" "${fixture_root}/bin/verify-manual-settings" \ - "${environment_page_root}/bin/" -cp -R "${root}/config" "${environment_page_root}/config" -cp -R "${root}/community-health" "${environment_page_root}/community-health" -cp -R "${root}/.github" "${environment_page_root}/.github" -jq ' - .github_actions_environments[0].deployment_branch_policy.patterns = - ([range(0; 100) | { - name: ("branch-" + tostring), - type: "branch" - }] + [{name: "main", type: "branch"}]) -' "${fixture_root}/config/manual-settings.json" \ - >"${environment_page_root}/config/manual-settings.json" -: >"${temporary}/gh.log" -output=$(PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" \ - FAKE_GH_SCENARIO=environment-page2 \ - GITHUB_ACTIONS=true GH_TOKEN=test-token \ - ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${environment_page_root}/bin/verify-manual-settings") -grep -Fq 'KEEP atrinik/classic environment discord-release metadata' <<<"${output}" -grep -Fq 'deployment-branch-policies?per_page=100&page=2' "${temporary}/gh.log" - -shared_root=${temporary}/shared-repository -mkdir -p "${shared_root}/bin" -cp "${root}/bin/validate" "${fixture_root}/bin/verify-manual-settings" \ - "${shared_root}/bin/" -cp -R "${root}/config" "${shared_root}/config" -cp -R "${root}/community-health" "${shared_root}/community-health" -cp -R "${root}/.github" "${shared_root}/.github" -jq ' - .github_actions_credentials += [ - .github_actions_credentials[0] | - .secret_name = "SECOND_SETTINGS_TOKEN" - ] -' "${fixture_root}/config/manual-settings.json" \ - >"${shared_root}/config/manual-settings.json" -: >"${temporary}/gh.log" -output=$(PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" \ - FAKE_GH_SCENARIO=shared-repository \ - GITHUB_ACTIONS=true GH_TOKEN=test-token \ - ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${shared_root}/bin/verify-manual-settings") -grep -Fq 'SECOND_SETTINGS_TOKEN' <<<"${output}" -[[ $(grep -Fc 'repos/atrinik/github-settings' "${temporary}/gh.log") == 2 ]] - -for scenario in missing identity-drift api-failure page2-failure; do - : >"${temporary}/gh.log" - if run_verify "${scenario}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: manual-settings verifier accepted ${scenario}" >&2 - exit 1 - fi -done - -for scenario in pin-drift malformed-pins; do - : >"${temporary}/gh.log" - if run_verify "${scenario}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: manual-settings verifier accepted ${scenario}" >&2 - exit 1 - fi -done - -app_failures=( - missing-external-app - missing-app - app-id-drift - app-installation-id-drift - app-slug-drift - app-selection-drift - app-account-drift - app-events-drift - app-permission-drift - app-suspended - missing-app-secret - missing-app-variable - malformed-app-installations - malformed-app-variables - app-api-failure - app-variable-api-failure - app-installations-page2-failure - external-app-id-drift - external-app-installation-id-drift - external-app-slug-drift - external-app-selection-drift - external-app-events-drift - external-app-permission-drift - external-app-suspended - planned-control-installed - planned-control-identity-drift - planned-control-license-drift - external-website-identity-drift - external-metaserver-identity-drift -) -for scenario in "${app_failures[@]}"; do - : >"${temporary}/gh.log" - if run_verify "${scenario}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: manual-settings verifier accepted ${scenario}" >&2 - exit 1 - fi -done -grep -Fq 'GitHub App installation is missing or ambiguous' \ - "${temporary}/missing-app.err" -grep -Fq 'external provider App installation is missing or ambiguous' \ - "${temporary}/missing-external-app.err" -grep -Fq 'GitHub App installation metadata or permission drift' \ - "${temporary}/app-permission-drift.err" -grep -Fq 'external provider App installation metadata or permission drift' \ - "${temporary}/external-app-permission-drift.err" -grep -Fq 'repository identity or active-state drift for atrinik/website' \ - "${temporary}/external-website-identity-drift.err" -grep -Fq 'repository identity or active-state drift for atrinik/deploy-control' \ - "${temporary}/planned-control-identity-drift.err" -grep -Fq 'planned external provider App has a live installation for atrinik-deploy-control' \ - "${temporary}/planned-control-installed.err" -grep -Fq 'repository visibility or license drift for atrinik/deploy-control' \ - "${temporary}/planned-control-license-drift.err" -grep -Fq 'GitHub App Actions secret name is missing' \ - "${temporary}/missing-app-secret.err" -grep -Fq 'GitHub App Actions variable name is missing' \ - "${temporary}/missing-app-variable.err" -grep -Fq 'returned invalid metadata' \ - "${temporary}/malformed-app-installations.err" -grep -Fq 'Actions variable metadata response is invalid' \ - "${temporary}/malformed-app-variables.err" -grep -Fq 'organization installation administration denied' \ - "${temporary}/app-api-failure.err" -grep -Fq 'Actions variable administration denied' \ - "${temporary}/app-variable-api-failure.err" -grep -Fq 'second installation page failed' \ - "${temporary}/app-installations-page2-failure.err" - -: >"${temporary}/gh.log" -output=$(run_verify app-installations-page2) -grep -Fq 'KEEP atrinik-classic-dependency-updater installation metadata and exact permissions' \ - <<<"${output}" -grep -Fq 'orgs/atrinik/installations?per_page=100&page=2' "${temporary}/gh.log" - -for failure in \ - app-api-failure:45 \ - app-variable-api-failure:46 \ - app-installations-page2-failure:47; do - scenario=${failure%%:*} - expected_status=${failure#*:} - : >"${temporary}/gh.log" - set +e - run_verify "${scenario}" \ - >"${temporary}/${scenario}-status.out" \ - 2>"${temporary}/${scenario}-status.err" - status=$? - set -e - if ((status != expected_status)); then - echo "error: ${scenario} exited ${status}, expected ${expected_status}" >&2 - exit 1 - fi -done -grep -Fq 'organization pin order or identity drift' \ - "${temporary}/pin-drift.err" -grep -Fq 'invalid organization pin metadata' \ - "${temporary}/malformed-pins.err" -grep -Fq 'MISSING atrinik/github-settings repository Actions secret ATRINIK_SETTINGS_TOKEN' \ - "${temporary}/missing.err" -grep -Fq 'repository identity or active-state drift' \ - "${temporary}/identity-drift.err" -grep -Fq 'gh: repository administration denied' "${temporary}/api-failure.err" -grep -Fq 'read atrinik/github-settings identity' "${temporary}/api-failure.err" -grep -Fq 'gh: second secret page failed' "${temporary}/page2-failure.err" -grep -Fq 'page 2' "${temporary}/page2-failure.err" - -environment_failures=( - missing-environment - environment-identity-drift - environment-repository-name-drift - environment-archived - environment-default-branch-drift - environment-name-drift - branch-mode-drift - branch-policy-drift - extra-reviewer - wait-timer - custom-protection-rule - missing-environment-secret - extra-environment-variable - malformed-branch-policy-response - environment-page2-failure -) -for scenario in "${environment_failures[@]}"; do - : >"${temporary}/gh.log" - if run_verify "${scenario}" \ - >"${temporary}/${scenario}.out" 2>"${temporary}/${scenario}.err"; then - echo "error: manual-settings verifier accepted ${scenario}" >&2 - exit 1 - fi -done -grep -Fq 'environment not found' "${temporary}/missing-environment.err" -grep -Fq 'read atrinik/classic environment discord-release' \ - "${temporary}/missing-environment.err" -grep -Fq 'repository identity or active-state drift for atrinik/classic' \ - "${temporary}/environment-identity-drift.err" -grep -Fq 'repository identity or active-state drift for atrinik/classic' \ - "${temporary}/environment-repository-name-drift.err" -grep -Fq 'repository identity or active-state drift for atrinik/classic' \ - "${temporary}/environment-archived.err" -grep -Fq 'repository identity or active-state drift for atrinik/classic' \ - "${temporary}/environment-default-branch-drift.err" -grep -Fq 'environment metadata is invalid' \ - "${temporary}/environment-name-drift.err" -grep -Fq 'deployment branch mode drift' \ - "${temporary}/branch-mode-drift.err" -grep -Fq 'deployment branch policy drift' \ - "${temporary}/branch-policy-drift.err" -grep -Fq 'required reviewer drift' "${temporary}/extra-reviewer.err" -grep -Fq 'protection rule drift' "${temporary}/wait-timer.err" -grep -Fq 'protection rule drift' "${temporary}/custom-protection-rule.err" -grep -Fq 'environment secret-name drift' \ - "${temporary}/missing-environment-secret.err" -grep -Fq 'environment variable-name drift' \ - "${temporary}/extra-environment-variable.err" -grep -Fq 'returned invalid metadata' \ - "${temporary}/malformed-branch-policy-response.err" -grep -Fq 'second environment branch-policy page failed' \ - "${temporary}/environment-page2-failure.err" -grep -Fq 'page 2' "${temporary}/environment-page2-failure.err" - -for failure in api-failure:41 page2-failure:42; do - scenario=${failure%%:*} - expected_status=${failure#*:} - : >"${temporary}/gh.log" - set +e - run_verify "${scenario}" \ - >"${temporary}/${scenario}-status.out" \ - 2>"${temporary}/${scenario}-status.err" - status=$? - set -e - if ((status != expected_status)); then - echo "error: ${scenario} exited ${status}, expected ${expected_status}" >&2 - exit 1 - fi -done - -: >"${temporary}/gh.log" -set +e -run_verify environment-page2-failure \ - >"${temporary}/environment-page2-failure-status.out" \ - 2>"${temporary}/environment-page2-failure-status.err" -status=$? -set -e -if ((status != 44)); then - echo "error: environment-page2-failure exited ${status}, expected 44" >&2 - exit 1 -fi - -: >"${temporary}/gh.log" -if PATH="${temporary}/bin:${PATH}" \ - FAKE_GH_LOG="${temporary}/gh.log" FAKE_GH_SCENARIO=present \ - GITHUB_ACTIONS=true GH_TOKEN='' ATRINIK_VALIDATION_TODAY=2026-10-18 \ - "${fixture_root}/bin/verify-manual-settings" \ - >"${temporary}/empty.out" 2>"${temporary}/empty.err"; then - echo "error: manual-settings verifier accepted an empty workflow credential" >&2 - exit 1 -fi -grep -Fq 'ATRINIK_SETTINGS_TOKEN is unavailable' "${temporary}/empty.err" -[[ ! -s ${temporary}/gh.log ]] - -echo "Manual settings live credential, GitHub App, external provider App, planned integration, Pages, and environment verification tests passed." diff --git a/tests/verify_crate_workflow.py b/tests/verify_crate_workflow.py deleted file mode 100644 index f7e3c2c..0000000 --- a/tests/verify_crate_workflow.py +++ /dev/null @@ -1,194 +0,0 @@ -"""Exercise the credential and executable provenance qualification boundaries.""" - -import copy -import importlib.util -from pathlib import Path -import sys -import unittest - -ROOT = Path(__file__).resolve().parents[1] -sys.dont_write_bytecode = True -spec = importlib.util.spec_from_file_location("crate_workflow", ROOT / "lib/verify_crate_workflow.py") -workflow = importlib.util.module_from_spec(spec) -spec.loader.exec_module(workflow) - - -class WorkflowBoundaryTests(unittest.TestCase): - def setUp(self): - self.publish = workflow.yaml.load((ROOT / "tests/fixtures/crate-publication.yml").read_text(), - Loader=workflow.UniqueLoader) - self.source = workflow.yaml.load((ROOT / "tests/fixtures/crate-source-release.yml").read_text(), - Loader=workflow.UniqueLoader) - - def publication(self, candidate): - return workflow.verify(workflow.yaml.dump(candidate), "atrinik/protocol", "1327106950") - - def signing(self, candidate): - return workflow.verify_source_release(workflow.yaml.dump(candidate), "atrinik/protocol") - - def reject(self, original, checker, mutate): - candidate = copy.deepcopy(original) - mutate(candidate) - with self.assertRaises((ValueError, KeyError, TypeError)): - checker(candidate) - - def test_reviewed_boundary(self): - self.publication(self.publish) - self.signing(self.source) - - def test_safe_full_checkout_and_confirmation_variants(self): - job = self.publish["jobs"]["automatic-publish"] - job["steps"][0]["with"]["fetch-depth"] = 0 - confirm = {"if": "${{ !cancelled() }}", "run": job["steps"][-1]["run"].replace(" upload ", " confirm ")} - job["steps"].append(confirm) - self.publication(self.publish) - - def test_publisher_least_privilege_and_inert_execution(self): - mutations = [ - lambda w: w["jobs"]["automatic-verify"]["permissions"].update({"contents": "write"}), - lambda w: w["jobs"]["automatic-verify"]["permissions"].pop("attestations"), - lambda w: w["jobs"]["automatic-publish"]["permissions"].update({"checks": "write"}), - lambda w: w["jobs"]["automatic-publish"]["permissions"].update({"contents": "read"}), - lambda w: w["jobs"]["automatic-publish"]["env"].update({"GH_INTENT_TOKEN": "${{ github.token }}"}), - lambda w: w["jobs"]["automatic-publish"]["env"].update({"BASH_ENV": "untrusted.sh"}), - lambda w: w["jobs"]["automatic-publish"].update({"container": "untrusted"}), - lambda w: w["jobs"]["automatic-publish"]["steps"][-1]["env"].pop("GH_INTENT_TOKEN"), - lambda w: w["jobs"]["automatic-publish"]["steps"].append({"run": "cargo build"}), - lambda w: w["jobs"]["automatic-publish"]["steps"].append({"uses": "owner/build@" + "1" * 40}), - lambda w: w["jobs"]["automatic-publish"]["steps"][1].update({"env": {"PYTHONPATH": "untrusted"}}), - lambda w: w["jobs"]["automatic-publish"]["steps"][0]["with"].update({"path": "alternate"}), - ] - for index, mutation in enumerate(mutations): - with self.subTest(index=index): - self.reject(self.publish, self.publication, mutation) - - def test_automatic_jobs_reject_matrix_and_reusable_job_fields(self): - for job_name in ("automatic-verify", "automatic-publish"): - for field, value in ( - ("strategy", {"matrix": {"target": ["unreviewed"]}}), - ("uses", "./.github/workflows/unreviewed.yml"), - ("with", {"target": "unreviewed"}), - ("secrets", "inherit"), - ): - with self.subTest(job=job_name, field=field): - self.reject( - self.publish, - self.publication, - lambda w, job_name=job_name, field=field, value=value: - w["jobs"][job_name].update({field: value}), - ) - - def test_source_jobs_reject_matrix_and_reusable_job_fields(self): - for job_name in ("package", "attest", "release"): - for field, value in ( - ("strategy", {"matrix": {"target": ["unreviewed"]}}), - ("uses", "./.github/workflows/unreviewed.yml"), - ("with", {"target": "unreviewed"}), - ("secrets", "inherit"), - ): - with self.subTest(job=job_name, field=field): - self.reject( - self.source, - self.signing, - lambda w, job_name=job_name, field=field, value=value: - w["jobs"][job_name].update({field: value}), - ) - - def test_registry_token_expressions_are_confined_to_the_upload_binding(self): - token_references = ( - "${{ steps.auth.outputs.token }}", - "${{ Steps.AUTH.outputs.token }}", - "${{ steps['auth'].outputs['token'] }}", - "${{ steps [ 'auth' ] . outputs [ 'token' ] }}", - "${{ format('}}{0}', steps.auth.outputs.token) }}", - "${{ toJSON(steps) }}", - "${{ steps[inputs.x].outputs.token }}", - "${{ steps.auth.outputs.token }} ", - ) - - def inject(job, location, token): - if location == "extra-env": - job["env"]["UNREVIEWED_TOKEN"] = token - elif location == "outputs": - job["outputs"] = {"token": token} - elif location == "concurrency": - job["concurrency"] = {"group": token, "cancel-in-progress": False} - elif location == "checkout-with": - job["steps"][0]["with"]["fetch-depth"] = token - elif location == "step-name": - job["steps"][1]["name"] = token - elif location == "step-run": - job["steps"][1]["run"] += " # " + token - elif location == "step-if": - job["steps"][1]["if"] = token - elif location == "step-env": - job["steps"][1]["env"] = {"UNREVIEWED_TOKEN": token} - else: - self.fail(f"unknown token injection location: {location}") - - locations = ( - "extra-env", "outputs", "concurrency", "checkout-with", - "step-name", "step-run", "step-if", "step-env", - ) - for job_name in ("automatic-verify", "automatic-publish"): - for location in locations: - for token in token_references: - with self.subTest(job=job_name, location=location, token=token): - self.reject( - self.publish, - self.publication, - lambda w, job_name=job_name, location=location, token=token: - inject(w["jobs"][job_name], location, token), - ) - - def test_only_the_exact_upload_token_expression_is_allowed(self): - variants = ( - "${{ Steps.AUTH.outputs.token }}", - "${{ steps['auth'].outputs['token'] }}", - "${{ steps [ 'auth' ] . outputs [ 'token' ] }}", - "${{ format('}}{0}', steps.auth.outputs.token) }}", - "${{ toJSON(steps) }}", - "${{ steps[inputs.x].outputs.token }}", - "${{ steps.auth.outputs.token }} ", - ) - for token in variants: - with self.subTest(token=token): - self.reject( - self.publish, - self.publication, - lambda w, token=token: w["jobs"]["automatic-publish"]["steps"][3]["env"].update( - {"CARGO_REGISTRY_TOKEN": token}), - ) - - def test_signer_isolation_and_dependency(self): - mutations = [ - lambda w: w["jobs"]["package"].update({"permissions": {"contents": "read", "id-token": "write"}}), - lambda w: w["jobs"]["release"]["permissions"].update({"id-token": "write"}), - lambda w: w["jobs"]["release"].update({"needs": ["package"]}), - lambda w: w["jobs"].pop("attest"), - lambda w: w["jobs"]["attest"].update({"if": "false"}), - lambda w: w["jobs"]["attest"].update({"continue-on-error": "true"}), - lambda w: w["jobs"]["attest"].update({"env": {"PYTHONPATH": "untrusted"}}), - lambda w: w["jobs"]["attest"].update({"container": "untrusted"}), - lambda w: w["jobs"]["attest"]["steps"].append({"run": "npm install"}), - lambda w: w["jobs"]["attest"]["steps"][2].update({"run": "cargo build"}), - lambda w: w["jobs"]["attest"]["steps"][2].update({"shell": "echo {0}"}), - lambda w: w["jobs"]["attest"]["steps"][2].update({"continue-on-error": "true"}), - lambda w: w["jobs"]["attest"]["steps"][2].update({"if": "false"}), - lambda w: w["jobs"]["attest"]["steps"][0]["with"].update({"ref": "main"}), - lambda w: w["jobs"]["attest"]["steps"][1]["with"].update({"run-id": "123"}), - lambda w: w["jobs"]["attest"]["steps"][3].update({"uses": "actions/attest-build-provenance@v4"}), - lambda w: w["jobs"]["attest"]["steps"][3]["with"].update({"subject-path": "build/release/*.crate"}), - lambda w: w["jobs"]["attest"]["steps"][3]["with"].update({"push-to-registry": "true"}), - ] - for index, mutation in enumerate(mutations): - with self.subTest(index=index): - self.reject(self.source, self.signing, mutation) - - def test_immutable_official_signer_can_receive_dependabot_updates(self): - self.source["jobs"]["attest"]["steps"][-1]["uses"] = "actions/attest-build-provenance@" + "2" * 40 - self.signing(self.source) - - -if __name__ == "__main__": - unittest.main() From ca44cf5f45e25bfd498c95e0e4836bc27e55bd6c Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Sat, 14 Nov 2026 13:20:24 -0600 Subject: [PATCH 2/4] docs: say where settings changes are recorded until the baseline lands Co-Authored-By: Claude --- AGENTS.md | 4 +++- README.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9dd723b..2c69bf4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,9 @@ the Git history and in release `v2.26.0` for reference only. - Settings are changed by hand under the owner's login, only when the current task authorizes that change. Record each change in this repository in the - same task, through a pull request. + same task, through a pull request. Until the baseline file lands, record it + in the description of the pull request or task that made it; do not invent + a record file here. - The **Atrinik work** Project is no longer filled automatically. Keep `config/planning.json` and its Status names as they are: agent skills read them. diff --git a/README.md b/README.md index bd9b9e0..b6d71b6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,9 @@ removed because: - The owner, or an agent session she authorizes, changes settings by hand under her own login, in GitHub's web pages or with `gh`. -- The change is recorded here in the same task, through a pull request. +- The change is recorded here in the same task, through a pull request. Until + the baseline file lands, it is recorded in the description of the pull + request or task that made it. - The **Atrinik work** Project board is no longer filled automatically. Add issues and pull requests to it by hand when they belong there. - [`atrinik/.github`](https://github.com/atrinik/.github) (issue forms, From 356c1fead30e4ab86b0416f0dfe419db093a3ae8 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Sat, 14 Nov 2026 13:22:26 -0600 Subject: [PATCH 3/4] ci: stop running dependency review on PR edits A PR body or title edit right after a push started a second run that cancelled the in-progress run for the same head (cancel-in-progress), leaving a cancelled Dependency review check on the commit. Co-Authored-By: Claude --- .github/workflows/dependency-review.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index d2ff903..9c1301e 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -2,7 +2,9 @@ name: Dependency review on: pull_request: - types: [opened, synchronize, reopened, edited] + # No "edited": a body or title edit would start a run that cancels the + # in-progress run for the same head and leaves a cancelled check on it. + types: [opened, synchronize, reopened] concurrency: group: dependency-review-${{ github.event.pull_request.number || github.ref }} From 13ec81fe5d51012a04e8543411d75110f39864a7 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Sat, 14 Nov 2026 13:27:28 -0600 Subject: [PATCH 4/4] chore: re-run checks after the CodeQL language update The repository's CodeQL default setup no longer analyses JavaScript, which this pull request removes. This empty commit gives the pull request a head without the stale failed JavaScript analysis. Co-Authored-By: Claude