From 71843674bcce0b1713d25bc80748d6015f3e51a9 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Fri, 20 Nov 2026 20:48:48 -0800 Subject: [PATCH 1/4] feat(release): a pre-release freezes nothing; only a final release runs the golden release step (ITL-1329) Developer direction (November 21, 2026): a candidate carries the hashes intended to be final, and the freeze is at the full release. - scripts/check_golden_tags.py: release_version, the one rule telling a PEP 440 pre-release (aN, bN, rcN, .devN) from a final X.Y.Z(.postN), and refusing anything else. --release-version of a pre-release checks that HEAD does NOT record it (nor as withdrawn) and allows unpinned type snapshots. --classify-version writes the workflow's outputs and refuses a spelling that is not the normal form. - generate_golden_hashes.py --release refuses a pre-release. - release.yml: a prerelease output from the script; the GitHub Release is marked as a pre-release, with a note that it freezes nothing; the Linear jobs skip a pre-release. The tag check runs for every version. - RELEASING.md, golden-hashes.md, CLAUDE.md, .zed/rules: the rule and a checklist for cutting a candidate. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 35 ++- .zed/rules | 11 +- CLAUDE.md | 11 +- RELEASING.md | 81 ++++- changelog.d/ITL-1329.md | 14 + docs/reference/golden-hashes.md | 22 +- scripts/check_golden_tags.py | 199 ++++++++++++- tests/test_check_golden_tags.py | 281 ++++++++++++++++++ .../golden/generate_golden_hashes.py | 42 ++- 9 files changed, 659 insertions(+), 37 deletions(-) create mode 100644 changelog.d/ITL-1329.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 64c3f7584..999e0d417 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -106,6 +106,9 @@ jobs: contents: write # required to push the release tag outputs: version: ${{ steps.normalize.outputs.version }} + # 'true' for a pre-release (aN, bN, rcN, .devN), 'false' for a final release: + # decided by scripts/check_golden_tags.py, the one rule (ITL-1329). + prerelease: ${{ steps.classify.outputs.prerelease }} steps: - name: Report skipped tests if: ${{ inputs.skip_tests }} @@ -133,15 +136,26 @@ jobs: fetch-depth: 0 # required: hatch-vcs reads tag to set version ref: ${{ inputs.branch }} + - name: Classify the version + id: classify + # Writes prerelease=true|false. Fails on a version that is not a release version + # in its PEP 440 normal form (0.4.0rc1, not 0.4.0-rc.1), so that the tag, the + # package, the GitHub Release and the Linear release name one version (ITL-1329). + env: + VERSION: ${{ steps.normalize.outputs.version }} + run: python3 scripts/check_golden_tags.py --classify-version "$VERSION" >> "$GITHUB_OUTPUT" + - name: Check the golden release step - # Nothing is tagged or published unless the release pull request ran - # generate_golden_hashes.py --release for this version (ITL-946). + # A final release: nothing is tagged or published unless the release pull request + # ran generate_golden_hashes.py --release for this version (ITL-946). A + # pre-release freezes nothing: HEAD must not record it as a release (ITL-1329). run: python3 scripts/check_golden_tags.py --release-version "${{ steps.normalize.outputs.version }}" - name: Check golden files against release tags # Every golden file, revision and pin an earlier release tag of the current data - # context shipped is unchanged here (ITL-946). Tags of no such release (older - # data contexts) are not checked; it fails only without git, history or tags. + # context shipped is unchanged here (ITL-946), for a pre-release too. Tags of no + # such release (older data contexts, pre-releases) are not checked; it fails only + # without git, history or tags. run: python3 scripts/check_golden_tags.py - name: Configure git identity @@ -237,16 +251,27 @@ jobs: tag_name: "v${{ needs.build.outputs.version }}" generate_release_notes: true files: dist/* + # A pre-release is marked as one, and its notes (prepended to the generated + # ones) say that it freezes nothing (ITL-1329). + prerelease: ${{ needs.build.outputs.prerelease == 'true' }} + body: >- + ${{ needs.build.outputs.prerelease == 'true' + && 'This is a pre-release. It carries the hashes intended for the final release, but freezes nothing: a golden value may still change before the final release (only for a blocking reason), and data stored with this pre-release is not guaranteed to be valid under the final release.' + || '' }} linear-sync: name: Sync Linear release needs: build # Explicit status check, because a skipped test job would otherwise skip this job too. + # Not for a pre-release (ITL-1329): sync with a version creates or targets a Linear + # release of exactly that version, which would split the candidate's issues from the + # final release; the open Linear release stays open for the final version. if: >- ${{ github.repository == 'metamorphic-labs/orcapod-python' && !cancelled() && needs.build.result == 'success' + && needs.build.outputs.prerelease == 'false' }} runs-on: ubuntu-latest timeout-minutes: 5 @@ -268,11 +293,13 @@ jobs: name: Complete Linear release needs: [build, publish-pypi, linear-sync] # Explicit status check, because a skipped test job would otherwise skip this job too. + # Not for a pre-release (ITL-1329): the Linear release is completed by the final one. if: >- ${{ github.repository == 'metamorphic-labs/orcapod-python' && !cancelled() && needs.build.result == 'success' + && needs.build.outputs.prerelease == 'false' && needs.publish-pypi.result == 'success' && needs.linear-sync.result == 'success' }} diff --git a/.zed/rules b/.zed/rules index b846869d2..d80127024 100644 --- a/.zed/rules +++ b/.zed/rules @@ -493,9 +493,14 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current `released_manifests.json`, with the date and the reason, so no v1 file is released today. Until 0.4.0, a change to any v1 golden value needs the developer's approval of the exact list of entries that move, each explained; it is made with `--remove `, then the - generator writes the new value. `--release 0.4.0` freezes v1. Any version published - before it, a pre-release included, would freeze v1 there: the Release workflow requires - the release step for every version. A withdrawn version is never released again. + generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes + nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended + to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the + one rule) requires that HEAD does NOT record it, and `--release` refuses it. Between a + candidate and the final release a golden value changes only for a blocking reason, with + the developer's approval of the exact list, then a new candidate; data stored with a + candidate is not guaranteed valid under the final release. A withdrawn version is never + released again. - Provisional operators are outside the freeze (developer, November 18, 2026, ITL-1266): `orcapod.operators.PROVISIONAL_OPERATORS` (`core/operators/provisional.py`) is the one list (name to the issue deciding its identity; today `PolarsFilter`), and each listed class diff --git a/CLAUDE.md b/CLAUDE.md index 3604b9eed..46da8d746 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -504,9 +504,14 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current `released_manifests.json`, with the date and the reason, so no v1 file is released today. Until 0.4.0, a change to any v1 golden value needs the developer's approval of the exact list of entries that move, each explained; it is made with `--remove `, then the - generator writes the new value. `--release 0.4.0` freezes v1. Any version published - before it, a pre-release included, would freeze v1 there: the Release workflow requires - the release step for every version. A withdrawn version is never released again. + generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes + nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended + to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the + one rule) requires that HEAD does NOT record it, and `--release` refuses it. Between a + candidate and the final release a golden value changes only for a blocking reason, with + the developer's approval of the exact list, then a new candidate; data stored with a + candidate is not guaranteed valid under the final release. A withdrawn version is never + released again. - Provisional operators are outside the freeze (developer, November 18, 2026, ITL-1266): `orcapod.operators.PROVISIONAL_OPERATORS` (`core/operators/provisional.py`) is the one list (name to the issue deciding its identity; today `PolarsFilter`), and each listed class diff --git a/RELEASING.md b/RELEASING.md index 70c8d9312..ceea96938 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -94,7 +94,8 @@ Per-release checklists live in `docs/dev/plans/` (for example ## Pre-release checklist -All of these hold before the developer runs the Release workflow: +All of these hold before the developer runs the Release workflow for a final version. A +release candidate (or another pre-release) has its own, shorter list: see *Pre-releases*. 1. **The full suite is green**: `uv run pytest tests/` passes on the commit to be released. 2. **The release pull request is merged** (`CHANGELOG.md` folded, section dated, @@ -126,9 +127,16 @@ against are in `docs/reference/golden-hashes.md`. - Data context v1 is open until `0.4.0` (developer, November 17, 2026, ITL-1255): `0.3.0` is withdrawn, so no v1 golden file is released. Until `0.4.0`, a change to a v1 value needs the developer's approval of the exact list of entries that move, each explained. The release - step of `0.4.0` freezes v1. Every published version needs the release step, a pre-release - included (the gate below refuses to tag one without it), so **publishing `0.4.0rc1` would - freeze v1 at the release candidate**: plan the release around it. + step of `0.4.0` freezes v1. +- **A pre-release freezes nothing** (developer, November 21, 2026, ITL-1329): only a final + version runs the release step. A candidate (`0.4.0rc1`) carries the hashes intended to be + final; the gate checks that HEAD does *not* record it as a release, and + `generate_golden_hashes.py --release` refuses it. Between a candidate and the final + release a golden value changes only for a blocking reason, with the developer's approval + of the exact list of entries that move, and a new candidate follows. Data stored with a + candidate is not guaranteed to be valid under the final release; the candidate's GitHub + Release says so (the workflow writes it). What an earlier final release froze stays + protected in a pre-release run: the tag check runs for every version. - Provisional operators (`orcapod.operators.PROVISIONAL_OPERATORS`, ITL-1266) are outside the freeze: the golden values of the cases that depend on one are in `tests/test_hashing/golden/data/v1/provisional/`, which no release step lists or pins. An @@ -190,10 +198,10 @@ on origin, and the ruleset `protect-release-tags` forbids deleting a `v*` tag, s ``` - Pre-flight: branch validation, then tests on Python 3.11, 3.12 and 3.13 and license check (parallel after validation); the tests are skipped only with `skip_tests` - - Build: normalises version (strips a leading `v`), checks the golden release step and the release tags, creates the local tag, builds wheel + sdist with `uv build`, aborts if the tag already exists on origin, pushes the tag, uploads `dist/` as an artifact + - Build: normalises version (strips a leading `v`), classifies it (`check_golden_tags.py --classify-version`: final or pre-release; a version not in its PEP 440 normal form is refused), checks the golden release step (for a pre-release: that HEAD does not record it) and the release tags, creates the local tag, builds wheel + sdist with `uv build`, aborts if the tag already exists on origin, pushes the tag, uploads `dist/` as an artifact - TestPyPI: in the `testpypi` environment, `uv publish --publish-url https://test.pypi.org/legacy/ dist/*` with an OIDC token (`id-token: write`) — a staging upload - - PyPI: in the `pypi` environment, after TestPyPI succeeds and a reviewer approves, `uv publish dist/*` with an OIDC token, then creates the GitHub Release for the tag with generated release notes and the dist files attached - - Linear: `linear-sync` starts immediately after build (parallel to publish); `linear-complete` runs after both PyPI publish and linear-sync succeed (see *Linear Release System*) + - PyPI: in the `pypi` environment, after TestPyPI succeeds and a reviewer approves, `uv publish dist/*` with an OIDC token, then creates the GitHub Release for the tag with generated release notes and the dist files attached; a pre-release is marked as one, and its notes start with a paragraph saying that it freezes nothing + - Linear: `linear-sync` starts immediately after build (parallel to publish); `linear-complete` runs after both PyPI publish and linear-sync succeed (see *Linear Release System*). Neither runs for a pre-release The tag is created by the workflow in this repository; there is nothing to fetch back. @@ -325,11 +333,48 @@ replace the secret as above. The job fails in between; that is the price of cont ## Pre-releases -Release candidates (e.g. `0.1.0rc1`) follow exactly the same path — enter the version in the -workflow input. PyPI handles the stable vs pre-release distinction natively: - -- `pip install orcapod` — installs the latest **stable** release only -- `pip install --pre orcapod` — installs the latest release including pre-releases +A pre-release is a version with an alpha, beta or release candidate part, or a development +part, as PEP 440 defines it: `0.4.0a1`, `0.4.0b2`, `0.4.0rc1`, `0.4.0.dev3`. One rule tells it +from a final version, `release_version` in `scripts/check_golden_tags.py`. A version that is +neither `X.Y.Z` (or `X.Y.Z.postN`) nor such a pre-release is refused, never guessed. + +A pre-release goes through the same Release workflow, with four differences (ITL-1329): + +- It freezes nothing: the build job requires that HEAD does **not** record it as a release + (no golden release step), and it allows data function type snapshots that are not pinned + yet. The tag check still runs, so what earlier final releases froze stays protected. +- The GitHub Release is marked as a pre-release, and its notes begin with a paragraph saying + that it freezes nothing and that data stored with it is not guaranteed to be valid under + the final release. +- `linear-sync` and `linear-complete` do not run: the open Linear release stays open for the + final version (see *Linear Release System*). +- The version must be given in its PEP 440 normal form (`0.4.0rc1`, not `0.4.0-rc.1` or + `0.4.0RC1`), so that the tag, the package, the GitHub Release and the Linear release name + one version; the build job refuses any other spelling and names the normal form. + +### Cutting a release candidate + +1. **No release pull request**: no `CHANGELOG.md` fold (the `changelog.d/` fragments stay for + the final release) and **no golden release step** (`generate_golden_hashes.py --release` + refuses a pre-release). +2. **The version is free**: no tag `v` on `metamorphic-labs`, and the version is on + neither PyPI nor TestPyPI. +3. **`main` is green**, and the full suite passes on the commit to be released. +4. **Do not rename the open Linear release**: it stays open for the final version. +5. **Run Release** with the version in its normal form (`0.4.0rc1`), as in *Cutting a + Release*, and approve the PyPI deployment. +6. **Install it** with `pip install orcapod==0.4.0rc1` (or `pip install --pre orcapod`, the + latest version including pre-releases; `pip install orcapod` installs the latest **final** + version only). + +### Between a candidate and the final release + +A candidate carries the hashes intended to be final. A golden value changes before the final +release only for a blocking reason, with the developer's approval of the exact list of +entries that move (`generate_golden_hashes.py --remove`, then `--add`), and a new candidate +(`0.4.0rc2`) follows. Data stored with a candidate is not guaranteed to be valid under the +final release. The final release is cut as usual, with the release pull request and the +golden release step (*Pre-release checklist*). ## Cutting a Hotfix Release @@ -387,7 +432,8 @@ being built and `hatch-vcs` reads that tag. The fix those two releases carried i | Alpha | `vMAJOR.MINOR.PATCHaN` | `v0.1.0a1` | | Beta | `vMAJOR.MINOR.PATCHbN` | `v0.1.0b1` | -The workflow input accepts any of the above (with or without a leading `v`). The version is +The workflow input accepts any of the above, with or without a leading `v`, in its PEP 440 +normal form (`0.1.0rc1`, not `0.1.0-rc.1`): the build job refuses another spelling. The version is derived from the git tag by `hatch-vcs` (`dynamic = ["version"]` in `pyproject.toml`) — no manual version bump is needed. @@ -404,8 +450,13 @@ run. | Trigger | Workflow / Job | Command | What it does | |---------|---------------|---------|--------------| | Push to `main` | `release-sync.yml / sync` | `sync` (no version) | Scans the commits since the last synced commit for Linear issue ids and pull request numbers, and adds them to the pipeline's open release (today one with no version set) | -| Release workflow `build` succeeds | `release.yml / linear-sync` | `sync --version vX.Y.Z` | Targets the release whose version is `vX.Y.Z`, or **creates** one, and adds the commits since the last synced commit | -| After `publish-pypi` succeeds | `release.yml / linear-complete` | `complete --version vX.Y.Z` | Completes the release whose version is `vX.Y.Z` | +| Release workflow `build` succeeds, final version | `release.yml / linear-sync` | `sync --version vX.Y.Z` | Targets the release whose version is `vX.Y.Z`, or **creates** one, and adds the commits since the last synced commit | +| After `publish-pypi` succeeds, final version | `release.yml / linear-complete` | `complete --version vX.Y.Z` | Completes the release whose version is `vX.Y.Z` | + +Neither release job runs for a pre-release (ITL-1329): with a version, `sync` creates or +targets a Linear release of exactly that version, so a candidate's sync would split its +issues from the final release, and nothing would complete it. The open release stays open +until the final version's run; do not rename it for a candidate. The workflow only syncs and completes the Linear release; any change of issue status that comes with a completed release is made by Linear, as the workspace configures it. diff --git a/changelog.d/ITL-1329.md b/changelog.d/ITL-1329.md new file mode 100644 index 000000000..a81fdfdd9 --- /dev/null +++ b/changelog.d/ITL-1329.md @@ -0,0 +1,14 @@ +### Changed + +- A pre-release no longer freezes the data context (ITL-1329). Only a final version runs the + golden release step. A release candidate (`0.4.0rc1`; also `aN`, `bN`, `.devN`) carries + the hashes intended to be final and is published without it: the Release workflow's gate + checks instead that HEAD does not record the pre-release as a release. + `generate_golden_hashes.py --release` refuses a pre-release. The tag check of earlier + final releases still runs for every version. The GitHub Release of a pre-release is marked + as one, and its notes say that it freezes nothing and that data stored with it is not + guaranteed to be valid under the final release. The Linear release jobs do not run for a + pre-release. The workflow's version must be in its PEP 440 normal form (`0.4.0rc1`, not + `0.4.0-rc.1`). `RELEASING.md` has the checklist for cutting a candidate and the rule + between a candidate and the final release: a golden value changes only for a blocking + reason, with the developer's approval of the exact list, and a new candidate follows. diff --git a/docs/reference/golden-hashes.md b/docs/reference/golden-hashes.md index 76d51388a..4af9e6bff 100644 --- a/docs/reference/golden-hashes.md +++ b/docs/reference/golden-hashes.md @@ -247,9 +247,18 @@ edit and the generator refuses to write over it. An operator that stops being provisional in this release has its entries moved into a frozen file (`--relocate`) before the release step, so that the release freezes them. -Every published version needs the release step, a pre-release included: the release gate -refuses to tag a version without it. So the first version of a data context published on -PyPI freezes it; for `v1`, publishing `0.4.0rc1` would freeze `v1` at the release candidate. +Every final version needs the release step: the release gate refuses to tag one without it. +A pre-release (`0.4.0rc1`, `0.4.0a1`, `0.4.0b2`, `0.4.0.dev3`) freezes nothing (developer, +November 21, 2026, ITL-1329). It carries the hashes intended to be final, the release gate +checks that HEAD does *not* record it as a release, and `generate_golden_hashes.py +--release` refuses it. So the first final version of a data context freezes it: for `v1`, +`0.4.0`, not `0.4.0rc1`. Between a candidate and the final release a golden value changes +only for a blocking reason, with the developer's approval of the exact list of entries that +move, and a new candidate follows. Data stored with a candidate is not guaranteed to be valid +under the final release, and the candidate's release notes say so (the Release workflow +writes it into the GitHub Release). What an earlier final release froze stays protected in a +pre-release run: the tag check runs for every version, and a pre-release's own tag pins no +release, so the tag check skips it. ### Withdrawing a release @@ -395,7 +404,12 @@ build job before the tag is made; tested by `tests/test_check_golden_tags.py` release `X.Y.Z` of the current data context, its `manifest` pin is set, and the pinned digest is the release revision of `X.Y.Z`, which is the last revision of HEAD's golden history: a golden file added after the release step would ship unreleased, so such a commit is not tagged. It fails without - git. + git. For a pre-release (ITL-1329) it checks the opposite: HEAD does not record that + version as a release (nor as withdrawn); the release step and the type snapshot pins are + not required. Which versions are pre-releases is one rule, `release_version` in the same + script (PEP 440; a version that is not `X.Y.Z` with an optional pre-release, post-release + or development part is refused, never guessed), which the Release workflow also reads + (`--classify-version`) to mark the GitHub Release and to skip the Linear jobs. - **Protects against:** a release cut without the release step (11). The final-release check cannot catch it in the Release workflow, whose tests run before the tag exists, under a development version. diff --git a/scripts/check_golden_tags.py b/scripts/check_golden_tags.py index 94985222c..d1e5a44b4 100644 --- a/scripts/check_golden_tags.py +++ b/scripts/check_golden_tags.py @@ -13,6 +13,12 @@ - the pins of the current data context at the tag (the manifest pin and every ``releases`` line) are present unchanged. +A pre-release (``0.4.0rc1``, ``0.4.0a1``, ``0.4.0b2``, ``0.4.0.dev3``) freezes nothing +(developer, November 21, 2026, ITL-1329): it carries the hashes intended to be final, and +only a final release runs the golden release step. ``--release-version`` of a pre-release +therefore checks that HEAD does NOT record it as a release; its tag pins no release, so the +tag check skips it. ``release_version`` is the one rule that tells the two apart. + A withdrawn release is not compared with HEAD (ITL-1255): when HEAD's ``released_manifests.json`` records release ``X.Y.Z`` under ``withdrawn`` of the current data context, the tag ``v`` is checked against that record instead: the record's @@ -28,6 +34,8 @@ Usage: uv run python scripts/check_golden_tags.py [--repo DIR] + uv run python scripts/check_golden_tags.py --release-version X.Y.Z + uv run python scripts/check_golden_tags.py --classify-version X.Y.Z It exits 1 on a difference. Without git, history or tags (not a repository, a shallow clone, no tags) it exits 1 in CI (``CI=true``) and 0 with a message elsewhere. The script @@ -39,6 +47,7 @@ import argparse import json import os +import re import subprocess import sys from collections.abc import Sequence @@ -55,6 +64,71 @@ class GitUnavailableError(RuntimeError): """git, the history or the tags cannot be read.""" +# A release version in the PEP 440 spellings this project uses: a release of exactly three +# numbers (``X.Y.Z``), an optional pre-release, post-release and development part, in any of +# the spellings PEP 440 normalizes (a leading ``v``, any case, ``-``/``_``/``.`` separators, +# ``alpha``/``beta``/``c``/``pre``/``preview``, an implicit number). No epoch, no local part: +# a version this project never publishes is refused, never guessed. +_RELEASE_VERSION = re.compile( + r""" + ^\s*v? + (?P[0-9]+\.[0-9]+\.[0-9]+) + (?:[-_.]?(?Palpha|beta|preview|pre|rc|a|b|c)[-_.]?(?P[0-9]+)?)? + (?:-(?P[0-9]+)|[-_.]?(?Ppost|rev|r)[-_.]?(?P[0-9]+)?)? + (?:[-_.]?(?Pdev)[-_.]?(?P[0-9]+)?)? + \s*$ + """, + re.IGNORECASE | re.VERBOSE, +) +_PRE_RELEASE_LETTERS = { + "a": "a", + "alpha": "a", + "b": "b", + "beta": "b", + "c": "rc", + "rc": "rc", + "pre": "rc", + "preview": "rc", +} + + +def release_version(text: str) -> tuple[str, bool]: + """The normalized form of a release version, and whether it is a pre-release. + + The one rule for telling a final release from a pre-release (ITL-1329). A final + release is ``X.Y.Z`` or ``X.Y.Z.postN``; a pre-release has an alpha, beta or release + candidate part (``0.4.0a1``, ``0.4.0b2``, ``0.4.0rc1``) or a development part + (``0.4.0.dev3``), as PEP 440 defines one. The spellings PEP 440 normalizes are + accepted (``v0.4.0``, ``0.4.0RC1``, ``0.4.0-rc.1``). + + Args: + text: The version, optionally with a leading ``v``. + + Returns: + The PEP 440 normalized version (``0.4.0rc1``) and ``True`` for a pre-release. + + Raises: + ValueError: If ``text`` is not a version of the form this project releases (an + epoch, a local part, or a release that is not three numbers): the gate never + guesses. + """ + match = _RELEASE_VERSION.match(text) + if match is None: + raise ValueError( + f"{text!r} is not a release version: give X.Y.Z, optionally with a " + "pre-release (aN, bN, rcN), post-release (.postN) or development (.devN) part" + ) + parts = [".".join(str(int(n)) for n in match["release"].split("."))] + if match["pre_l"]: + letter = _PRE_RELEASE_LETTERS[match["pre_l"].lower()] + parts.append(f"{letter}{int(match['pre_n'] or 0)}") + if match["post_n1"] is not None or match["post_l"]: + parts.append(f".post{int(match['post_n1'] or match['post_n2'] or 0)}") + if match["dev_l"]: + parts.append(f".dev{int(match['dev_n'] or 0)}") + return "".join(parts), bool(match["pre_l"] or match["dev_l"]) + + # Variables that point git at another repository than ``--repo`` (git(1), "Environment # Variables"); they are removed so that the repository read is the one named, and # ``--no-replace-objects`` keeps replace refs from substituting the objects read. @@ -378,13 +452,22 @@ def check_release(repo: Path, release: str) -> list[str]: release revision of ``release`` in HEAD's golden history, which is its last revision (no golden file added after the release step ships unreleased). + A pre-release is checked by ``check_pre_release`` instead (ITL-1329). + Args: repo: Repository root. - release: The library version being released, without a leading ``v``. + release: The library version being released, optionally with a leading ``v``. Returns: - One sentence per problem; empty when HEAD records the release. + One sentence per problem; empty when HEAD records the release (or, for a + pre-release, does not). """ + try: + release, prerelease = release_version(release) + except ValueError as exc: + return [str(exc)] + if prerelease: + return check_pre_release(repo, release) version = _current_version(repo) step = ( f"run generate_golden_hashes.py --release {release} in the release pull request" @@ -431,6 +514,78 @@ def check_release(repo: Path, release: str) -> list[str]: return problems +def check_pre_release(repo: Path, release: str) -> list[str]: + """Check that HEAD does not record a pre-release as a release, before it is tagged. + + A pre-release carries the hashes intended to be final but freezes nothing: only a + final release runs the golden release step (developer, November 21, 2026, ITL-1329). + So HEAD must not record ``release`` under the current data context's ``releases``, nor + as withdrawn (a package index never takes a version twice). Unpinned data function + type snapshots are allowed: the final release step pins them. What earlier final + releases froze is checked by the tag check, which the Release workflow runs for a + pre-release too. + + Args: + repo: Repository root. + release: The normalized pre-release version (``release_version``). + + Returns: + One sentence per problem; empty when HEAD does not record the pre-release. + """ + version = _current_version(repo) + pins = _show_json(repo, "HEAD", PINS) + pin = pins.get(version) if isinstance(pins, dict) else None + releases = pin.get("releases") if isinstance(pin, dict) else None + recorded = sorted(releases) if isinstance(releases, dict) else [] + problems: list[str] = [] + if any(_same_version(name, release) for name in recorded): + problems.append( + f"HEAD records pre-release {release} as a release of data context {version}: " + "a pre-release never runs the golden release step (only a final release " + "freezes a data context); revert the release step's commit" + ) + if any(_same_version(name, release) for name in _head_withdrawn(repo, version)): + problems.append( + f"release {release} of data context {version} was withdrawn and is never " + "released again: a package index never takes a version twice" + ) + return problems + + +def _same_version(name: str, release: str) -> bool: + """Whether a recorded version name is ``release``, in any spelling.""" + try: + return release_version(name)[0] == release + except ValueError: + return False + + +def classify_version(text: str) -> tuple[str, bool]: + """The version the Release workflow tags, and whether it is a pre-release. + + The workflow tags ``v`` and ``hatch-vcs`` builds the package version from + that tag, so the version must already be in its PEP 440 normal form: a spelling PEP + 440 would normalize (``0.4.0-rc.1``) is refused, naming the normal form, so that the + tag, the package, the GitHub Release and the Linear release name the same version. + + Args: + text: The workflow's version input, optionally with a leading ``v``. + + Returns: + The version and ``True`` for a pre-release. + + Raises: + ValueError: If ``text`` is not a release version, or not in its normal form. + """ + normalized, prerelease = release_version(text) + if text.removeprefix("v") != normalized: + raise ValueError( + f"{text!r} is not in its PEP 440 normal form: give it as {normalized!r}, so " + "that the tag and the package name the same version" + ) + return normalized, prerelease + + def main(argv: Sequence[str] | None = None) -> int: """Run the check. @@ -452,22 +607,54 @@ def main(argv: Sequence[str] | None = None) -> int: "(the Release workflow's gate before it tags); fails without git" ), ) + _ = parser.add_argument( + "--classify-version", + metavar="X.Y.Z", + help=( + "print 'version=' and 'prerelease=true|false' for the Release " + "workflow's step outputs; fails on a version that is not a release version " + "in its normal form" + ), + ) args = parser.parse_args(argv) + if args.classify_version is not None: + try: + normalized, prerelease = classify_version(args.classify_version) + except ValueError as exc: + print(f"error: {exc}", file=sys.stderr) + return 1 + print(f"version={normalized}") + print(f"prerelease={'true' if prerelease else 'false'}") + return 0 if args.release_version is not None: + try: + _, prerelease = release_version(args.release_version) + except ValueError as exc: + print(f"error: {exc}", file=sys.stderr) + return 1 try: problems = check_release(args.repo, args.release_version.removeprefix("v")) except GitUnavailableError as exc: print(f"error: cannot read HEAD: {exc}", file=sys.stderr) return 1 if problems: - print( - f"release {args.release_version} is not recorded in the golden history:", - file=sys.stderr, + heading = ( + f"pre-release {args.release_version} cannot be tagged:" + if prerelease + else f"release {args.release_version} is not recorded in the golden history:" ) + print(heading, file=sys.stderr) for problem in problems: print(f" {problem}", file=sys.stderr) return 1 - print(f"HEAD records release {args.release_version} in the golden history") + if prerelease: + print( + f"{args.release_version} is a pre-release: it freezes nothing, so no golden " + "release step is required and HEAD does not record it; the data function " + "type snapshots may stay unpinned until the final release step pins them" + ) + else: + print(f"HEAD records release {args.release_version} in the golden history") return 0 in_ci = os.environ.get("CI", "").lower() == "true" try: diff --git a/tests/test_check_golden_tags.py b/tests/test_check_golden_tags.py index 022daeafd..6c746b927 100644 --- a/tests/test_check_golden_tags.py +++ b/tests/test_check_golden_tags.py @@ -644,3 +644,284 @@ def show(repo_: Path, rev: str, path: Any) -> bytes | None: monkeypatch.setattr(module, "_show", show) problems = module.unpinned_type_snapshots(repo) assert problems == [f"git cannot read data function type snapshot {key}"] + + +# --------------------------------------------------------------------------- +# Pre-releases freeze nothing (ITL-1329) +# --------------------------------------------------------------------------- + +# (text, normal form, pre-release) for every spelling the gate accepts. +VERSIONS = [ + ("0.4.0", "0.4.0", False), + ("v0.4.0", "0.4.0", False), + ("V0.4.0", "0.4.0", False), + ("00.04.00", "0.4.0", False), + ("0.4.0.post1", "0.4.0.post1", False), + ("0.4.0-1", "0.4.0.post1", False), + ("0.4.0.rev2", "0.4.0.post2", False), + ("0.4.0rc1", "0.4.0rc1", True), + ("v0.4.0rc1", "0.4.0rc1", True), + ("0.4.0RC1", "0.4.0rc1", True), + ("0.4.0-rc.1", "0.4.0rc1", True), + ("0.4.0_rc_1", "0.4.0rc1", True), + ("0.4.0.rc01", "0.4.0rc1", True), + ("0.4.0c1", "0.4.0rc1", True), + ("0.4.0pre2", "0.4.0rc2", True), + ("0.4.0preview3", "0.4.0rc3", True), + ("0.4.0rc", "0.4.0rc0", True), + ("0.4.0a1", "0.4.0a1", True), + ("0.4.0alpha1", "0.4.0a1", True), + ("0.4.0b2", "0.4.0b2", True), + ("0.4.0beta2", "0.4.0b2", True), + ("0.4.0.dev3", "0.4.0.dev3", True), + ("0.4.0dev3", "0.4.0.dev3", True), + ("0.4.0-dev", "0.4.0.dev0", True), + ("0.4.0rc1.dev2", "0.4.0rc1.dev2", True), + ("0.4.0.post1.dev1", "0.4.0.post1.dev1", True), +] +# Texts the gate refuses: valid PEP 440 it never releases (an epoch, a local part, a +# release that is not three numbers), and texts that are no version at all. +NOT_RELEASE_VERSIONS = [ + "1!0.4.0", + "0.4.0+local", + "0.4", + "0.4.0.1", + "0.4.0rc1x", + "latest", + "", + "v", + "0.4.0-", + "0.4.0 rc1", +] + + +@pytest.mark.parametrize(("text", "normal", "prerelease"), VERSIONS) +def test_release_version_tells_a_pre_release_from_a_final_one( + text: str, normal: str, prerelease: bool +) -> None: + """The one rule agrees with PEP 440 (``packaging``) on every spelling it accepts.""" + from packaging.version import Version + + module = _gate_module() + assert module.release_version(text) == (normal, prerelease) + reference = Version(text) + assert (str(reference), reference.is_prerelease) == (normal, prerelease) + + +@pytest.mark.parametrize("text", NOT_RELEASE_VERSIONS) +def test_release_version_refuses_what_it_does_not_release(text: str) -> None: + """A version the project never releases is refused, never guessed.""" + module = _gate_module() + with pytest.raises(ValueError, match="is not a release version"): + module.release_version(text) + + +def _classify(version: str) -> subprocess.CompletedProcess[str]: + return subprocess.run( + [sys.executable, str(SCRIPT), "--classify-version", version], + capture_output=True, + text=True, + check=False, + env=_env(ci=False), + ) + + +@pytest.mark.parametrize( + ("version", "prerelease"), + [ + ("0.4.0", "false"), + ("0.4.0rc1", "true"), + ("v0.4.0b2", "true"), + ("0.4.0.dev3", "true"), + ], +) +def test_classify_writes_the_step_outputs(version: str, prerelease: str) -> None: + """The Release workflow's outputs, one ``name=value`` line each.""" + result = _classify(version) + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines() == [ + f"version={version.removeprefix('v')}", + f"prerelease={prerelease}", + ] + + +@pytest.mark.parametrize( + ("version", "normal"), [("0.4.0-rc.1", "0.4.0rc1"), ("0.4.0RC1", "0.4.0rc1")] +) +def test_classify_refuses_a_spelling_that_is_not_the_normal_form( + version: str, normal: str +) -> None: + """The tag and the package must name one version: the normal form is named.""" + result = _classify(version) + assert result.returncode == 1 + assert result.stdout == "" + assert f"give it as '{normal}'" in result.stderr + + +def test_classify_refuses_what_is_not_a_release_version() -> None: + result = _classify("0.4.0+local") + assert result.returncode == 1 + assert "is not a release version" in result.stderr + + +@pytest.mark.parametrize("candidate", ["0.4.0rc1", "0.4.0a1", "0.4.0b2", "0.4.0.dev3"]) +def test_the_gate_passes_a_pre_release_with_no_record( + repo: Path, candidate: str +) -> None: + """A pre-release needs no release step: the gate passes when HEAD does not record + it, and says that it freezes nothing.""" + result = _gate(repo, candidate) + assert result.returncode == 0, result.stderr + assert f"{candidate} is a pre-release: it freezes nothing" in result.stdout + assert "unpinned" in result.stdout + + +@pytest.mark.parametrize("recorded", ["0.4.0rc1", "0.4.0-rc.1"]) +def test_the_gate_refuses_a_pre_release_that_head_records( + repo: Path, recorded: str +) -> None: + """A pre-release recorded as a release (in any spelling) is refused: a pre-release + never runs the release step.""" + pins = store.read_json(store.pins_path(repo)) + pins[VERSION]["releases"][recorded] = "1" * 64 + store.write_json(store.pins_path(repo), pins) + _commit(repo, "record a pre-release as a release") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert "pre-release 0.4.0rc1 cannot be tagged" in result.stderr + assert "a pre-release never runs the golden release step" in result.stderr + + +def test_the_gate_refuses_a_withdrawn_pre_release(repo: Path) -> None: + pins = store.read_json(store.pins_path(repo)) + pins[VERSION].setdefault("withdrawn", {})["0.4.0rc1"] = { + "date": "2026-11-21", + "reason": "test", + "revision": "2" * 64, + "manifest": "3" * 64, + } + store.write_json(store.pins_path(repo), pins) + _commit(repo, "withdraw a pre-release") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert "was withdrawn and is never released again" in result.stderr + + +def test_a_final_version_without_its_release_step_still_fails(repo: Path) -> None: + """A final version behaves as before: the release step is required.""" + result = _gate(repo, "0.4.0") + assert result.returncode == 1 + assert "generate_golden_hashes.py --release 0.4.0" in result.stderr + post = _gate(repo, "0.3.0.post1") + assert post.returncode == 1 + assert "generate_golden_hashes.py --release 0.3.0.post1" in post.stderr + + +def test_the_gate_refuses_a_version_it_does_not_release(repo: Path) -> None: + result = _gate(repo, "0.4.0+local") + assert result.returncode == 1 + assert "is not a release version" in result.stderr + + +def test_a_pre_release_allows_an_unpinned_type_snapshot(repo: Path) -> None: + """Snapshots are pinned by the final release step; a pre-release may ship them open.""" + import json + + snapshot = repo / SNAPSHOT + snapshot.parent.mkdir(parents=True, exist_ok=True) + _ = snapshot.write_text('{"revision": 2}\n') + key = SNAPSHOT.relative_to(PINS.parent).as_posix() + _ = (repo / PINS).write_text( + json.dumps({key: {"released_in": None, "sha256": None}}, indent=2) + "\n" + ) + _commit(repo, "add a snapshot after the release step") + assert _gate(repo, "0.3.0").returncode == 1 + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 0, result.stderr + + +def test_a_pre_release_run_still_fails_on_a_changed_released_file(repo: Path) -> None: + """The Release workflow runs the gate and then the tag check for every version: a + pre-release passes the gate, and the tag check still catches HEAD changing a file + that the final release 0.3.0 froze.""" + released = next(_folder(repo).glob("*.json")) + _ = released.write_text(released.read_text().replace("{", "{ ", 1)) + _commit(repo, "edit a released golden file") + assert _gate(repo, "0.4.0rc1").returncode == 0 + result = _check(repo, ci=True) + assert result.returncode == 1 + assert "differs from the released file" in result.stderr + + +def test_a_pre_release_tag_is_not_a_release(repo: Path) -> None: + """A candidate's tag pins no release, so the tag check skips it and still checks + the final release before it.""" + (repo / "README.candidate").write_text("a commit after 0.3.0\n") + _commit(repo, "work after the release") + assert _gate(repo, "0.4.0rc1").returncode == 0 + _git(repo, "tag", "v0.4.0rc1") + module = _gate_module() + assert module.tag_release(repo, "v0.4.0rc1", VERSION) is None + assert module.check_tag(repo, "v0.4.0rc1", VERSION) is None + result = _check(repo, ci=True) + assert result.returncode == 0, result.stderr + assert "HEAD keeps what v0.3.0 released" in result.stdout + assert "v0.4.0rc1" not in result.stdout + + +def test_the_generator_refuses_to_release_a_pre_release(repo: Path) -> None: + """``--release`` of a pre-release freezes nothing: it refuses and writes nothing.""" + pins_before = store.pins_path(repo).read_bytes() + manifest = store.manifest_path(repo, VERSION) + manifest_before = manifest.read_bytes() + for candidate in ("0.4.0rc1", "0.4.0.dev1", "v0.4.0b1"): + with pytest.raises(SystemExit, match="is a pre-release"): + main(["--root", str(repo), "--release", candidate]) + assert store.pins_path(repo).read_bytes() == pins_before + assert manifest.read_bytes() == manifest_before + + +# --------------------------------------------------------------------------- +# The Release workflow reads the rule (ITL-1329) +# --------------------------------------------------------------------------- + +WORKFLOW = REPO_ROOT / ".github" / "workflows" / "release.yml" + + +def _job(name: str) -> str: + """The text of one job of the Release workflow (up to the next job).""" + text = WORKFLOW.read_text() + start = text.index(f"\n {name}:\n") + following = [ + text.find(f"\n {other}:\n", start + 1) + for other in ( + "test", + "license-check", + "build", + "publish-testpypi", + "publish-pypi", + "linear-sync", + "linear-complete", + ) + ] + end = min((i for i in following if i > start), default=len(text)) + return text[start:end] + + +def test_the_workflow_classifies_the_version_with_the_script() -> None: + """The build job's ``prerelease`` output comes from the script, before the gate.""" + build = _job("build") + assert "prerelease: ${{ steps.classify.outputs.prerelease }}" in build + classify = build.index("id: classify") + assert "--classify-version" in build[classify : classify + 600] + assert classify < build.index("--release-version") + # The tag check runs for every version, a pre-release included. + assert "run: python3 scripts/check_golden_tags.py\n" in build + + +def test_the_workflow_marks_a_pre_release_and_skips_linear() -> None: + publish = _job("publish-pypi") + assert "prerelease: ${{ needs.build.outputs.prerelease == 'true' }}" in publish + assert "freezes nothing" in publish + for name in ("linear-sync", "linear-complete"): + assert "needs.build.outputs.prerelease == 'false'" in _job(name), name diff --git a/tests/test_hashing/golden/generate_golden_hashes.py b/tests/test_hashing/golden/generate_golden_hashes.py index 513ea5eef..119a223ec 100644 --- a/tests/test_hashing/golden/generate_golden_hashes.py +++ b/tests/test_hashing/golden/generate_golden_hashes.py @@ -28,8 +28,11 @@ ``withdrawn`` in ``released_manifests.json``, so no file is released today. Until 0.4.0, a change to any v1 value needs the developer's approval of the exact list of entries that move, each explained; it is made with ``--remove`` then ``--add`` (rule 4). 0.4.0 - freezes v1 with ``--release 0.4.0``; so would any version published before it, a - pre-release included (the Release workflow requires the release step for every version). + freezes v1 with ``--release 0.4.0``. A pre-release (``0.4.0rc1``) freezes nothing + (developer, November 21, 2026, ITL-1329): it carries the hashes intended to be final, + ``--release`` refuses it, and the Release workflow publishes it without the release step. + Between a candidate and the final release a value changes only for a blocking reason, + with the developer's approval of the exact list, and a new candidate follows. 1. A golden file listed by a released revision never changes and is never removed. This script never rewrites one. 2. Adding values is allowed in any release. ``--add`` (the default) writes the entries the @@ -488,6 +491,40 @@ def release(root: pathlib.Path, version: str, release_text: str) -> str: return history[-1]["digest"] +def refuse_pre_release(release_text: str) -> None: + """Refuse to run the release step for a pre-release (ITL-1329). + + Only a final release freezes a data context; a pre-release carries the hashes intended + to be final and is published without the release step. The rule is the Release + workflow's gate, ``release_version`` in ``scripts/check_golden_tags.py`` (standard + library only, so the workflow runs it before installing anything), loaded from this + repository by path: ``scripts`` is not a package. + + Args: + release_text: The version given to ``--release``. + + Raises: + SystemExit: If ``release_text`` is a pre-release, or not a release version. + """ + import importlib.util + + script = _PROJECT_ROOT / "scripts" / "check_golden_tags.py" + spec = importlib.util.spec_from_file_location("check_golden_tags_script", script) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + try: + name, prerelease = module.release_version(release_text) + except ValueError as exc: + raise SystemExit(str(exc)) from exc + if prerelease: + raise SystemExit( + f"{name} is a pre-release: a pre-release never runs the release step, only a " + "final release freezes a data context (RELEASING.md, Pre-releases); nothing " + "was released" + ) + + def _data_function_types_script(root: pathlib.Path) -> Any | None: """The module ``scripts/data_function_types.py`` of ``root``. @@ -662,6 +699,7 @@ def main(argv: list[str] | None = None) -> None: _ = remove(args.root, version, args.remove) return if args.release is not None: + refuse_pre_release(args.release) check_data_function_types(args.root) module = _data_function_types_script(args.root) snapshots = args.root / "src" / "orcapod" / "data_function_types" From 5f056463c13d2d7196f861123b3838e1c0affba0 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Fri, 20 Nov 2026 21:26:07 -0800 Subject: [PATCH 2/4] fix(release): no release record names a pre-release; a pre-release tag protects nothing; one version normalization (ITL-1329) Codex review of PR 470: - The candidate gate refuses a pre-release in ANY release record at HEAD: the releases pins, a golden history release revision, a data function type snapshot pin (released_in), in any spelling; and a withdrawn candidate as before. - Nothing pins under a pre-release: scripts/data_function_types.py --release refuses one (the gate's rule, loaded by path). The tag check skips a tag whose name is a pre-release, in check_type_snapshots and in tag_release, so a candidate tag never freezes anything; every other tag is checked as before. - release.yml: the classify step is the one normalization of the raw input (at most one leading lowercase v); every later use of the version is its output. The Normalize version step is removed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 30 +++--- .zed/rules | 4 +- CLAUDE.md | 4 +- RELEASING.md | 21 ++-- changelog.d/ITL-1329.md | 10 +- docs/reference/golden-hashes.md | 13 ++- scripts/check_golden_tags.py | 90 +++++++++++++++--- scripts/data_function_types.py | 44 ++++++++- tests/test_check_golden_tags.py | 153 +++++++++++++++++++++++++++++- tests/test_data_function_types.py | 18 ++++ 10 files changed, 334 insertions(+), 53 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 999e0d417..771611f45 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -105,7 +105,7 @@ jobs: permissions: contents: write # required to push the release tag outputs: - version: ${{ steps.normalize.outputs.version }} + version: ${{ steps.classify.outputs.version }} # 'true' for a pre-release (aN, bN, rcN, .devN), 'false' for a final release: # decided by scripts/check_golden_tags.py, the one rule (ITL-1329). prerelease: ${{ steps.classify.outputs.prerelease }} @@ -124,13 +124,6 @@ jobs: echo "Validation, the license check and the build ran as usual." } >> "$GITHUB_STEP_SUMMARY" - - name: Normalize version - id: normalize - run: | - VERSION="${{ inputs.version }}" - VERSION="${VERSION#v}" - echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: fetch-depth: 0 # required: hatch-vcs reads tag to set version @@ -138,18 +131,21 @@ jobs: - name: Classify the version id: classify - # Writes prerelease=true|false. Fails on a version that is not a release version - # in its PEP 440 normal form (0.4.0rc1, not 0.4.0-rc.1), so that the tag, the - # package, the GitHub Release and the Linear release name one version (ITL-1329). + # The one normalization of the version input (ITL-1329): writes version= + # (without the leading v) and prerelease=true|false. Fails on anything that is + # not a release version in its PEP 440 normal form with at most one leading + # lowercase v (0.4.0rc1 or v0.4.0rc1; not 0.4.0-rc.1, V0.4.0 or vv0.4.0), so that + # the tag, the package, the GitHub Release and the Linear release name one + # version. Every later step uses its version output. env: - VERSION: ${{ steps.normalize.outputs.version }} + VERSION: ${{ inputs.version }} run: python3 scripts/check_golden_tags.py --classify-version "$VERSION" >> "$GITHUB_OUTPUT" - name: Check the golden release step # A final release: nothing is tagged or published unless the release pull request # ran generate_golden_hashes.py --release for this version (ITL-946). A # pre-release freezes nothing: HEAD must not record it as a release (ITL-1329). - run: python3 scripts/check_golden_tags.py --release-version "${{ steps.normalize.outputs.version }}" + run: python3 scripts/check_golden_tags.py --release-version "${{ steps.classify.outputs.version }}" - name: Check golden files against release tags # Every golden file, revision and pin an earlier release tag of the current data @@ -164,7 +160,7 @@ jobs: git config user.email "github-actions[bot]@users.noreply.github.com" - name: Create local release tag - run: git tag "v${{ steps.normalize.outputs.version }}" + run: git tag "v${{ steps.classify.outputs.version }}" - name: Install uv uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 @@ -174,13 +170,13 @@ jobs: - name: Guard against duplicate tag run: | - if git ls-remote --tags origin "refs/tags/v${{ steps.normalize.outputs.version }}" | grep -q .; then - echo "::error::Tag v${{ steps.normalize.outputs.version }} already exists on origin. Aborting." + if git ls-remote --tags origin "refs/tags/v${{ steps.classify.outputs.version }}" | grep -q .; then + echo "::error::Tag v${{ steps.classify.outputs.version }} already exists on origin. Aborting." exit 1 fi - name: Push release tag - run: git push origin "v${{ steps.normalize.outputs.version }}" + run: git push origin "v${{ steps.classify.outputs.version }}" - name: Upload dist artifact uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/.zed/rules b/.zed/rules index d80127024..ae4126553 100644 --- a/.zed/rules +++ b/.zed/rules @@ -496,7 +496,9 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that HEAD does NOT record it, and `--release` refuses it. Between a + one rule) requires that no release record at HEAD names a pre-release (pins, golden + history, snapshot `released_in`), the tag check gives a pre-release tag no protecting + power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a candidate is not guaranteed valid under the final release. A withdrawn version is never diff --git a/CLAUDE.md b/CLAUDE.md index 46da8d746..7d851a6e3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -507,7 +507,9 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that HEAD does NOT record it, and `--release` refuses it. Between a + one rule) requires that no release record at HEAD names a pre-release (pins, golden + history, snapshot `released_in`), the tag check gives a pre-release tag no protecting + power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a candidate is not guaranteed valid under the final release. A withdrawn version is never diff --git a/RELEASING.md b/RELEASING.md index ceea96938..ad12c2fe4 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -198,7 +198,7 @@ on origin, and the ruleset `protect-release-tags` forbids deleting a `v*` tag, s ``` - Pre-flight: branch validation, then tests on Python 3.11, 3.12 and 3.13 and license check (parallel after validation); the tests are skipped only with `skip_tests` - - Build: normalises version (strips a leading `v`), classifies it (`check_golden_tags.py --classify-version`: final or pre-release; a version not in its PEP 440 normal form is refused), checks the golden release step (for a pre-release: that HEAD does not record it) and the release tags, creates the local tag, builds wheel + sdist with `uv build`, aborts if the tag already exists on origin, pushes the tag, uploads `dist/` as an artifact + - Build: classifies the version input (`check_golden_tags.py --classify-version`, the one normalization: it strips one leading `v`, says final or pre-release, and refuses a version not in its PEP 440 normal form; every later step uses its output), checks the golden release step (for a pre-release: that HEAD does not record it) and the release tags, creates the local tag, builds wheel + sdist with `uv build`, aborts if the tag already exists on origin, pushes the tag, uploads `dist/` as an artifact - TestPyPI: in the `testpypi` environment, `uv publish --publish-url https://test.pypi.org/legacy/ dist/*` with an OIDC token (`id-token: write`) — a staging upload - PyPI: in the `pypi` environment, after TestPyPI succeeds and a reviewer approves, `uv publish dist/*` with an OIDC token, then creates the GitHub Release for the tag with generated release notes and the dist files attached; a pre-release is marked as one, and its notes start with a paragraph saying that it freezes nothing - Linear: `linear-sync` starts immediately after build (parallel to publish); `linear-complete` runs after both PyPI publish and linear-sync succeed (see *Linear Release System*). Neither runs for a pre-release @@ -340,16 +340,20 @@ neither `X.Y.Z` (or `X.Y.Z.postN`) nor such a pre-release is refused, never gues A pre-release goes through the same Release workflow, with four differences (ITL-1329): -- It freezes nothing: the build job requires that HEAD does **not** record it as a release - (no golden release step), and it allows data function type snapshots that are not pinned - yet. The tag check still runs, so what earlier final releases froze stays protected. +- It freezes nothing: the build job requires that no release record at HEAD names a + pre-release (no `releases` pin, no release revision in the golden history, no data + function type snapshot pinned as released in one; so no golden release step, and + `data_function_types.py --release` refuses a pre-release too), and it allows data + function type snapshots that are not pinned yet. The tag check still runs, so what + earlier final releases froze stays protected; it skips every pre-release tag, which + protects nothing. - The GitHub Release is marked as a pre-release, and its notes begin with a paragraph saying that it freezes nothing and that data stored with it is not guaranteed to be valid under the final release. - `linear-sync` and `linear-complete` do not run: the open Linear release stays open for the final version (see *Linear Release System*). -- The version must be given in its PEP 440 normal form (`0.4.0rc1`, not `0.4.0-rc.1` or - `0.4.0RC1`), so that the tag, the package, the GitHub Release and the Linear release name +- The version must be given in its PEP 440 normal form, with at most one leading lowercase + `v` (`0.4.0rc1` or `v0.4.0rc1`; not `0.4.0-rc.1`, `0.4.0RC1` or `vv0.4.0rc1`), so that the tag, the package, the GitHub Release and the Linear release name one version; the build job refuses any other spelling and names the normal form. ### Cutting a release candidate @@ -432,8 +436,9 @@ being built and `hatch-vcs` reads that tag. The fix those two releases carried i | Alpha | `vMAJOR.MINOR.PATCHaN` | `v0.1.0a1` | | Beta | `vMAJOR.MINOR.PATCHbN` | `v0.1.0b1` | -The workflow input accepts any of the above, with or without a leading `v`, in its PEP 440 -normal form (`0.1.0rc1`, not `0.1.0-rc.1`): the build job refuses another spelling. The version is +The workflow input accepts any of the above, with or without one leading lowercase `v`, in +its PEP 440 normal form (`0.1.0rc1`, not `0.1.0-rc.1`): the build job refuses another +spelling. The version is derived from the git tag by `hatch-vcs` (`dynamic = ["version"]` in `pyproject.toml`) — no manual version bump is needed. diff --git a/changelog.d/ITL-1329.md b/changelog.d/ITL-1329.md index a81fdfdd9..3e8ffcb88 100644 --- a/changelog.d/ITL-1329.md +++ b/changelog.d/ITL-1329.md @@ -3,12 +3,16 @@ - A pre-release no longer freezes the data context (ITL-1329). Only a final version runs the golden release step. A release candidate (`0.4.0rc1`; also `aN`, `bN`, `.devN`) carries the hashes intended to be final and is published without it: the Release workflow's gate - checks instead that HEAD does not record the pre-release as a release. + checks instead that no release record at HEAD names a pre-release (a `releases` pin, a + golden history release revision or a data function type snapshot pin), and the tag + check gives a pre-release tag no protecting power. `data_function_types.py --release` + refuses a pre-release. `generate_golden_hashes.py --release` refuses a pre-release. The tag check of earlier final releases still runs for every version. The GitHub Release of a pre-release is marked as one, and its notes say that it freezes nothing and that data stored with it is not guaranteed to be valid under the final release. The Linear release jobs do not run for a - pre-release. The workflow's version must be in its PEP 440 normal form (`0.4.0rc1`, not - `0.4.0-rc.1`). `RELEASING.md` has the checklist for cutting a candidate and the rule + pre-release. The workflow's version must be in its PEP 440 normal form, with at most one + leading lowercase `v` (`0.4.0rc1`, not `0.4.0-rc.1` or `vv0.4.0rc1`), and the workflow + normalizes it once. `RELEASING.md` has the checklist for cutting a candidate and the rule between a candidate and the final release: a golden value changes only for a blocking reason, with the developer's approval of the exact list, and a new candidate follows. diff --git a/docs/reference/golden-hashes.md b/docs/reference/golden-hashes.md index 4af9e6bff..6cf1a4360 100644 --- a/docs/reference/golden-hashes.md +++ b/docs/reference/golden-hashes.md @@ -250,7 +250,7 @@ file (`--relocate`) before the release step, so that the release freezes them. Every final version needs the release step: the release gate refuses to tag one without it. A pre-release (`0.4.0rc1`, `0.4.0a1`, `0.4.0b2`, `0.4.0.dev3`) freezes nothing (developer, November 21, 2026, ITL-1329). It carries the hashes intended to be final, the release gate -checks that HEAD does *not* record it as a release, and `generate_golden_hashes.py +checks that no release record at HEAD names it, and `generate_golden_hashes.py --release` refuses it. So the first final version of a data context freezes it: for `v1`, `0.4.0`, not `0.4.0rc1`. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list of entries that @@ -404,9 +404,14 @@ build job before the tag is made; tested by `tests/test_check_golden_tags.py` release `X.Y.Z` of the current data context, its `manifest` pin is set, and the pinned digest is the release revision of `X.Y.Z`, which is the last revision of HEAD's golden history: a golden file added after the release step would ship unreleased, so such a commit is not tagged. It fails without - git. For a pre-release (ITL-1329) it checks the opposite: HEAD does not record that - version as a release (nor as withdrawn); the release step and the type snapshot pins are - not required. Which versions are pre-releases is one rule, `release_version` in the same + git. For a pre-release (ITL-1329) it checks the opposite: no release record at HEAD + names a pre-release, in any spelling (the `releases` pins, a release revision of the + golden history, a data function type snapshot's `released_in`), and the version is not + withdrawn; the release step and the type snapshot pins are not required. The tag check + skips every tag whose name is a pre-release (`v0.4.0rc1`), so such a tag protects no + golden file, revision, pin or snapshot; every other tag is checked as before. + `scripts/data_function_types.py --release` refuses a pre-release too, so nothing can be + pinned under one. Which versions are pre-releases is one rule, `release_version` in the same script (PEP 440; a version that is not `X.Y.Z` with an optional pre-release, post-release or development part is refused, never guessed), which the Release workflow also reads (`--classify-version`) to mark the GitHub Release and to skip the Linear jobs. diff --git a/scripts/check_golden_tags.py b/scripts/check_golden_tags.py index d1e5a44b4..88e579dd1 100644 --- a/scripts/check_golden_tags.py +++ b/scripts/check_golden_tags.py @@ -228,8 +228,11 @@ def tag_release(repo: Path, tag: str, version: str) -> str | None: Returns: ``X.Y.Z`` when the tag is ``v`` and its ``released_manifests.json`` pins - release ``X.Y.Z`` of ``version``; otherwise ``None``. + release ``X.Y.Z`` of ``version``; otherwise ``None``, always for the tag of a + pre-release, which freezes nothing (ITL-1329). """ + if is_pre_release_tag(tag): + return None release = tag.removeprefix("v") tag_pins = _show_json(repo, tag, PINS) pin = tag_pins.get(version) if isinstance(tag_pins, dict) else None @@ -356,6 +359,8 @@ def check_tag(repo: Path, tag: str, version: str) -> list[str] | None: def check_type_snapshots(repo: Path, tag: str) -> list[str]: """What HEAD changed of the data function type snapshots ``tag`` released. + The tag of a pre-release released nothing (ITL-1329): it has no problem to report. + Every snapshot the tag's ``released.json`` pins (a ``sha256`` that is not null) must be at HEAD with the same bytes, and pinned there with the same ``sha256`` and version: rewriting a released snapshot together with its pin is caught here, as a @@ -368,6 +373,8 @@ def check_type_snapshots(repo: Path, tag: str) -> list[str]: Returns: One problem per changed snapshot or pin; empty when HEAD keeps them. """ + if is_pre_release_tag(tag): + return [] pins_path = TYPE_SNAPSHOTS / "released.json" released = _show_json(repo, tag, pins_path) if not isinstance(released, dict): @@ -515,15 +522,16 @@ def check_release(repo: Path, release: str) -> list[str]: def check_pre_release(repo: Path, release: str) -> list[str]: - """Check that HEAD does not record a pre-release as a release, before it is tagged. + """Check that HEAD records no pre-release as a release, before a pre-release is tagged. A pre-release carries the hashes intended to be final but freezes nothing: only a final release runs the golden release step (developer, November 21, 2026, ITL-1329). - So HEAD must not record ``release`` under the current data context's ``releases``, nor - as withdrawn (a package index never takes a version twice). Unpinned data function - type snapshots are allowed: the final release step pins them. What earlier final - releases froze is checked by the tag check, which the Release workflow runs for a - pre-release too. + So no release record at HEAD names a pre-release, in any spelling: not the current + data context's ``releases`` pins, not a release revision of its golden history, not + a data function type snapshot pin (``released_in``). Nor may ``release`` be withdrawn + (a package index never takes a version twice). Unpinned data function type snapshots + are allowed: the final release step pins them. What earlier final releases froze is + checked by the tag check, which the Release workflow runs for a pre-release too. Args: repo: Repository root. @@ -537,13 +545,46 @@ def check_pre_release(repo: Path, release: str) -> list[str]: pin = pins.get(version) if isinstance(pins, dict) else None releases = pin.get("releases") if isinstance(pin, dict) else None recorded = sorted(releases) if isinstance(releases, dict) else [] - problems: list[str] = [] - if any(_same_version(name, release) for name in recorded): - problems.append( - f"HEAD records pre-release {release} as a release of data context {version}: " - "a pre-release never runs the golden release step (only a final release " - "freezes a data context); revert the release step's commit" + manifest = _show_json(repo, "HEAD", CONTEXTS / "data" / f"{version}.json") + golden = manifest.get("golden") if isinstance(manifest, dict) else None + history = golden.get("history") if isinstance(golden, dict) else None + revisions = [ + str(revision["release"]) + for revision in (history if isinstance(history, list) else []) + if isinstance(revision, dict) and revision.get("release") is not None + ] + snapshot_pins = _show_json(repo, "HEAD", TYPE_SNAPSHOTS / "released.json") + snapshot_releases = { + relative: str(snapshot_pin["released_in"]) + for relative, snapshot_pin in ( + snapshot_pins.items() if isinstance(snapshot_pins, dict) else [] ) + if isinstance(snapshot_pin, dict) + and snapshot_pin.get("released_in") is not None + } + step = ( + "a pre-release never runs the golden release step (only a final release " + "freezes a data context); revert the release step's commit" + ) + problems: list[str] = [] + for name in recorded: + if _is_pre_release(name): + problems.append( + f"HEAD records pre-release {name} as a release of data context " + f"{version}: {step}" + ) + for name in revisions: + if _is_pre_release(name): + problems.append( + f"the golden history of data context {version} at HEAD has a release " + f"revision of pre-release {name}: {step}" + ) + for relative, name in sorted(snapshot_releases.items()): + if _is_pre_release(name): + problems.append( + f"data function type snapshot {relative} is pinned as released in " + f"pre-release {name}: a pre-release pins no snapshot; revert the pin" + ) if any(_same_version(name, release) for name in _head_withdrawn(repo, version)): problems.append( f"release {release} of data context {version} was withdrawn and is never " @@ -552,6 +593,23 @@ def check_pre_release(repo: Path, release: str) -> list[str]: return problems +def _is_pre_release(name: str) -> bool: + """Whether a recorded version name is a pre-release, in any spelling.""" + try: + return release_version(name)[1] + except ValueError: + return False + + +def is_pre_release_tag(tag: str) -> bool: + """Whether ``tag`` names a pre-release (``v0.4.0rc1``): such a tag froze nothing. + + A tag that names no release version (not a version, or one this project does not + release) is not a pre-release tag, and is checked as before. + """ + return _is_pre_release(tag) + + def _same_version(name: str, release: str) -> bool: """Whether a recorded version name is ``release``, in any spelling.""" try: @@ -670,6 +728,12 @@ def main(argv: Sequence[str] | None = None) -> int: checked: list[str] = [] problems: list[str] = [] for tag in sorted(tags): + if is_pre_release_tag(tag): + # A pre-release froze nothing (ITL-1329): its tag protects nothing. + print( + f"{tag}: a pre-release, which freezes nothing; not compared with HEAD" + ) + continue # The data function type snapshots do not belong to a data context. problems.extend(check_type_snapshots(args.repo, tag)) found = check_tag(args.repo, tag, version) diff --git a/scripts/data_function_types.py b/scripts/data_function_types.py index ee0c7967f..8eababce3 100644 --- a/scripts/data_function_types.py +++ b/scripts/data_function_types.py @@ -16,7 +16,10 @@ uv run python scripts/data_function_types.py --write # after changing a declaration uv run python scripts/data_function_types.py --release X.Y.Z # the release step -``--release`` pins every open snapshot; ``generate_golden_hashes.py --release`` runs it. +``--release`` pins every open snapshot; ``generate_golden_hashes.py --release`` runs it. It +refuses a pre-release (ITL-1329): only a final release pins, so that a release candidate +freezes nothing. Which versions are pre-releases is the release gate's rule, +``release_version`` in ``check_golden_tags.py`` beside this script. """ from __future__ import annotations @@ -157,8 +160,41 @@ def open_snapshots(snapshots: Path) -> list[str]: ) +def _refuse_pre_release(version: str) -> None: + """Refuse to pin for a pre-release, or for a text that is not a release version. + + The rule is ``release_version`` of ``check_golden_tags.py`` beside this script (the + release gate's, standard library only), loaded by path: ``scripts`` is not a package. + + Raises: + SystemExit: If ``version`` is a pre-release or not a release version, or the gate + script is missing (the rule is never guessed). + """ + import importlib.util + + gate = Path(__file__).resolve().with_name("check_golden_tags.py") + if not gate.is_file(): + raise SystemExit( + f"{gate} is missing: it decides which versions are pre-releases; nothing " + "was pinned" + ) + spec = importlib.util.spec_from_file_location("check_golden_tags_script", gate) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + try: + name, prerelease = module.release_version(version) + except ValueError as exc: + raise SystemExit(str(exc)) from exc + if prerelease: + raise SystemExit( + f"{name} is a pre-release: a pre-release pins no snapshot, only a final " + "release does (ITL-1329); nothing was pinned" + ) + + def release(snapshots: Path, version: str) -> list[str]: - """Pin every open snapshot as released in ``version``. + """Pin every open snapshot as released in ``version``, a final release. Args: snapshots: The snapshot folder. @@ -166,7 +202,11 @@ def release(snapshots: Path, version: str) -> list[str]: Returns: The relative paths pinned now. + + Raises: + SystemExit: If ``version`` is a pre-release (ITL-1329), or a snapshot is unsound. """ + _refuse_pre_release(version) problems = check(snapshots) if problems: raise SystemExit("\n".join(problems)) diff --git a/tests/test_check_golden_tags.py b/tests/test_check_golden_tags.py index 6c746b927..591e0c48c 100644 --- a/tests/test_check_golden_tags.py +++ b/tests/test_check_golden_tags.py @@ -7,6 +7,7 @@ from __future__ import annotations import os +import re import subprocess import sys from pathlib import Path @@ -866,7 +867,7 @@ def test_a_pre_release_tag_is_not_a_release(repo: Path) -> None: result = _check(repo, ci=True) assert result.returncode == 0, result.stderr assert "HEAD keeps what v0.3.0 released" in result.stdout - assert "v0.4.0rc1" not in result.stdout + assert "v0.4.0rc1: a pre-release, which freezes nothing" in result.stdout def test_the_generator_refuses_to_release_a_pre_release(repo: Path) -> None: @@ -888,6 +889,13 @@ def test_the_generator_refuses_to_release_a_pre_release(repo: Path) -> None: WORKFLOW = REPO_ROOT / ".github" / "workflows" / "release.yml" +def _classify_step(build: str) -> tuple[str, str]: + """The text of the build job's classify step, and the text of the steps after it.""" + start = build.rindex(" - name:", 0, build.index("id: classify")) + end = build.index("\n - ", start + 1) + return build[start:end], build[end:] + + def _job(name: str) -> str: """The text of one job of the Release workflow (up to the next job).""" text = WORKFLOW.read_text() @@ -912,9 +920,9 @@ def test_the_workflow_classifies_the_version_with_the_script() -> None: """The build job's ``prerelease`` output comes from the script, before the gate.""" build = _job("build") assert "prerelease: ${{ steps.classify.outputs.prerelease }}" in build - classify = build.index("id: classify") - assert "--classify-version" in build[classify : classify + 600] - assert classify < build.index("--release-version") + step, later = _classify_step(build) + assert "--classify-version" in step + assert "--release-version" in later # The tag check runs for every version, a pre-release included. assert "run: python3 scripts/check_golden_tags.py\n" in build @@ -925,3 +933,140 @@ def test_the_workflow_marks_a_pre_release_and_skips_linear() -> None: assert "freezes nothing" in publish for name in ("linear-sync", "linear-complete"): assert "needs.build.outputs.prerelease == 'false'" in _job(name), name + + +# --------------------------------------------------------------------------- +# No release record at HEAD names a pre-release (Codex review of PR 470) +# --------------------------------------------------------------------------- + + +def _pin_snapshot(repo: Path, released_in: str | None, content: str) -> str: + """Write the snapshot ``content`` and pin it as released in ``released_in``.""" + import hashlib + import json + + snapshot = repo / SNAPSHOT + snapshot.parent.mkdir(parents=True, exist_ok=True) + _ = snapshot.write_text(content) + key = SNAPSHOT.relative_to(PINS.parent).as_posix() + digest = hashlib.sha256(snapshot.read_bytes()).hexdigest() + pin = {"released_in": released_in, "sha256": digest if released_in else None} + _ = (repo / PINS).write_text(json.dumps({key: pin}, indent=2) + "\n") + return key + + +@pytest.mark.parametrize("spelling", ["0.4.0rc1", "0.4.0-rc.1"]) +def test_a_pre_release_in_the_golden_history_only_is_refused( + repo: Path, spelling: str +) -> None: + """A release revision of the candidate in the golden history, with no pin, is a + release record: the candidate gate refuses it, so the workflow stops before the tag + check and the tag.""" + path = store.manifest_path(repo, VERSION) + manifest = store.read_json(path) + manifest["golden"]["history"] = store.with_release( + manifest["golden"]["history"], spelling, "2026-11-21" + ) + store.write_json(path, manifest) + _commit(repo, "a release revision of a candidate, without its pin") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert f"has a release revision of pre-release {spelling}" in result.stderr + + +@pytest.mark.parametrize("spelling", ["0.4.0rc1", "0.4.0-rc.1", "0.3.1b1"]) +def test_a_snapshot_pinned_in_a_pre_release_is_refused( + repo: Path, spelling: str +) -> None: + """A snapshot pin naming any pre-release is refused at the candidate gate: a + pre-release pins nothing.""" + key = _pin_snapshot(repo, spelling, '{"value": 1}\n') + _commit(repo, "a snapshot pinned by a candidate") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert f"snapshot {key} is pinned as released in pre-release {spelling}" in ( + result.stderr + ) + + +def test_a_candidate_tag_never_freezes_a_snapshot(repo: Path) -> None: + """The reviewer's sequence: a candidate that pinned a snapshot is refused at the + gate; and were its tag to exist anyway, a later change of that snapshot before the + final release is not blocked by it.""" + _ = _pin_snapshot(repo, "0.4.0rc1", '{"value": 1}\n') + _commit(repo, "a candidate pins a snapshot") + assert _gate(repo, "0.4.0rc1").returncode == 1 + _git(repo, "tag", "v0.4.0rc1") + module = _gate_module() + _ = _pin_snapshot(repo, None, '{"value": 2}\n') + _commit(repo, "the snapshot changes before the final release") + assert module.check_type_snapshots(repo, "v0.4.0rc1") == [] + result = _check(repo, ci=True) + assert result.returncode == 0, result.stderr + assert "v0.4.0rc1: a pre-release, which freezes nothing" in result.stdout + + +def test_a_pre_release_tag_is_never_a_release_even_with_a_record(repo: Path) -> None: + """A candidate tag whose commit records it (a malformed state) still protects + nothing: the tag check classifies the tag by its name.""" + pins = store.read_json(store.pins_path(repo)) + pins[VERSION]["releases"]["0.4.0rc1"] = "1" * 64 + store.write_json(store.pins_path(repo), pins) + _commit(repo, "a candidate recorded as a release") + _git(repo, "tag", "v0.4.0rc1") + module = _gate_module() + assert module.tag_release(repo, "v0.4.0rc1", VERSION) is None + assert module.check_tag(repo, "v0.4.0rc1", VERSION) is None + + +def test_final_tags_keep_protecting_beside_a_later_candidate(repo: Path) -> None: + """In a run for a later candidate, every final tag protects as before: a golden file + 0.3.0 froze and a snapshot 9.9.9 pinned are both caught; the candidate tag is + skipped.""" + _release_a_snapshot(repo) # final v9.9.9 pins a snapshot + (repo / "README.candidate").write_text("after 9.9.9\n") + _commit(repo, "work after the release") + _git(repo, "tag", "v10.0.0rc1") + assert _check(repo, ci=True).returncode == 0 + snapshot = repo / SNAPSHOT + _ = snapshot.write_text('{"revision": 99}\n') + released = _folder(repo) / "semantic-01.json" + _ = released.write_text( + released.read_text().replace("semantic_v1", "semantic_v2", 1) + ) + _commit(repo, "change what final releases froze") + assert _gate(repo, "10.0.0rc2").returncode == 0 + result = _check(repo, ci=True) + assert result.returncode == 1 + assert "v9.9.9: data function type snapshot" in result.stderr + assert "semantic-01.json differs from the released file" in result.stderr + assert "v10.0.0rc1: a pre-release, which freezes nothing" in result.stdout + + +def test_the_workflow_normalizes_the_version_once() -> None: + """The classify step is the one normalization: it reads the raw input, and every + later use of the version is its output (a double ``v`` cannot reach a tag).""" + build = _job("build") + assert "steps.normalize" not in WORKFLOW.read_text() + assert "id: normalize" not in build + step, later = _classify_step(build) + assert build.count("inputs.version") == 1 + assert "VERSION: ${{ inputs.version }}" in step + uses = re.findall(r"\$\{\{ ([a-z_.]+)\.version \}\}", later) + assert uses and set(uses) == {"steps.classify.outputs"}, uses + assert "version: ${{ steps.classify.outputs.version }}" in build + assert 'git tag "v${{ steps.classify.outputs.version }}"' in build + assert 'git push origin "v${{ steps.classify.outputs.version }}"' in build + for name in ("publish-pypi", "linear-sync", "linear-complete"): + assert '"v${{ needs.build.outputs.version }}"' in _job(name), name + + +@pytest.mark.parametrize( + "version", ["vv0.4.0rc1", "V0.4.0rc1", " 0.4.0rc1", "0.4.0rc1\n"] +) +def test_classify_refuses_a_raw_input_that_is_not_the_normal_form(version: str) -> None: + """The workflow hands the raw input to the classifier: anything but the normal form + with at most one leading lowercase ``v`` is refused.""" + result = _classify(version) + assert result.returncode == 1 + assert result.stdout == "" diff --git a/tests/test_data_function_types.py b/tests/test_data_function_types.py index bc545f91d..d6cb3908e 100644 --- a/tests/test_data_function_types.py +++ b/tests/test_data_function_types.py @@ -49,6 +49,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] SCRIPT = REPO_ROOT / "scripts" / "data_function_types.py" +GATE = REPO_ROOT / "scripts" / "check_golden_tags.py" SNAPSHOTS = REPO_ROOT / "src" / "orcapod" / "data_function_types" RECORD_ID = "_record_id" @@ -486,6 +487,7 @@ def test_a_release_with_an_unsound_snapshot_writes_nothing(tmp_path: Path) -> No store.reopen_tree(root, version, "2026-11-18") (root / "scripts").mkdir(exist_ok=True) shutil.copy(SCRIPT, root / "scripts" / SCRIPT.name) + shutil.copy(GATE, root / "scripts" / GATE.name) shutil.copytree( _open_copy(tmp_path), root / "src" / "orcapod" / "data_function_types" ) @@ -638,6 +640,7 @@ def _release_tree(tmp_path: Path, *, with_script: bool = True) -> Path: if with_script: (root / "scripts").mkdir(exist_ok=True) shutil.copy(SCRIPT, root / "scripts" / SCRIPT.name) + shutil.copy(GATE, root / "scripts" / GATE.name) shutil.copytree( _open_copy(tmp_path), root / "src" / "orcapod" / "data_function_types" ) @@ -725,3 +728,18 @@ def failing_pin(_root: Path, _release: str) -> None: (root / "src" / "orcapod" / "data_function_types" / "released.json").read_text() ) assert pins[CURRENT]["sha256"] is None + + +@pytest.mark.parametrize("version", ["0.4.0rc1", "0.4.0.dev2", "v0.4.0b1"]) +def test_release_refuses_a_pre_release_and_pins_nothing( + tmp_path: Path, version: str +) -> None: + """A pre-release pins no snapshot (ITL-1329): only a final release does.""" + snapshots = _open_copy(tmp_path) + before = (snapshots / "released.json").read_bytes() + result = _run("--release", version, "--snapshots", snapshots) + assert result.returncode != 0 + assert "is a pre-release: a pre-release pins no snapshot" in ( + result.stdout + result.stderr + ) + assert (snapshots / "released.json").read_bytes() == before From 275563ef1a238b80b429c04b9a6dfff1a97e9aeb Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Fri, 20 Nov 2026 21:50:22 -0800 Subject: [PATCH 3/4] fix(release): the manifest's released_in and every context's pins are release records (ITL-1329) CodeRabbit on PR 470: the data context manifest's own released_in records the release that froze it; a pre-release there, in any spelling, is now refused at the candidate gate (null and final values pass). The releases pins of every data context in released_manifests.json are checked, not only the current one's. The release records at HEAD are now all covered: released_manifests.json (releases, withdrawn), the manifest (released_in, golden history releases) and the snapshot pins (released_in). Co-Authored-By: Claude Opus 5.5 --- .zed/rules | 4 +-- CLAUDE.md | 4 +-- RELEASING.md | 5 ++-- changelog.d/ITL-1329.md | 5 ++-- docs/reference/golden-hashes.md | 3 +- scripts/check_golden_tags.py | 30 ++++++++++++++------ tests/test_check_golden_tags.py | 49 +++++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 17 deletions(-) diff --git a/.zed/rules b/.zed/rules index 5150e2020..dfb1a085d 100644 --- a/.zed/rules +++ b/.zed/rules @@ -496,8 +496,8 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that no release record at HEAD names a pre-release (pins, golden - history, snapshot `released_in`), the tag check gives a pre-release tag no protecting + one rule) requires that no release record at HEAD names a pre-release (`releases` pins, + the manifest's `released_in`, golden history, snapshot `released_in`), the tag check gives a pre-release tag no protecting power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a diff --git a/CLAUDE.md b/CLAUDE.md index 21a17f8c1..39710886c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -507,8 +507,8 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that no release record at HEAD names a pre-release (pins, golden - history, snapshot `released_in`), the tag check gives a pre-release tag no protecting + one rule) requires that no release record at HEAD names a pre-release (`releases` pins, + the manifest's `released_in`, golden history, snapshot `released_in`), the tag check gives a pre-release tag no protecting power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a diff --git a/RELEASING.md b/RELEASING.md index ad12c2fe4..dd8fff529 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -341,8 +341,9 @@ neither `X.Y.Z` (or `X.Y.Z.postN`) nor such a pre-release is refused, never gues A pre-release goes through the same Release workflow, with four differences (ITL-1329): - It freezes nothing: the build job requires that no release record at HEAD names a - pre-release (no `releases` pin, no release revision in the golden history, no data - function type snapshot pinned as released in one; so no golden release step, and + pre-release (no `releases` pin of any data context, no `released_in` of the data context + manifest, no release revision in the golden history, no data function type snapshot + pinned as released in one; so no golden release step, and `data_function_types.py --release` refuses a pre-release too), and it allows data function type snapshots that are not pinned yet. The tag check still runs, so what earlier final releases froze stays protected; it skips every pre-release tag, which diff --git a/changelog.d/ITL-1329.md b/changelog.d/ITL-1329.md index 3e8ffcb88..668e01881 100644 --- a/changelog.d/ITL-1329.md +++ b/changelog.d/ITL-1329.md @@ -3,8 +3,9 @@ - A pre-release no longer freezes the data context (ITL-1329). Only a final version runs the golden release step. A release candidate (`0.4.0rc1`; also `aN`, `bN`, `.devN`) carries the hashes intended to be final and is published without it: the Release workflow's gate - checks instead that no release record at HEAD names a pre-release (a `releases` pin, a - golden history release revision or a data function type snapshot pin), and the tag + checks instead that no release record at HEAD names a pre-release (a `releases` pin, the + data context manifest's `released_in`, a golden history release revision or a data + function type snapshot pin), and the tag check gives a pre-release tag no protecting power. `data_function_types.py --release` refuses a pre-release. `generate_golden_hashes.py --release` refuses a pre-release. The tag check of earlier diff --git a/docs/reference/golden-hashes.md b/docs/reference/golden-hashes.md index 6cf1a4360..e8c1c9b70 100644 --- a/docs/reference/golden-hashes.md +++ b/docs/reference/golden-hashes.md @@ -405,7 +405,8 @@ build job before the tag is made; tested by `tests/test_check_golden_tags.py` `X.Y.Z`, which is the last revision of HEAD's golden history: a golden file added after the release step would ship unreleased, so such a commit is not tagged. It fails without git. For a pre-release (ITL-1329) it checks the opposite: no release record at HEAD - names a pre-release, in any spelling (the `releases` pins, a release revision of the + names a pre-release, in any spelling (the `releases` pins of every data context in + `released_manifests.json`, the current manifest's `released_in`, a release revision of its golden history, a data function type snapshot's `released_in`), and the version is not withdrawn; the release step and the type snapshot pins are not required. The tag check skips every tag whose name is a pre-release (`v0.4.0rc1`), so such a tag protects no diff --git a/scripts/check_golden_tags.py b/scripts/check_golden_tags.py index 88e579dd1..acd7a9cee 100644 --- a/scripts/check_golden_tags.py +++ b/scripts/check_golden_tags.py @@ -526,9 +526,11 @@ def check_pre_release(repo: Path, release: str) -> list[str]: A pre-release carries the hashes intended to be final but freezes nothing: only a final release runs the golden release step (developer, November 21, 2026, ITL-1329). - So no release record at HEAD names a pre-release, in any spelling: not the current - data context's ``releases`` pins, not a release revision of its golden history, not - a data function type snapshot pin (``released_in``). Nor may ``release`` be withdrawn + So no release record at HEAD names a pre-release, in any spelling. The release + records at HEAD are: the ``releases`` pins of every data context in + ``released_manifests.json``; the current data context manifest's ``released_in`` and + the ``release`` of each revision of its golden history; and the ``released_in`` of + each data function type snapshot pin. Nor may ``release`` be withdrawn (a package index never takes a version twice). Unpinned data function type snapshots are allowed: the final release step pins them. What earlier final releases froze is checked by the tag check, which the Release workflow runs for a pre-release too. @@ -542,10 +544,17 @@ def check_pre_release(repo: Path, release: str) -> list[str]: """ version = _current_version(repo) pins = _show_json(repo, "HEAD", PINS) - pin = pins.get(version) if isinstance(pins, dict) else None - releases = pin.get("releases") if isinstance(pin, dict) else None - recorded = sorted(releases) if isinstance(releases, dict) else [] + recorded = [ + (context, str(name)) + for context, context_pin in sorted( + pins.items() if isinstance(pins, dict) else [] + ) + if isinstance(context_pin, dict) + and isinstance(context_pin.get("releases"), dict) + for name in sorted(context_pin["releases"]) + ] manifest = _show_json(repo, "HEAD", CONTEXTS / "data" / f"{version}.json") + released_in = manifest.get("released_in") if isinstance(manifest, dict) else None golden = manifest.get("golden") if isinstance(manifest, dict) else None history = golden.get("history") if isinstance(golden, dict) else None revisions = [ @@ -567,12 +576,17 @@ def check_pre_release(repo: Path, release: str) -> list[str]: "freezes a data context); revert the release step's commit" ) problems: list[str] = [] - for name in recorded: + for context, name in recorded: if _is_pre_release(name): problems.append( f"HEAD records pre-release {name} as a release of data context " - f"{version}: {step}" + f"{context}: {step}" ) + if released_in is not None and _is_pre_release(str(released_in)): + problems.append( + f"the manifest of data context {version} at HEAD names pre-release " + f"{released_in} as the release that froze it (released_in): {step}" + ) for name in revisions: if _is_pre_release(name): problems.append( diff --git a/tests/test_check_golden_tags.py b/tests/test_check_golden_tags.py index 591e0c48c..7954cd1ba 100644 --- a/tests/test_check_golden_tags.py +++ b/tests/test_check_golden_tags.py @@ -1070,3 +1070,52 @@ def test_classify_refuses_a_raw_input_that_is_not_the_normal_form(version: str) result = _classify(version) assert result.returncode == 1 assert result.stdout == "" + + +def _set_released_in(repo: Path, value: str | None) -> None: + path = store.manifest_path(repo, VERSION) + manifest = store.read_json(path) + manifest["released_in"] = value + store.write_json(path, manifest) + + +@pytest.mark.parametrize("spelling", ["0.4.0rc1", "0.4.0-rc.1"]) +def test_a_pre_release_in_the_manifest_released_in_only_is_refused( + repo: Path, spelling: str +) -> None: + """The manifest's own ``released_in`` is a release record: a pre-release there, + with no other record, is refused (CodeRabbit, #470).""" + _set_released_in(repo, spelling) + _commit(repo, "released_in names a candidate") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert f"names pre-release {spelling} as the release that froze it" in result.stderr + + +@pytest.mark.parametrize("value", ["0.3.1.post1", None]) +def test_a_final_or_null_manifest_released_in_passes( + repo: Path, value: str | None +) -> None: + """A final version or null in ``released_in`` is no pre-release record: the + candidate gate passes (the fixture's own 0.3.0 passes in every other test).""" + manifest = store.read_json(store.manifest_path(repo, VERSION)) + assert manifest["released_in"] == "0.3.0" + assert _gate(repo, "0.4.0rc1").returncode == 0 + _set_released_in(repo, value) + _commit(repo, "released_in final or null") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 0, result.stderr + + +def test_a_pre_release_in_another_data_context_s_releases_is_refused( + repo: Path, +) -> None: + """Every data context's ``releases`` pins are release records, not only the + current one's.""" + pins = store.read_json(store.pins_path(repo)) + pins["v0"] = {"manifest": None, "releases": {"0.2.0b1": "4" * 64}} + store.write_json(store.pins_path(repo), pins) + _commit(repo, "another context records a candidate") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert "pre-release 0.2.0b1 as a release of data context v0" in result.stderr From f66b7a04c17a0230345d89ca9274a300184a63a7 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Fri, 20 Nov 2026 22:19:11 -0800 Subject: [PATCH 4/4] fix(release): unclassifiable release records fail closed; withdrawal in every data context (ITL-1329) Second Codex review of PR 470, and CodeRabbit: - A release record at HEAD holding a version text the gate cannot classify (0.4.0rc1+local, 0.4rc1, 1!0.4.0rc1) is refused, in every field and in a pre-release run and a final run alike; it is never read as final. A tag v + such text is still checked as before, and named. - The requested version withdrawn in ANY data context (any spelling the gate accepts) is refused, for a pre-release and a final release; a pre-release in any context's withdrawn records is refused like one in releases. Co-Authored-By: Claude Opus 5.5 --- .zed/rules | 11 +- CLAUDE.md | 11 +- RELEASING.md | 7 +- changelog.d/ITL-1329.md | 8 +- docs/reference/golden-hashes.md | 15 +- scripts/check_golden_tags.py | 268 +++++++++++++++++++++++--------- tests/test_check_golden_tags.py | 127 +++++++++++++++ 7 files changed, 352 insertions(+), 95 deletions(-) diff --git a/.zed/rules b/.zed/rules index dc59dcc5b..00d82a7c4 100644 --- a/.zed/rules +++ b/.zed/rules @@ -496,13 +496,14 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that no release record at HEAD names a pre-release (`releases` pins, - the manifest's `released_in`, golden history, snapshot `released_in`), the tag check gives a pre-release tag no protecting - power, and `--release` (golden and `data_function_types.py`) refuses it. Between a + one rule) requires that no release record at HEAD names a pre-release (`releases` and + `withdrawn` keys of every context, the manifest's `released_in`, golden history, + snapshot `released_in`; a record it cannot classify fails closed, in every run), the tag + check gives a pre-release tag no protecting power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a - candidate is not guaranteed valid under the final release. A withdrawn version is never - released again. + candidate is not guaranteed valid under the final release. A version withdrawn in any + data context is never released again. - Provisional operators are outside the freeze (developer, November 18, 2026, ITL-1266): `orcapod.operators.PROVISIONAL_OPERATORS` (`core/operators/provisional.py`) is the one list (name to the issue deciding its identity; today `PolarsFilter`), and each listed class diff --git a/CLAUDE.md b/CLAUDE.md index 116b6fc73..8c6e8487a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -507,13 +507,14 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current generator writes the new value. `--release 0.4.0` freezes v1. A pre-release freezes nothing (developer, November 21, 2026, ITL-1329): `0.4.0rc1` carries the hashes intended to be final, the release gate (`scripts/check_golden_tags.py`, `release_version` is the - one rule) requires that no release record at HEAD names a pre-release (`releases` pins, - the manifest's `released_in`, golden history, snapshot `released_in`), the tag check gives a pre-release tag no protecting - power, and `--release` (golden and `data_function_types.py`) refuses it. Between a + one rule) requires that no release record at HEAD names a pre-release (`releases` and + `withdrawn` keys of every context, the manifest's `released_in`, golden history, + snapshot `released_in`; a record it cannot classify fails closed, in every run), the tag + check gives a pre-release tag no protecting power, and `--release` (golden and `data_function_types.py`) refuses it. Between a candidate and the final release a golden value changes only for a blocking reason, with the developer's approval of the exact list, then a new candidate; data stored with a - candidate is not guaranteed valid under the final release. A withdrawn version is never - released again. + candidate is not guaranteed valid under the final release. A version withdrawn in any + data context is never released again. - Provisional operators are outside the freeze (developer, November 18, 2026, ITL-1266): `orcapod.operators.PROVISIONAL_OPERATORS` (`core/operators/provisional.py`) is the one list (name to the issue deciding its identity; today `PolarsFilter`), and each listed class diff --git a/RELEASING.md b/RELEASING.md index dd8fff529..97174c68a 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -341,9 +341,10 @@ neither `X.Y.Z` (or `X.Y.Z.postN`) nor such a pre-release is refused, never gues A pre-release goes through the same Release workflow, with four differences (ITL-1329): - It freezes nothing: the build job requires that no release record at HEAD names a - pre-release (no `releases` pin of any data context, no `released_in` of the data context - manifest, no release revision in the golden history, no data function type snapshot - pinned as released in one; so no golden release step, and + pre-release, in any spelling the gate accepts (no `releases` or `withdrawn` key of any + data context, no `released_in` of the data context manifest, no release revision in the + golden history, no data function type snapshot pinned as released in one; a record the + gate cannot classify is refused, for every version; so no golden release step, and `data_function_types.py --release` refuses a pre-release too), and it allows data function type snapshots that are not pinned yet. The tag check still runs, so what earlier final releases froze stays protected; it skips every pre-release tag, which diff --git a/changelog.d/ITL-1329.md b/changelog.d/ITL-1329.md index 668e01881..2cc5d39c7 100644 --- a/changelog.d/ITL-1329.md +++ b/changelog.d/ITL-1329.md @@ -3,9 +3,11 @@ - A pre-release no longer freezes the data context (ITL-1329). Only a final version runs the golden release step. A release candidate (`0.4.0rc1`; also `aN`, `bN`, `.devN`) carries the hashes intended to be final and is published without it: the Release workflow's gate - checks instead that no release record at HEAD names a pre-release (a `releases` pin, the - data context manifest's `released_in`, a golden history release revision or a data - function type snapshot pin), and the tag + checks instead that no release record at HEAD names a pre-release (a `releases` or + `withdrawn` key, the data context manifest's `released_in`, a golden history release + revision or a data function type snapshot pin), in any spelling the gate accepts; a + record holding a version it cannot classify is refused in every run (fail closed), and a + version withdrawn in any data context is never released again. The tag check gives a pre-release tag no protecting power. `data_function_types.py --release` refuses a pre-release. `generate_golden_hashes.py --release` refuses a pre-release. The tag check of earlier diff --git a/docs/reference/golden-hashes.md b/docs/reference/golden-hashes.md index e8c1c9b70..de5654b12 100644 --- a/docs/reference/golden-hashes.md +++ b/docs/reference/golden-hashes.md @@ -405,12 +405,17 @@ build job before the tag is made; tested by `tests/test_check_golden_tags.py` `X.Y.Z`, which is the last revision of HEAD's golden history: a golden file added after the release step would ship unreleased, so such a commit is not tagged. It fails without git. For a pre-release (ITL-1329) it checks the opposite: no release record at HEAD - names a pre-release, in any spelling (the `releases` pins of every data context in - `released_manifests.json`, the current manifest's `released_in`, a release revision of its - golden history, a data function type snapshot's `released_in`), and the version is not - withdrawn; the release step and the type snapshot pins are not required. The tag check + names a pre-release, in any spelling `release_version` accepts (the `releases` and + `withdrawn` keys of every data context in `released_manifests.json`, the current + manifest's `released_in`, a release revision of its golden history, a data function type + snapshot's `released_in`), and the version is not withdrawn in any data context; the + release step and the type snapshot pins are not required. A release record holding a + version text the gate cannot classify (`0.4.0rc1+local`, `0.4rc1`, `1!0.4.0rc1`) is + refused in a pre-release run and in a final run alike: it fails closed, never read as + final. A final run also refuses a version withdrawn in any data context. The tag check skips every tag whose name is a pre-release (`v0.4.0rc1`), so such a tag protects no - golden file, revision, pin or snapshot; every other tag is checked as before. + golden file, revision, pin or snapshot; every other tag is checked as before, one whose + name the gate cannot classify (`v0.4.0rc1+local`) included, and the output names it. `scripts/data_function_types.py --release` refuses a pre-release too, so nothing can be pinned under one. Which versions are pre-releases is one rule, `release_version` in the same script (PEP 440; a version that is not `X.Y.Z` with an optional pre-release, post-release diff --git a/scripts/check_golden_tags.py b/scripts/check_golden_tags.py index acd7a9cee..51059cab4 100644 --- a/scripts/check_golden_tags.py +++ b/scripts/check_golden_tags.py @@ -16,8 +16,12 @@ A pre-release (``0.4.0rc1``, ``0.4.0a1``, ``0.4.0b2``, ``0.4.0.dev3``) freezes nothing (developer, November 21, 2026, ITL-1329): it carries the hashes intended to be final, and only a final release runs the golden release step. ``--release-version`` of a pre-release -therefore checks that HEAD does NOT record it as a release; its tag pins no release, so the -tag check skips it. ``release_version`` is the one rule that tells the two apart. +therefore checks that no release record at HEAD names a pre-release, in any spelling +``release_version`` accepts, and that the version is withdrawn in no data context. A release +record holding a version text the gate cannot classify is refused in every run, a final +one included (fail closed). The tag check skips a tag whose name is a pre-release; a tag it +cannot classify is checked as before. ``release_version`` is the one rule that tells a +pre-release from a final release. A withdrawn release is not compared with HEAD (ITL-1255): when HEAD's ``released_manifests.json`` records release ``X.Y.Z`` under ``withdrawn`` of the current data @@ -52,7 +56,7 @@ import sys from collections.abc import Sequence from pathlib import Path, PurePosixPath -from typing import Any +from typing import Any, NamedTuple REPO_ROOT = Path(__file__).resolve().parents[1] CONTEXTS = PurePosixPath("src/orcapod/contexts") @@ -479,21 +483,23 @@ def check_release(repo: Path, release: str) -> list[str]: step = ( f"run generate_golden_hashes.py --release {release} in the release pull request" ) + # A release record nobody can classify never ships, whatever is released (ITL-1329). + unclassified = unclassifiable_records(repo) pins = _show_json(repo, "HEAD", PINS) pin = pins.get(version) if isinstance(pins, dict) else None releases = pin.get("releases") if isinstance(pin, dict) else None if not isinstance(pin, dict) or not isinstance(releases, dict): - return [f"HEAD has no pin of data context {version}: {step}"] - if release in _head_withdrawn(repo, version): - return [ - f"release {release} of data context {version} was withdrawn and is never " - "released again: a package index never takes a version twice" - ] + return [f"HEAD has no pin of data context {version}: {step}", *unclassified] + # Withdrawn in any data context, in any spelling the gate accepts. + withdrawn = _withdrawn_problems(repo, release) + if withdrawn: + return [*withdrawn, *unclassified] if release not in releases: return [ - f"HEAD does not record release {release} of data context {version}: {step}" + f"HEAD does not record release {release} of data context {version}: {step}", + *unclassified, ] - problems: list[str] = [] + problems: list[str] = [*unclassified] if pin.get("manifest") is None: problems.append(f"the manifest of data context {version} is not pinned: {step}") manifest = _show_json(repo, "HEAD", CONTEXTS / "data" / f"{version}.json") @@ -526,13 +532,12 @@ def check_pre_release(repo: Path, release: str) -> list[str]: A pre-release carries the hashes intended to be final but freezes nothing: only a final release runs the golden release step (developer, November 21, 2026, ITL-1329). - So no release record at HEAD names a pre-release, in any spelling. The release - records at HEAD are: the ``releases`` pins of every data context in - ``released_manifests.json``; the current data context manifest's ``released_in`` and - the ``release`` of each revision of its golden history; and the ``released_in`` of - each data function type snapshot pin. Nor may ``release`` be withdrawn - (a package index never takes a version twice). Unpinned data function type snapshots - are allowed: the final release step pins them. What earlier final releases froze is + So no release record at HEAD (``_release_records``) names a pre-release, in any + spelling ``release_version`` accepts, a withdrawn record included: a pre-release has + no release record of any kind. A record whose version text the gate cannot classify + is refused too (fail closed). Nor may ``release`` be withdrawn in any data context (a + package index never takes a version twice). Unpinned data function type snapshots are + allowed: the final release step pins them. What earlier final releases froze is checked by the tag check, which the Release workflow runs for a pre-release too. Args: @@ -543,76 +548,188 @@ def check_pre_release(repo: Path, release: str) -> list[str]: One sentence per problem; empty when HEAD does not record the pre-release. """ version = _current_version(repo) - pins = _show_json(repo, "HEAD", PINS) - recorded = [ - (context, str(name)) - for context, context_pin in sorted( - pins.items() if isinstance(pins, dict) else [] - ) - if isinstance(context_pin, dict) - and isinstance(context_pin.get("releases"), dict) - for name in sorted(context_pin["releases"]) - ] - manifest = _show_json(repo, "HEAD", CONTEXTS / "data" / f"{version}.json") - released_in = manifest.get("released_in") if isinstance(manifest, dict) else None - golden = manifest.get("golden") if isinstance(manifest, dict) else None - history = golden.get("history") if isinstance(golden, dict) else None - revisions = [ - str(revision["release"]) - for revision in (history if isinstance(history, list) else []) - if isinstance(revision, dict) and revision.get("release") is not None - ] - snapshot_pins = _show_json(repo, "HEAD", TYPE_SNAPSHOTS / "released.json") - snapshot_releases = { - relative: str(snapshot_pin["released_in"]) - for relative, snapshot_pin in ( - snapshot_pins.items() if isinstance(snapshot_pins, dict) else [] - ) - if isinstance(snapshot_pin, dict) - and snapshot_pin.get("released_in") is not None - } step = ( "a pre-release never runs the golden release step (only a final release " "freezes a data context); revert the release step's commit" ) problems: list[str] = [] - for context, name in recorded: - if _is_pre_release(name): - problems.append( - f"HEAD records pre-release {name} as a release of data context " - f"{context}: {step}" + for record in _release_records(repo, version): + kind = _version_kind(record.text) + if kind is None: + problems.append(_unclassifiable(record)) + elif kind: + problems.append(_pre_release_record(record, step)) + problems.extend(_withdrawn_problems(repo, release)) + return problems + + +class _ReleaseRecord(NamedTuple): + """A version text a release record at HEAD holds. + + ``kind`` names the field: ``releases`` or ``withdrawn`` (``owner`` is the data + context in ``released_manifests.json``), ``released_in`` or ``history`` (``owner`` is + the data context of the manifest), or ``snapshot`` (``owner`` is the snapshot's path + in ``released.json``). + """ + + kind: str + owner: str + text: str + + +def _release_records(repo: Path, version: str) -> list[_ReleaseRecord]: + """Every version text a release record at HEAD holds (ITL-1329). + + The release records are: the ``releases`` and ``withdrawn`` keys of every data + context in ``released_manifests.json``; the current data context manifest's + ``released_in`` and the ``release`` of each revision of its golden history; and the + ``released_in`` of each data function type snapshot pin. + + Args: + repo: Repository root. + version: The current data context. + + Returns: + One record per version text, in a fixed order. + """ + records: list[_ReleaseRecord] = [] + pins = _show_json(repo, "HEAD", PINS) + for context, context_pin in sorted(pins.items() if isinstance(pins, dict) else []): + if not isinstance(context_pin, dict): + continue + for kind in ("releases", "withdrawn"): + names = context_pin.get(kind) + if isinstance(names, dict): + records.extend( + _ReleaseRecord(kind, str(context), str(name)) + for name in sorted(names) + ) + manifest = _show_json(repo, "HEAD", CONTEXTS / "data" / f"{version}.json") + if isinstance(manifest, dict): + if manifest.get("released_in") is not None: + records.append( + _ReleaseRecord("released_in", version, str(manifest["released_in"])) ) - if released_in is not None and _is_pre_release(str(released_in)): - problems.append( - f"the manifest of data context {version} at HEAD names pre-release " - f"{released_in} as the release that froze it (released_in): {step}" + golden = manifest.get("golden") + history = golden.get("history") if isinstance(golden, dict) else None + records.extend( + _ReleaseRecord("history", version, str(revision["release"])) + for revision in (history if isinstance(history, list) else []) + if isinstance(revision, dict) and revision.get("release") is not None ) - for name in revisions: - if _is_pre_release(name): - problems.append( - f"the golden history of data context {version} at HEAD has a release " - f"revision of pre-release {name}: {step}" - ) - for relative, name in sorted(snapshot_releases.items()): - if _is_pre_release(name): - problems.append( - f"data function type snapshot {relative} is pinned as released in " - f"pre-release {name}: a pre-release pins no snapshot; revert the pin" + snapshot_pins = _show_json(repo, "HEAD", TYPE_SNAPSHOTS / "released.json") + for relative, snapshot_pin in sorted( + snapshot_pins.items() if isinstance(snapshot_pins, dict) else [] + ): + if ( + isinstance(snapshot_pin, dict) + and snapshot_pin.get("released_in") is not None + ): + records.append( + _ReleaseRecord( + "snapshot", str(relative), str(snapshot_pin["released_in"]) + ) ) - if any(_same_version(name, release) for name in _head_withdrawn(repo, version)): - problems.append( - f"release {release} of data context {version} was withdrawn and is never " - "released again: a package index never takes a version twice" + return records + + +def _field(record: _ReleaseRecord) -> str: + """The field of a release record, as an error names it.""" + if record.kind in ("releases", "withdrawn"): + return f"{PINS.name} {record.owner}.{record.kind}" + if record.kind == "released_in": + return f"the manifest of data context {record.owner} (released_in)" + if record.kind == "history": + return f"the golden history of data context {record.owner}" + return f"{TYPE_SNAPSHOTS.name}/released.json {record.owner}.released_in" + + +def _unclassifiable(record: _ReleaseRecord) -> str: + """The problem of a release record whose version text the gate cannot classify.""" + return ( + f"release record {_field(record)} holds a version this gate cannot classify: " + f"{record.text!r}; a release record names X.Y.Z, optionally with a pre-release, " + "post-release or development part (fail closed: correct the record)" + ) + + +def _pre_release_record(record: _ReleaseRecord, step: str) -> str: + """The problem of a release record that names a pre-release.""" + name = record.text + if record.kind == "releases": + return ( + f"HEAD records pre-release {name} as a release of data context " + f"{record.owner}: {step}" ) - return problems + if record.kind == "withdrawn": + return ( + f"HEAD records pre-release {name} as withdrawn in data context " + f"{record.owner}: a pre-release has no release record of any kind" + ) + if record.kind == "released_in": + return ( + f"the manifest of data context {record.owner} at HEAD names pre-release " + f"{name} as the release that froze it (released_in): {step}" + ) + if record.kind == "history": + return ( + f"the golden history of data context {record.owner} at HEAD has a release " + f"revision of pre-release {name}: {step}" + ) + return ( + f"data function type snapshot {record.owner} is pinned as released in " + f"pre-release {name}: a pre-release pins no snapshot; revert the pin" + ) -def _is_pre_release(name: str) -> bool: - """Whether a recorded version name is a pre-release, in any spelling.""" +def _withdrawn_problems(repo: Path, release: str) -> list[str]: + """``release`` withdrawn in any data context, in any spelling the gate accepts.""" + pins = _show_json(repo, "HEAD", PINS) + return [ + f"release {release} of data context {context} was withdrawn and is never " + "released again: a package index never takes a version twice" + for context, context_pin in sorted( + pins.items() if isinstance(pins, dict) else [] + ) + if isinstance(context_pin, dict) + and isinstance(context_pin.get("withdrawn"), dict) + and any(_same_version(name, release) for name in context_pin["withdrawn"]) + ] + + +def unclassifiable_records(repo: Path) -> list[str]: + """The release records at HEAD whose version text the gate cannot classify. + + A final release run refuses them too (fail closed): a record nobody can classify + never ships, whatever is released. + + Args: + repo: Repository root. + + Returns: + One problem per such record. + """ + version = _current_version(repo) + return [ + _unclassifiable(record) + for record in _release_records(repo, version) + if _version_kind(record.text) is None + ] + + +def _version_kind(name: str) -> bool | None: + """``True`` for a pre-release, ``False`` for a final version, ``None`` when the + gate cannot classify the text (``release_version`` refuses it).""" try: return release_version(name)[1] except ValueError: - return False + return None + + +def _is_pre_release(name: str) -> bool: + """Whether a version name is a pre-release; ``False`` when it cannot be classified, + so a caller that must fail closed uses ``_version_kind``.""" + return _version_kind(name) is True def is_pre_release_tag(tag: str) -> bool: @@ -748,6 +865,9 @@ def main(argv: Sequence[str] | None = None) -> int: f"{tag}: a pre-release, which freezes nothing; not compared with HEAD" ) continue + if tag.startswith("v") and _version_kind(tag) is None: + # Never skipped: a tag the gate cannot classify is checked as before. + print(f"{tag}: names no version this gate can classify; checked as before") # The data function type snapshots do not belong to a data context. problems.extend(check_type_snapshots(args.repo, tag)) found = check_tag(args.repo, tag, version) diff --git a/tests/test_check_golden_tags.py b/tests/test_check_golden_tags.py index 7954cd1ba..da6a959d0 100644 --- a/tests/test_check_golden_tags.py +++ b/tests/test_check_golden_tags.py @@ -1119,3 +1119,130 @@ def test_a_pre_release_in_another_data_context_s_releases_is_refused( result = _gate(repo, "0.4.0rc1") assert result.returncode == 1 assert "pre-release 0.2.0b1 as a release of data context v0" in result.stderr + + +# --------------------------------------------------------------------------- +# Fail closed, and withdrawal in every data context (second Codex review of PR 470) +# --------------------------------------------------------------------------- + +# PEP 440 pre-releases the gate's parser does not accept: a local part, a release of two +# numbers, an epoch. +UNCLASSIFIABLE = ["0.4.0rc1+local", "0.4rc1", "1!0.4.0rc1"] +RECORD_FIELDS = ["releases", "withdrawn", "released_in", "history", "snapshot"] + + +def _withdrawn_record() -> dict[str, str]: + return { + "date": "2026-11-21", + "reason": "test", + "revision": "2" * 64, + "manifest": "3" * 64, + } + + +def _record(repo: Path, field: str, text: str) -> None: + """Write ``text`` into one release record field at HEAD, and commit.""" + if field in ("releases", "withdrawn"): + pins = store.read_json(store.pins_path(repo)) + value: Any = "5" * 64 if field == "releases" else _withdrawn_record() + pins[VERSION].setdefault(field, {})[text] = value + store.write_json(store.pins_path(repo), pins) + elif field == "released_in": + _set_released_in(repo, text) + elif field == "history": + path = store.manifest_path(repo, VERSION) + manifest = store.read_json(path) + history = manifest["golden"]["history"] + history.append( + { + "date": "2026-11-21", + "release": text, + "added": {}, + "previous": history[-1]["digest"], + "digest": "6" * 64, + } + ) + store.write_json(path, manifest) + else: + _ = _pin_snapshot(repo, text, '{"value": 1}\n') + _commit(repo, f"a release record {field} holding {text}") + + +@pytest.mark.parametrize("text", UNCLASSIFIABLE) +@pytest.mark.parametrize("field", RECORD_FIELDS) +@pytest.mark.parametrize("requested", ["0.4.0rc1", "0.3.0"], ids=["candidate", "final"]) +def test_a_release_record_the_gate_cannot_classify_is_refused( + repo: Path, field: str, text: str, requested: str +) -> None: + """A version text the parser cannot classify, in any release record field, fails + closed in a candidate run and in a final run: it is never read as final.""" + _record(repo, field, text) + result = _gate(repo, requested) + assert result.returncode == 1 + assert f"holds a version this gate cannot classify: {text!r}" in result.stderr + + +def test_a_tag_the_gate_cannot_classify_is_checked_as_before(repo: Path) -> None: + """A tag ``v`` + text the parser cannot classify is never skipped: a snapshot pinned + at it stays protected, and the output names the tag.""" + _ = _pin_snapshot(repo, "0.3.0", '{"value": 1}\n') + _commit(repo, "a snapshot pinned in 0.3.0") + _git(repo, "tag", "v0.4.0rc1+local") + first = _check(repo, ci=True) + assert first.returncode == 0, first.stderr + assert "v0.4.0rc1+local: names no version this gate can classify" in first.stdout + _ = _pin_snapshot(repo, None, '{"value": 2}\n') + _commit(repo, "the snapshot changes") + result = _check(repo, ci=True) + assert result.returncode == 1 + assert "v0.4.0rc1+local: data function type snapshot" in result.stderr + + +@pytest.mark.parametrize("spelling", ["0.4.0rc1", "0.4.0-rc.1"]) +def test_a_candidate_withdrawn_in_another_data_context_is_refused( + repo: Path, spelling: str +) -> None: + """The reviewer's first reproduction: the requested candidate withdrawn under + another data context is never released again.""" + pins = store.read_json(store.pins_path(repo)) + pins["v0"] = {"manifest": None, "releases": {}, "withdrawn": {}} + store.write_json(store.pins_path(repo), pins) + _commit(repo, "another data context") + assert _gate(repo, "0.4.0rc1").returncode == 0 + pins["v0"]["withdrawn"][spelling] = _withdrawn_record() + store.write_json(store.pins_path(repo), pins) + _commit(repo, "the candidate withdrawn under another context") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert "release 0.4.0rc1 of data context v0 was withdrawn" in result.stderr + + +def test_a_final_withdrawn_in_another_data_context_is_refused(repo: Path) -> None: + """A final version withdrawn under another data context is refused too.""" + assert _gate(repo, "0.3.0").returncode == 0 + pins = store.read_json(store.pins_path(repo)) + pins["v0"] = { + "manifest": None, + "releases": {}, + "withdrawn": {"0.3.0": _withdrawn_record()}, + } + store.write_json(store.pins_path(repo), pins) + _commit(repo, "0.3.0 withdrawn under another context") + result = _gate(repo, "0.3.0") + assert result.returncode == 1 + assert "release 0.3.0 of data context v0 was withdrawn" in result.stderr + + +def test_any_withdrawn_pre_release_is_refused(repo: Path) -> None: + """The reviewer's second reproduction: a pre-release has no release record of any + kind, so an unrelated withdrawn pre-release is refused like one in ``releases``.""" + pins = store.read_json(store.pins_path(repo)) + pins[VERSION].setdefault("withdrawn", {})["0.3.1b1"] = _withdrawn_record() + store.write_json(store.pins_path(repo), pins) + _commit(repo, "an unrelated withdrawn pre-release") + result = _gate(repo, "0.4.0rc1") + assert result.returncode == 1 + assert ( + f"HEAD records pre-release 0.3.1b1 as withdrawn in data context {VERSION}" + in (result.stderr) + )