mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-23 02:49:17 +08:00
## Description Merging release PR #4643 did not create `v0.43.0` because its body contained repeated carriage returns (`CRCRLF`). Release Please removes one CRLF layer and then looks for exact `---` delimiter lines; the leftover CR prevents release detection. The merge-triggered [run](https://github.com/headroomlabs-ai/headroom/actions/runs/42065983322) succeeded while logging `Pull request body did not match` and `could not parse pull request body as a release PR`, leaving #4643 labeled `autorelease: pending` and opening #4661 from the old release baseline. Normalize only the damaged envelope before Release Please reads pending merged releases. Eligibility requires a merged bot PR, a main base, a release-please main branch in this repository, the pending label, and repeated-CR damage. Ordinary CRLF, open PRs, human PRs, forks and unrelated historical bodies are untouched. The normalized body must still have a valid release-note envelope. JSON is sent through stdin, avoiding another Windows text-file conversion. The malformed body came from Windows text-mode maintainer tooling, not contributor runtime code. That local writer has separately been corrected to preserve LF. ## Type of Change - [x] Bug fix (release automation) ## Changes Made - Add a narrow, default-read-only body normalizer and tests. - Run it with the workflow's existing release credential before release detection. - Allowlist the checked-in helper in `.gitignore`. ## Testing - `pytest scripts/tests/test_normalize_release_pr_bodies.py tests/test_release_workflows.py -q`: **75 passed**. - Ruff 0.17.3 check/format and `git diff --check`: pass. - `actionlint .github/workflows/release-please.yml`: pass. - Regression tests demonstrate the old exact-delimiter parser fails on CRCRLF, then verify repaired delimiters, eligibility exclusions, dry-run no writes, JSON-stdin transport and workflow ordering. ## Real Behavior Proof - Environment: Windows, Python 3.12.13, gh CLI; current main `8d3e9e5ca`. - Exact command: `python scripts/normalize_release_pr_bodies.py --repo headroomlabs-ai/headroom` (default read-only). - Observed result: `Would normalize release PR #4643`, exit 0. Other historical pending PR formats were not edited. Current GitHub has no `v0.43.0` tag/release; the exact merge-triggered log identifies the failed body parse above. - Not tested: deliberately did not run `--apply`, repair the live body, create a tag/release, dispatch a release workflow, or publish packages. No hosted release recovery is claimed. ## Runtime Rollout Safety - Rollout-managed feature(s): none; trusted main release automation only. - Stable/default behavior changed: on the next normal main push after this fix merges, the workflow can normalize #4643's damaged body and let Release Please create its pending release. This is the intended recovery; review this effect before merging. - Disable/rollback: revert the normalization step. The helper defaults to read-only when invoked manually without `--apply`. - No package versions, notes, labels, tags or releases are directly changed by the helper; Release Please retains those responsibilities. ## Review Readiness - [ ] This PR is ready for human merge review (draft pending independent review/hosted checks). ## Additional Notes Do not manually remove repeated generated entries from #4661. Once 0.43.0 is recovered, release notes should be regenerated from that proper baseline. This PR does not perform that recovery or change generated `CHANGELOG.md` itself.
130 lines
4.4 KiB
Python
130 lines
4.4 KiB
Python
"""Regression coverage for Windows-corrupted release-please PR envelopes."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[1] / "normalize_release_pr_bodies.py"
|
|
|
|
|
|
def load_module():
|
|
spec = importlib.util.spec_from_file_location("normalize_release_pr_bodies", SCRIPT)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
BODY = ":robot: I have created a release *beep* *boop*\n\n---\n\n## [0.43.0](url)\n\n- fix\n\n---\n\nGenerated by Release Please.\n"
|
|
|
|
|
|
@pytest.mark.parametrize("ending", ["\n", "\r\n", "\r\r\n", "\r\r\r\n"])
|
|
def test_normalization_restores_exact_release_please_delimiters(ending):
|
|
module = load_module()
|
|
damaged = BODY.replace("\n", ending)
|
|
# This is release-please's splitBody normalization: an extra CR survives.
|
|
if ending.count("\r") > 1:
|
|
assert "---" not in damaged.strip().replace("\r\n", "\n").split("\n")
|
|
assert module.normalize_body(damaged) == BODY
|
|
|
|
|
|
def pending_release(**overrides):
|
|
pr = {
|
|
"number": 4643,
|
|
"merged_at": "2026-11-05T16:35:16Z",
|
|
"base": {"ref": "main"},
|
|
"head": {
|
|
"ref": "release-please--branches--main--components--headroom-ai",
|
|
"repo": {"full_name": "owner/repo"},
|
|
},
|
|
"user": {"type": "Bot"},
|
|
"labels": [{"name": "autorelease: pending"}],
|
|
"body": BODY.replace("\n", "\r\r\n"),
|
|
}
|
|
return {**pr, **overrides}
|
|
|
|
|
|
def test_dry_run_never_writes(monkeypatch):
|
|
module = load_module()
|
|
monkeypatch.setattr(
|
|
module, "github_json", lambda *args, **kwargs: pytest.fail("unexpected write")
|
|
)
|
|
assert module.repair_release("owner/repo", pending_release(), apply=False)
|
|
|
|
|
|
def test_api_write_uses_json_stdin_without_windows_text_file_roundtrip(monkeypatch):
|
|
module = load_module()
|
|
calls = []
|
|
|
|
def run(command, **kwargs):
|
|
calls.append((command, kwargs))
|
|
return SimpleNamespace(stdout="{}")
|
|
|
|
monkeypatch.setattr(module.subprocess, "run", run)
|
|
module.github_json("repos/owner/repo/pulls/4643", body=BODY)
|
|
command, kwargs = calls[0]
|
|
assert command[-4:] == ["--method", "PATCH", "--input", "-"]
|
|
assert module.json.loads(kwargs["input"])["body"] == BODY
|
|
|
|
|
|
def test_workflow_repairs_before_release_detection():
|
|
workflow = SCRIPT.parents[1] / ".github" / "workflows" / "release-please.yml"
|
|
source = workflow.read_text(encoding="utf-8")
|
|
assert source.index("python scripts/normalize_release_pr_bodies.py") < source.index(
|
|
"uses: googleapis/release-please-action"
|
|
)
|
|
assert '--repo "${{ github.repository }}" --apply' in source
|
|
|
|
|
|
def test_repairs_only_merged_pending_release_prs(monkeypatch):
|
|
module = load_module()
|
|
calls = []
|
|
monkeypatch.setattr(
|
|
module, "github_json", lambda endpoint, **kwargs: calls.append((endpoint, kwargs))
|
|
)
|
|
assert module.repair_release("owner/repo", pending_release())
|
|
assert calls == [("repos/owner/repo/pulls/4643", {"body": BODY})]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"overrides",
|
|
[
|
|
{"merged_at": None},
|
|
{"labels": [{"name": "autorelease: tagged"}]},
|
|
{"base": {"ref": "maintenance"}},
|
|
{"head": {"ref": "contributor-feature"}},
|
|
{"user": {"type": "User"}},
|
|
{
|
|
"head": {
|
|
"ref": "release-please--branches--main--components--headroom-ai",
|
|
"repo": {"full_name": "someone/fork"},
|
|
}
|
|
},
|
|
{"body": BODY},
|
|
{"body": BODY.replace("\n", "\r\n")},
|
|
],
|
|
)
|
|
def test_does_not_edit_unrelated_or_already_valid_prs(monkeypatch, overrides):
|
|
module = load_module()
|
|
monkeypatch.setattr(
|
|
module, "github_json", lambda *args, **kwargs: pytest.fail("unexpected write")
|
|
)
|
|
assert not module.repair_release("owner/repo", pending_release(**overrides))
|
|
|
|
|
|
def test_missing_release_envelope_fails_instead_of_silently_making_another_release(monkeypatch):
|
|
module = load_module()
|
|
monkeypatch.setattr(
|
|
module, "github_json", lambda *args, **kwargs: pytest.fail("unexpected write")
|
|
)
|
|
with pytest.raises(ValueError, match="4643.*release-please envelope"):
|
|
module.repair_release(
|
|
"owner/repo", pending_release(body="Oversized notes are elsewhere.\r\r\n")
|
|
)
|