The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.
Python
Verify npm publication after registry processing
Sina Atalay15715c584983
diff --git a/docs/content/developer-guide/github-workflows.md b/docs/content/developer-guide/github-workflows.mdindex d4a7d563..9afd63dc 100644--- a/docs/content/developer-guide/github-workflows.md+++ b/docs/content/developer-guide/github-workflows.md@@ -169,7 +169,8 @@ See [Documentation](documentation.md#deployment) for how the site is served.6. **Publish to npm:** `publish-npm.yaml` acquires the browser's tarball from the publicGitHub release and verifies its attestation against the release workflow, tag and commit.It confirms the matching Python browser wheel is public on PyPI before publishing with- provenance. A retry accepts an existing version only when its SHA512 integrity matches+ provenance. After an accepted upload, verification waits up to five minutes for registry+ visibility. A retry accepts an existing version only when its SHA512 integrity matchesthe exact tarball. The same workflow can run by hand from `main`, with a published `tag`,to retry publication with current tools without rebuilding or moving that tag.For the first release, before the package exists on npm, create a@@ -187,6 +188,10 @@ See [Documentation](documentation.md#deployment) for how the site is served.`ghcr.io/academa-labs/manimgx`, tagged `X.Y.Z` and `X.Y` (a pre-release,`X.Y.Z` only), labeled `MIT AND GPL-3.0-or-later`: ManimGX's code, and the engine, whichx264 makes GPL-3.0-or-later as a whole. It needs no new package resolution or image build.+ After the first upload, set the container package's+ [visibility to Public](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#configuring-visibility-of-packages-for-an-organization)+ in its GitHub package settings; repository visibility does not set package visibility.+ Confirm an anonymous pull before announcing the release.8. **Confirm completion:** all registry uploads have succeeded and the GitHub release ispublic. Publication across registries is not atomic; a failed destination can be retriedusing the retained artifacts. Publishing alone does not lock the release's files or tag: that requiresdiff --git a/scripts/release/publish_npm.py b/scripts/release/publish_npm.pyindex 28ae8a53..4694e498 100644--- a/scripts/release/publish_npm.py+++ b/scripts/release/publish_npm.py@@ -7,6 +7,7 @@ import jsonimport subprocessimport tarfilefrom pathlib import Path+from time import monotonic, sleepdef publish(archive: Path) -> None:@@ -22,12 +23,13 @@ def publish(archive: Path) -> None:hashlib.sha512(archive.read_bytes()).digest()).decode("ascii")- def exists() -> bool:+ def exists(timeout: float | None = None) -> bool:result = subprocess.run(["npm", "view", name, "dist.integrity", "--json"],capture_output=True,text=True,check=False,+ timeout=timeout,)record = json.loads(result.stdout)if result.returncode:@@ -46,8 +48,17 @@ def publish(archive: Path) -> None:["npm", "publish", str(archive), "--provenance", "--access", "public"],check=True,)- if not exists():- raise RuntimeError(f"{name} was not available after publication")+ # Acceptance precedes registry visibility while npm processes a publication.+ deadline = monotonic() + 300+ while True:+ remaining = deadline - monotonic()+ if remaining <= 0:+ raise TimeoutError(+ f"{name} was not available within five minutes of publication"+ )+ if exists(timeout=remaining):+ break+ sleep(min(5, max(0, deadline - monotonic())))if __name__ == "__main__":diff --git a/tests/test_release.py b/tests/test_release.pyindex f61851f0..16c28f1d 100644--- a/tests/test_release.py+++ b/tests/test_release.py@@ -403,6 +403,73 @@ def test_npm_retry_requires_the_exact_tarball(assert uploaded == ([archive.read_bytes()] if state == "new" else [])[email protected]("outcome", ["visible", "timeout", "unauthorized", "different"])+def test_npm_waits_for_visibility_after_one_accepted_upload(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, outcome: str+) -> None:+ archive = tmp_path / "package.tgz"+ with tarfile.open(archive, "w:gz") as package:+ body = b'{"name":"manimgx","version":"0.1.0"}'+ member = tarfile.TarInfo("package/package.json")+ member.size = len(body)+ package.addfile(member, io.BytesIO(body))+ integrity = (+ "sha512-"+ + base64.b64encode(hashlib.sha512(archive.read_bytes()).digest()).decode()+ )+ now = 0.0+ uploads = []+ inspections = []++ def sleep(seconds: float) -> None:+ nonlocal now+ assert 0 < seconds <= 5+ now += seconds++ def run(command: list[str], **options: object) -> subprocess.CompletedProcess[str]:+ if command[1] == "publish":+ uploads.append(command)+ return subprocess.CompletedProcess(command, 0, "", "")+ if not uploads:+ return subprocess.CompletedProcess(+ command, 1, '{"error":{"code":"E404"}}', ""+ )+ inspections.append((now, options.get("timeout")))+ if outcome == "timeout" or (outcome == "visible" and len(inspections) < 3):+ return subprocess.CompletedProcess(+ command, 1, '{"error":{"code":"E404"}}', ""+ )+ if outcome == "unauthorized":+ return subprocess.CompletedProcess(+ command, 1, '{"error":{"code":"E401"}}', ""+ )+ return subprocess.CompletedProcess(+ command, 0, json.dumps("other" if outcome == "different" else integrity), ""+ )++ monkeypatch.setattr(subprocess, "run", run)+ monkeypatch.setattr(publish_npm, "monotonic", lambda: now)+ monkeypatch.setattr(publish_npm, "sleep", sleep)+ if outcome == "timeout":+ with pytest.raises(TimeoutError, match="not available"):+ publish_npm.publish(archive)+ assert now == 300+ elif outcome == "unauthorized":+ with pytest.raises(RuntimeError, match="cannot inspect"):+ publish_npm.publish(archive)+ assert now == 0+ elif outcome == "different":+ with pytest.raises(ValueError, match="different artifact bytes"):+ publish_npm.publish(archive)+ assert now == 0+ else:+ publish_npm.publish(archive)+ assert now == 10+ assert len(uploads) == 1+ assert inspections+ assert all(timeout == 300 - instant for instant, timeout in inspections)++def test_release_smoke_records_decoded_audio_and_a_complete_versioned_take(tmp_path: Path,) -> None: