From 8d0dc2fbe00ee75a811c3b6a4bc2bbe70ad5ed8b Mon Sep 17 00:00:00 2001 From: Pedro Brito <74918167+pedrobritx@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:18:11 -0300 Subject: [PATCH] Gate production acceptance on CI and the exact Pages deployment --- .github/workflows/production-smoke.yml | 7 +++- docs/ACCEPTANCE.md | 18 +++++--- outputs/verification.json | 26 ++++++++++++ tests/acceptance/wait_pages.py | 48 ++++++++++++++++++++++ tests/test_deployment_gate.py | 57 ++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 tests/acceptance/wait_pages.py create mode 100644 tests/test_deployment_gate.py diff --git a/.github/workflows/production-smoke.yml b/.github/workflows/production-smoke.yml index db87f4f..019682a 100644 --- a/.github/workflows/production-smoke.yml +++ b/.github/workflows/production-smoke.yml @@ -2,13 +2,14 @@ name: Deployed site acceptance on: workflow_run: - workflows: ["pages build and deployment"] + workflows: ["CI"] types: [completed] branches: [main] workflow_dispatch: permissions: contents: read + actions: read jobs: production: @@ -32,6 +33,10 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12' + - name: Confirm successful Pages deployment for this revision + env: + GITHUB_TOKEN: ${{ github.token }} + run: python3 tests/acceptance/wait_pages.py - uses: actions/setup-node@v4 with: node-version: '24' diff --git a/docs/ACCEPTANCE.md b/docs/ACCEPTANCE.md index 36356a6..249586c 100644 --- a/docs/ACCEPTANCE.md +++ b/docs/ACCEPTANCE.md @@ -33,11 +33,19 @@ Reports are written under `test-results/production/` and `playwright-report/production/`, separately from the existing browser suite. The normal CI matrix runs the local rehearsal on all three engines. The -`Deployed site acceptance` workflow is configured to run after a successful, -same-repository main-branch Pages workflow, and can also be dispatched manually. -It checks out the triggering deployment's source revision. The new workflow -must be merged to the default branch before its post-deployment trigger can be -verified; its configured trigger is not evidence that it has run. +`Deployed site acceptance` workflow runs after successful same-repository +main-branch CI, and can also be dispatched manually. Before checking the live +site, it requires a successful GitHub-managed Pages deployment of that exact +revision, with a three-minute bounded wait. A failed or missing deployment fails +the gate; an older deployment cannot satisfy it. The checked-out revision and +browser report metadata use the triggering CI's source SHA. + +The first PR #10 merge (`dfbed94`) passed main CI and Pages, but the original +`workflow_run` subscription to the GitHub-managed dynamic Pages workflow did +not start any acceptance run. The follow-up uses the repository's normal CI +workflow as its entry point and checks Pages explicitly. Its actual hosted +trigger remains unverified until the follow-up merges and runs; a configured +trigger alone is not evidence of execution. ## Native macOS dry-run compatibility diff --git a/outputs/verification.json b/outputs/verification.json index ee5d390..4ff598e 100644 --- a/outputs/verification.json +++ b/outputs/verification.json @@ -242,5 +242,31 @@ "reason": "BRITX dry run exceeded original 60-second collector budget", "realInstallationPerformed": false } + }, + "deploymentTriggerFollowUp": { + "verifiedDateBrasilia": "2026-10-25", + "testedBaseCommit": "dfbed9484a85124d88859be8797fbe147dcd6856", + "mainCi": "https://github.com/pedrobritx/mac-setup/actions/runs/40199599717", + "mainCiConclusion": "success", + "pagesDeployment": "https://github.com/pedrobritx/mac-setup/actions/runs/40199599590", + "pagesDeploymentConclusion": "success", + "originalPagesWorkflowSubscriptionProducedAcceptanceRun": false, + "replacementEntryPoint": "successful same-repository main CI; require successful Pages run for the exact SHA", + "localTests": { + "node": 15, + "python": 21, + "deploymentGateRegressions": 4 + }, + "realApiDeploymentGatePassed": true, + "workflowLint": "actionlint 1.7.12 passed", + "dockerAvailable": false, + "hostedReplacementTriggerVerified": false, + "realInstallationPerformed": false, + "humanAcceptancePerformed": false, + "sourceSha256": { + ".github/workflows/production-smoke.yml": "694ee7202f7dd5381e45e92f09fcdd251be8e3a91453c7b6eb838ef2ccf29b89", + "tests/acceptance/wait_pages.py": "cd7bdc8e586de024222e3ed27678308cc7d16b760e2d4cb1faf71aa9f6e443a3", + "tests/test_deployment_gate.py": "bf0185049ede5ed39426f55c64ca0a23d3cdf50199184e867d0fa146eba049ab" + } } } diff --git a/tests/acceptance/wait_pages.py b/tests/acceptance/wait_pages.py new file mode 100644 index 0000000..1a1525c --- /dev/null +++ b/tests/acceptance/wait_pages.py @@ -0,0 +1,48 @@ +"""Require a successful Pages deployment of the exact revision under test.""" + +import json +import os +import time +from urllib.parse import urlencode +from urllib.request import Request, urlopen + + +def wait_for_pages(fetch_runs, sha, repository, *, timeout=180, interval=5, + clock=time.monotonic, pause=time.sleep): + deadline = clock() + timeout + while True: + candidates = [run for run in fetch_runs() if ( + run.get("path") == "dynamic/pages/pages-build-deployment" + and run.get("head_sha") == sha + and run.get("head_branch") == "main" + and (run.get("head_repository") or {}).get("full_name") == repository + )] + if candidates: + run = max(candidates, key=lambda run: run["id"]) + if run["status"] == "completed": + if run["conclusion"] != "success": + raise RuntimeError(f"Pages deployment {run['id']}: {run['conclusion']}") + return run + if clock() >= deadline: + raise TimeoutError(f"No successful Pages deployment for {sha} within {timeout}s") + pause(min(interval, max(0, deadline - clock()))) + + +def fetch_runs(repository, sha): + query = urlencode({"head_sha": sha, "per_page": 100}) + headers = {"Accept": "application/vnd.github+json"} + if os.environ.get("GITHUB_TOKEN"): + headers["Authorization"] = "Bearer " + os.environ["GITHUB_TOKEN"] + request = Request( + f"https://api.github.com/repos/{repository}/actions/runs?{query}", + headers=headers, + ) + with urlopen(request, timeout=15) as response: + return json.load(response)["workflow_runs"] + + +if __name__ == "__main__": + repository = os.environ["GITHUB_REPOSITORY"] + sha = os.environ["MAC_SETUP_EXPECTED_COMMIT"] + run = wait_for_pages(lambda: fetch_runs(repository, sha), sha, repository) + print(f"Confirmed Pages deployment for {sha}: {run['html_url']}") diff --git a/tests/test_deployment_gate.py b/tests/test_deployment_gate.py new file mode 100644 index 0000000..5d9a1a8 --- /dev/null +++ b/tests/test_deployment_gate.py @@ -0,0 +1,57 @@ +"""Deployment gate checks: require the tested revision, never an older success.""" + +import importlib.util +from pathlib import Path +import unittest + +spec = importlib.util.spec_from_file_location( + "wait_pages", Path(__file__).parent / "acceptance/wait_pages.py" +) +gate = importlib.util.module_from_spec(spec) +spec.loader.exec_module(gate) + + +class DeploymentGateTests(unittest.TestCase): + def run_record(self, **changes): + return dict({ + "id": 1, "path": "dynamic/pages/pages-build-deployment", + "head_sha": "tested", "head_branch": "main", + "head_repository": {"full_name": "owner/repo"}, + "status": "completed", "conclusion": "success", + }, **changes) + + def wait(self, batches): + now = [0] + def pause(seconds): + now[0] += seconds + return gate.wait_for_pages( + lambda: next(batches), "tested", "owner/repo", timeout=2, + interval=1, clock=lambda: now[0], pause=pause, + ) + + def test_waits_for_matching_revision_and_completed_deployment(self): + result = self.wait(iter([ + [self.run_record(head_sha="old")], + [self.run_record(status="in_progress", conclusion=None)], + [self.run_record()], + ])) + self.assertEqual(result["head_sha"], "tested") + + def test_latest_failed_run_cannot_be_hidden_by_old_success(self): + with self.assertRaisesRegex(RuntimeError, "Pages deployment 2: failure"): + self.wait(iter([[self.run_record(), self.run_record(id=2, conclusion="failure")]])) + + def test_wrong_workflow_branch_and_repository_cannot_satisfy_gate(self): + runs = [self.run_record(path=".github/workflows/ci.yml"), + self.run_record(head_branch="feature"), + self.run_record(head_repository={"full_name": "fork/repo"})] + with self.assertRaises(TimeoutError): + self.wait(iter([runs, runs, runs])) + + def test_missing_run_expires_instead_of_accepting_old_deployment(self): + with self.assertRaises(TimeoutError): + self.wait(iter([[], [], []])) + + +if __name__ == "__main__": + unittest.main()