diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index c163d95..c943a45 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,87 +1,49 @@ -# Copilot Instructions — repo-template +# Copilot Instructions — worldchest ## About -`repo-template` is the org baseline scaffold for new `combsmith` repositories: -click **Use this template** to create a repo pre-wired with the standard workflow -stubs and baseline files, then follow `BOOTSTRAP.md` (an agent-executable runbook) -to customize it. Its "code" is GitHub Actions workflows, Markdown docs, and a bats -suite that guards the workflows. There is no application runtime. The workflow -stubs and baseline files are a distribution artifact of the org standards in -[`combsmith/.github`](https://github.com/combsmith/.github) (`standards/`) -and are regenerated from there. +WorldChest is automatic backup, sync, restore and versioning for Minecraft Bedrock +worlds on kids' phones and tablets (parents are the buyer). This repo is pre-code: +the brief is [combsmith/incubator discussion #5](https://github.com/combsmith/incubator/discussions/5). ## Tech Stack -- **Runtime:** None — a template/scaffold repo, not a deployable application. -- **CI / config:** GitHub Actions workflow stubs (YAML) under `.github/workflows/`; Dependabot; SonarCloud. -- **Docs:** Markdown (`AGENTS.md`, `CLAUDE.md`, `BOOTSTRAP.md`, `README.md`, `SECURITY.md`). -- **Tooling:** `bats` (compliance regression tests in `tests/`), `shellcheck`, `yq`, `python3` + PyYAML, `gh` CLI. +- **Runtime:** not chosen yet. Candidates from the brief: Android app (Kotlin, + share-sheet + Shizuku), desktop companion, cloud backend for storage/versioning. +- **CI / config:** org baseline GitHub Actions stubs; `ci.yml` runs shell lint, gitleaks and a coverage job that is green until tests exist. +- **Testing / Linting:** to be set with the stack. ## Project Structure -``` -.github/ - workflows/ # Thin-caller stubs (keep verbatim) + ci.yml / sonarcloud.yml / - # copilot-setup-steps.yml (customize-per-stack) - copilot-instructions.md # This file - CODEOWNERS # * @combsmith/org-leads - dependabot.yml # frontend stack by default — swapped during bootstrap -standards/rulesets/ - pr-quality.json # Codified copy of the org ruleset, guarded by tests/ -tests/*.bats # Template-only guards: stub byte-identity, ci.yml invariants, - # gitignore baseline, ruleset drift. Removed in child repos. -AGENTS.md # Org pointer + rules specific to this template -BOOTSTRAP.md # Customization runbook for repos created from this template -sonar-project.properties # SonarCloud project key (customize per repo) -``` +No application code yet. `.github/` holds the org-standard workflow stubs and this file. ## Local Dev Commands -There is no install/build/dev-run step. - -- Test: `bats tests/` ← needs `bats`, `yq`, `python3` + PyYAML, GNU bash 5 - (on macOS: `brew install bats-core yq` and run with Homebrew bash first on `PATH`). -- Lint: `shellcheck *.sh` (no shell scripts ship today). -- Workflow YAML validation: push a branch and let CI run, or use `act` locally. +- Install: none yet +- Test: none yet +- Lint: none yet ## Required Environment Variables -No application secrets are needed for local work. In CI, all are org-level and inherited: - -- `SONAR_TOKEN`: SonarCloud analysis token; the `sonarcloud` workflow is a green no-op until present. -- `GITHUB_TOKEN`: provided automatically by GitHub Actions. -- `CLAUDE_CODE_OAUTH_TOKEN`: used by `dev-lead.yml`. -- `APP_ID` / `APP_PRIVATE_KEY`: GitHub App credentials used by `dependabot-automerge.yml`. -- `GH_PAT_WORKFLOWS`: used by `pr-review-mention.yml`. - -Never commit a real token. +- None. ## Testing Framework -- `bats` regression guards in `tests/`, run by the `build-and-test` and `coverage` - jobs of `ci.yml`. They assert that each thin-caller stub is byte-identical to - its canonical template (trailing newline included — the committed stubs have - none), that `ci.yml` keeps its retry/timeout/concurrency invariants, that the - `.gitignore` secrets baseline is unmodified, and that no workflow carries a - `TODO`/`FIXME` (SonarCloud S1135). -- No coverage threshold applies — there is no application code to cover. +- None yet. First code lands with tests; the `coverage` job enforces from then on. ## Repo-Specific Overrides -- **Edit the standards, not these copies.** Workflow stubs and baseline files are - regenerated from `combsmith/.github` (`standards/`); `README.md`, `BOOTSTRAP.md`, - `AGENTS.md` and `sonar-project.properties` are generated by - `seed-repo-template.sh` in `combsmith/.github-private`. A change to any of those - made here must also land in the seeder or the next seed PR proposes reverting it. -- `ci.yml` and `sonarcloud.yml` are intentionally ahead of their canonical templates - and allowlisted in the template drift guard; keep them in step with `tests/ci-*.bats`. -- Deleting a file under `tests/` may be gated on the `ack-test-deletion` PR label; add it if asked. +- Use "Minecraft" only as a secondary title; never in the brand, domain, handles or + package names. Keep the NOT AN OFFICIAL MINECRAFT PRODUCT disclaimer on any + user-facing surface. +- Treat any stored world data as a minor's data (COPPA / GDPR-K). +- Frameworks (BMAD) are vendored from `combsmith/.github-private` or + `software-factory`; never `npx bmad-method install`. ## Org Standards See [combsmith/.github — AGENTS.md](https://github.com/combsmith/.github/blob/main/AGENTS.md) for org-wide development standards. -_No language-specific instruction files are deployed to `.github/instructions/` in this repo, so -the per-language links block is intentionally omitted per the Copilot Instructions Standard._ +_No language-specific instruction files are deployed to `.github/instructions/` yet +(`STACK=none`); add them with the stack per the Copilot Instructions Standard._ diff --git a/.github/workflows/feature-ideation.yml b/.github/workflows/feature-ideation.yml index 788688f..686cc75 100644 --- a/.github/workflows/feature-ideation.yml +++ b/.github/workflows/feature-ideation.yml @@ -195,9 +195,20 @@ jobs: # its target users, and the competitive landscape. The more specific you # are, the more useful the proposals. project_context: | - TODO: Replace this with a description of the project and its market. - Example: "ProjectX is a [type of product] for [target user]. Competitors - include A, B, C. Key emerging trends in this space: X, Y, Z." + WorldChest is automatic backup, sync, restore and versioning for Minecraft + Bedrock worlds that live in a single fragile folder on kids' phones and + tablets; a new device, a cracked screen or a bad update wipes them with no + undo. Primary users are young Bedrock players (7-15); the buyer is their + parents, who already pay for photo backup and device insurance; secondary + users are map creators, streamers and Minecraft Education classrooms. The + freemium model targets a family subscription (~$5/month). Competitors and + substitutes: Realms (paid hosted multiplayer, not local-world preservation), + device-transfer tools such as Samsung Smart Switch (corrupt worlds), manual + ADB/.mcworld workflows. Key constraints and trends: Android 11+/iOS + owner-only app storage (tiered access: .mcworld share sheet, Shizuku power + mode, desktop companion, official Mojang API as the long-term goal), the + Minecraft Usage Guidelines (brand never contains "Minecraft"; NOT AN + OFFICIAL MINECRAFT PRODUCT disclaimer), and COPPA/GDPR-K for minors' data. # === OPTIONAL: repo-local reputable source list === # Copy standards/feature-ideation-sources.md from combsmith/.github # to .github/feature-ideation-sources.md and customise it. The reusable diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a5e4585..a257236 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -4,8 +4,13 @@ # # ADOPTING THIS WORKFLOW: # 1. This ships verbatim into repos created from combsmith/repo-template. -# 2. Set sonar.projectKey / sonar.organization in sonar-project.properties to -# match your repo (see BOOTSTRAP.md), and add the SONAR_TOKEN repo secret. +# 2. The project key and organization are derived from the repo at run time +# (_ / ) via `args:` on both scan steps, so a new repo +# needs no per-repo edit — add the SONAR_TOKEN repo secret and it scans into +# its own SonarCloud project (auto-provisioned on the first scan). +# sonar-project.properties carries only stack-agnostic sources/exclusions. +# If the repo is renamed, update the key on the existing SonarCloud project +# (Administration → Update Key) so its history follows the new name. # 3. The job name `SonarCloud` is the required status check — keep it. # 4. The scan is guarded on SONAR_TOKEN, so the job is a green no-op until the # secret is set — a fresh repo is not blocked on day 0. @@ -16,6 +21,9 @@ # • first scan is continue-on-error with a single retry (SonarCloud's analysis # endpoint is occasionally flaky) # • SHA-pin every third-party action (never a tag/branch) +# • both scan steps pass the derived -Dsonar.projectKey / -Dsonar.organization +# (a hard-coded key would make every repo cut from the template scan into +# the template's project and fail PR analysis with an unknown PR key) # ───────────────────────────────────────────────────────────────────────────── name: SonarCloud Analysis @@ -52,10 +60,18 @@ jobs: id: sonar if: env.SONAR_TOKEN != '' uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0 + with: + args: >- + -Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }} + -Dsonar.organization=${{ github.repository_owner }} continue-on-error: true - name: Wait before SonarCloud retry if: env.SONAR_TOKEN != '' && steps.sonar.outcome == 'failure' run: sleep 30 - name: SonarCloud Scan (retry) if: env.SONAR_TOKEN != '' && steps.sonar.outcome == 'failure' - uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0 \ No newline at end of file + uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0 + with: + args: >- + -Dsonar.projectKey=${{ github.repository_owner }}_${{ github.event.repository.name }} + -Dsonar.organization=${{ github.repository_owner }} diff --git a/AGENTS.md b/AGENTS.md index 6587df0..0526e73 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,53 +6,51 @@ This repository follows the organization-wide development standards defined in Read that file before making changes that touch CI, agent configuration, repo settings, or labels. Repo-specific deviations, if any, are documented below. -## What this repository is - -`repo-template` is the org's **template repository**: the scaffold every new -`combsmith` repo starts from via **Use this template**. It has no application -code. Its contents are the org-standard workflow stubs, baseline files, and a -bats suite that guards them. - -- **Creating a repo from this template?** Follow [`BOOTSTRAP.md`](./BOOTSTRAP.md). - It is an agent-executable runbook: inputs, per-file actions, verification, - and the org-admin hand-off. -- **Changing this template?** Most files here are a distribution artifact of - `combsmith/.github` `standards/` and are regenerated by - `seed-repo-template.sh` (in `combsmith/.github-private`). Edit the standard, - not the copy. Only `tests/` and `.github/copilot-instructions.md` are owned - here outright. `README.md`, `BOOTSTRAP.md`, `AGENTS.md` and - `sonar-project.properties` are *generated* by the seeder: a change made here - must also be mirrored into the seeder's heredocs, or the next seed PR will - propose reverting it. +## Project overview + +WorldChest backs up, syncs, restores and versions Minecraft Bedrock worlds for +young players on phones and tablets; parents are the buyer. The brief, the n=1 +proof (232 worlds migrated S22 → S24 by hand) and the open legal and platform +questions are in +[combsmith/incubator discussion #5](https://github.com/combsmith/incubator/discussions/5). +No application code exists yet and no stack has been chosen (`STACK=none` at +bootstrap). Candidate shape from the brief: a mobile app (Android first, Bedrock +share-sheet + Shizuku power mode), a desktop companion for migrations, and a +cloud backend for storage and versioning. ## Local Development Commands -- Install: none (no application dependencies). Tests need `bats`, `shellcheck`, - `yq`, `python3` with PyYAML, and GNU bash 5 (`brew install bash bats-core shellcheck yq`; - on macOS run tests with Homebrew bash first on `PATH`, stock bash 3.2 cannot - parse the test heredocs). +- Install: none yet (no application code) - Dev run: n/a -- Test: `bats tests/` -- Lint: `find . -path ./.git -prune -o -name '*.sh' -exec shellcheck {} +` (no - shell scripts ship today, so a bare `shellcheck *.sh` fails on the unmatched - glob; CI uses `shopt -s nullglob` for the same reason) +- Test: none yet; CI runs the org baseline (`build-and-test` shell lint, `Secret scan (gitleaks)`, `coverage`) until a stack lands +- Lint: n/a - Typecheck: n/a +When the stack is chosen, replace this section and update `ci.yml`, +`.github/dependabot.yml`, `copilot-setup-steps.yml` and +`.github/copilot-instructions.md` per the org `AGENTS.md` +"Creating a new repository" step 3 (the template's `BOOTSTRAP.md` steps 2–4 and 7). + ## Required Environment Variables -- None for local work. CI secrets (`SONAR_TOKEN`, `APP_ID`/`APP_PRIVATE_KEY`, - `GH_PAT_WORKFLOWS`, `CLAUDE_CODE_OAUTH_TOKEN`) are org-level and inherited. - -## Rules specific to this template - -- **Stubs are byte-exact.** `tests/*-stub.bats` compare each thin-caller - workflow against an inline snapshot of the canonical template, trailing - newline included (the committed stubs have none). Never reformat them. -- **`ci.yml` and `sonarcloud.yml` are intentionally ahead of the canonical - templates** (retry/backoff, timeouts, `persist-credentials: false`). They are - allowlisted in the template drift guard; keep their invariants in sync with - `tests/ci-*.bats` and `tests/sonarcloud-stub.bats`. -- **No `TODO`/`FIXME` in workflow files.** SonarCloud rule S1135 is enforced by - the stub tests. Reword to `Customize:`. -- **Deleting a file under `tests/`** may be gated by PR automation on the - `ack-test-deletion` label (created by the org bootstrap). Add it if asked. +- None. + +## Testing + +- No test suite yet. First code must arrive with tests (org TDD rule); the + `coverage` CI job stays green until tests exist and enforces from then on. + +## Rules specific to this repository + +- **Naming (Minecraft Usage Guidelines).** The brand is WorldChest. "Minecraft" + appears only as a secondary title ("backup for Minecraft worlds"), never in the + brand, domain, handles or package names. Every listing and site carries the + NOT AN OFFICIAL MINECRAFT PRODUCT disclaimer. +- **Minors' data.** Storing kids' worlds is COPPA / GDPR-K territory: design + parent-consent flows and data handling before any backend stores user content. +- **Frameworks are vendored, not installed.** BMAD and other agent frameworks + come from `combsmith/.github-private` or `software-factory` as `git subtree`; + never run `npx bmad-method install` here. +- **Stubs are org-managed.** The `.github/workflows/*.yml` thin-caller stubs, + `CODEOWNERS`, `CLAUDE.md`, `.gitleaks.toml` and the `.gitignore` secrets + baseline are synced by org automation; do not hand-edit them. diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md deleted file mode 100644 index 6bb7143..0000000 --- a/BOOTSTRAP.md +++ /dev/null @@ -1,432 +0,0 @@ -# Bootstrap a new repo from this template - -This file is the **customization runbook** for a repository that was just created -from `combsmith/repo-template` with **Use this template**. It is written so an -agent (Claude Code, Copilot coding agent, Codex) can execute it end to end from -a handful of inputs, with a human doing only the org-admin steps it cannot. - -Everything the template ships is already org-compliant. Bootstrapping is the -small set of edits that turn the generic scaffold into *this* project, plus the -removal of the files that only exist to test the template itself. - -Run the steps in order. Each step says what to edit, what to leave alone, and -how to check it. When every step is done, including the hand-off (step 9) and the done criteria (step 10), delete this file as the very last action. - -_Last validated end to end on 2026-10-20 with `STACK=backend-python` on a -throwaway repo: the untouched template was green on every check at creation, -and the bootstrap PR was green on every required check. The stack-specific -notes below (pip-audit file, ruff and Markdown, org-secret grant) come from -that run._ - ---- - -## 0. Inputs — collect these before editing anything - -| Input | Example | Used by | -|---|---|---| -| `REPO` — `owner/name` of the new repo | `combsmith/hive-health` | `sonar-project.properties`, `README.md`, `copilot-instructions.md`, `feature-ideation.yml` | -| `DESCRIPTION` — one sentence, what the repo is | `Beehive telemetry dashboard and alerting service` | `README.md`, `copilot-instructions.md`, repo description | -| `STACK` — one of `frontend`, `backend-go`, `backend-python`, `backend-rust`, `fullstack`, `infra-terraform`, `none` | `backend-python` | `dependabot.yml`, `ci.yml`, `copilot-setup-steps.yml`, `.gitignore` L2, `.github/instructions/` | -| `PROJECT_CONTEXT` — 3 to 5 sentences: product, target users, competitive landscape | see `feature-ideation.yml` header | `feature-ideation.yml` (`project_context`) | -| `BMAD` — `yes` for product repos (org default), `no` for data/tooling repos | `yes` | step 8 | - -Rules for an agent: - -- If `STACK` or `PROJECT_CONTEXT` is missing, **ask once** and stop. Do not infer - the stack from an empty repo. -- `none` is valid for `STACK` (docs-only or not-yet-decided repos): keep the - shipped shell-based `ci.yml` and the `frontend` Dependabot file, and revisit - when code lands. -- **Ask the maintainer to run step 9 item 1 (`bootstrap-new-repo.sh`) before - you open the PR.** A repo fresh from the template has no rulesets, so nothing - gates a merge: on the validation run the bootstrap PR was merged two minutes - after it was opened, with no approving review, and a Dependabot major bump - merged the same way. If the rulesets are not in place yet, open the PR as a - **draft** and say so in the hand-off. -- Work on a branch and open one PR titled `chore: bootstrap from repo-template`. - Never push to `main`. The PR body must carry the org's required sections, - each at least one line: `## Problem`, `## Risk`, `## Test plan`, - `## Rollback`, `## Monitoring` (PR triage escalates a PR missing three or - more of them). -- Commit with a GitHub no-reply address (`+@users.noreply.github.com`, - as in `git config user.email` of an existing checkout). GitHub rejects a push - whose commits carry a private personal email (`GH007`). -- Run every `gh api … | base64 -d > file` download with `set -o pipefail` (or - check the file is non-empty before using it). Without it, an auth or 404 - failure in `gh` is masked by `base64`'s zero exit and leaves an empty file. -- If the stack's toolchain is not available locally (wrong Python, no Node), - do not fake a local run: push the branch and let the PR's CI verify. Report - which checks you could and could not run. - ---- - -## 1. File inventory — what to do with every shipped file - -**Keep verbatim** (managed by org automation; the standards sweep re-syncs them -by PR, and the compliance audit flags any hand edit as drift): - -| Path | Why it is untouchable | -|---|---| -| `.github/workflows/add-to-project.yml`, `agent-shield.yml`, `auto-rebase.yml`, `dependabot-automerge.yml`, `dependabot-rebase.yml`, `dependency-audit.yml`, `dev-lead.yml`, `initiative-driver.yml`, `persona-mention.yml`, `pr-auto-review.yml`, `pr-review-mention.yml` | Thin caller stubs. Behaviour lives in the org reusables; the `uses:` pin is moved centrally. `agent-shield.yml` is additionally a security boundary agents must never modify. | -| `.github/CODEOWNERS` | `* @combsmith/org-leads` must stay the first owner on every line. Add path lines only *after* it. | -| `CLAUDE.md`, `SECURITY.md`, `LICENSE` | Org pointers and license. | -| `.gitignore` — the block between `>>> BEGIN combsmith secrets baseline` and `<<< END` | Hash-checked by the compliance audit. Edit only **below** the END marker. | -| `.gitleaks.toml` | Keep the file; you may only **append** allowlist paths under `[allowlist]`. | -| `.github/workflows/sonarcloud.yml` | Keep as shipped; the `SonarCloud` job name is a required check. | - -**Customize** (step numbers below): - -| Path | Step | -|---|---| -| `.github/dependabot.yml` | 2 | -| `.github/workflows/ci.yml` | 3 | -| `.github/workflows/copilot-setup-steps.yml` | 4 | -| `.github/workflows/feature-ideation.yml` | 5 | -| `sonar-project.properties` | 6 | -| `README.md`, `AGENTS.md`, `.github/copilot-instructions.md`, `.github/instructions/` | 7 | -| `.gitignore` (below the END marker), `.worktreeinclude` | 7 | - -**Delete** (template-only; they exist to test the template repo itself): - -| Path | Why | -|---|---| -| `tests/*.bats` | Regression guards for *this template's* stubs and its shell `ci.yml`. In a product repo they fail the moment `ci.yml` is customized, and the org compliance audit already guards the stubs. Delete them (step 8 names the one narrow exception for shell-script repos). If PR automation asks for the `ack-test-deletion` label, add it: these are not product tests. | -| `standards/rulesets/pr-quality.json` | Codified copy used by the template's tests. The live ruleset is applied to the new repo by `bootstrap-new-repo.sh` (step 9). | -| `BOOTSTRAP.md` | This runbook, deleted as the very last action after step 10. | - ---- - -## 2. Dependabot — pick the stack - -For `STACK=none`, skip this step: keep the shipped `frontend` file untouched. -Otherwise replace `.github/dependabot.yml` with the canonical file for `STACK` -(`frontend` ships by default). Every stack file already contains the required -`github-actions` entry; do not add a second one. - -```bash -set -o pipefail -gh api repos/combsmith/.github/contents/standards/dependabot/${STACK}.yml \ - --jq '.content' | base64 -d > .github/dependabot.yml.new \ - && [ -s .github/dependabot.yml.new ] \ - && mv .github/dependabot.yml.new .github/dependabot.yml -``` - -Adjust only `directory:` paths if manifests are not at the repo root. Policy: -[`standards/dependabot-policy.md`](https://github.com/combsmith/.github/blob/main/standards/dependabot-policy.md). - -`fullstack.yml` carries `npm`, `gomod`, `terraform` and `github-actions` -entries but **no `pip` entry**. A `fullstack` repo that also has Python code -adds the `pip` block from `backend-python.yml` (same `schedule`, `groups` and -`labels` shape as the other entries; adjust `directory:`), still with a single -`github-actions` entry. - -**Python stacks (`backend-python`, or `fullstack` with Python) also need -`scripts/pip-audit-requirements.txt`.** The org `dependency-audit` reusable's -`pip-audit` job installs pip-audit from that hash-pinned file in the consumer -repo and fails with "No such file" when it is absent (observed on the -validation run). Copy it verbatim: - -```bash -mkdir -p scripts -gh api repos/combsmith/.github/contents/scripts/pip-audit-requirements.txt \ - --jq '.content' | base64 -d > scripts/pip-audit-requirements.txt \ - && [ -s scripts/pip-audit-requirements.txt ] -``` - -The other ecosystems (npm, pnpm, Go, Cargo) need no extra file; their audit -jobs key off the lockfile. - -Check: the file parses as YAML with `version: 2`. Use whichever parser is -installed: `yq '.version' .github/dependabot.yml` or -`python3 -c 'import yaml; print(yaml.safe_load(open(".github/dependabot.yml"))["version"])'` -(PyYAML is not in the standard library; `python3 -m pip install pyyaml` if needed). - ---- - -## 3. `ci.yml` — replace the shell checks with your stack's checks - -For `STACK=none`, skip this step: there are no stack-specific checks, so keep -the shipped shell-based `ci.yml` as is. - -`.github/workflows/ci.yml` ships with three jobs. Keep all three job ids and -display names; two of them are org required checks and the third is this repo's -required CI check: - -| Job id | `name:` | What to change | -|---|---|---| -| `build-and-test` | `build-and-test` | Replace the *Install tools*, *Lint shell scripts* and *Run bats tests* steps with your stack's lint, format check, type check and unit tests. | -| `secret-scan` | `Secret scan (gitleaks)` | Nothing. | -| `coverage` | `coverage` | Replace the shell/bats block with your stack's coverage command (examples are in the file's trailing comment). It must stay green when no tests exist yet. | - -Do **not** change: the workflow `name: CI` (`pr-auto-review.yml` waits on that -name), the triggers, `permissions: {}` at top level with `contents: read` per -job, the `concurrency` block, or `timeout-minutes` on every job. SHA-pin every -third-party action (`uses: owner/action@<40-char sha> # vX.Y.Z`). Keep the -retry-with-increasing-backoff pattern for any network install step; the Fleet -Monitor flags flaky installs. - -Stack patterns: -[`ci-standards.md` → Workflow Patterns by Tech Stack](https://github.com/combsmith/.github/blob/main/standards/ci-standards.md#workflow-patterns-by-tech-stack). -Those patterns show `@vN` tags; the SHA-pinned equivalents for `setup-node`, -`pnpm/action-setup`, `setup-go` and `setup-python` are already in the comment -blocks of `copilot-setup-steps.yml`. To pin any other action, resolve the tag -yourself and record the tag in the trailing comment: - -```bash -gh api repos///git/ref/tags/ --jq '.object | "\(.type) \(.sha)"' -# type "commit" → use the sha. type "tag" (annotated) → dereference once more: -gh api repos///git/tags/ --jq '.object.sha' -``` - -Stack notes from the validation run: - -- **Coverage guard.** When the stack has no tests yet, let the test runner - decide (`python -m pytest --collect-only -q`, `npm test -- --listTests`, …) - rather than globbing filenames, so both `test_*.py` and `*_test.py` styles - count. Treat only the runner's documented "no tests collected" result as the - green-until-tests case and propagate every other exit code. For pytest that - result is exit status 5: - - ```bash - rc=0 - python -m pytest --collect-only -q >/dev/null 2>&1 || rc=$? # `|| rc=$?` keeps bash -e from aborting on exit 5 - if [ "$rc" -eq 5 ]; then echo "No tests found — coverage is green until tests exist."; exit 0; fi - [ "$rc" -eq 0 ] || exit "$rc" - python -m pytest -q --cov=src --cov-report=term --cov-report=xml - ``` -- **Python.** `ruff format --check .` also formats Python code blocks inside - Markdown, including the copied `.github/instructions/python.instructions.md`. - Either run `ruff format` once over the repo before committing, or add - `extend-exclude = [".github/instructions"]` under `[tool.ruff]`. - -Check: the file still parses as YAML (same parser options as step 2), and both -the job ids and the display names are intact (each command prints `3`): - -```bash -grep -cE '^ (build-and-test|secret-scan|coverage):$' .github/workflows/ci.yml -grep -cE '^ name: (build-and-test|Secret scan \(gitleaks\)|coverage)$' .github/workflows/ci.yml -``` - ---- - -## 4. `copilot-setup-steps.yml` — enable your stack block - -In `.github/workflows/copilot-setup-steps.yml`, uncomment the block(s) matching -`STACK` (Node/npm, Node/pnpm, Go, Python) and **delete** the blocks that do not -apply. Do not touch the job name, the fork guard, the triggers, or the -*Verify environment* step. For `STACK=none`, leave the file as shipped. - ---- - -## 5. `feature-ideation.yml` — set `project_context` - -Replace the `TODO:`/`Example:` placeholder under `project_context:` with -`PROJECT_CONTEXT`. This is the only edit allowed in that file; the compliance -audit raises `feature-ideation-placeholder-context` until it is done. - -Check: `! grep -q 'TODO: Replace this' .github/workflows/feature-ideation.yml` exits 0. - ---- - -## 6. `sonar-project.properties` — set the project key - -Set the values as follows. Java properties files only treat `#` as a comment -at the start of a line: a trailing `# note` after a value becomes part of the -value, so do not annotate the lines themselves. - -- `sonar.projectKey` — `REPO` with `/` replaced by `_` (`combsmith_`). -- `sonar.sources` — the source directories, e.g. `src`, or `.` for small repos. -- `sonar.tests` — the test directory; omit the line if there are no tests yet. - -```properties -sonar.projectKey=combsmith_ -sonar.organization=combsmith -sonar.sources= -sonar.tests= -sonar.exclusions=**/node_modules/**,**/vendor/**,**/dist/** -``` - -Remove the two "Customize…" comment lines at the top. SonarCloud is enabled -org-wide; no console step is needed for a public repo. - ---- - -## 7. Docs and per-repo config - -1. **`README.md`** — replace everything above the `---` rule with the project's - own title, `DESCRIPTION`, quick start and usage. **Keep the - `## 💼 Commercial Support & Enterprise Services` section verbatim**; it is - org-standard text. -2. **`AGENTS.md`** — keep the org-standards pointer paragraph. Replace the - template-specific sections with this repo's: project overview and - architecture, `## Local Development Commands`, `## Required Environment - Variables`, testing approach and coverage threshold, code style. The two - `##` headings named here are mandatory per the org `AGENTS.md`. -3. **`.github/copilot-instructions.md`** — rewrite for this repo following the - required sections in - [`copilot-instructions-standard.md`](https://github.com/combsmith/.github/blob/main/standards/copilot-instructions-standard.md) - (About, Tech Stack, Project Structure, Local Dev Commands, Required - Environment Variables, Testing Framework, Repo-Specific Overrides, Org - Standards). Keep it to about two pages. -4. **`.github/instructions/`** — for each language in `STACK`, copy the - canonical path-scoped file and list it under `## Org Standards` in - `copilot-instructions.md`. The language list follows from `STACK`; add - `shell` whenever the repo has shell scripts of its own, whatever the stack, - and `python` for a `fullstack` repo that has Python code (the same repos - that add the `pip` Dependabot block in step 2). The canonical repo has no - Rust file, so `STACK=backend-rust` gets no language-specific instruction - file: - - | `STACK` | Languages | - |---|---| - | `frontend` | `typescript javascript` | - | `backend-go` | `go` | - | `backend-python` | `python` | - | `backend-rust` | none | - | `infra-terraform` | `terraform` | - | `fullstack` | `typescript javascript go terraform`, plus `python` when the repo has Python code | - | `none` | none | - - ```bash - set -o pipefail - mkdir -p .github/instructions - case "$STACK" in - frontend) langs="typescript javascript" ;; - backend-go) langs="go" ;; - backend-python) langs="python" ;; - infra-terraform) langs="terraform" ;; - fullstack) langs="typescript javascript go terraform" ;; - backend-rust|none) langs="" ;; - *) echo "unknown STACK: $STACK" >&2; exit 1 ;; - esac - if find . -path ./.git -prune -o -name '*.sh' -print -quit | grep -q .; then - langs="$langs shell" - fi - if [ "$STACK" = fullstack ] \ - && find . -path ./.git -prune -o -name '*.py' -print -quit | grep -q .; then - langs="$langs python" - fi - for lang in $langs; do - gh api repos/combsmith/.github/contents/.github/instructions/${lang}.instructions.md \ - --jq '.content' | base64 -d > .github/instructions/${lang}.instructions.md \ - && [ -s .github/instructions/${lang}.instructions.md ] - done - ``` - -5. **`.gitignore`** — append the matching - [github/gitignore](https://github.com/github/gitignore) template **below** - the `<<< END combsmith secrets baseline <<<` marker. Never re-ignore a path - the baseline negates (`!.env.example`, `!*.crt`, `!*.pub`, `!*.enc.yaml`). -6. **`.worktreeinclude`** (optional) — list gitignored files agents need copied - into worktrees, typically `.env` and `.env.local`. -7. **`.gitleaks.toml`** — append allowlist paths only for real false positives - (test fixtures, generated keys). Keep the `_bmad/` entry. - -Check: no template placeholder text survives. The patterns below are the -template's own wording, so a project that legitimately mentions -`repo-template` (for example in a provenance line) still passes. `grep` exits -`1` for "no match" and `2` for an error such as a missing file; only `1` is a -pass, so a negated `! grep -q …` would silently pass when a listed file is -absent. Branch on the exit code instead: - -```bash -rc=0 -grep -E 'Org baseline scaffold|combsmith_repo-template|Copilot Instructions — repo-template|What this repository is' \ - README.md AGENTS.md .github/copilot-instructions.md sonar-project.properties || rc=$? -case "$rc" in - 1) echo "OK: no template placeholder text" ;; - 0) echo "FAIL: template placeholder text survives (matches above)" >&2; exit 1 ;; - *) echo "ERROR: grep exited $rc — a listed file is missing or unreadable" >&2; exit "$rc" ;; -esac -``` - ---- - -## 8. Remove template-only files; install BMAD if a product repo - -Every template Bats file other than `tests/ci-*.bats` (the `*-stub.bats` -guards, `gitignore-baseline.bats`, `pr-quality-ruleset.bats`, -`dependabot-github-actions-ecosystem.bats`, `pr-auto-review-concurrency.bats`) -tests the template, not the project, and goes in every repo. Derive the set -from the directory rather than naming files, so nothing is left behind: - -```bash -find tests -maxdepth 1 -name '*.bats' ! -name 'ci-*.bats' -exec git rm {} + -git rm -r standards -``` - -The `tests/ci-*.bats` files guard the template's shell `ci.yml` and go too, -with one exception: a `STACK=none` repo whose code is itself shell scripts -tested with Bats may keep individual `tests/ci-*.bats` files as a starting -point. For every other repo: - -```bash -git rm tests/ci-*.bats -``` - -Remove only the Bats files, not the `tests/` directory: your own test suite -(`tests/test_*.py`, `tests/*.test.ts`, …) may already live there or will. - -If `BMAD=yes`, install the BMAD Method (org standard for product repos: -spec-driven development, planning artifacts in `_bmad-output/`): - -```bash -npx bmad-method install -``` - -`_bmad/` is already allowlisted in `.gitleaks.toml`. Commit the generated files. - ---- - -## 9. Org-admin steps (human; the agent cannot do these) - -Report these to the maintainer as the hand-off. None of them require code changes. - -| # | Action | Command / where | -|---|---|---| -| 1 | Apply repo settings, GHAS + push protection, the `pr-quality` and `code-quality` rulesets, the standard label set, CODEOWNERS verification, and confirm the release ring. | In a checkout of `combsmith/.github`: `DRY_RUN=true bash scripts/bootstrap-new-repo.sh REPO`, review, then `bash scripts/bootstrap-new-repo.sh REPO`. Needs a classic PAT with `repo` + `admin:org`. | -| 2 | Set the repo description and topics; enable Discussions and create the **Ideas** (💡) and **General** (💬) categories. | `gh repo edit REPO --description "DESCRIPTION"`; categories via Settings → Discussions (no REST API). | -| 3 | Add the new repo to the advisory review bots' per-repo lists. | Gemini Code Assist: Google Cloud → Developer Connect (`code-assist-`, `us-east1`) → Link Repositories. Codex: ChatGPT Codex connector settings. Verify with a throwaway PR and `/gemini review`. CodeRabbit and SonarCloud need no per-repo step. | -| 4 | Confirm CodeQL default setup is `configured` (the org security configuration applies it at creation; step 1 re-asserts it). | `gh api repos/REPO/code-scanning/default-setup --jq .state` | -| 5 | Grant the new repo access to the **selected-visibility** org secrets `INITIATIVES_APP_ID` and `INITIATIVES_APP_PRIVATE_KEY` (the `combsmith-planner` app), and make sure that app's installation includes the repo. Until then every `add-to-project` run fails with `The 'client-id' … must be set to a non-empty string` (observed on the validation run). | Org settings → Secrets and variables → Actions → each secret → Repository access; or `gh api -X PUT orgs/combsmith/actions/secrets/INITIATIVES_APP_ID/repositories/` (same for the private key). | - -All other org secrets the stubs use (`SONAR_TOKEN`, `APP_ID`/`APP_PRIVATE_KEY`, -`GH_PAT_WORKFLOWS`, `CLAUDE_CODE_OAUTH_TOKEN`) have **all-repositories** -visibility and need nothing per repo. The Claude and CodeRabbit GitHub Apps are -installed org-wide. `DRY_RUN=true` for item 1 was verified to print the full plan -and `PASS` with a plain `gh auth token`; the real run needs the classic PAT -because the CodeQL and check-suite-preference reads return 404 otherwise. - ---- - -## 10. Done criteria - -- [ ] `.github/dependabot.yml` is the `STACK` file (or `frontend` for `none`). -- [ ] `ci.yml` runs the stack's lint / format / typecheck / tests / coverage; jobs `build-and-test`, `Secret scan (gitleaks)`, `coverage` still exist; workflow is still named `CI`. -- [ ] `copilot-setup-steps.yml` has exactly the stack block(s) enabled. -- [ ] `feature-ideation.yml` carries a real `project_context`. -- [ ] `sonar-project.properties` names `combsmith_`. -- [ ] `README.md`, `AGENTS.md`, `copilot-instructions.md` describe this repo; language instruction files copied and listed. -- [ ] `tests/*.bats` and `standards/` removed (step 8 exception aside). -- [ ] No stub listed under *Keep verbatim* has a diff. -- [ ] The bootstrap PR is green on `build-and-test`, `Secret scan (gitleaks)`, `coverage`, `SonarCloud`, `CodeQL`, `agent-shield / AgentShield`, `dependency-audit / Detect ecosystems`, and on the stack's own audit job (`dependency-audit / pip-audit`, `npm audit`, `govulncheck` or `cargo audit`). `dev-lead / *` jobs showing *cancelled* is normal: a burst of review events collapses them onto the newest run. -- [ ] Hand-off message to the maintainer lists the five org-admin actions in step 9, and says `add-to-project` will stay red until item 5 is done. -- [ ] Last action: `git rm BOOTSTRAP.md` and commit, once every item above is checked. - ---- - -## Why the template looks the way it does - -- **Stubs are a distribution artifact.** Everything under *Keep verbatim* is - regenerated from [`combsmith/.github`](https://github.com/combsmith/.github) - `standards/` by `seed-repo-template.sh` (in `combsmith/.github-private`) and - kept in sync in every repo by `deploy-standard-workflows.sh`. Fix the - standard, not the copy. -- **Framework subtrees (`frameworks/`) are not seeded.** `bmad-method`, - `spec-kit` and `gsd` are `git subtree` tooling maintained in - `combsmith/.github-private`; add one on demand with `git subtree add`. -- **App installs are org-level.** The bootstrap script only disables the - Claude/CodeRabbit check-suite auto-trigger on the new repo so queued-but-never- - completed suites cannot block auto-merge. - -Standards index: [`combsmith/.github/AGENTS.md`](https://github.com/combsmith/.github/blob/main/AGENTS.md). diff --git a/README.md b/README.md index e1a5424..3ae484e 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,32 @@ -# repo-template - -Org baseline scaffold for new `combsmith` repositories. Click **Use this -template** to create a repo pre-wired with the standard workflow stubs and -baseline files, then hand the new repo to an agent with: - -> Follow `BOOTSTRAP.md` to bootstrap this repo. Stack: ` backend-python | backend-rust | fullstack | infra-terraform | none>`. -> Description: ``. Project context: `<3–5 sentences>`. - -**[BOOTSTRAP.md](./BOOTSTRAP.md)** is the agent-executable runbook: the inputs -to collect, what to do with every shipped file (keep / customize / delete), the -verification checks, and the short list of org-admin steps a human finishes. - -## What you get on day 0 - -| Area | Shipped | Status in a new repo | -|---|---|---| -| Thin-caller workflow stubs (dev-lead, pr-auto-review, pr-review-mention, persona-mention, dependabot-automerge/rebase, dependency-audit, agent-shield, auto-rebase, add-to-project, initiative-driver, feature-ideation) | `.github/workflows/` | Working as-is; `feature-ideation.yml` needs its `project_context` set | -| CI (`build-and-test`, `Secret scan (gitleaks)`, `coverage`) and SonarCloud | `ci.yml`, `sonarcloud.yml` | Green out of the box; replace the shell steps with your stack's | -| Copilot cloud-agent setup | `copilot-setup-steps.yml` | Uncomment your stack block | -| Dependabot | `.github/dependabot.yml` | `frontend` stack by default; swap for yours | -| Baseline files | `CODEOWNERS`, `AGENTS.md`, `CLAUDE.md`, `SECURITY.md`, `LICENSE`, `.gitignore` (secrets baseline), `.gitleaks.toml`, `sonar-project.properties`, `copilot-instructions.md` | Docs and Sonar key need the project's name | -| Repo settings, rulesets, labels, GHAS | not files | Applied by `bootstrap-new-repo.sh` in `combsmith/.github` (org admin) | -| Initiatives board (`add-to-project`) | stub only | Red until an org admin both grants the repo the `INITIATIVES_APP_*` org secrets (selected visibility) and adds it to the `combsmith-planner` app installation | - -The workflow stubs and baseline files here are a distribution artifact of the org -standards in [`combsmith/.github`](https://github.com/combsmith/.github) -(`standards/`) and are regenerated from it — edit the standards, not this copy. -`tests/` holds the bats guards that keep this template byte-aligned with those -standards; they are template-only and are removed during bootstrap. +# WorldChest + +Automatic backup, sync, restore and versioning for Minecraft Bedrock worlds, so +a kid's worlds survive a new phone, a cracked screen or a bad update, and can be +rewound to an earlier save without any technical work. + +> NOT AN OFFICIAL MINECRAFT PRODUCT. NOT APPROVED BY OR ASSOCIATED WITH MOJANG +> OR MICROSOFT. "Minecraft" is used only as a secondary title, never in the +> brand, domain, handles or packages, per the Minecraft Usage Guidelines. + +**Status:** pre-code. The product brief, evidence and open questions live in +[combsmith/incubator discussion #5](https://github.com/combsmith/incubator/discussions/5) +(working name BlockVault; brand decision 2026-10-19: WorldChest, `worldchest.app`). +The stack is not chosen yet; CI runs the org baseline checks until it is. + +## What it will do + +- **Backup** a device's whole local world library to the cloud, integrity-verified. +- **Restore** every world onto a new device with no cables and no corruption + (the naive Smart Switch path crashes the game; the in-scope file set is known). +- **Version** saves so a player can rewind. +- **Tiered device access:** `.mcworld` share-sheet baseline for everyone, Shizuku + (ADB, no root) power mode for automatic full-library backup, a desktop companion + for big migrations, and the official Mojang API as the long-term goal. + +## Working here + +Read [`AGENTS.md`](./AGENTS.md) first. Frameworks such as BMAD are vendored from +`combsmith/.github-private` or `software-factory`, never installed per repo. --- diff --git a/sonar-project.properties b/sonar-project.properties index 9cd2434..4c9a8a6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,3 @@ -# Customize sonar.projectKey / sonar.organization for this repo before enabling -# the sonarcloud workflow. See BOOTSTRAP.md. -sonar.projectKey=combsmith_repo-template -sonar.organization=combsmith +# Project key / organization are derived from the repo by .github/workflows/sonarcloud.yml. sonar.sources=. -sonar.exclusions=**/node_modules/**,**/vendor/**,**/dist/** \ No newline at end of file +sonar.exclusions=**/node_modules/**,**/vendor/**,**/dist/** diff --git a/standards/rulesets/pr-quality.json b/standards/rulesets/pr-quality.json deleted file mode 100644 index 35d6d0e..0000000 --- a/standards/rulesets/pr-quality.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "pr-quality", - "target": "branch", - "enforcement": "active", - "bypass_actors": [ - { - "actor_type": "OrganizationAdmin", - "bypass_mode": "always" - }, - { - "actor_id": 3167543, - "actor_type": "Integration", - "bypass_mode": "always" - } - ], - "conditions": { - "ref_name": { - "include": ["~DEFAULT_BRANCH"], - "exclude": [] - } - }, - "rules": [ - { - "type": "pull_request", - "parameters": { - "required_approving_review_count": 1, - "require_code_owner_review": true, - "required_review_thread_resolution": true, - "dismiss_stale_reviews_on_push": true, - "require_last_push_approval": true, - "allowed_merge_methods": ["squash"] - } - } - ] -} diff --git a/tests/agent-shield-stub.bats b/tests/agent-shield-stub.bats deleted file mode 100644 index 5873ae8..0000000 --- a/tests/agent-shield-stub.bats +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the agent-shield thin caller stub. -# -# .github/workflows/agent-shield.yml is copied VERBATIM from the canonical -# org template (combsmith/.github → standards/workflows/agent-shield.yml) -# and must stay byte-identical across every adopting repo, modulo the per-repo -# channel pin on the `uses:` ref. Any other diff is drift — the silent-revert -# class of failure the fleet stub-drift monitor exists to catch (fleet_stub_drift.sh). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger events, and top-level `permissions:` block are drift-protected and -# MUST NOT be edited in the caller (see the file's own "AGENTS — READ BEFORE -# EDITING" banner and ci-standards.md → Centralization tiers). In particular the -# ref MUST be pinned to the major-scoped `agent-shield/v2-stable` channel: a bare -# `agent-shield/stable` tier pin is drift (compliance check non-stub-agent-shield.yml). -# This guard pins those invariants so drift is caught in CI rather than in -# production run health. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/agent-shield.yml" - -@test "agent-shield stub exists" { - [ -f "$STUB" ] -} - -@test "agent-shield stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/agent-shield.yml) changes. - local canon - canon="$(mktemp)" - # The committed stub has NO trailing newline, so emit the heredoc with its - # trailing newline stripped (printf '%s') to stay byte-faithful to the - # committed, production stub that the fleet stub-drift monitor compares SHAs against. - printf '%s' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/agent-shield.yml -# Standard: combsmith/.github/standards/agent-standards.md -# Reusable: combsmith/.github/.github/workflows/agent-shield-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. The AgentShield CLI scan and the -# org-specific structural checks live in the reusable workflow above. -# • You MAY change: the `with:` inputs (min-severity, agentshield-version, -# required-files, org-standards-ref) — only if your repo genuinely needs -# a different policy. -# • You MUST NOT change: trigger events, the `uses:` line, or the job name -# (used as a required status check). NOTE: `merge_group` is part of the -# standard trigger set — it is required so this stub's `agent-shield / -# AgentShield` check reports on a merge queue's `gh-readonly-queue/*` ref -# (see standards/ci-standards.md). Do not drop it on sync and do not flag it -# as drift. -# • If you need different behaviour beyond the inputs, open a PR against -# the reusable in the central repo. -# ───────────────────────────────────────────────────────────────────────────── -# -# AgentShield — thin caller for the org-level reusable. -# To adopt: copy this file to .github/workflows/agent-shield.yml in your repo. -name: AgentShield - -on: - push: - branches: [main] - pull_request: - branches: [main] - merge_group: - -permissions: - contents: read - -jobs: - agent-shield: - uses: combsmith/.github/.github/workflows/agent-shield-reusable.yml@agent-shield/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref -CANONICAL -)" > "$canon" - run diff -u "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical:" - echo "$output" - return 1 - } -} - -@test "uses: ref is pinned to the agent-shield/v2-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/agent-shield-reusable.yml@agent-shield/v2-stable' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'agent-shield-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9]+([[:space:]#]|$))' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the agent-shield/v2-stable channel." >&2 - return 1 - fi -} - -@test "uses: ref is not pinned to the bare agent-shield/stable tier" { - # A bare `@agent-shield/stable` tier pin is drift — the ref must be scoped to a - # major channel `@agent-shield/v-stable` (compliance check non-stub-agent-shield.yml). - if grep -qE 'agent-shield-reusable\.yml@agent-shield/stable' "$STUB"; then - echo "Error: The uses: ref in $STUB is pinned to the bare agent-shield/stable tier." >&2 - echo "It must be pinned to the major-scoped agent-shield/v2-stable channel." >&2 - return 1 - fi -} - -@test "both trigger events are present" { - grep -qE '^ push:' "$STUB" || { echo "Missing push trigger"; return 1; } - grep -qE '^ pull_request:' "$STUB" || { echo "Missing pull_request trigger"; return 1; } -} - -@test "top-level permissions are locked down to contents: read" { - grep -qE '^permissions:' "$STUB" || { echo "Missing top-level permissions block"; return 1; } - grep -qE '^ contents: read$' "$STUB" || { echo "Top-level permissions must grant contents: read only"; return 1; } -} diff --git a/tests/auto-rebase-stub.bats b/tests/auto-rebase-stub.bats deleted file mode 100644 index 69fdc98..0000000 --- a/tests/auto-rebase-stub.bats +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the auto-rebase thin caller stub. -# -# .github/workflows/auto-rebase.yml is copied VERBATIM from the canonical org -# template (combsmith/.github → standards/workflows/auto-rebase.yml) and must -# stay byte-identical across every adopting repo. The `uses:` ref is pinned to the -# `auto-rebase/v2-stable` channel — the only permitted channel; never repoint it to -# a bare `auto-rebase/stable`, @main, a SHA, or a frozen @vN. Any other diff is -# drift — the silent-revert class of failure the fleet stub-drift monitor exists to -# catch (fleet_stub_drift.sh). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger events, concurrency group, job `permissions:` block, and -# `secrets: inherit` stanza are drift-protected and MUST NOT be edited in the -# caller (see the file's own "AGENTS — READ BEFORE EDITING" banner and -# ci-standards.md → Reusable workflow versioning). -# -# The reusable requires `secrets: inherit` so GITHUB_TOKEN and any org secrets -# are forwarded automatically (S7635 suppressed with NOSONAR — first-party -# trusted reusable). - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/auto-rebase.yml" - -@test "auto-rebase stub exists" { - [ -f "$STUB" ] -} - -@test "uses: ref is pinned to the auto-rebase/v2-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/auto-rebase-reusable.yml@auto-rebase/v2-stable' "$STUB" -} - -@test "uses: ref is not repointed to bare stable, @main, a SHA, or a frozen @vN" { - if grep -qE 'auto-rebase-reusable\.yml@(auto-rebase/stable([^/]|$)|main|[0-9a-f]{7,40}|v[0-9]+)' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (bare stable, main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the auto-rebase/v2-stable channel." >&2 - return 1 - fi -} - -@test "trigger events (push to main + workflow_dispatch) are present" { - grep -qE '^ push:' "$STUB" || { echo "Missing push trigger"; return 1; } - grep -qE '^ workflow_dispatch:' "$STUB" || { echo "Missing workflow_dispatch trigger"; return 1; } -} - -@test "concurrency group is auto-rebase with cancel-in-progress off" { - grep -qE '^ group: auto-rebase$' "$STUB" || { echo "Wrong/missing concurrency group"; return 1; } - grep -qE '^ cancel-in-progress: false$' "$STUB" || { echo "cancel-in-progress must be false"; return 1; } -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly contents: write + pull-requests: write" { - grep -qE '^ contents: write' "$STUB" || { echo "Missing contents: write permission"; return 1; } - grep -qE '^ pull-requests: write' "$STUB" || { echo "Missing pull-requests: write permission"; return 1; } -} - -@test "stub uses secrets: inherit (first-party trusted reusable)" { - grep -qE '^ secrets:[[:space:]]+inherit' "$STUB" || { - echo "Error: $STUB must use 'secrets: inherit' — the reusable is a first-party trusted workflow." >&2 - return 1 - } -} - -@test "auto-rebase stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central - # template (combsmith/.github/standards/workflows/auto-rebase.yml) changes. - # The committed stub has NO trailing newline, so capture via command - # substitution (strips trailing newlines) + printf '%s' (adds none) to stay - # byte-faithful to the committed production stub. - local canon - canon="$(mktemp)" - printf '%s' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/auto-rebase.yml -# Standard: combsmith/.github/standards/ci-standards.md -# Reusable: combsmith/.github/.github/workflows/auto-rebase-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All branch-update logic lives in the -# reusable workflow above. -# • You MUST NOT change: the `uses:` ref — it is pinned to the -# `auto-rebase/v2-stable` channel, a moving tag advanced centrally. Never -# repoint it to `@main`, a SHA, or a frozen `@vX` (see ci-standards.md → -# Reusable workflow versioning). Also do not change the trigger event, -# the concurrency group name, -# or the job-level `permissions:` block — reusable workflows can be -# granted no more permissions than the calling job has, so removing -# the stanza breaks the reusable's gh API calls. -# • If you need different behaviour, open a PR against the reusable in the -# central repo. -# ───────────────────────────────────────────────────────────────────────────── -# -# Auto-rebase non-Dependabot PRs — thin caller for the org-level reusable. -# To adopt: copy this file to .github/workflows/auto-rebase.yml in your repo. -# No secrets required — uses GITHUB_TOKEN only. -# -# By default the reusable updates *every* behind PR (`eligibility: all`). The -# `eligibility` input is a tunable extension point for future modes; to select -# one, pass it to the reusable, e.g.: -# -# with: -# eligibility: all # default — update every behind PR -# -name: Auto-rebase non-Dependabot PRs - -on: - push: - branches: - - main - workflow_dispatch: - -concurrency: - group: auto-rebase - cancel-in-progress: false - -permissions: {} - -jobs: - auto-rebase: - permissions: - contents: write # update-branch via GITHUB_TOKEN (may touch .github/workflows/) - pull-requests: write # post comments on PRs - uses: combsmith/.github/.github/workflows/auto-rebase-reusable.yml@auto-rebase/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref - secrets: inherit # NOSONAR(githubactions:S7635) first-party trusted reusable -CANONICAL -)" > "$canon" - run diff -u -- "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical: $output" - return 1 - } -} diff --git a/tests/ci-apt-retry.bats b/tests/ci-apt-retry.bats deleted file mode 100644 index 0f8e41c..0000000 --- a/tests/ci-apt-retry.bats +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml apt-install reliability (issue #155). -# -# Issue #152 removed the uninstallable `kcov` package and added an `apt-get update` -# before `apt-get install` so a stale package index could not turn a bats install -# into a hard failure. It did NOT make apt resilient to *transient* failures: -# `apt-get update` / `apt-get install` still ran exactly once, so a single network -# hiccup (temporary DNS failure, hash-sum mismatch, a briefly-unavailable mirror) -# hard-fails the whole job on the first attempt — the same install surface that -# produced the #152 `kcov` failures. -# -# This guard pins the fix: every job that installs packages via apt must wrap the -# install in a bounded retry loop with a backoff, so a transient failure is retried -# instead of failing the run. It complements ci-runner-setup.bats (which pins the -# update-before-install ordering and the kcov ban). - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Print the body of a top-level job block — from ` :` up to the next -# top-level job key — so an assertion can be scoped to a single job. -job_block() { - awk -v job="$1" ' - $0 ~ "^ " job ":[[:space:]]*(#.*)?$" { f = 1; print; next } - f && (/^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ || /^[A-Za-z]/) { f = 0 } - f { print } - ' "$CI_YML" -} - -# First line number (within a job block) matching a regex, or empty if none. -first_line() { - printf '%s\n' "$1" | grep -nE "$2" | head -1 | cut -d: -f1 -} - -# Assert that a single job block wraps its apt install in a bounded retry loop. -assert_apt_install_is_retried() { - local job="$1" block - block="$(job_block "$job")" - - # Locate the retry-loop opener as a whole word so that one-liner loops - # (e.g. `for i in {1..5}; do ... || sleep 5; done`) are also matched. - local loop_line - loop_line="$(first_line "$block" '([[:space:]]|^)(for|while|until)[[:space:]]')" - [ -n "$loop_line" ] || { echo "$job: apt install is not wrapped in a retry loop"; return 1; } - - # Find the `done` that closes the loop so assertions can be scoped to its body. - local done_line - done_line="$(printf '%s\n' "$block" | awk -v lo="$loop_line" ' - NR > lo && /^[[:space:]]*done([[:space:]]|$)/ { print NR; exit } - ')" - [ -n "$done_line" ] || { echo "$job: retry loop has no closing done"; return 1; } - - # Extract the bounded retry-loop body and the lines that follow it. - local loop_body after_loop - loop_body="$(printf '%s\n' "$block" | awk -v lo="$loop_line" -v hi="$done_line" 'NR >= lo && NR <= hi')" - after_loop="$(printf '%s\n' "$block" | awk -v lo="$done_line" 'NR > lo')" - - # The loop must be bounded to three attempts. - printf '%s\n' "$loop_body" | grep -qE 'in[[:space:]]+(1[[:space:]]+2[[:space:]]+3|\{1\.\.3\})' \ - || { echo "$job: retry loop is not bounded to 3 attempts"; return 1; } - - # apt update and apt install must both appear inside the loop body (preserves - # the #152 fix that update must precede install, now scoped to the loop). - local update_line install_line - update_line="$(first_line "$loop_body" 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+update')" - install_line="$(first_line "$loop_body" 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+install')" - [ -n "$update_line" ] || { echo "$job: apt update not found inside the retry loop"; return 1; } - [ -n "$install_line" ] || { echo "$job: apt install not found inside the retry loop"; return 1; } - [ "$update_line" -lt "$install_line" ] || { echo "$job: apt update must precede install inside the loop"; return 1; } - - # A backoff sleep must appear inside the loop body (matched as a word so - # mid-line occurrences like `... || sleep 5; done` are also caught). - local sleep_line - sleep_line="$(first_line "$loop_body" '([[:space:]]|^)sleep[[:space:]]')" - [ -n "$sleep_line" ] || { echo "$job: retry loop has no backoff sleep"; return 1; } - - # A post-loop failure gate (`command -v`) must exist after the closing done - # so an exhausted retry loop fails loudly rather than continuing silently. - printf '%s\n' "$after_loop" | grep -qE 'command[[:space:]]+-v' \ - || { echo "$job: no post-loop command -v failure check after the retry loop"; return 1; } -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "build-and-test retries its apt package install" { - assert_apt_install_is_retried build-and-test -} - -@test "coverage retries its apt package install" { - assert_apt_install_is_retried coverage -} - -@test "no apt-using job installs the uninstallable kcov package" { - # Reinforce the #152 invariant at the same time we harden the install: a retry - # loop must never sit atop a package that can never resolve. - ! grep -qE 'apt(-get)?[[:space:]]+install.*[[:space:]]kcov([[:space:]]|$)' "$CI_YML" -} diff --git a/tests/ci-concurrency-cancellation.bats b/tests/ci-concurrency-cancellation.bats deleted file mode 100644 index 618d9f5..0000000 --- a/tests/ci-concurrency-cancellation.bats +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml concurrency scoping (issue #208). -# -# The org CI standard now mandates SHA-scoped concurrency. Source of truth: -# combsmith/.github standards/ci-standards.md §1 ("Why SHA-scoped -# concurrency?") and standards/workflows/ci.yml, which require: -# -# concurrency: -# group: ci-${{ github.ref }}-${{ github.sha }} -# cancel-in-progress: true -# -# A per-ref-only group (`ci-${{ github.ref }}`) with `cancel-in-progress: true` -# creates a race: when the final push arrives while the previous cancellation is -# still in flight, GitHub may not fire a new `pull_request: synchronize` event, -# leaving the HEAD commit with no CI results and blocking the PR indefinitely -# (issue #208). Scoping the group to `github.sha` gives every commit its own -# concurrency slot so CI always runs to completion on HEAD. -# -# `cancel-in-progress: true` is retained: with SHA-scoped groups no two pushes -# share a slot, so it is effectively a no-op, but it is kept to declare intent — -# if the group formula is ever changed back to a per-ref pattern, the intended -# cancellation behaviour takes effect immediately without a separate edit. -# -# NOTE (policy history): an earlier remediation (#201) keyed the group by ref -# *only* and forbade github.sha. The org standard has since reversed that -# decision to fix the #208 race; this guard now pins the current standard. -# -# This guard pins the fix: ci.yml's concurrency group must be keyed by both -# github.ref and github.sha, and cancel-in-progress must stay true. - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Print the top-level `concurrency:` block — from the `concurrency:` line up to the -# next top-level (column-0) key — so assertions are scoped to it. Comment lines are -# dropped so a commented-out key can never satisfy a guard. -concurrency_block() { - awk ' - /^concurrency:[[:space:]]*(#.*)?$/ { f = 1; print; next } - f && /^[A-Za-z]/ { f = 0 } - f { print } - ' "$CI_YML" | grep -v '^[[:space:]]*#' -} - -# The value of the concurrency `group:` key (everything after `group:`), or empty. -# An inline YAML comment (` # …`) is stripped so comment text can never satisfy a -# guard — e.g. `group: ci-static # github.ref is required` must NOT pass the -# github.ref check on the strength of the comment alone. -group_value() { - concurrency_block | grep -E '^[[:space:]]+group:' | head -1 \ - | sed -E 's/^[[:space:]]+group:[[:space:]]*//; s/[[:space:]]+#.*$//; s/[[:space:]]+$//' -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "ci.yml declares a top-level concurrency block" { - grep -qE '^concurrency:[[:space:]]*(#.*)?$' "$CI_YML" -} - -@test "concurrency block defines a group" { - local group - group="$(group_value)" - [ -n "$group" ] || { echo "ci.yml concurrency has no 'group:' key"; return 1; } -} - -@test "concurrency group is keyed by github.ref" { - local group - group="$(group_value)" - printf '%s\n' "$group" | grep -qE 'github\.ref' \ - || { echo "concurrency group must be keyed by github.ref so pushes to a ref share a group: $group"; return 1; } -} - -@test "concurrency group embeds github.sha (gives every commit its own slot)" { - local group - group="$(group_value)" - # A sha in the group gives every commit a unique slot so a burst of pushes never - # leaves HEAD with no CI results via a dropped synchronize event (issue #208). - # Require the full `${{ github.sha }}` expression, not just the literal text - # `github.sha`, so a group that omits the expression wrapper (e.g. - # `ci-github.ref-github.sha`) cannot pass while failing to interpolate at runtime. - # Literal `[{][{]`/`[}][}]` character classes with basic grep avoid GNU grep 3.8+ - # stray-backslash warnings, and `[[:space:]]` keeps the pattern POSIX-portable. - printf '%s\n' "$group" | grep -q '[$][{][{][[:space:]]*github\.sha[[:space:]]*[}][}]' \ - || { echo "concurrency group must contain the github.sha expression (e.g. \${{ github.sha }}): $group"; return 1; } -} - -@test "cancel-in-progress is enabled so a new push supersedes the stale run" { - # Accept an optionally quoted `true` and tolerate a trailing inline comment so a - # valid config (`cancel-in-progress: "true" # …`) is not a false negative. - concurrency_block | grep -qE '^[[:space:]]+cancel-in-progress:[[:space:]]*(true|"true"|'\''true'\'')([[:space:]]*|[[:space:]]+#.*)$' \ - || { echo "concurrency must set cancel-in-progress: true"; return 1; } -} diff --git a/tests/ci-job-timeout.bats b/tests/ci-job-timeout.bats deleted file mode 100644 index 772a883..0000000 --- a/tests/ci-job-timeout.bats +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml job-timeout reliability (issue #169). -# -# The CI workflow failed at ~60% across the monitored window with a p50 of 20s but -# a p95 of 404s — the classic bimodal "normal vs. stalled" signature. Prior -# remediations hardened the *retry* surface (#152 stale apt index, #155 transient -# apt install retry, #163 gitleaks download retry) but every job could still hang -# for GitHub's 360-minute default when a network operation stalls without ever -# returning (apt/curl/checkout wedged on a bad mirror or DNS) — a retry loop never -# advances while its command is blocked. An un-bounded hang inflates p95, ties up a -# runner, and ultimately counts against the workflow's failure rate. -# -# This guard pins the fix: every runner job in ci.yml must declare a bounded -# `timeout-minutes` so a stalled run fails fast instead of consuming the full -# default budget. It complements ci-runner-setup.bats / ci-apt-retry.bats / -# ci-secret-scan.bats, which harden the individual install/download surfaces. - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Upper bound for a sane CI job timeout. Normal runs finish in ~20s (p50); a cap -# far above that still catches a wedged run well before the 360-minute default. -# -# ci.yml is a customize-per-stack stub: an adopter whose build/integration/test -# steps legitimately run longer can raise this cap by exporting -# CI_JOB_TIMEOUT_MAX_MINUTES (an explicit, opt-in workflow policy) rather than -# having a valid longer timeout rejected outright. The guard's intent is only -# that every job stays *bounded* well below GitHub's 360-minute default, not that -# it fits one fixed number, so the default stays sane while the cap is tunable. -MAX_TIMEOUT_MINUTES="${CI_JOB_TIMEOUT_MAX_MINUTES:-30}" - -# Print the body of a top-level job block — from ` :` up to the next -# top-level job key — so an assertion can be scoped to a single job. -job_block() { - awk -v job="$1" ' - $0 ~ "^ " job ":[[:space:]]*(#.*)?$" { f = 1; print; next } - f && (/^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ || /^[A-Za-z]/) { f = 0 } - f { print } - ' "$CI_YML" -} - -# List every top-level job that targets a runner (has a `runs-on:` line). This -# discovers jobs dynamically so a newly-added runner job is covered automatically. -runner_jobs() { - awk ' - /^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ { - name = $1; sub(/:$/, "", name); job = name - } - job && /^ runs-on:/ && !printed[job] { - print job; printed[job] = 1 - } - ' "$CI_YML" -} - -# The job-level `timeout-minutes:` integer value, or empty if none. Anchored to -# the 4-space job-key indentation so a deeper step-level `timeout-minutes:` can -# never satisfy the guard on behalf of the whole job. -job_timeout_value() { - job_block "$1" \ - | grep -E '^ timeout-minutes:[[:space:]]*[0-9]+[[:space:]]*(#.*)?$' \ - | head -1 \ - | sed -E 's/^ timeout-minutes:[[:space:]]*([0-9]+).*/\1/' -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "ci.yml declares at least one runner job" { - # Guards the discovery helper itself: if this ever finds nothing, the - # per-job timeout assertions below would vacuously pass. - run runner_jobs - [ "$status" -eq 0 ] - [ -n "$output" ] -} - -@test "every runner job declares a bounded timeout-minutes" { - local failures=0 - while IFS= read -r job; do - [ -n "$job" ] || continue - local value - value="$(job_timeout_value "$job")" - if [ -z "$value" ]; then - echo "$job: no job-level 'timeout-minutes' — a stalled run can hang for the 360-minute default" - failures=1 - continue - fi - if [ "$value" -lt 1 ]; then - echo "$job: timeout-minutes must be a positive integer (got '$value')" - failures=1 - fi - if [ "$value" -gt "$MAX_TIMEOUT_MINUTES" ]; then - echo "$job: timeout-minutes '$value' exceeds the sane cap of ${MAX_TIMEOUT_MINUTES}m" - failures=1 - fi - done < <(runner_jobs) - [ "$failures" -eq 0 ] -} diff --git a/tests/ci-network-timeout.bats b/tests/ci-network-timeout.bats deleted file mode 100644 index 8f2fe84..0000000 --- a/tests/ci-network-timeout.bats +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml network-operation reliability (issue #196). -# -# The CI workflow failed at ~75% across the monitored window with the classic -# bimodal "normal vs. stalled" signature (p50 61s, p95 1245s). Prior remediations -# hardened the *retry* surface (#152 stale apt index, #155 transient apt install -# retry, #163 gitleaks download retry) and bounded the total job runtime (#169 -# per-job timeout-minutes). But the retry loops wrap network commands that are -# NOT bounded per attempt: a single stalled `apt-get update`/`apt-get install`/ -# `curl` (a wedged mirror, a hung DNS lookup, a half-open TCP connection) blocks -# the loop indefinitely — a retry loop "never advances while its command is -# blocked" (see ci-job-timeout.bats). The job then runs until the 10-minute job -# timeout kills it and is counted as a FAILURE, not a recovery, inflating both -# p95 and the failure rate. -# -# This guard pins the fix: every network command inside a CI retry loop must be -# bounded per attempt — apt commands wrapped in `timeout `, and the -# gitleaks download given `curl --max-time ` — so a stall is killed -# quickly and the surrounding retry loop can actually recover on the next attempt -# instead of consuming the whole job budget. It complements ci-apt-retry.bats / -# ci-secret-scan.bats (which pin the retry loops themselves) and -# ci-job-timeout.bats (which pins the per-job ceiling). - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Print the body of a top-level job block — from ` :` up to the next -# top-level job key — so an assertion can be scoped to a single job. Comment lines -# are dropped and `\`-continued lines are joined so a command split across several -# lines for readability is matched as a single logical command (and a commented-out -# command can never satisfy a guard). -job_block() { - awk -v job="$1" ' - $0 ~ "^ " job ":[[:space:]]*(#.*)?$" { f = 1; print; next } - f && (/^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ || /^[A-Za-z]/) { f = 0 } - f { print } - ' "$CI_YML" | grep -v '^[[:space:]]*#' | awk '{ if (sub(/\\$/, "")) printf "%s ", $0; else print }' -} - -# Assert that a job's apt commands are each bounded by a per-attempt `timeout`, -# so a stalled apt operation is killed quickly and the retry loop can recover. -assert_apt_is_time_bounded() { - local job="$1" block - block="$(job_block "$job")" - - local update_line install_line - update_line="$(printf '%s\n' "$block" | grep -E 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+update' | head -1)" - install_line="$(printf '%s\n' "$block" | grep -E 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+install' | head -1)" - - [ -n "$update_line" ] || { echo "$job: no apt update command found"; return 1; } - [ -n "$install_line" ] || { echo "$job: no apt install command found"; return 1; } - - # `timeout ` must directly govern each apt network command — i.e. the - # `timeout ` token must immediately precede the apt invocation (an optional - # `sudo` between them is allowed). Requiring the binding, rather than a bare - # `timeout` anywhere on the line, closes the gap where unrelated text containing - # the word `timeout` could satisfy the guard while apt itself stays unbounded. - printf '%s\n' "$update_line" | grep -qE 'timeout[[:space:]]+[0-9]+[[:space:]]+(sudo[[:space:]]+)?apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+update' \ - || { echo "$job: apt update is not directly bounded by a per-attempt 'timeout '"; return 1; } - printf '%s\n' "$install_line" | grep -qE 'timeout[[:space:]]+[0-9]+[[:space:]]+(sudo[[:space:]]+)?apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+install' \ - || { echo "$job: apt install is not directly bounded by a per-attempt 'timeout '"; return 1; } -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "build-and-test bounds its apt commands with a per-attempt timeout" { - assert_apt_is_time_bounded build-and-test -} - -@test "coverage bounds its apt commands with a per-attempt timeout" { - assert_apt_is_time_bounded coverage -} - -@test "secret-scan bounds the gitleaks download with curl --connect-timeout and --max-time" { - block="$(job_block secret-scan)" - curl_lines="$(printf '%s\n' "$block" | grep -E '([[:space:]]|^)curl[[:space:]]')" - [ -n "$curl_lines" ] || { echo "secret-scan: no curl download command found"; return 1; } - # Every curl invocation must cap both the connection-establishment time - # (--connect-timeout) and the total transfer time (--max-time) so neither a hung - # DNS/TCP handshake nor a half-open connection mid-transfer can hang the download - # until the job timeout; the retry loop then recovers on retry. Checking every - # curl line — not just the first — closes the gap where a second, unbounded - # download (e.g. an added tool fetch) could slip in without failing this guard. - while IFS= read -r curl_line; do - [ -n "$curl_line" ] || continue - printf '%s\n' "$curl_line" | grep -qE -- '--connect-timeout[[:space:]]+[0-9]+' \ - || { echo "secret-scan: a gitleaks curl is not bounded by --connect-timeout : $curl_line"; return 1; } - printf '%s\n' "$curl_line" | grep -qE -- '--max-time[[:space:]]+[0-9]+' \ - || { echo "secret-scan: a gitleaks curl is not bounded by --max-time : $curl_line"; return 1; } - done <<< "$curl_lines" -} diff --git a/tests/ci-retry-backoff.bats b/tests/ci-retry-backoff.bats deleted file mode 100644 index 2499ff0..0000000 --- a/tests/ci-retry-backoff.bats +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml retry-backoff reliability (issue #204). -# -# The CI workflow degraded to a 25% failure rate (2 / 8 runs) with a *pure* -# fast-failure signature — p50 25s, p95 33s, no stall tail — landing immediately -# after the concurrency-key fix (#201). Prior remediations hardened every network -# surface: apt/gitleaks are retried (#155, #163), each network command is -# per-attempt time-bounded (#196), and every job is timeout-capped (#169). What -# remained was the *width* of the retry window: each retry loop is bounded to three -# attempts (pinned by ci-apt-retry.bats / ci-secret-scan.bats) spaced by a FIXED -# `sleep 5`, so the whole window spans only ~10s. A transient outage that outlasts -# that window — a briefly-wedged mirror, a slow DNS recovery, or dpkg-lock -# contention from the runner's background unattended-upgrades — burns all three -# attempts within seconds and fast-fails the job, exactly the tight fast-failure -# band the Fleet Monitor flagged. (The repo's own flaky-endpoint convention in -# sonarcloud.yml already waits 30s before retrying; ci.yml waited only 5s.) -# -# This guard pins the fix: every retry-loop backoff must GROW with the attempt -# counter (an increasing/exponential backoff) instead of sleeping a fixed constant, -# so the effective retry window is wide enough to ride out a short transient outage -# rather than exhausting on the first blip. It complements ci-apt-retry.bats / -# ci-secret-scan.bats (which pin the retry loops themselves and the 3-attempt bound) -# and ci-network-timeout.bats (which pins the per-attempt ceiling). - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Every retry-loop backoff line: a `sleep` guarded by the `$attempt -lt 3` check -# that gates the pre-final-attempt wait. Comment lines are dropped so a -# commented-out backoff can never satisfy a guard. -backoff_lines() { - grep -vE '^[[:space:]]*#' "$CI_YML" \ - | awk '{ if (sub(/\\$/, "")) printf "%s ", $0; else print }' \ - | grep -E '\[[[:space:]]*"?\$attempt"?[[:space:]]+-lt[[:space:]]+3[[:space:]]*\].*([[:space:]]|;|&)sleep[[:space:]]' || true -} - -# Attempt-guarded backoff lines confined to a SINGLE retry loop, selected by its -# 1-based ordinal (1st, 2nd, 3rd `for attempt in 1 2 3` block). Unlike -# backoff_lines (which aggregates across the whole file), this scopes the grep to -# the requested loop's `for … do … done` body, so a loop that lost its sleep -# cannot be masked by another loop that gained a second one. Comment lines are -# dropped and line-continuations joined exactly as in backoff_lines. -loop_backoff_lines() { - local requested="$1" - grep -vE '^[[:space:]]*#' "$CI_YML" \ - | awk -v requested="$requested" ' - /for[[:space:]]+attempt[[:space:]]+in[[:space:]]+1[[:space:]]+2[[:space:]]+3/ { - loop++ - in_requested = (loop == requested) - } - { - if (in_requested) { - line = $0 - if (sub(/\\$/, "", line)) printf "%s ", line - else print line - } - } - in_requested && /^[[:space:]]*done[[:space:]]*$/ { in_requested = 0 } - ' \ - | grep -E '\[[[:space:]]*"?\$attempt"?[[:space:]]+-lt[[:space:]]+3[[:space:]]*\].*([[:space:]]|;|&)sleep[[:space:]]' || true -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "ci.yml declares exactly three attempt-bounded retry loops" { - # build-and-test install, coverage install, and secret-scan download. Pinning the - # count means a newly-added retry loop cannot slip in without a backoff guard, and - # a removed one cannot make the per-loop assertions below pass vacuously. - local count - count="$(grep -vE '^[[:space:]]*#' "$CI_YML" \ - | grep -cE 'for[[:space:]]+attempt[[:space:]]+in[[:space:]]+1[[:space:]]+2[[:space:]]+3' || true)" - [ "$count" -eq 3 ] || { echo "expected 3 attempt-bounded retry loops, found $count"; return 1; } -} - -@test "every retry loop has a backoff sleep" { - # Validate each retry loop independently: an aggregate count of 3 across the - # whole file could be satisfied even if one loop lost its guarded sleep while - # another gained a second one. Scope the assertion to each `for attempt in - # 1 2 3` block so every loop must carry exactly one attempt-guarded sleep. - local loop count - for loop in 1 2 3; do - count="$(loop_backoff_lines "$loop" | grep -c 'sleep' || true)" - [ "$count" -eq 1 ] || { - echo "expected 1 attempt-guarded backoff sleep in retry loop $loop, found $count" - return 1 - } - done -} - -@test "every retry backoff strictly increases with the attempt counter (increasing backoff)" { - # Merely mentioning $attempt is not enough: a decreasing expression like - # `sleep $(( 45 - attempt ))` or a constant one like `sleep $(( attempt * 0 ))` - # both contain "attempt" yet defeat the purpose. Extract the sleep argument and - # evaluate it for attempts 1, 2, 3, then require each delay to be a positive - # integer that grows strictly — the property that actually widens the retry - # window enough to outlast a short transient outage (#204). - while IFS= read -r line; do - [ -n "$line" ] || continue - local expr - expr="$(printf '%s\n' "$line" | sed -E 's/.*[^[:alnum:]_]sleep[[:space:]]+//')" - [ -n "$expr" ] || { echo "could not extract sleep argument: $line"; return 1; } - printf '%s\n' "$expr" | grep -q 'attempt' \ - || { echo "retry backoff does not reference \$attempt: $line"; return 1; } - local prev=0 n delay - for n in 1 2 3; do - delay="$(attempt="$n"; eval "echo $expr")" \ - || { echo "could not evaluate backoff argument '$expr': $line"; return 1; } - case "$delay" in - ''|*[!0-9]*) echo "backoff did not evaluate to a non-negative integer (got '$delay'): $line"; return 1;; - esac - [ "$delay" -gt "$prev" ] \ - || { echo "backoff is not strictly increasing/positive (attempt $n -> ${delay}s, previous ${prev}s): $line"; return 1; } - prev="$delay" - done - done < <(backoff_lines) -} - -@test "no retry backoff uses a fixed-constant sleep" { - # A bare `sleep ` is the ~10s fixed window that fast-fails on a transient - # outage (issue #204 root cause); reject it directly. - while IFS= read -r line; do - [ -n "$line" ] || continue - if printf '%s\n' "$line" | grep -qE 'sleep[[:space:]]+[0-9]+([[:space:]]|;|$)'; then - echo "retry backoff uses a fixed-constant sleep: $line" - return 1 - fi - done < <(backoff_lines) -} diff --git a/tests/ci-runner-setup.bats b/tests/ci-runner-setup.bats deleted file mode 100644 index 7aa17d2..0000000 --- a/tests/ci-runner-setup.bats +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for ci.yml runner-setup reliability (issue #152). -# -# The CI workflow failed at ~80% across the monitored window for two runner-setup -# reasons, both guarded here: -# 1. The coverage job tried to `apt-get install kcov`. kcov is not in the Ubuntu -# runner's apt repositories, so every run died with -# "E: Unable to locate package kcov". -# 2. bats was installed without first refreshing the apt package index, which -# fails intermittently once the runner image's cached index goes stale. - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -# Print the body of a top-level job block — from ` :` up to the next -# top-level job key — so an assertion can be scoped to a single job. -job_block() { - awk -v job="$1" ' - $0 ~ "^ " job ":[[:space:]]*(#.*)?$" { f = 1; print; next } - f && (/^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ || /^[A-Za-z]/) { f = 0 } - f { print } - ' "$CI_YML" -} - -@test "ci.yml exists at the expected path" { - [ -f "$CI_YML" ] -} - -@test "build-and-test refreshes the apt cache before installing packages" { - block="$(job_block build-and-test)" - update_line="$(printf '%s\n' "$block" | grep -nE 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+update' | head -1 | cut -d: -f1)" - install_line="$(printf '%s\n' "$block" | grep -nE 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+install' | head -1 | cut -d: -f1)" - # An install must be present, and an update must run before it so a stale - # package index can never turn "install bats" into a hard failure. - [ -n "$install_line" ] - [ -n "$update_line" ] - [ "$update_line" -lt "$install_line" ] -} - -@test "coverage refreshes the apt cache before installing packages" { - block="$(job_block coverage)" - update_line="$(printf '%s\n' "$block" | grep -nE 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+update' | head -1 | cut -d: -f1)" - install_line="$(printf '%s\n' "$block" | grep -nE 'apt(-get)?([[:space:]]+-[a-zA-Z0-9-]+)*[[:space:]]+install' | head -1 | cut -d: -f1)" - [ -n "$install_line" ] - [ -n "$update_line" ] - [ "$update_line" -lt "$install_line" ] -} - -@test "ci.yml never apt-get installs the uninstallable kcov package" { - # kcov is absent from the Ubuntu runner's apt repositories; installing it is the - # documented root cause of issue #152. Any coverage stack must install a package - # that actually resolves. - ! grep -qE 'apt(-get)?[[:space:]]+install.*[[:space:]]kcov([[:space:]]|$)' "$CI_YML" -} diff --git a/tests/ci-secret-scan.bats b/tests/ci-secret-scan.bats deleted file mode 100644 index a9f4a96..0000000 --- a/tests/ci-secret-scan.bats +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for push-protection.md#required-ci-job: -# ci.yml must carry the canonical gitleaks secret-scan job and the repo must -# ship a .gitleaks.toml config, or the `Secret scan (gitleaks)` required check -# cannot run. - -CI_YML="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" -GITLEAKS_TOML="${BATS_TEST_DIRNAME}/../.gitleaks.toml" - -# Print the body of a top-level job block — from ` :` up to the next -# top-level job key — so an assertion can be scoped to a single job. -job_block() { - awk -v job="$1" ' - $0 ~ "^ " job ":[[:space:]]*(#.*)?$" { f = 1; print; next } - f && (/^ [A-Za-z][A-Za-z0-9_-]*:[[:space:]]*(#.*)?$/ || /^[A-Za-z]/) { f = 0 } - f { print } - ' "$CI_YML" -} - -# First line number (within a block passed as the first argument $1) matching a regex. -first_line() { - printf '%s\n' "$1" | grep -nE "$2" | head -1 | cut -d: -f1 -} - -@test "ci.yml defines a secret-scan job" { - grep -qE '^ secret-scan:' "$CI_YML" -} - -@test "secret-scan job has the required display name" { - grep -qF 'name: Secret scan (gitleaks)' "$CI_YML" -} - -@test "secret-scan checks out full git history" { - grep -qE 'fetch-depth: 0' "$CI_YML" -} - -@test "secret-scan installs the pinned, checksum-verified gitleaks version" { - grep -qF 'GITLEAKS_VERSION: "8.30.1"' "$CI_YML" - grep -qF 'GITLEAKS_CHECKSUM: "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb"' "$CI_YML" -} - -@test "secret-scan runs gitleaks detect with the required flags" { - grep -qF 'gitleaks detect --source . --config .gitleaks.toml --redact --verbose --exit-code 1' "$CI_YML" -} - -# Guards githubactions:S6506 — the gitleaks download must restrict redirects to -# HTTPS so a redirect can never downgrade the fetch to an insecure http:// host. -@test "secret-scan downloads gitleaks with insecure redirects disabled" { - grep -qE "curl.*--proto-redir '=https'.*gitleaks\.tar\.gz" "$CI_YML" -} - -# Compliance regression guard for ci.yml secret-scan reliability (issue #163). -# -# The `build-and-test` and `coverage` jobs already retry their apt installs -# (see ci-apt-retry.bats). The secret-scan job, however, fetched the gitleaks -# tarball with a single `curl` — one transient network failure (temporary DNS -# failure, a briefly-unavailable GitHub releases mirror) hard-failed the org -# required `Secret scan (gitleaks)` check, degrading the whole CI status. This -# guard pins the fix: the download must be wrapped in a bounded retry loop with a -# backoff and a post-loop failure gate so a transient fetch is retried instead of -# failing the run on the first attempt. -@test "secret-scan retries the gitleaks download" { - block="$(job_block secret-scan)" - - # A bounded retry-loop opener (matched as a whole word so one-liner loops are - # also caught) must exist within the secret-scan job. - loop_line="$(first_line "$block" '([[:space:]]|^)(for|while|until)[[:space:]]')" - [ -n "$loop_line" ] || { echo "secret-scan: gitleaks download is not wrapped in a retry loop"; return 1; } - - # Find the `done` that closes the loop so assertions can be scoped to its body. - done_line="$(printf '%s\n' "$block" | awk -v lo="$loop_line" ' - NR > lo && /^[[:space:]]*done([[:space:]]|$)/ { print NR; exit } - ')" - [ -n "$done_line" ] || { echo "secret-scan: retry loop has no closing done"; return 1; } - - loop_body="$(printf '%s\n' "$block" | awk -v lo="$loop_line" -v hi="$done_line" 'NR >= lo && NR <= hi')" - after_loop="$(printf '%s\n' "$block" | awk -v lo="$done_line" 'NR > lo')" - - # The loop must be bounded to three attempts. - printf '%s\n' "$loop_body" | grep -qE 'in[[:space:]]+(1[[:space:]]+2[[:space:]]+3|[{]1\.\.3[}])' \ - || { echo "secret-scan: retry loop is not bounded to 3 attempts"; return 1; } - - # The gitleaks download (curl) must live inside the retry loop. - [ -n "$(first_line "$loop_body" '([[:space:]]|^)curl[[:space:]]')" ] \ - || { echo "secret-scan: curl download not found inside the retry loop"; return 1; } - - # The backoff sleep must be guarded by an attempt-less-than-3 check so the - # final attempt does not emit a spurious "retrying" message or waste 5 s. - printf '%s\n' "$loop_body" | grep -qE '\[.*"?\$attempt"?[[:space:]]+-lt[[:space:]]+3' \ - || { echo "secret-scan: retry sleep is not guarded by attempt < 3 check"; return 1; } - [ -n "$(first_line "$loop_body" '([[:space:]]|^)sleep[[:space:]]')" ] \ - || { echo "secret-scan: retry loop has no backoff sleep"; return 1; } - - # A post-loop failure gate must exist after the closing done so an exhausted - # retry loop fails loudly rather than checksumming a missing/partial tarball. - printf '%s\n' "$after_loop" | grep -qE '(command[[:space:]]+-v|test[[:space:]]+-s|\[[[:space:]]+-s)' \ - || { echo "secret-scan: no post-loop failure check after the retry loop"; return 1; } -} - -@test ".gitleaks.toml config exists at the repo root" { - [ -f "$GITLEAKS_TOML" ] -} - -@test ".gitleaks.toml declares an allowlist section" { - grep -qE '^\[allowlist\]' "$GITLEAKS_TOML" -} diff --git a/tests/dependabot-automerge-stub.bats b/tests/dependabot-automerge-stub.bats deleted file mode 100644 index 09d6c9f..0000000 --- a/tests/dependabot-automerge-stub.bats +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the dependabot-automerge thin caller stub. -# -# .github/workflows/dependabot-automerge.yml is copied VERBATIM from the canonical -# org template (combsmith/.github → standards/workflows/dependabot-automerge.yml) -# and must stay byte-identical across every adopting repo, modulo the per-repo -# channel pin on the `uses:` ref. Any other diff is drift — the silent-revert -# class of failure the fleet stub-drift monitor exists to catch (fleet_stub_drift.sh). -# -# This guard specifically pins the compliance invariant from issue #105: the -# `uses:` ref MUST target the major-scoped channel `dependabot-automerge/v-stable` -# (currently v2-stable). A bare `dependabot-automerge/stable` tier pin is drift per -# ci-standards.md → Reusable workflow versioning (Centralization tiers). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger event, job `permissions:` block, and `secrets: inherit` stanza are -# drift-protected and MUST NOT be edited in the caller (see the file's own -# "AGENTS — READ BEFORE EDITING" banner). This guard pins those invariants so -# drift is caught in CI rather than in production run health. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/dependabot-automerge.yml" - -@test "dependabot-automerge stub exists" { - [ -f "$STUB" ] -} - -@test "dependabot-automerge stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/dependabot-automerge.yml) changes. - local canon - canon="$(mktemp)" - # The committed stub has NO trailing newline, so emit the heredoc with its - # trailing newline stripped (printf '%s') to stay byte-faithful to the committed, - # production stub that the fleet stub-drift monitor compares SHAs against. - printf '%s' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/dependabot-automerge.yml -# Standard: combsmith/.github/standards/dependabot-policy.md -# Reusable: combsmith/.github/.github/workflows/dependabot-automerge-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All eligibility logic and the GitHub -# App token dance live in the reusable workflow above. -# • You MAY change: nothing in this file in normal use. Adopt verbatim. -# • You MUST NOT change: trigger event (must be `pull_request_target`), -# the `uses:` line, `secrets: inherit`, or the job-level `permissions:` -# block — reusable workflows can be granted no more permissions than the -# calling job has, so removing the stanza breaks the reusable's gh API -# calls. -# • If you need different behaviour, open a PR against the reusable in the -# central repo. -# ───────────────────────────────────────────────────────────────────────────── -# -# Dependabot auto-merge — thin caller for the org-level reusable. -# To adopt: copy this file to .github/workflows/dependabot-automerge.yml in your repo. -# Required org/repo secrets (inherited): -# APP_ID — GitHub App ID with contents:write and pull-requests:write -# APP_PRIVATE_KEY — GitHub App private key -name: Dependabot auto-merge - -on: - pull_request_target: - branches: - - main - -permissions: {} - -jobs: - dependabot-automerge: - permissions: - contents: read - pull-requests: read - uses: combsmith/.github/.github/workflows/dependabot-automerge-reusable.yml@dependabot-automerge/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref - secrets: inherit # NOSONAR(githubactions:S7635) first-party trusted reusable -CANONICAL -)" > "$canon" - run diff -u "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical:" - echo "$output" - return 1 - } -} - -@test "uses: ref is pinned to the dependabot-automerge/v2-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/dependabot-automerge-reusable.yml@dependabot-automerge/v2-stable' "$STUB" -} - -@test "uses: ref is not a bare dependabot-automerge/stable tier pin (issue #105)" { - if grep -qE 'dependabot-automerge-reusable\.yml@dependabot-automerge/stable' "$STUB"; then - echo "Error: The uses: ref in $STUB is a bare 'dependabot-automerge/stable' tier pin." >&2 - echo "It must be pinned to the major-scoped 'dependabot-automerge/v-stable' channel." >&2 - return 1 - fi -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'dependabot-automerge-reusable\.yml@(main[^a-z0-9-]|[0-9a-f]{7,40}[^a-z0-9-]|v[0-9]+[^a-z-])' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the dependabot-automerge/v2-stable channel." >&2 - return 1 - fi -} - -@test "trigger is pull_request_target on main" { - grep -qE '^ pull_request_target:' "$STUB" || { echo "Missing/renamed pull_request_target trigger"; return 1; } - grep -qE '^ - main$' "$STUB" || { echo "Trigger not scoped to the main branch"; return 1; } -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly contents: read + pull-requests: read and uses secrets: inherit" { - grep -qE '^ contents: read' "$STUB" || { echo "Missing contents: read permission"; return 1; } - grep -qE '^ pull-requests: read' "$STUB" || { echo "Missing pull-requests: read permission"; return 1; } - grep -qE '^ secrets:[[:space:]]+inherit' "$STUB" || { echo "Missing 'secrets: inherit' (first-party trusted reusable)"; return 1; } -} diff --git a/tests/dependabot-github-actions-ecosystem.bats b/tests/dependabot-github-actions-ecosystem.bats deleted file mode 100644 index 85423f6..0000000 --- a/tests/dependabot-github-actions-ecosystem.bats +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for the Dependabot GitHub Actions ecosystem -# (combsmith/.github → standards/dependabot-policy.md#github-actions-all-repos). -# -# Every repo MUST include a dedicated `github-actions` ecosystem entry in -# .github/dependabot.yml. Unlike application ecosystems (npm, etc.) which run -# security-only with open-pull-requests-limit: 0, GitHub Actions use *version -# updates* on a weekly schedule with open-pull-requests-limit: 10, because -# pinned action SHAs do not affect application runtime stability and the -# auto-merge workflow approves all version bumps (SHA-pinned; CI catches -# breaking interface changes). -# -# This guard mirrors the weekly compliance audit's missing-github-actions- -# ecosystem check offline so drift is caught in CI. It parses the config with -# yq rather than grepping, so field placement/ordering is irrelevant. - -DEPENDABOT="${BATS_TEST_DIRNAME}/../.github/dependabot.yml" - -# yq filter selecting the github-actions update entry (empty if absent). -GHA_SELECT='.updates[] | select(.["package-ecosystem"] == "github-actions")' - -setup() { - if ! command -v yq >/dev/null 2>&1; then - echo "yq is required but not installed" >&2 - return 1 - fi -} - -@test "dependabot.yml exists at .github/dependabot.yml" { - [ -f "$DEPENDABOT" ] -} - -@test "dependabot.yml is valid YAML and version 2" { - run yq '.version' "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "$output" = "2" ] -} - -@test "a github-actions ecosystem entry is present" { - run yq "[$GHA_SELECT] | length" "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "$output" -eq 1 ] || { - echo "Expected exactly one github-actions ecosystem entry, found: $output" - return 1 - } -} - -@test "github-actions entry targets directory /" { - run yq "$GHA_SELECT | .directory" "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "${output//\"/}" = "/" ] -} - -@test "github-actions entry uses a weekly schedule" { - run yq "$GHA_SELECT | .schedule.interval" "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "${output//\"/}" = "weekly" ] -} - -@test "github-actions entry sets open-pull-requests-limit to 10 (version updates)" { - run yq "$GHA_SELECT | .[\"open-pull-requests-limit\"]" "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "$output" -eq 10 ] -} - -@test "github-actions entry carries the security and dependencies labels" { - run yq "$GHA_SELECT | .labels[]" "$DEPENDABOT" - [ "$status" -eq 0 ] - echo "$output" | tr -d '"' | grep -q "^security$" - echo "$output" | tr -d '"' | grep -q "^dependencies$" -} - -@test "pre-existing npm ecosystem entry is preserved (no regression)" { - run yq '[.updates[] | select(.["package-ecosystem"] == "npm")] | length' "$DEPENDABOT" - [ "$status" -eq 0 ] - [ "$output" -eq 1 ] || { - echo "Expected exactly one npm ecosystem entry, found: $output" - return 1 - } - - run yq '.updates[] | select(.["package-ecosystem"] == "npm") | .labels[]' "$DEPENDABOT" - [ "$status" -eq 0 ] - echo "$output" | tr -d '"' | grep -q "^security$" - echo "$output" | tr -d '"' | grep -q "^dependencies$" -} diff --git a/tests/dependabot-rebase-stub.bats b/tests/dependabot-rebase-stub.bats deleted file mode 100644 index e6fe77c..0000000 --- a/tests/dependabot-rebase-stub.bats +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the dependabot-rebase thin caller stub. -# -# .github/workflows/dependabot-rebase.yml is copied VERBATIM from the canonical -# org template (combsmith/.github → standards/workflows/dependabot-rebase.yml) -# and must stay byte-identical across every adopting repo, modulo the per-repo -# channel pin on the `uses:` ref. Any other diff is drift — the silent-revert -# class of failure the fleet stub-drift monitor exists to catch (fleet_stub_drift.sh). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger events, concurrency group, job `permissions:` block, and secrets block -# are drift-protected and MUST NOT be edited in the caller (see the file's own -# "AGENTS — READ BEFORE EDITING" banner and ci-standards.md → Reusable workflow -# versioning). This guard pins those invariants so drift is caught in CI rather -# than in production run health. NOTE: this guard cannot catch transient upstream -# failures (e.g. an api.github.com/graphql 504 inside the reusable's merge step) — -# those are hardened in the central reusable, not in this caller stub. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/dependabot-rebase.yml" - -@test "dependabot-rebase stub exists" { - [ -f "$STUB" ] -} - -@test "dependabot-rebase stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/dependabot-rebase.yml) changes. - local canon - canon="$(mktemp)" - # The committed stub has NO trailing newline — unlike pr-review-mention.yml - # which ships with one — so emit the heredoc with its trailing newline - # stripped (printf '%s') to stay byte-faithful to the committed, production stub - # that the fleet stub-drift monitor compares SHAs against. - printf '%s' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/dependabot-rebase.yml -# Standard: combsmith/.github/standards/dependabot-policy.md -# Reusable: combsmith/.github/.github/workflows/dependabot-rebase-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All rebase/merge serialization logic -# lives in the reusable workflow above. -# • You MUST NOT change: the `uses:` ref — it is pinned to the -# `dependabot-rebase/v2-stable` channel, a moving tag advanced centrally. -# Never repoint it to `@main`, a SHA, or a frozen `@vX` (see -# ci-standards.md → Reusable workflow versioning). Also do not change the -# concurrency group name, the explicit secrets -# block, or the job-level `permissions:` block — reusable workflows can be -# granted no more permissions than the calling job has, so removing the -# stanza breaks the reusable's gh API calls. Do not remove any trigger -# (`push` keeps the self-sustaining chain; `schedule` is the safety net -# when no PR merges have occurred recently; `workflow_dispatch` allows -# manual queue flushes). -# • If you need different behaviour, open a PR against the reusable in the -# central repo. -# ───────────────────────────────────────────────────────────────────────────── -# -# Dependabot update-and-merge — thin caller for the org-level reusable. -# To adopt: copy THIS file (standards/workflows/dependabot-rebase.yml) to -# .github/workflows/dependabot-rebase.yml in your repo. Do NOT copy -# .github/workflows/dependabot-rebase.yml from this repo — that file uses a -# local ref only valid in the source-of-truth repo. -# Required org/repo secrets (inherited): -# APP_ID — GitHub App ID with contents:write and pull-requests:write -# APP_PRIVATE_KEY — GitHub App private key -name: Dependabot update and merge - -on: - push: - branches: - - main - schedule: - - cron: '0 */4 * * *' # every 4 hours — safety net when no pushes to main trigger the chain - workflow_dispatch: # allow manual trigger to flush Dependabot PR queue - -concurrency: - group: dependabot-update-and-merge - cancel-in-progress: false - -permissions: {} - -jobs: - dependabot-rebase: - permissions: - contents: write # GITHUB_TOKEN scope for caller; update-branch and merge-PR operations use APP_TOKEN (via APP_ID/APP_PRIVATE_KEY) to bypass recursive guard - pull-requests: write # GITHUB_TOKEN scope for caller; update-branch and merge-PR operations use APP_TOKEN (via APP_ID/APP_PRIVATE_KEY) to bypass merge gates - uses: combsmith/.github/.github/workflows/dependabot-rebase-reusable.yml@dependabot-rebase/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref - secrets: - APP_ID: ${{ secrets.APP_ID }} - APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} -CANONICAL -)" > "$canon" - run diff -u "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical:" - echo "$output" - return 1 - } -} - -@test "uses: ref is pinned to the dependabot-rebase/v2-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/dependabot-rebase-reusable.yml@dependabot-rebase/v2-stable' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'dependabot-rebase-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9]+$)' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the dependabot-rebase/v2-stable channel." >&2 - return 1 - fi -} - -@test "all three trigger events are present" { - grep -qE '^ push:' "$STUB" || { echo "Missing push trigger"; return 1; } - grep -qE '^ schedule:' "$STUB" || { echo "Missing schedule trigger"; return 1; } - grep -qE '^ workflow_dispatch:' "$STUB" || { echo "Missing workflow_dispatch trigger"; return 1; } -} - -@test "concurrency group is dependabot-update-and-merge with cancel-in-progress off" { - grep -qE '^ group: dependabot-update-and-merge$' "$STUB" || { echo "Wrong/missing concurrency group"; return 1; } - grep -qE '^ cancel-in-progress: false$' "$STUB" || { echo "cancel-in-progress must be false (merges serialize, not cancel)"; return 1; } -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly contents: write + pull-requests: write and forwards named secrets" { - grep -qE '^ contents: write' "$STUB" || { echo "Missing contents: write permission"; return 1; } - grep -qE '^ pull-requests: write' "$STUB" || { echo "Missing pull-requests: write permission"; return 1; } - grep -qF 'APP_ID: ${{ secrets.APP_ID }}' "$STUB" \ - || { echo "Missing APP_ID secret"; return 1; } - grep -qF 'APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}' "$STUB" \ - || { echo "Missing APP_PRIVATE_KEY secret"; return 1; } -} diff --git a/tests/dependency-audit-stub.bats b/tests/dependency-audit-stub.bats deleted file mode 100644 index 21629ec..0000000 --- a/tests/dependency-audit-stub.bats +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the dependency-audit thin caller stub. -# -# .github/workflows/dependency-audit.yml is a THIN CALLER STUB whose ecosystem -# detection and vulnerability-audit logic live entirely in the central reusable -# (combsmith/.github → .github/workflows/dependency-audit-reusable.yml). It -# is adopted VERBATIM: its own "AGENTS — READ BEFORE EDITING" banner says you may -# change nothing in normal use, and MUST NOT change the trigger events, the -# `uses:` line, or the job name (the job feeds the required status check). Any -# other diff is drift — the silent-revert class of failure the fleet stub-drift -# monitor exists to catch (fleet_stub_drift.sh). This guard pins those invariants -# so drift is caught in CI rather than in production run health. -# -# NOTE: this guard cannot catch transient upstream failures (e.g. an advisory-DB -# fetch hiccup inside the reusable's audit step) — those are hardened in the -# central reusable, not in this caller stub. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/dependency-audit.yml" - -@test "dependency-audit stub exists" { - [ -f "$STUB" ] -} - -@test "stub carries no TODO/FIXME marker (SonarCloud githubactions:S1135 regression guard)" { - if grep -nE '(TODO|FIXME)' "$STUB"; then - echo "Error: $STUB still contains a TODO/FIXME marker — SonarCloud S1135 will re-open." >&2 - echo "Complete the task and reword the comment instead of leaving a TODO." >&2 - return 1 - fi -} - -@test "dependency-audit stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/dependency-audit.yml) changes. - local canon - canon="$(mktemp)" - # The committed stub has NO trailing newline, so emit the heredoc with its - # trailing newline stripped (printf '%s') to stay byte-faithful to the - # committed, production stub that the fleet stub-drift monitor compares SHAs against. - printf '%s' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/dependency-audit.yml -# Standard: combsmith/.github/standards/ci-standards.md#7-dependency-audit-dependency-audityml -# Reusable: combsmith/.github/.github/workflows/dependency-audit-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All ecosystem-detection and audit logic -# lives in the reusable workflow above. -# • You MAY change: nothing in this file in normal use. Adopt verbatim. -# • You MUST NOT change: trigger events, the `uses:` line, or job name -# (used as a required status check). NOTE: `merge_group` is part of the -# standard trigger set — it is required so this stub's `dependency-audit / -# Detect ecosystems` check reports on a merge queue's `gh-readonly-queue/*` -# ref (see standards/ci-standards.md). Do not drop it on sync and do not -# flag it as drift. -# • If you need different behaviour (new ecosystem, tool version bump), -# open a PR against the reusable in the central repo. -# ───────────────────────────────────────────────────────────────────────────── -# -# Dependency vulnerability audit — thin caller for the org-level reusable. -# To adopt: copy this file to .github/workflows/dependency-audit.yml in your repo. -# Add "dependency-audit / Detect ecosystems" as a required status check -# in branch protection. -name: Dependency audit - -on: - pull_request: - branches: [main] - push: - branches: [main] - merge_group: - -permissions: - contents: read - -jobs: - dependency-audit: - uses: combsmith/.github/.github/workflows/dependency-audit-reusable.yml@dependency-audit/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref -CANONICAL -)" > "$canon" - run diff -u "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical:" - echo "$output" - return 1 - } -} - -@test "uses: ref is pinned to the dependency-audit/v2-stable channel" { - # Match the actual `uses:` field (not comments) and anchor the end so a suffix - # like @dependency-audit/v2-stable-rogue cannot slip through. - grep -qE '^[[:space:]]+uses:[[:space:]]+combsmith/\.github/\.github/workflows/dependency-audit-reusable\.yml@dependency-audit/v2-stable([[:space:]]|$|#)' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'dependency-audit-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9])' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the dependency-audit/v2-stable channel." >&2 - return 1 - fi -} - -@test "both trigger events are present on the main branch" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding="utf-8") as f: - wf = yaml.safe_load(f) -# PyYAML (YAML 1.1) parses the bare key 'on' as boolean True -on = wf.get(True) or wf.get('on') or {} -for event in ('pull_request', 'push'): - if event not in on: - print(f"Missing trigger event: {event}") - sys.exit(1) - branches = (on[event] or {}).get('branches', []) - if branches != ['main']: - print(f"{event}.branches must be exactly ['main'], got {branches}") - sys.exit(1) -PYEOF -} - -@test "top-level permissions grant exactly contents: read (least privilege)" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding="utf-8") as f: - wf = yaml.safe_load(f) -perms = wf.get('permissions', {}) or {} -if perms != {'contents': 'read'}: - print(f"Top-level permissions must be exactly {{'contents': 'read'}}, got {perms}") - sys.exit(1) -PYEOF -} - -@test "job adds no elevated permissions and forwards no secrets" { - # A read-only audit inherits the top-level contents: read grant; the job must - # not widen the effective token (no job-level permissions) or forward secrets. - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding="utf-8") as f: - wf = yaml.safe_load(f) -job = wf.get('jobs', {}).get('dependency-audit', {}) or {} -if 'permissions' in job: - print(f"Job must not declare its own permissions (inherits contents: read), got {job['permissions']}") - sys.exit(1) -if 'secrets' in job: - print(f"Job must not forward any secrets, got {job['secrets']}") - sys.exit(1) -PYEOF -} diff --git a/tests/gitignore-baseline.bats b/tests/gitignore-baseline.bats deleted file mode 100644 index 7c45788..0000000 --- a/tests/gitignore-baseline.bats +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for the .gitignore Standard -# (combsmith/.github → standards/gitignore-standard.md#managed-block-markers). -# -# Every repo's .gitignore MUST open with the org-managed L1 "secrets baseline" -# block, copied VERBATIM (markers included) from the org /.gitignore. The weekly -# audit (pp_check_gitignore_baseline in scripts/lib/push-protection.sh) locates -# the BEGIN … END markers, extracts the span inclusive of the markers, and -# compares its SHA-256 — trailing-newline tolerant — against the org canonical -# block. Everything BELOW the END marker is the per-repo L2 extension and is -# never inspected. -# -# This guard mirrors that check offline: it pins the canonical span's SHA-256 so -# drift inside the markers is caught in CI rather than only by the weekly audit. -# If the org updates the baseline (and the audit re-flags this repo), re-copy the -# block verbatim from the org /.gitignore and update GITIGNORE_L1_SHA256 below to -# the new digest. - -GITIGNORE="${BATS_TEST_DIRNAME}/../.gitignore" - -# Canonical marker lines — must match push-protection.sh byte-for-byte. -BEGIN_MARKER='# >>> BEGIN combsmith secrets baseline (managed by .github — do not edit) >>>' -END_MARKER='# <<< END combsmith secrets baseline <<<' - -# SHA-256 of the org canonical L1 span (BEGIN … END markers inclusive), computed -# the same way pp_check_gitignore_baseline does: extract the span, then -# `printf '%s' "$span" | sha256sum` (command substitution strips the trailing -# newline, so the hash is trailing-newline tolerant). -GITIGNORE_L1_SHA256='5923c09c4183e1c104f3c04f57eba4d86ae5547913321c6d8bc053bf81d95a57' - -# Extract the L1 secrets-baseline span (markers inclusive) from stdin, mirroring -# pp_extract_baseline_block. Prints nothing and exits non-zero if the block is -# absent or the BEGIN marker has no matching END. -extract_l1_span() { - sed 's/\r$//' | awk -v b="$BEGIN_MARKER" -v e="$END_MARKER" ' - $0 == b { inblock = 1 } - inblock { buf = buf $0 "\n" } - $0 == e && inblock { printf "%s", buf; found = 1; exit } - END { if (!found) exit 1 } - ' -} - -@test ".gitignore exists at the repo root" { - [ -f "$GITIGNORE" ] -} - -@test ".gitignore contains the BEGIN secrets-baseline marker exactly once" { - run grep -cxF "$BEGIN_MARKER" "$GITIGNORE" - [ "$status" -eq 0 ] - [ "$output" -eq 1 ] -} - -@test ".gitignore contains the END secrets-baseline marker exactly once" { - run grep -cxF "$END_MARKER" "$GITIGNORE" - [ "$status" -eq 0 ] - [ "$output" -eq 1 ] -} - -@test "nothing appears above the BEGIN marker (baseline is at the top)" { - # The BEGIN marker must be the first line of the file — the standard requires - # "Nothing goes above the BEGIN marker." - run head -n 1 "$GITIGNORE" - [ "$output" = "$BEGIN_MARKER" ] -} - -@test "L1 secrets-baseline span is byte-identical to the org canonical block" { - local span actual - span="$(extract_l1_span < "$GITIGNORE")" || { - echo "BEGIN … END secrets-baseline block not found in .gitignore" - return 1 - } - # Portable hash computation: try sha256sum (Linux), shasum (macOS), openssl (fallback). - if command -v sha256sum >/dev/null 2>&1; then - actual="$(printf '%s' "$span" | sha256sum | awk '{print $1}')" - elif command -v shasum >/dev/null 2>&1; then - actual="$(printf '%s' "$span" | shasum -a 256 | awk '{print $1}')" - elif command -v openssl >/dev/null 2>&1; then - actual="$(printf '%s' "$span" | openssl dgst -sha256 | awk '{print $NF}')" - else - echo "No sha256sum / shasum / openssl found — cannot compute hash" - return 1 - fi - [ "$actual" = "$GITIGNORE_L1_SHA256" ] || { - echo "L1 baseline drift: expected $GITIGNORE_L1_SHA256, got $actual" - echo "Re-copy the block verbatim from the org /.gitignore; never edit inside the markers." - return 1 - } -} - -@test "SOPS/age-encrypted files (.enc.yaml) are re-allowed by the baseline" { - # *.secret.* is ignored (section 11), but the baseline now re-allows SOPS/age - # encrypted variants (!*.enc.yaml, !*.enc.yml, !*.enc.json, !*.sops.yaml, !*.sops.yml, !*.sops.json) because - # they are safe to commit. The later negation wins, so config.secret.enc.yaml - # is NOT ignored. check-ignore exits 1 when the path is not ignored. - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index "config.secret.enc.yaml" - [ "$status" -eq 1 ] -} - -@test "public certificate files (.crt) are not ignored" { - # !ca.crt and !*.crt are explicit negations in section 4 of the baseline. - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index "ca.crt" - [ "$status" -ne 0 ] -} - -@test "public key files (.pub) are not ignored" { - # id_rsa.* is ignored, but !*.pub re-allows public key files. - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index "id_rsa.pub" - [ "$status" -ne 0 ] -} - -@test "private key files (.pem) are ignored" { - # *.pem is in the ignore list (section 4); private keys must not slip through. - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index "private.pem" - [ "$status" -eq 0 ] -} - -@test "database dump files (.sql.gz) are ignored" { - # *.sql.gz is in the ignore list (section 7). - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index "backup.sql.gz" - [ "$status" -eq 0 ] -} - -@test ".env.vault is ignored by the baseline (dotenv family, no re-allow)" { - # .env.* catches .env.vault. The baseline no longer carries a !.env.vault - # re-allow, so .env.vault is ignored like the rest of the dotenv family; a repo - # that must commit dotenv-vault ciphertext re-allows it below the END marker. - run git -C "$BATS_TEST_DIRNAME/.." check-ignore --no-index ".env.vault" - [ "$status" -eq 0 ] -} - -@test "L2 does not re-ignore a baseline-negated dotenv path" { - # The baseline ignores the dotenv family but re-allows committed templates via - # negations (!.env.example, !.env.sample, …). A broad `.env` or `.env.*` - # wildcard in L2 (below END, evaluated later) would silently re-hide those, - # violating negation discipline (gitignore-standard.md#negation-discipline). - # Specific patterns like `.env.local` are fine; only the broad wildcard forms - # (optionally with a leading `/` or trailing whitespace) are forbidden. - local l2 - l2="$(awk -v e="$END_MARKER" 'past { print } $0 == e { past = 1 }' "$GITIGNORE")" - run grep -Exq '/?\.env(\.\*)?\s*' <<< "$l2" - [ "$status" -ne 0 ] || { - echo "L2 contains a broad .env or .env.* wildcard that re-ignores baseline-negated templates — remove it from below the END marker." - return 1 - } -} diff --git a/tests/persona-mention-stub.bats b/tests/persona-mention-stub.bats deleted file mode 100644 index 9e2f299..0000000 --- a/tests/persona-mention-stub.bats +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the persona-mention thin caller stub. -# -# .github/workflows/persona-mention.yml is copied VERBATIM from the canonical -# org template (combsmith/.github → standards/workflows/persona-mention.yml) -# and must stay byte-identical across every adopting repo, modulo the per-repo -# channel pin on the `uses:` ref. Any other diff is drift — the silent-revert -# class of failure the fleet stub-drift monitor exists to catch (fleet_stub_drift.sh). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger events, and job `permissions:` block are drift-protected and MUST NOT -# be edited in the caller (see the file's own "AGENTS — READ BEFORE EDITING" -# banner and ci-standards.md → Centralization tiers). This guard pins those -# invariants so drift is caught in CI rather than by the compliance audit. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/persona-mention.yml" - -@test "persona-mention stub exists" { - [ -f "$STUB" ] -} - -@test "persona-mention stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/persona-mention.yml) changes. - # The live canonical ships with a single trailing newline; printf '%s\n' - # reproduces it exactly so this guard stays byte-faithful to the upstream blob. - local canon - canon="$(mktemp)" - printf '%s\n' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/persona-mention.yml -# Standard: combsmith/.github/standards/persona-standards.md (§4.1) -# Reusable: combsmith/.github/.github/workflows/persona-mention-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All routing logic lives in the reusable -# workflow above, and every per-persona decision lives in that persona's -# manifest — not here and not in the reusable. -# • You MUST NOT change: the `uses:` ref — it is pinned to the -# `persona-mention/v1-stable` channel, a moving tag advanced centrally. -# Never repoint it to `@main`, a SHA, or a frozen `@vX.Y.Z` (see -# ci-standards.md → Reusable workflow versioning). Also do not change the -# trigger events or the job-level `permissions:` block — reusable workflows -# can be granted no more permissions than the calling job, so removing the -# stanza breaks the reusable's gh API calls. -# • Do NOT add a per-persona stub. ONE router serves every persona (§4.1); -# a stub per agent is the drift the manifest exists to prevent. -# • If you need different behaviour, open a PR against the reusable in the -# central repo. A new release is rolled out by moving the channel tag -# centrally — never by editing callers, so no fanout PR is needed. -# ───────────────────────────────────────────────────────────────────────────── -# -# Persona Mention Router — thin caller for the org-level reusable. -# -# Adopting this file makes every persona that enables the `mention` surface -# addressable in this repo as `@combsmith/` — e.g. -# -# @combsmith/qa-lead please assess test risk on this PR -# -# The handle is an org TEAM, never a user account: '@qa-lead' is a real GitHub -# account owned by an unrelated person (§4.1). -# -# To adopt: copy this file to .github/workflows/persona-mention.yml in your repo. -# Requires: GH_PAT_WORKFLOWS org secret (already present in combsmith org). -name: Persona — Mention Router - -on: - # issue_comment covers BOTH issues and PR conversation comments. - issue_comment: - types: [created] - pull_request_review_comment: - types: [created] - # Discussions cannot run an agent inline (#571) — but this router only parses - # and dispatches, and the agent itself runs on the resulting - # repository_dispatch, which is exactly the bridge the manifest declares. - discussion_comment: - types: [created] - # The router also serves the pull_request EVENT surface (#1165): it derives - # which personas fire from their manifests' declared `pull_request` surfaces - # and dispatches each PR-advisory, binding the same stop-marker / opt-out / - # write-gate / trust-floor brakes as the mention path. This path activates - # once the reusable at the pinned channel below advances to include it — - # rollout is central (bump the channel, then sweep), never a stub edit. - # - # Subscribe only the actions a persona can declare on its `pull_request` - # surface today: opened, ready_for_review, reopened. `synchronize` is NOT - # subscribed — no persona declares it (qa-lead excludes it deliberately) and - # the router would discard every synchronize event once the declared-events - # gate is in, so subscribing it only burns a runner in every repo on every - # push. It would be added here only if a persona declares it. (Reviewer - # assignment, review_requested, is still correctly omitted — see below.) - pull_request: - types: [opened, ready_for_review, reopened] -# NOTE: reviewer assignment (pull_request/review_requested) is still NOT -# subscribed here, even though §4 says "Reviewer-assignment counts here too". -# The router has no path for it — and a trigger that fires into a router which -# ignores it is a dead trigger that only burns runs. Tracked as finding 10 in -# combsmith/.github#755; that trigger lands with its routing, not before. - -permissions: {} - -jobs: - persona-mention: - permissions: - contents: read # the reusable checks out its tooling repo — required, - # or the call fails at startup (a reusable is granted - # no more than the caller; persona-standards.md §5) - issues: read - pull-requests: read - uses: combsmith/.github/.github/workflows/persona-mention-reusable.yml@persona-mention/v1-stable # NOSONAR(githubactions:S7637) first-party channel ref - secrets: inherit # NOSONAR(githubactions:S7635) org secrets are scoped to first-party reusables -CANONICAL -)" > "$canon" - run cmp -- "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical: $output" - return 1 - } -} - -@test "uses: ref is pinned to the persona-mention/v1-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/persona-mention-reusable.yml@persona-mention/v1-stable' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'persona-mention-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9]+)([[:space:]]|$)' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the persona-mention/v1-stable channel." >&2 - return 1 - fi -} - -@test "all four trigger events are present" { - grep -qE '^ issue_comment:' "$STUB" || { echo "Missing issue_comment trigger"; return 1; } - grep -qE '^ pull_request_review_comment:' "$STUB" || { echo "Missing pull_request_review_comment trigger"; return 1; } - grep -qE '^ discussion_comment:' "$STUB" || { echo "Missing discussion_comment trigger"; return 1; } - grep -qE '^ pull_request:' "$STUB" || { echo "Missing pull_request trigger"; return 1; } - grep -qE '^ types: \[opened, ready_for_review, reopened\]' "$STUB" \ - || { echo "Missing pull_request opened/ready_for_review/reopened types"; return 1; } -} - -@test "pull_request does not subscribe synchronize or review_requested" { - if grep -qE '^ types: \[.*(synchronize|review_requested)' "$STUB"; then - echo "pull_request must not subscribe synchronize or review_requested (dead triggers)" - return 1 - fi -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants contents/issues/pull-requests read and inherits secrets" { - grep -qE '^ contents: read' "$STUB" || { echo "Missing contents: read permission"; return 1; } - grep -qE '^ issues: read' "$STUB" || { echo "Missing issues: read permission"; return 1; } - grep -qE '^ pull-requests: read' "$STUB" || { echo "Missing pull-requests: read permission"; return 1; } - grep -qE '^ secrets: inherit' "$STUB" || { echo "Missing secrets: inherit"; return 1; } -} diff --git a/tests/pr-auto-review-concurrency.bats b/tests/pr-auto-review-concurrency.bats deleted file mode 100644 index 6ca2d0c..0000000 --- a/tests/pr-auto-review-concurrency.bats +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for the pr-auto-review thin caller stub's -# `concurrency:` surface (issue #209). -# -# .github/workflows/pr-auto-review.yml is a THIN CALLER STUB. Its `on:` triggers, -# `permissions:` grants, and `concurrency:` block are owned centrally by -# combsmith/.github → standards/workflows/pr-auto-review.yml and are NOT -# repo-adjustable (only the documented `with:` inputs and the tier channel pin -# may differ per repo). This guard pins the centrally-owned `concurrency:` -# surface so it cannot silently drift back out of sync. -# -# The canonical block deduplicates ONLY the default-branch-context triggers -# (issue #1126): -# • check_suite / workflow_run — head_branch=main, the check does NOT attach to -# the PR head, so superseding an in-flight run is SAFE. Both events collapse -# onto one group per PR (`…-pr-`) with cancel-in-progress: true. -# • pull_request / pull_request_review — run on the PR head; a cancelled run -# would leave a cancelled run, so they get a unique-per-run group (keyed by -# github.run_id) and never cancel. -# A default-branch trigger with no associated PR also falls back to the -# unique-per-run group so unrelated PRs never collapse into one group. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/pr-auto-review.yml" - -# Semantic parser to extract concurrency fields from the YAML stub. -# This avoids fragile regex/awk parsing of YAML and handles multi-line folded -# strings, comments, and key-ordering changes. PyYAML is already a project test -# dependency (see pr-auto-review-stub.bats). -get_concurrency_val() { - python3 - "$STUB" "$1" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding="utf-8") as f: - stub = yaml.safe_load(f) -concurrency = stub.get('concurrency') or {} -val = concurrency.get(sys.argv[2]) -if val is None: - sys.exit(1) -if isinstance(val, str): - print(" ".join(val.split())) -else: - print(val) -PYEOF -} - -@test "pr-auto-review stub exists" { - [ -f "$STUB" ] -} - -@test "stub declares a top-level concurrency block" { - grep -qE '^concurrency:[[:space:]]*(#.*)?$' "$STUB" \ - || { echo "pr-auto-review.yml is missing its centrally-owned top-level concurrency block"; return 1; } -} - -@test "concurrency block defines a group" { - get_concurrency_val "group" >/dev/null \ - || { echo "concurrency block has no 'group:' key"; return 1; } -} - -@test "group collapses check_suite runs onto one per-PR slot" { - local group - group="$(get_concurrency_val "group")" || return 1 - [[ "$group" == '${{'* && "$group" == *'}}' ]] \ - || { echo "group expression must be wrapped in \${{ ... }}"; return 1; } - printf '%s\n' "$group" | grep -qF "github.event.check_suite.pull_requests[0].number" \ - || { echo "group must key check_suite runs by their PR number"; return 1; } - printf '%s\n' "$group" | grep -qF "format('pr-auto-review-ready-check-pr-{0}', github.event.check_suite.pull_requests[0].number)" \ - || { echo "group must map a check_suite PR to the shared 'pr-auto-review-ready-check-pr-' slot"; return 1; } -} - -@test "group collapses workflow_run runs onto one per-PR slot" { - local group - group="$(get_concurrency_val "group")" || return 1 - [[ "$group" == '${{'* && "$group" == *'}}' ]] \ - || { echo "group expression must be wrapped in \${{ ... }}"; return 1; } - printf '%s\n' "$group" | grep -qF "github.event.workflow_run.pull_requests[0].number" \ - || { echo "group must key workflow_run runs by their PR number"; return 1; } - printf '%s\n' "$group" | grep -qF "format('pr-auto-review-ready-check-pr-{0}', github.event.workflow_run.pull_requests[0].number)" \ - || { echo "group must map a workflow_run PR to the shared 'pr-auto-review-ready-check-pr-' slot"; return 1; } -} - -@test "group falls back to a unique-per-run slot keyed by github.run_id" { - local group - group="$(get_concurrency_val "group")" || return 1 - [[ "$group" == '${{'* && "$group" == *'}}' ]] \ - || { echo "group expression must be wrapped in \${{ ... }}"; return 1; } - # PR-head triggers (and default-branch triggers with no PR) must get their own - # slot so a cancellation never leaves a cancelled check on a PR head. - printf '%s\n' "$group" | grep -qF "format('pr-auto-review-ready-check-unique-{0}', github.run_id)" \ - || { echo "group must fall back to a unique-per-run slot ('pr-auto-review-ready-check-unique-')"; return 1; } -} - -@test "cancel-in-progress is gated to check_suite and workflow_run only" { - local cancel - cancel="$(get_concurrency_val "cancel-in-progress")" || return 1 - [[ "$cancel" == '${{'* && "$cancel" == *'}}' ]] \ - || { echo "cancel-in-progress expression must be wrapped in \${{ ... }}"; return 1; } - # It must NOT be a bare `true`: PR-head triggers must never be cancelled. - printf '%s\n' "$cancel" | grep -qF "github.event_name == 'check_suite' || github.event_name == 'workflow_run'" \ - || { echo "cancel-in-progress must be gated to check_suite/workflow_run only, not a bare true"; return 1; } -} diff --git a/tests/pr-auto-review-stub.bats b/tests/pr-auto-review-stub.bats deleted file mode 100644 index 1783a57..0000000 --- a/tests/pr-auto-review-stub.bats +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the pr-auto-review thin caller stub. -# -# .github/workflows/pr-auto-review.yml is a THIN CALLER STUB whose readiness-gate -# logic lives entirely in the central reusable (combsmith/.github → -# .github/workflows/pr-auto-review-reusable.yml). Its `uses:` channel ref, trigger -# event types, and job `permissions:` block are drift-protected and MUST NOT be -# edited in the caller (see the file's own "AGENTS — READ BEFORE EDITING" banner -# and ci-standards.md → Reusable workflow versioning). -# -# Unlike the other caller stubs, ONE thing IS a per-repo customization point: the -# `workflow_run.workflows` list must name this repo's CI workflow(s). For -# repo-template that workflow is named "CI" (.github/workflows/ci.yml), so the -# shipped value is already correct and carries no outstanding TODO. This guard -# pins that invariant — and, per SonarCloud githubactions:S1135 (issue #98), -# asserts no TODO/FIXME marker lingers in the stub so the finding stays at zero. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/pr-auto-review.yml" -CI_WORKFLOW="${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" - -@test "pr-auto-review stub exists" { - [ -f "$STUB" ] -} - -@test "stub carries no TODO/FIXME marker (SonarCloud githubactions:S1135 regression guard)" { - if grep -nE '(TODO|FIXME)' "$STUB"; then - echo "Error: $STUB still contains a TODO/FIXME marker — SonarCloud S1135 will re-open." >&2 - echo "Complete the task and reword the comment instead of leaving a TODO." >&2 - return 1 - fi -} - -@test "workflow_run.workflows names this repo's CI workflow" { - # The stub gates on the named CI workflow completing; that name must match the - # `name:` of the repo's actual CI workflow. repo-template ships ci.yml as "CI". - # Parse YAML semantically so any valid representation (inline or block list) is accepted. - python3 - "$STUB" "$CI_WORKFLOW" <<'PYEOF' -import yaml, sys -stub = yaml.safe_load(open(sys.argv[1], encoding="utf-8")) -ci_wf = yaml.safe_load(open(sys.argv[2], encoding="utf-8")) -# PyYAML (YAML 1.1) parses the bare key 'on' as boolean True -on = stub.get(True) or stub.get('on') or {} -workflows = on.get('workflow_run', {}).get('workflows', []) -if workflows != ['CI']: - print("workflow_run.workflows does not contain 'CI'") - sys.exit(1) -if ci_wf.get('name') != 'CI': - print("ci.yml is not named 'CI' — update the stub's workflows list to match") - sys.exit(1) -PYEOF -} - -@test "uses: ref is pinned to the pr-auto-review/v1-stable channel" { - # Match the actual `uses:` field (not comments) and anchor the end so a suffix - # like @pr-auto-review/v1-stable-rogue cannot slip through. - grep -qE '^\s+uses:\s+combsmith/\.github/\.github/workflows/pr-auto-review-reusable\.yml@pr-auto-review/v1-stable(\s|$|#)' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'pr-auto-review-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9])' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the pr-auto-review/v1-stable channel." >&2 - return 1 - fi -} - -@test "all four trigger events are present" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -wf = yaml.safe_load(open(sys.argv[1], encoding="utf-8")) -# PyYAML (YAML 1.1) parses the bare key 'on' as boolean True -on = wf.get(True) or wf.get('on') or {} -required = { - 'workflow_run': {'completed'}, - 'check_suite': {'completed'}, - 'pull_request_review': {'submitted', 'dismissed'}, - 'pull_request': {'opened', 'reopened', 'synchronize', 'ready_for_review'}, -} -for event, expected_types in required.items(): - if event not in on: - print(f"Missing trigger event: {event}") - sys.exit(1) - actual = set((on[event] or {}).get('types', [])) - if actual != expected_types: - print(f"{event} types must be exactly {sorted(expected_types)}, got {sorted(actual)}") - sys.exit(1) -PYEOF -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly the read scopes the reusable needs and forwards the named secret" { - # Parse the job permissions via YAML to reject any extra scopes (e.g. contents: write) - # that would silently broaden the reusable's effective token. - python3 - "$STUB" <<'PYEOF' -import yaml, sys -wf = yaml.safe_load(open(sys.argv[1], encoding="utf-8")) -job = wf.get('jobs', {}).get('pr-auto-review', {}) -perms = job.get('permissions', {}) or {} -expected = {'pull-requests': 'read', 'checks': 'read', 'actions': 'read'} -if perms != expected: - print(f"Job permissions must be exactly {expected}") - print(f"Got: {perms}") - sys.exit(1) -secrets = job.get('secrets', {}) or {} -expected_secret = '${{ secrets.GH_PAT_DON_PETRY || secrets.GH_PAT_WORKFLOWS }}' -if secrets.get('GH_PAT_WORKFLOWS') != expected_secret: - print("GH_PAT_WORKFLOWS secret forwarding is incorrect") - sys.exit(1) -PYEOF -} diff --git a/tests/pr-quality-ruleset.bats b/tests/pr-quality-ruleset.bats deleted file mode 100644 index db049e4..0000000 --- a/tests/pr-quality-ruleset.bats +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bats -# Compliance regression guard for the pr-quality ruleset Standard -# (combsmith/.github → standards/github-settings.md#pr-quality--standard-ruleset-all-repositories, -# codified at standards/rulesets/pr-quality.json). -# -# The org "pr-quality" branch ruleset enforces PR-review quality on the default -# branch. Its parameters are codified as JSON in the org repo (the source of -# truth) and applied to the live repo by the org tooling scripts/apply-rulesets.sh. -# The weekly compliance audit flags drift between the live ruleset and that -# codified standard — e.g. issue #145: require_last_push_approval drifted from the -# expected true to false. -# -# This guard mirrors that audit offline: it pins the codified pull_request rule -# parameters — copied verbatim from the org source of truth into -# standards/rulesets/pr-quality.json — so drift in the codified value is caught in -# CI rather than only by the weekly audit. If the org updates the standard, -# re-copy standards/rulesets/pr-quality.json and update the expectations below. - -RULESET_JSON="${BATS_TEST_DIRNAME}/../standards/rulesets/pr-quality.json" - -# Read one value from the pull_request rule's parameters as its JSON literal. -# Uses python3 (already installed in CI for the compliance job) — no jq dependency. -pr_param() { - python3 - "$RULESET_JSON" "$1" << 'PY' -import json, sys -with open(sys.argv[1], encoding='utf-8') as f: - data = json.load(f) -rule = next(r for r in data["rules"] if r["type"] == "pull_request") -print(json.dumps(rule["parameters"][sys.argv[2]])) -PY -} - -@test "codified pr-quality ruleset exists" { - [ -f "$RULESET_JSON" ] -} - -@test "codified pr-quality ruleset is valid JSON" { - python3 -c 'import json,sys -with open(sys.argv[1], encoding="utf-8") as f: - json.load(f)' "$RULESET_JSON" -} - -@test "ruleset targets the default branch with active enforcement" { - run python3 -c 'import json,sys -with open(sys.argv[1], encoding="utf-8") as f: - d = json.load(f) -print(json.dumps({"target": d["target"], "enforcement": d["enforcement"], "include": d["conditions"]["ref_name"]["include"], "exclude": d["conditions"]["ref_name"]["exclude"]}, separators=(",", ":")))' "$RULESET_JSON" - [ "$status" -eq 0 ] - [ "$output" = '{"target":"branch","enforcement":"active","include":["~DEFAULT_BRANCH"],"exclude":[]}' ] -} - -@test "require_last_push_approval is enabled (guards issue #145 drift)" { - [ "$(pr_param require_last_push_approval)" = "true" ] -} - -@test "required_approving_review_count is 1" { - [ "$(pr_param required_approving_review_count)" = "1" ] -} - -@test "require_code_owner_review is enabled" { - [ "$(pr_param require_code_owner_review)" = "true" ] -} - -@test "required_review_thread_resolution is enabled" { - [ "$(pr_param required_review_thread_resolution)" = "true" ] -} - -@test "dismiss_stale_reviews_on_push is enabled" { - [ "$(pr_param dismiss_stale_reviews_on_push)" = "true" ] -} - -@test "allowed_merge_methods is squash-only" { - [ "$(pr_param allowed_merge_methods)" = '["squash"]' ] -} diff --git a/tests/pr-review-mention-stub.bats b/tests/pr-review-mention-stub.bats deleted file mode 100644 index 0cbe4a5..0000000 --- a/tests/pr-review-mention-stub.bats +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bats -# Drift & compliance regression guard for the pr-review-mention thin caller stub. -# -# .github/workflows/pr-review-mention.yml is copied VERBATIM from the canonical -# org template (combsmith/.github → standards/workflows/pr-review-mention.yml) -# and must stay byte-identical across every adopting repo, modulo the per-repo -# channel pin on the `uses:` ref. Any other diff is drift — the silent-revert -# class of failure the fleet stub-drift monitor exists to catch (fleet_stub_drift.sh). -# -# The stub's behavior lives entirely in the central reusable; its `uses:` ref, -# trigger events, and job `permissions:` block are drift-protected and MUST NOT -# be edited in the caller (see the file's own "AGENTS — READ BEFORE EDITING" -# banner and ci-standards.md → Reusable workflow versioning). This guard pins -# those invariants so drift is caught in CI rather than in production run health. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/pr-review-mention.yml" - -@test "pr-review-mention stub exists" { - [ -f "$STUB" ] -} - -@test "pr-review-mention stub is byte-identical to the canonical template" { - # Inline canonical snapshot — update this heredoc whenever the central template - # (combsmith/.github/standards/workflows/pr-review-mention.yml) changes. - # Replaces the external seed-repo-template.sh dependency that was not present in - # this repo and caused CI to fail with exit 127 on every run. - local canon - canon="$(mktemp)" - # The live canonical (combsmith/.github → standards/workflows/pr-review-mention.yml, - # blob 2d6c410e) ships this stub WITH a single trailing newline. Emit the heredoc - # with exactly one trailing newline (printf '%s\n') so this guard stays byte-faithful - # to the upstream blob that the fleet stub-drift monitor compares SHAs against. - printf '%s\n' "$(cat << 'CANONICAL' -# ───────────────────────────────────────────────────────────────────────────── -# SOURCE OF TRUTH: combsmith/.github/standards/workflows/pr-review-mention.yml -# Standard: combsmith/.github/standards/ci-standards.md -# Reusable: combsmith/.github/.github/workflows/pr-review-mention-reusable.yml -# -# AGENTS — READ BEFORE EDITING: -# • This file is a THIN CALLER STUB. All review-dispatch logic lives in the -# reusable workflow above. -# • You MUST NOT change: the `uses:` ref — it is pinned to the -# `pr-review-mention/v2-stable` channel, a moving tag advanced centrally. -# Never repoint it to `@main`, a SHA, or a frozen `@vX` (see -# ci-standards.md → Reusable workflow versioning). Also do not change the -# trigger events or the job-level `permissions:` block — reusable workflows -# can be granted no more permissions than the calling job, so removing the -# stanza breaks the reusable's gh API calls. -# • If you need different behaviour, open a PR against the reusable in the -# central repo. A new release is rolled out by moving the channel tag -# centrally — never by editing callers, so no fanout PR is needed. -# ───────────────────────────────────────────────────────────────────────────── -# -# PR Review Mention — thin caller for the org-level reusable. -# To adopt: copy this file to .github/workflows/pr-review-mention.yml in your repo. -# Requires (org secrets, already present in combsmith org): -# GH_PAT_DON_PETRY canonical PAT for API calls and dispatching the review agent. -# GH_PAT_WORKFLOWS is the deprecated transition alias, kept as the -# `||` fallback until the persona rename lands fleet-wide. -# DON_PETRY_BOT_GH_PAT PAT owned by donpetry-bot, for posting acknowledgement comments. -name: PR Review — Mention Trigger - -on: - issue_comment: - types: [created] - pull_request_review_comment: - types: [created] - pull_request: - types: [review_requested] - -permissions: {} - -jobs: - pr-review-mention: - permissions: - pull-requests: write - uses: combsmith/.github/.github/workflows/pr-review-mention-reusable.yml@pr-review-mention/v2-stable # NOSONAR(githubactions:S7637) first-party channel ref - secrets: - GH_PAT_WORKFLOWS: ${{ secrets.GH_PAT_DON_PETRY || secrets.GH_PAT_WORKFLOWS }} - DON_PETRY_BOT_GH_PAT: ${{ secrets.DON_PETRY_BOT_GH_PAT }} -CANONICAL -)" > "$canon" - run cmp -- "$canon" "$STUB" - rm -f "$canon" - [ "$status" -eq 0 ] || { - echo "stub drifted from canonical: $output" - return 1 - } -} - -@test "uses: ref is pinned to the pr-review-mention/v2-stable channel" { - grep -qF 'uses: combsmith/.github/.github/workflows/pr-review-mention-reusable.yml@pr-review-mention/v2-stable' "$STUB" -} - -@test "uses: ref is not repointed to @main, a SHA, or a frozen @vN" { - if grep -qE 'pr-review-mention-reusable\.yml@(main|[0-9a-f]{7,40}|v[0-9]+([[:space:]]|$))' "$STUB"; then - echo "Error: The uses: ref in $STUB is pointed to a forbidden ref (main, SHA, or frozen vN)." >&2 - echo "It must be pinned to the pr-review-mention/v2-stable channel." >&2 - return 1 - fi -} - -@test "all three trigger events are present" { - grep -qE '^ issue_comment:' "$STUB" || { echo "Missing issue_comment trigger"; return 1; } - grep -qE '^ pull_request_review_comment:' "$STUB" || { echo "Missing pull_request_review_comment trigger"; return 1; } - grep -qE '^ pull_request:' "$STUB" || { echo "Missing pull_request trigger"; return 1; } - grep -qE '^ types: \[review_requested\]' "$STUB" || { echo "Missing pull_request review_requested type"; return 1; } -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly pull-requests: write and forwards named secrets" { - grep -qE '^ pull-requests: write' "$STUB" || { echo "Missing pull-requests: write permission"; return 1; } - grep -qF 'GH_PAT_WORKFLOWS: ${{ secrets.GH_PAT_DON_PETRY || secrets.GH_PAT_WORKFLOWS }}' "$STUB" \ - || { echo "Missing GH_PAT_WORKFLOWS secret with GH_PAT_DON_PETRY fallback"; return 1; } - grep -qF 'DON_PETRY_BOT_GH_PAT: ${{ secrets.DON_PETRY_BOT_GH_PAT }}' "$STUB" \ - || { echo "Missing DON_PETRY_BOT_GH_PAT secret"; return 1; } -} diff --git a/tests/sonarcloud-stub.bats b/tests/sonarcloud-stub.bats deleted file mode 100644 index 3e0c6a5..0000000 --- a/tests/sonarcloud-stub.bats +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env bats -# Behavior & drift guard for the SonarCloud analysis workflow. -# -# .github/workflows/sonarcloud.yml ships verbatim into repos created from -# combsmith/repo-template (SOURCE OF TRUTH: -# combsmith/.github/standards/workflows/sonarcloud.yml). Its job name is the -# required `SonarCloud` status check, and the org convention is a first scan that -# is continue-on-error with a SINGLE retry (the analysis endpoint is occasionally -# flaky). -# -# Issue #137 (Fleet Monitor): the workflow's failure rate crossed the 10% -# threshold because the retry fired IMMEDIATELY after the first failure, so a -# transient endpoint blip failed both attempts back-to-back. The fix inserts a -# short backoff between the failed scan and the retry. This guard pins that -# backoff plus the invariants it must not break. - -STUB="${BATS_TEST_DIRNAME}/../.github/workflows/sonarcloud.yml" - -@test "sonarcloud workflow exists" { - [ -f "$STUB" ] -} - -@test "job name is the required 'SonarCloud' status check" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding='utf-8') as f: - wf = yaml.safe_load(f) -job = wf.get('jobs', {}).get('sonarcloud', {}) -if job.get('name') != 'SonarCloud': - print(f"job 'sonarcloud' name must be 'SonarCloud', got {job.get('name')!r}") - sys.exit(1) -PYEOF -} - -@test "first scan is continue-on-error and the retry is gated on its failure" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding='utf-8') as f: - wf = yaml.safe_load(f) -steps = wf.get('jobs', {}).get('sonarcloud', {}).get('steps', []) -first = next((s for s in steps if s.get('id') == 'sonar'), None) -if first is None: - print("no step with id 'sonar' (the first scan) found") - sys.exit(1) -if first.get('continue-on-error') is not True: - print("the first scan (id: sonar) must set continue-on-error: true") - sys.exit(1) -scans = [s for s in steps if 'sonarqube-scan-action' in str(s.get('uses', ''))] -if len(scans) != 2: - print(f"expected exactly 2 sonarqube-scan-action steps, got {len(scans)}") - sys.exit(1) -retry = scans[1] -if "steps.sonar.outcome == 'failure'" not in str(retry.get('if', '')): - print("retry step must be gated on steps.sonar.outcome == 'failure'") - sys.exit(1) -PYEOF -} - -@test "a backoff step waits between the failed scan and the retry (issue #137)" { - # The whole point of the fix: a transient endpoint blip must not fail both - # attempts back-to-back. A backoff (sleep) step, gated on the same failure - # condition, must sit AFTER the first scan and BEFORE the retry. - python3 - "$STUB" <<'PYEOF' -import yaml, sys, re -with open(sys.argv[1], encoding='utf-8') as f: - wf = yaml.safe_load(f) -steps = wf.get('jobs', {}).get('sonarcloud', {}).get('steps', []) - -def idx(pred): - return next((i for i, s in enumerate(steps) if pred(s)), None) - -first_i = idx(lambda s: s.get('id') == 'sonar') -retry_i = idx(lambda s: s.get('id') != 'sonar' - and 'sonarqube-scan-action' in str(s.get('uses', ''))) -if first_i is None or retry_i is None: - print("could not locate both the first scan and the retry scan") - sys.exit(1) - -backoff_i = None -for i, s in enumerate(steps): - run = str(s.get('run', '')) - if re.search(r'\bsleep\b', run): - backoff_i = i - gate = str(s.get('if', '')) - if "steps.sonar.outcome == 'failure'" not in gate: - print("backoff step must be gated on steps.sonar.outcome == 'failure' " - "so it only runs on the retry path") - sys.exit(1) - m = re.search(r'sleep\s+(\d+)', run) - if not m or int(m.group(1)) != 30: - print("backoff step must sleep exactly 30 seconds") - sys.exit(1) - break - -if backoff_i is None: - print("no backoff (sleep) step found — an immediate retry lands in the same " - "transient outage window (issue #137)") - sys.exit(1) -if not (first_i < backoff_i < retry_i): - print("backoff step must sit AFTER the first scan and BEFORE the retry") - sys.exit(1) -PYEOF -} - -@test "top-level permissions are locked down to {}" { - grep -q '^permissions: {}' "$STUB" || { echo "Top-level permissions are not locked down to {}"; return 1; } -} - -@test "job grants exactly the read scopes the scan needs" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding='utf-8') as f: - wf = yaml.safe_load(f) -job = wf.get('jobs', {}).get('sonarcloud', {}) -perms = job.get('permissions', {}) or {} -expected = {'contents': 'read', 'pull-requests': 'read'} -if perms != expected: - print(f"Job permissions must be exactly {expected}, got {perms}") - sys.exit(1) -PYEOF -} - -@test "triggers are push + pull_request to main and checkout uses fetch-depth: 0" { - python3 - "$STUB" <<'PYEOF' -import yaml, sys -with open(sys.argv[1], encoding='utf-8') as f: - wf = yaml.safe_load(f) -# PyYAML (YAML 1.1) parses the bare key 'on' as boolean True -on = wf.get(True) or wf.get('on') or {} -allowed_events = {'push', 'pull_request'} -extra_events = {str(k) for k in on.keys()} - allowed_events -if extra_events: - print(f"trigger set must be exactly {{push, pull_request}}, found extra: {sorted(extra_events)}") - sys.exit(1) -for event in ('push', 'pull_request'): - branches = (on.get(event) or {}).get('branches', []) - if branches != ['main']: - print(f"{event} must target branches [main], got {branches}") - sys.exit(1) -steps = wf.get('jobs', {}).get('sonarcloud', {}).get('steps', []) -checkout = next((s for s in steps if 'actions/checkout' in str(s.get('uses', ''))), None) -if checkout is None: - print("no checkout step found") - sys.exit(1) -if (checkout.get('with') or {}).get('fetch-depth') != 0: - print("checkout must set fetch-depth: 0") - sys.exit(1) -PYEOF -} - -@test "every third-party action is pinned to a full-length commit SHA" { - # Match `uses:` lines (not comments) and require a 40-hex SHA ref. - while IFS= read -r ref; do - if ! printf '%s' "$ref" | grep -qE '@[0-9a-f]{40}$'; then - echo "action ref is not pinned to a 40-char SHA: $ref" >&2 - return 1 - fi - done < <(grep -oE 'uses:[[:space:]]+[^[:space:]#]+' "$STUB" | awk '{print $2}') -} - -@test "stub carries no TODO/FIXME marker (SonarCloud githubactions:S1135 regression guard)" { - if grep -nE '(TODO|FIXME)' "$STUB"; then - echo "Error: $STUB still contains a TODO/FIXME marker — SonarCloud S1135 will re-open." >&2 - return 1 - fi -} - -@test "ci.yml defines the required secret-scan job" { - grep -qE '^ secret-scan:' "${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" -} - -@test "secret-scan job has the required display name" { - grep -qF 'name: Secret scan (gitleaks)' "${BATS_TEST_DIRNAME}/../.github/workflows/ci.yml" -}