Repository navigation
fix(ci): hash-pin the Python build backend the PyPI publish job executes - #362
Merged
Merged
Conversation
`publish-release.yml`'s `publish-pytest` job carries `environment: pypi` and `id-token: write`, and it is the job that publishes aimock-pytest to PyPI through OIDC trusted publishing. It installed `hatch` by bare name from PyPI and then ran it. Measured, not reasoned about: with the registry serving substituted bytes, `pip install hatch` installed them (exit 0) and `hatch build` EXECUTED them (exit 0), beside the publish identity. Pinning `hatch` would not have closed it. `hatch build` builds in an ISOLATED environment and resolves this project's `build-system.requires` — hatchling — from PyPI at build time, unpinned: the same pinned-wrapper / unpinned-payload shape the Ollama installer had. Against an empty index, `hatch build` dies with "hatchling was not found in the package registry". So the backend itself is hash-pinned in `.github/requirements/hatchling.txt` (6 requirements, `==`-pinned, sha256-hashed, universal across 3.10-3.13) and the build invokes it directly with no isolation, fetching nothing. `hatch build` and `python -m hatchling build` produce byte-identical sdist and wheel for this package at 0.5.2, so the published artifacts do not change. `test-pytest.yml` had the same hole with no wrapper at all: the substituted `hatchling.build` was imported twice before pip did anything else. It now installs from the same pinned file and builds with isolation off. Its runtime and test dependencies (requests, pytest) are still resolved unpinned, on purpose — that job exists to catch breakage against current releases and holds no secret; freezing them would retire the signal. `--require-hashes` is scoped to the one install invocation. Job-wide it would also hit the already-published probe, whose FAILURE means "not published yet", so a hash-gated probe would fail for the wrong reason and publish unconditionally. A guard asserts that scope, and that both publishing steps stay conditioned on the probe.
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
publish-release.yml'spublish-pytestjob carriesenvironment: pypiandid-token: write, and it is the job that publishesaimock-pytestto PyPIthrough OIDC trusted publishing. It installed
hatchby bare name from PyPI andthen ran it. The Python test matrix had the same shape with no wrapper at all.
Both now install a hash-pinned build backend and build with isolation off.
RED — measured, not reasoned about
Real
pip, the committed step bodies run verbatim, only the registrysubstituted (
PIP_NO_INDEX=1 PIP_FIND_LINKS=<dir>— that directory is the entirenetwork, the pip analogue of stubbing
curl).Both steps reported success and the substituted package executed, beside the
publish identity.
test-pytest.yml's one-liner imported a substitutedhatchling.buildtwice —get_requires_for_build_wheel, then metadatapreparation — before pip did anything else.
Pinning
hatchwould NOT have closed ithatch buildbuilds in an isolated environment and resolves this project'sbuild-system.requires(hatchling) from PyPI at build time, unpinned — thesame pinned-wrapper / unpinned-payload shape
install.shhad. Against an emptyindex:
python -m hatchling buildagainst the same empty index exits 0. It fetchesnothing.
So the smallest sound option is to pin the backend and build without
isolation: 6 requirements / 57 hashes, versus 44 packages / 331 hashes for
hatch— smaller and the one that actually closes the hole.The published artifacts do not change.
hatch buildandpython -m hatchling buildproduced byte-identical sdist and wheel at 0.5.2:29ac7b3a…2c35(wheel) and0a54957b…8580(sdist);diff -rover bothunpacked: no differences.
GREEN
The refusal is the demonstrated absence of the payload at an interpreter, not
an inference from an exit code. Under GitHub's exact default shell flags
(
bash --noprofile --norc -e -o pipefail) the test-matrix body fails closed —its second line never runs.
Positive control, genuine bytes, fully offline: install exit 0, build exit 0,
artifacts byte-identical to what
hatch buildproduces. On Python 3.10 and 3.13the matrix body also succeeds (3.10 pulls
tomlivia its marker, 3.13 does not)and
import aimock_pytest, pytest, requestsworks.Hashes
Three independent sources agree, none taken on trust:
uv pip compile --generate-hashes; PyPI's JSON API, matched hash-by-hash (57/57, no extras,none missing); and
sha256of the bytespip download --require-hashesactually fetched.
The publish gate is intact — an unchanged-version push publishes NOTHING
No
if:,needs:, orid:line changed. Both gates were run verbatim againstthe live registries, read-only, no credential in the environment:
The second was run after
--require-hashesin the same environment — directevidence that hash-pinning does not poison the probe. That is also why
--require-hashesis scoped to the one install and not set job-wide: the probe'sfailure means "not published yet", so a hash-gated probe would fail for an
unrelated reason and publish unconditionally. Both gates still discriminate
(a bogus version returns
published=falseon both sides).publish-release.ymlwas not renamed or moved — trusted publishing is boundto the workflow filename. It has no
pull_requesttrigger, so this PR cannotpublish. No workflow was dispatched and no run re-run.
Guard suite —
src/__tests__/publish-pin-workflow.test.ts, 9 testsSeven static, two EXECUTE real pip against the repo's own pin file. The executed
pair matches pip's tamper message rather than an exit code, since a non-zero exit
cannot distinguish a hash refusal from any other error. A separate test throws
when
CIis set if nopython3 -m pipexists — a skipped guard in CI provesnothing.
RE-BREAK — 7 mutations, each applied, run, restored; all touched files
md5-identical before and after:
pip install hatchhatch buildhatchlingloses its--hashlinesPIP_REQUIRE_HASHESset job-wideif:Still unpinned after this PR — named, not glossed
requests/pytestintest-pytest.yml— deliberate. That job exists tocatch breakage against current releases and holds no secret (
contents: read,zero
secrets.references). Pinning them was compiled and measured(17 requirements, 170 hashes) and rejected for the coverage loss, not effort.
publish-commit.yml:20npx pkg-pr-new publish— not inpackage.json,not in the lockfile, so npx fetches
latest. Another agent owns that file.pnpm/action-setup— pnpm resolved at thepackageManagerversion with nointegrity hash beside it. Another agent owns the toolchain.
publish-release.yml'spip install … --dry-run --no-depsprobe installsnothing and executes no downloaded code; hash-gating it would break the gate
open.
Every
uses:in both changed files is pinned to a 40-hex commit SHA.Gates
pnpm build0 ·pnpm test0 (5075 passed, 173 files, +9 all in the newfile) ·
pnpm test:drift0 ·tsc --noEmit0 ·pnpm lint0 ·pnpm test:exports0 · prettier clean ·zizmor --min-severity medium0 ·bash -non 21run:bodies, 0 failures ·commitlint0.actionlintreports one pre-existing info (SC2086on>> $GITHUB_ENV,identical on
origin/main). A second pre-existing info —SC2102on theunquoted
[test]extras — is gone, quoted while editing that line.None of the named pre-existing flakes (
proxy-buffer-cap,ws-framing,timing-recording) appeared.Scope
Exactly
.github/requirements/hatchling.txt,.github/workflows/publish-release.yml,.github/workflows/test-pytest.yml,src/__tests__/publish-pin-workflow.test.ts. Nopackage.json,CHANGELOG.md,.claude-plugin/*,charts/*,packages/aimock-pytest/*orpnpm-lock.yaml.No version consumed.
packages/aimock-pytestwas copied to scratch for everybuild; the tree's copy was never written to.
This PR touches
src/**, sotest-pytest.ymlruns on it and exercises the newinstall path across 3.10–3.13 × Node 20/22/24 — which is the point. It matches
none of
test-drift.yml'spaths:, so the credit-spendingdrift-live-prjobdoes not fire.