The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.
Python
Restore the pull request previews of the docs and the coverage report
Sina Atalaycfa0cbb4301a
diff --git a/.github/deploy/cleanup.py b/.github/deploy/cleanup.pynew file mode 100644index 00000000..bbe97801--- /dev/null+++ b/.github/deploy/cleanup.py@@ -0,0 +1,39 @@+"""Delete one PR preview; a preview that was never built is already absent."""++import json+import os+from urllib.error import HTTPError+from urllib.parse import quote+from urllib.request import Request, urlopen+++def delete_preview(account_id: str, worker: str, preview: str, token: str) -> None:+ """Delete the preview, tolerating only the API's not-found response."""+ request = Request(+ "https://api.cloudflare.com/client/v4/accounts/"+ f"{quote(account_id, safe='')}/workers/workers/"+ f"{quote(worker, safe='')}/previews/{quote(preview, safe='')}",+ method="DELETE",+ headers={"Authorization": f"Bearer {token}"},+ )+ try:+ with urlopen(request, timeout=30) as response:+ result = json.load(response)+ except HTTPError as error:+ error.close()+ if error.code != 404:+ raise+ print(f"{worker}/{preview} is already absent")+ return+ if not isinstance(result, dict) or result.get("success") is not True:+ raise RuntimeError(f"Cloudflare did not confirm deletion of {worker}/{preview}")+ print(f"Deleted {worker}/{preview}")+++if __name__ == "__main__":+ delete_preview(+ os.environ["CLOUDFLARE_ACCOUNT_ID"],+ os.environ["WORKER"],+ f"pr-{int(os.environ['PR_NUMBER'])}",+ os.environ["CLOUDFLARE_API_TOKEN"],+ )diff --git a/.github/deploy/coverage.jsonc b/.github/deploy/coverage.jsoncindex bdf884ac..6c89ea12 100644--- a/.github/deploy/coverage.jsonc+++ b/.github/deploy/coverage.jsonc@@ -7,6 +7,9 @@"assets": { "directory": "../../htmlcov" },// Academa's internal/manimgx-hosting Terraform unit owns the domain and Worker identity."workers_dev": false,- // the domain is the only address: no version is served on workers.dev either- "preview_urls": false+ // each commit's report is a deployment in the preview "main" or "pr-<number>", at+ // <preview>-manimgx-coverage.<account subdomain>.workers.dev; Cloudflare retains their+ // deployment history within the account plan's preview limits+ "preview_urls": true,+ "previews": {}}diff --git a/.github/deploy/docs.jsonc b/.github/deploy/docs.jsoncindex 3b6e27b4..ced4fd0f 100644--- a/.github/deploy/docs.jsonc+++ b/.github/deploy/docs.jsonc@@ -13,7 +13,9 @@},// Academa's internal/manimgx-hosting Terraform unit owns the domain and Worker identity."workers_dev": false,- // the domain is the only address: no version is served on workers.dev either- "preview_urls": false,+ // a pull request is previewed at pr-<number>-manimgx-docs.<account subdomain>.workers.dev+ // (set explicitly because `workers_dev` is disabled)+ "preview_urls": true,+ "previews": {},"observability": { "enabled": true }}diff --git a/.github/workflows/deploy-docs.yaml b/.github/workflows/deploy-docs.yamlindex c1d95cda..9c3e8459 100644--- a/.github/workflows/deploy-docs.yaml+++ b/.github/workflows/deploy-docs.yaml@@ -1,7 +1,7 @@# The docs site, on Cloudflare Workers (.github/deploy/docs.jsonc): built on every push and-# pull request, and deployed from main to https://manimgx.academa.ai. The build gets no-# secrets. The deploy uses main's deployment configuration, checked out separately from the-# artifact, which contains only the built site.+# pull request, deployed from main to https://manimgx.academa.ai, and previewed per pull request.+# The build gets no secrets. Publishing uses the base branch's deployment configuration,+# checked out separately from the artifact, which contains only the built site.name: Deploy docs@@ -9,6 +9,7 @@ on:push:branches: [main]pull_request:+ types: [opened, synchronize, reopened, closed]workflow_dispatch:permissions: {}@@ -24,6 +25,7 @@ env:jobs:build:name: Build+ if: github.event.action != 'closed'runs-on: macos-26# A cold build compiles the engine and renders the full gallery before hundreds of# short API examples. Measured cold work exceeds 45 minutes; warm builds reuse films.@@ -137,6 +139,7 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:+ ref: ${{ github.event.pull_request.base.sha || github.sha }}persist-credentials: falsesparse-checkout: .github/deploysparse-checkout-cone-mode: false@@ -155,3 +158,81 @@ jobs:env:CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}++ preview:+ name: Preview+ needs: build+ # pull requests from forks and from Dependabot get no secrets: they are built, not previewed+ if: >-+ github.event_name == 'pull_request'+ && github.event.pull_request.head.repo.full_name == github.repository+ && github.actor != 'dependabot[bot]'+ runs-on: ubuntu-24.04+ timeout-minutes: 10+ permissions:+ contents: read+ environment:+ name: docs-preview+ url: ${{ steps.preview.outputs.url }}+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ ref: ${{ github.event.pull_request.base.sha || github.sha }}+ persist-credentials: false+ sparse-checkout: .github/deploy+ sparse-checkout-cone-mode: false++ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1+ with:+ name: docs+ path: docs/site++ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0++ - name: Preview the site+ id: preview+ run: |+ bunx "wrangler@${WRANGLER_VERSION}" preview --config .github/deploy/docs.jsonc \+ --name "pr-${PR_NUMBER}" --message "${HEAD_SHA}"+ url="$(jq -er 'select(.type == "preview") | .preview_urls[0]' "${WRANGLER_OUTPUT_FILE_PATH}")"+ echo "url=${url}" >> "${GITHUB_OUTPUT}"+ env:+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}+ CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}+ WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/wrangler.ndjson+ PR_NUMBER: ${{ github.event.pull_request.number }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}++ delete-preview:+ name: Delete the ${{ matrix.site }} preview+ if: >-+ github.event.action == 'closed'+ && github.event.pull_request.head.repo.full_name == github.repository+ && github.actor != 'dependabot[bot]'+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ strategy:+ fail-fast: false+ matrix:+ site: [docs, coverage]+ permissions:+ contents: read+ environment:+ name: ${{ matrix.site }}-preview+ deployment: false+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ ref: ${{ github.event.pull_request.base.sha || github.sha }}+ persist-credentials: false+ sparse-checkout: .github/deploy+ sparse-checkout-cone-mode: false++ - name: Delete the preview+ # Only an absent preview is ignored; authentication and API failures fail the job.+ run: python3 .github/deploy/cleanup.py+ env:+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}+ CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}+ WORKER: manimgx-${{ matrix.site }}+ PR_NUMBER: ${{ github.event.pull_request.number }}diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yamlindex fd241142..be947234 100644--- a/.github/workflows/release.yaml+++ b/.github/workflows/release.yaml@@ -87,6 +87,7 @@ jobs:uses: $/.github/workflows/test.yamlpermissions:contents: read+ statuses: writewheels:name: Wheelsdiff --git a/.github/workflows/test.yaml b/.github/workflows/test.yamlindex b89616aa..e284a960 100644--- a/.github/workflows/test.yaml+++ b/.github/workflows/test.yaml@@ -1,7 +1,7 @@# The checks every change must pass: the pre-commit checks, and the tests on each OS and Python-# ManimGX supports. Their coverage is combined into one report, whose table is in the run's-# summary; main's report is published on Cloudflare, at https://coverage.manimgx.academa.ai.-# A tagged release requires these checks before publication.+# ManimGX supports. Their coverage is combined into one report on Cloudflare: main's at+# https://coverage.manimgx.academa.ai, a pull request's on its preview URL, and each commit's+# linked from its "coverage" status. A tagged release requires these checks before publication.name: Test@@ -293,20 +293,26 @@ jobs:publish-coverage:name: Publish the coverageneeds: coverage- # main's complete report; every run's summary has its own table+ # main's pushes, and pull requests from this repository: pull requests from forks and from+ # Dependabot get no secretsif: >-- github.event_name == 'push' && github.ref == 'refs/heads/main'- && needs.coverage.outputs.total != '' && needs.coverage.outputs.total != 'partial'+ needs.coverage.outputs.total != '' && needs.coverage.outputs.total != 'partial' && (+ (github.event_name == 'push' && github.ref == 'refs/heads/main')+ || (github.event_name == 'pull_request'+ && github.event.pull_request.head.repo.full_name == github.repository+ && github.actor != 'dependabot[bot]'))runs-on: ubuntu-24.04timeout-minutes: 10permissions:contents: read+ statuses: writeenvironment:- name: coverage- url: https://coverage.manimgx.academa.ai+ name: ${{ github.event_name == 'push' && 'coverage' || 'coverage-preview' }}+ url: ${{ steps.publish.outputs.url }}steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:+ ref: ${{ github.event.pull_request.base.sha || github.sha }}persist-credentials: falsesparse-checkout: .github/deploysparse-checkout-cone-mode: false@@ -318,10 +324,32 @@ jobs:- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0+ # main's report goes to its domain; every commit's report is also a deployment of its own+ # (in the Worker's preview "main", or "pr-<number>"), which its status links to- name: Publish the report- run: >-- bunx "wrangler@${WRANGLER_VERSION}" deploy --config .github/deploy/coverage.jsonc- --message "${GITHUB_SHA}"+ id: publish+ run: |+ if [[ "${GITHUB_EVENT_NAME}" == push ]]; then+ bunx "wrangler@${WRANGLER_VERSION}" deploy --config .github/deploy/coverage.jsonc \+ --message "${SHA}"+ url="https://coverage.manimgx.academa.ai"+ preview="main"+ else+ preview="pr-${PR_NUMBER}"+ fi+ bunx "wrangler@${WRANGLER_VERSION}" preview --config .github/deploy/coverage.jsonc \+ --name "${preview}" --message "${SHA}"+ deployment="$(jq -er 'select(.type == "preview") | .deployment_urls[0]' "${WRANGLER_OUTPUT_FILE_PATH}")"+ url="${url:-$(jq -er 'select(.type == "preview") | .preview_urls[0]' "${WRANGLER_OUTPUT_FILE_PATH}")}"+ echo "url=${url}" >> "${GITHUB_OUTPUT}"+ gh api "repos/${GITHUB_REPOSITORY}/statuses/${SHA}" --field state=success \+ --field context=coverage --field description="${TOTAL}% of lines run" \+ --field target_url="${deployment}"env:CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}+ WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/wrangler.ndjson+ GH_TOKEN: ${{ github.token }}+ SHA: ${{ github.event.pull_request.head.sha || github.sha }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ TOTAL: ${{ needs.coverage.outputs.total }}diff --git a/docs/content/_headers b/docs/content/_headersindex a4e67082..2c366059 100644--- a/docs/content/_headers+++ b/docs/content/_headers@@ -14,3 +14,7 @@/assets/stylesheets/*Cache-Control: public, max-age=31536000, immutable++# workers.dev hosts (previews, and the site until it has its domain) stay out of search results+https://:version.:subdomain.workers.dev/*+ X-Robots-Tag: noindexdiff --git a/docs/content/changelog.md b/docs/content/changelog.mdindex cf98de01..e12f7989 100644--- a/docs/content/changelog.md+++ b/docs/content/changelog.md@@ -37,10 +37,6 @@ The notable changes to ManimGX, release by release. The format follows- Preserve the benchmark comparison images' aspect ratios when PyPI narrows the README table.- Credit Filament, whose code the 3D lighting is adapted from, in the README and the wheels' third-party notices.-### Removed--- Remove the pull request previews of the documentation and the coverage report, and the "coverage" commit status; `main` still publishes both sites.-## 0.1.1### Changeddiff --git a/docs/content/developer-guide/documentation.md b/docs/content/developer-guide/documentation.mdindex 382bae83..2f885cf6 100644--- a/docs/content/developer-guide/documentation.md+++ b/docs/content/developer-guide/documentation.md@@ -490,23 +490,24 @@ assets: no Worker script runs, and every request is answered from the files in `configures it:- The Worker, `manimgx-docs`, serves the site at its domain,- [manimgx.academa.ai](https://manimgx.academa.ai), and only there: neither the Worker nor a- version of it has a `workers.dev` address.+ [manimgx.academa.ai](https://manimgx.academa.ai).- A page is a folder (`changelog/index.html`): a request for `/changelog` is redirected to`/changelog/`.- A path that matches nothing gets the nearest `404.html`, with status 404.- `docs/content/_headers` is copied to the site's root, where Cloudflare reads it (it is- never served): security headers for every page, and long caching for the theme's bundles- (their names change with their content).+ never served): security headers for every page, long caching for the theme's bundles+ (their names change with their content), and `noindex` on `workers.dev` hosts.Academa's `internal/manimgx-hosting` Terraform unit provisions the Worker identity,custom domain and deployment credential. It also provisions the coverage report's-Worker and domain. Wrangler publishes the assets; it leaves domain ownership+Worker and domain. Wrangler publishes assets and previews; it leaves domain ownershipto Terraform. The account ID is a GitHub repository variable, and each site's deployment-token is installed in its environment by Terraform.+token is installed in its production and preview environments by Terraform.The workflow [`deploy-docs.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/deploy-docs.yaml)-builds the site on every push and pull request, and deploys it from `main`. See+builds the site on every push and pull request, deploys it from `main`, and previews each+pull request from a branch of the repository at its own address,+`pr-<number>-manimgx-docs.<account subdomain>.workers.dev`. See[GitHub workflows](github-workflows.md#3-deploy-docsyaml-the-docs-site).## Learn more@@ -518,4 +519,4 @@ builds the site on every push and pull request, and deploys it from `main`. See- [mkdocstrings' Python handler](https://mkdocstrings.github.io/python/): the options in`zensical.toml`.- [Cloudflare's static assets](https://developers.cloudflare.com/workers/static-assets/):- routing, headers.+ routing, headers, previews.diff --git a/docs/content/developer-guide/github-workflows.md b/docs/content/developer-guide/github-workflows.mdindex 6367feb6..9afd63dc 100644--- a/docs/content/developer-guide/github-workflows.md+++ b/docs/content/developer-guide/github-workflows.md@@ -6,7 +6,7 @@ Some tasks must run the same way every time:- **For every change**, pushed to `main` or proposed in a pull request: run the checks,and the tests on every system and Python ManimGX supports; time it against the code- before it; build the docs; and, from `main`, publish them and the tests' coverage.+ before it; build the docs; publish the tests' coverage and a preview of the docs.- **For every release:** test; build the wheels, the source distribution, the fontpackages and the executables; publish them to GitHub and PyPI, the package for thebrowser to npm, and the Docker image to ghcr.io.@@ -63,10 +63,12 @@ The seven regular build, release and collaboration workflows are in5. **Combine the coverage**, even when a test job failed: `just combine-coverage` makes onereport of the jobs' data, and its table goes in the run's summary. The report is kept,with the data of a coverage badge (`badge.json`).-6. **Publish the coverage**, for `main`'s pushes: to the Worker `manimgx-coverage`- ([`.github/deploy/coverage.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/coverage.jsonc)),- which serves `main`'s report at <https://coverage.manimgx.academa.ai>. A pull request's- coverage is the table in its run's summary.+6. **Publish the coverage**, for `main`'s pushes and for pull requests from a branch of the+ repository: to the Worker `manimgx-coverage`+ ([`.github/deploy/coverage.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/coverage.jsonc)).+ `main`'s report is served at <https://coverage.manimgx.academa.ai>. Each commit's report+ is also a preview deployment of its own (in the preview `main`, or `pr-<number>`), which+ the commit's "coverage" status links to.### 2. [`benchmark.yaml`](https://github.com/academa-labs/manimgx/blob/main/.github/workflows/benchmark.yaml): the timed benchmarks@@ -92,21 +94,28 @@ on a quiet machine. Linux and Windows keep their functional rendering tests.**When it runs:**- Every push to `main`.-- Every pull request.+- Every pull request, as it is opened, updated, reopened and closed.- By hand, from GitHub's interface.-**What it does**, in two jobs:+**What it does**, in four jobs:-1. **Build**, on macOS: checks the docs' JavaScript interactions and reference declarations,- restores verified film-cache entries, runs `just render-docs`, saves completed films, then- runs `just build-docs-pages`. Metal draws the examples; narrated examples speak from- `docs/voice/`, so no voice key is needed. The built `docs/site/` is kept for seven days.- The deploy checks out its configuration from `main`, separately from the artifact, so the- build cannot supply commands for a job with credentials to execute.+1. **Build**, on macOS for every run except a pull request's closing: checks the docs'+ JavaScript interactions and reference declarations, restores verified film-cache entries,+ runs `just render-docs`, saves completed films, then runs `just build-docs-pages`.+ Metal draws the examples; narrated examples speak from `docs/voice/`, so no voice key is+ needed. The built `docs/site/` is kept for seven days. Deployment configuration is checked+ out separately from the trusted base commit, so the build cannot supply commands for a job+ with credentials to execute.2. **Deploy**, from `main` (a push, or a run by hand): deploys what the build made toCloudflare Workers with `wrangler deploy --config .github/deploy/docs.jsonc`, thecommit's hash as its message. The `docs` environment shows the site's address,<https://manimgx.academa.ai>.+3. **Preview**, for a pull request from a branch of the repository: uploads the build as a+ preview named `pr-<number>`, at its own address, shown on the `docs-preview`+ environment.+4. **Delete the previews**, when a pull request closes, for both docs and coverage. An+ absent preview is already clean; authentication failures and other API errors fail+ the job.See [Documentation](documentation.md#deployment) for how the site is served.@@ -270,20 +279,21 @@ pull request is opened or marked ready for review.## Deployment credentials-Builds and tests receive no deployment credentials. The deploying jobs run only for `main`,-and use only its deployment files and the static artifacts:+Builds and tests receive no deployment credentials. Publishing jobs use only the trusted+base commit's deployment files and the static artifacts:- The checks, the tests and the docs' build run the repository's code (they build theengine and render scenes), with a token that can only read the repository. The jobs that- get Cloudflare's API token run a pinned Wrangler on the built files. Neither+ get Cloudflare's API token run a pinned Wrangler on the built files (and `gh`, to set+ the coverage status). Cleanup uses the trusted base commit's `cleanup.py`. Neitherdeployment configuration nor executable code is taken from a build artifact.- Academa's `internal/manimgx-hosting` Terraform unit owns the Worker identities,custom domains, GitHub environments and credentials. Each site's`CLOUDFLARE_API_TOKEN` can edit only that Worker; the account ID is the repository- variable `CLOUDFLARE_ACCOUNT_ID`. The sites' environments, `docs` and `coverage`, allow- only `main`.-- Pull requests, from a branch of the repository, a fork or Dependabot alike, are built and- tested; nothing of theirs is published.+ variable `CLOUDFLARE_ACCOUNT_ID`. Production environments allow `main`; preview+ environments also allow pull request merge refs.+- Pull requests from forks and from Dependabot get no secrets: they are built and tested,+ not previewed, and their coverage is not published.- The first reply's model can only read, and the job that posts its reply runs no model.- The @claude assistant is the exception: it runs the repository's code (`just sync`, thechecks, the tests) with the AWS session at hand, and its sandbox hides the session fromdiff --git a/docs/content/developer-guide/testing.md b/docs/content/developer-guide/testing.mdindex fbae72bb..ddce49c2 100644--- a/docs/content/developer-guide/testing.md+++ b/docs/content/developer-guide/testing.md@@ -320,10 +320,12 @@ in the ones they start (the corpus renders each case in its own), with paths relthe repository, so that runs on different systems combine: `just combine-coverage <folder>`makes one report of their data files.-The Test workflow combines the coverage of its runs into one report, whose table is in the-run's summary, and publishes `main`'s, served by Cloudflare as+The Test workflow combines the coverage of its runs and publishes the report, served by+Cloudflare as[`.github/deploy/coverage.jsonc`](https://github.com/academa-labs/manimgx/blob/main/.github/deploy/coverage.jsonc)-says, at <https://coverage.manimgx.academa.ai>.+says: `main`'s at <https://coverage.manimgx.academa.ai>, a pull request's (from a branch of+this repository) at a preview address, and each commit's linked from its "coverage"+status.## Benchmarksdiff --git a/tests/test_deployment.py b/tests/test_deployment.pyindex 7b8d5c47..b74b10a1 100644--- a/tests/test_deployment.py+++ b/tests/test_deployment.py@@ -1,21 +1,26 @@-"""Deployment credentials reach only main, with its own configuration, and nothing is-previewed."""+"""Deployment credentials see trusted configuration and failures stay visible."""-import re+import io+import json+import runpy+import urllib.request+from http.client import HTTPMessagefrom pathlib import Path+from typing import Never+from urllib.error import HTTPError+from urllib.request import Requestimport pytestimport yamlROOT = Path(__file__).parents[1]-WORKFLOWS = {- path.stem: yaml.safe_load(path.read_text(encoding="utf-8"))["jobs"]- for path in sorted((ROOT / ".github/workflows").glob("*.yaml"))-}+CLEANUP = ROOT / ".github/deploy/cleanup.py"def test_docs_snapshots_can_resume_failures_and_save_repairs() -> None:- steps = WORKFLOWS["deploy-docs"]["build"]["steps"]+ steps = yaml.safe_load(+ (ROOT / ".github/workflows/deploy-docs.yaml").read_text(encoding="utf-8")+ )["jobs"]["build"]["steps"]restore, save = [step for step in steps if step.get("uses", "").startswith("actions/cache/")]@@ -42,17 +47,68 @@ def test_docs_snapshots_can_resume_failures_and_save_repairs() -> None:assert "steps.completed.outputs.state != steps.restored.outputs.state" in condition[email protected]("status", [401, 403, 429, 500])+def test_cleanup_does_not_hide_api_failures(+ monkeypatch: pytest.MonkeyPatch, status: int+) -> None:+ def rejected(request: Request, timeout: int) -> Never:+ raise HTTPError(request.full_url, status, "rejected", HTTPMessage(), None)++ monkeypatch.setattr(urllib.request, "urlopen", rejected)+ delete = runpy.run_path(str(CLEANUP))["delete_preview"]+ with pytest.raises(HTTPError) as error:+ delete("account", "manimgx-docs", "pr-42", "test-token")+ assert error.value.code == status+++def test_cleanup_of_a_preview_that_never_existed_succeeds(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ def missing(request: Request, timeout: int) -> Never:+ raise HTTPError(request.full_url, 404, "not found", HTTPMessage(), None)++ monkeypatch.setattr(urllib.request, "urlopen", missing)+ delete = runpy.run_path(str(CLEANUP))["delete_preview"]+ delete("account", "manimgx-docs", "pr-42", "test-token")++[email protected]("success", [True, False])+def test_cleanup_requires_confirmation_and_deletes_only_the_named_preview(+ monkeypatch: pytest.MonkeyPatch, success: bool+) -> None:+ def respond(request: Request, timeout: int) -> io.BytesIO:+ assert request.method == "DELETE"+ assert request.full_url == (+ "https://api.cloudflare.com/client/v4/accounts/account/"+ "workers/workers/manimgx-docs/previews/pr-42"+ )+ assert request.get_header("Authorization") == "Bearer test-token"+ assert timeout == 30+ return io.BytesIO(json.dumps({"success": success}).encode())++ monkeypatch.setattr(urllib.request, "urlopen", respond)+ delete = runpy.run_path(str(CLEANUP))["delete_preview"]+ if success:+ delete("account", "manimgx-docs", "pr-42", "test-token")+ else:+ with pytest.raises(RuntimeError, match="did not confirm"):+ delete("account", "manimgx-docs", "pr-42", "test-token")++@pytest.mark.parametrize(("workflow", "build", "publish", "assets"),[("deploy-docs", "build", "deploy", "docs/site"),+ ("deploy-docs", "build", "preview", "docs/site"),("test", "coverage", "publish-coverage", "htmlcov"),],)def test_build_artifacts_cannot_supply_the_deployment_configuration(workflow: str, build: str, publish: str, assets: str) -> None:- jobs = WORKFLOWS[workflow]+ jobs = yaml.safe_load(+ (ROOT / f".github/workflows/{workflow}.yaml").read_text(encoding="utf-8")+ )["jobs"]upload = next(step["with"]for step in jobs[build]["steps"]@@ -65,7 +121,7 @@ def test_build_artifacts_cannot_supply_the_deployment_configuration(for step in stepsif step.get("uses", "").startswith("actions/checkout@"))- assert "ref" not in checkout # the configuration of the commit it publishes, main's+ assert checkout["ref"] == "${{ github.event.pull_request.base.sha || github.sha }}"assert checkout["sparse-checkout"] == ".github/deploy"assert checkout["persist-credentials"] is Falsedownload = next(@@ -78,33 +134,3 @@ def test_build_artifacts_cannot_supply_the_deployment_configuration(# replace the trusted configuration at the workspace root.injected_config = ROOT / download["path"] / ".github/deploy/docs.jsonc"assert not injected_config.is_relative_to(ROOT / ".github/deploy")---def test_only_main_gets_the_deployment_credentials() -> None:- credentialed = {- (workflow, name): job- for workflow, jobs in WORKFLOWS.items()- for name, job in jobs.items()- if "secrets.CLOUDFLARE_API_TOKEN" in str(job)- }- assert set(credentialed) == {- ("deploy-docs", "deploy"),- ("test", "publish-coverage"),- }- for job in credentialed.values():- assert "github.ref == 'refs/heads/main'" in job["if"]- # the production environments, which admit only main- assert job["environment"]["name"] in {"docs", "coverage"}---def test_nothing_is_previewed() -> None:- for jobs in WORKFLOWS.values():- for job in jobs.values():- assert "preview" not in str(job.get("environment", ""))- for step in job.get("steps", []):- assert not re.search(r"wrangler\S*\s+preview\b", step.get("run", ""))- # nor is any version of a site served on workers.dev- for site in ("docs", "coverage"):- config = (ROOT / f".github/deploy/{site}.jsonc").read_text(encoding="utf-8")- assert re.search(r'"preview_urls":\s*false', config)- assert '"previews"' not in config