diff --git a/benchmarks/aft-search/slice-descriptors/fix-release-retry-version-files.json b/benchmarks/aft-search/slice-descriptors/fix-release-retry-version-files.json new file mode 100644 index 0000000000..6891f114dd --- /dev/null +++ b/benchmarks/aft-search/slice-descriptors/fix-release-retry-version-files.json @@ -0,0 +1,13 @@ +{ + "slice_class": "non_ranking", + "targeted_mechanism": "none", + "kind": "harness", + "fixtures": [ + "scripts/lib/release_retry.py", + "scripts/lib/test_pr_landing.py" + ], + "slices": [ + "fix-release-retry-version-files" + ], + "note": "Release tooling only: the patch-retry check accepts a version bump in any crate or package manifest and lockfile, instead of a fixed path list that predates the crates added in 0.67. No product code changes." +} diff --git a/scripts/lib/release_retry.py b/scripts/lib/release_retry.py index dda8760b57..a6c874d238 100644 --- a/scripts/lib/release_retry.py +++ b/scripts/lib/release_retry.py @@ -19,14 +19,11 @@ from landing_policy import ROOT, git VERSION = re.compile(r"v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)") -VERSION_FILES = { - "bun.lock", "Cargo.lock", "crates/aft/Cargo.toml", - "crates/aft-tokenizer/Cargo.toml", "crates/secret-rules/Cargo.toml", - *(f"packages/{name}/package.json" for name in - ("aft-bridge", "aft-cli", "opencode-plugin", "pi-plugin")), - *(f"packages/npm/{name}/package.json" for name in - ("darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "win32-arm64", "win32-x64")), -} +# version-sync rewrites the version in every published crate and package +# manifest and in both lockfiles. Matching by file name instead of listing paths +# keeps a newly added crate or package from failing every retry; verify_lineage +# still proves that each such file changed only its version string. +VERSION_FILE_NAMES = {"Cargo.toml", "package.json", "Cargo.lock", "bun.lock"} @contextmanager @@ -129,7 +126,8 @@ def verify_lineage(oid: str, line: str, seen: set[str] | None = None) -> None: raise ValueError(f"retry head has not bumped {package} to {version}") notes_path = f".alfonso/release-notes/v{version}.md" changed = set(git("diff-tree", "--no-commit-id", "--name-only", "-r", oid).splitlines()) - if not changed <= VERSION_FILES | {notes_path} or notes_path not in changed: + if notes_path not in changed or any( + path != notes_path and Path(path).name not in VERSION_FILE_NAMES for path in changed): raise ValueError("retry bump changes files other than versions and notes") for path in changed - {notes_path}: before = git("show", f"{oid}^:{path}") diff --git a/scripts/lib/test_pr_landing.py b/scripts/lib/test_pr_landing.py index bc80684a7f..48817e4e32 100644 --- a/scripts/lib/test_pr_landing.py +++ b/scripts/lib/test_pr_landing.py @@ -382,6 +382,11 @@ def setUp(self) -> None: for path in pathlib.Path('packages').glob('*/package.json'): value = json.loads(path.read_text()); value['version'] = args[1] path.write_text(json.dumps(value)) + import re + for path in pathlib.Path('crates').glob('*/Cargo.toml'): + path.write_text(re.sub(r'(?m)^version = "[^"]*"', f'version = "{args[1]}"', path.read_text())) + if os.environ.get('PR_TEST_SYNC_EXTRA'): + pathlib.Path('fix-one').write_text('changed by the version bump\n') sys.exit(0) state = pathlib.Path(os.environ['PR_TEST_STATE']) head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip() @@ -1277,11 +1282,15 @@ def test_tag_commit_refuses_a_release_that_has_not_started(self) -> None: class ReleaseRetryTests(PRFixture): - def prepare_retry(self) -> list[str]: + def prepare_retry(self, extra_files: dict[str, str] | None = None) -> list[str]: self.git("checkout", "-q", "main") notes = self.repo / ".alfonso/release-notes/v1.0.0.md" notes.parent.mkdir(parents=True) notes.write_text("# v1.0.0\n\nOriginal approved notes for 1.0.0.\n") + for name, text in (extra_files or {}).items(): + path = self.repo / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text) workflows = self.repo / ".github/workflows" workflows.mkdir() (workflows / "tests.yml").write_text('on:\n push:\n branches:\n - main\n - "release/**"\n') @@ -1355,6 +1364,23 @@ def test_retry_accepts_a_commit_hook_trailer_on_the_bump(self) -> None: self.assertIn("Release-retry-from: v1.0.0", bump) self.assertIn("Co-authored-by: alfonso-aft ", bump) + def test_retry_accepts_a_version_bump_in_a_newly_added_crate(self) -> None: + # The bump rewrites the version in every crate manifest, including + # crates added after the retry check was written. + fixes = self.prepare_retry( + {"crates/aft-newcrate/Cargo.toml": '[package]\nname = "aft-newcrate"\nversion = "1.0.0"\n'}) + result = self.retry(fixes) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn('version = "1.0.1"', self.git("show", "v1.0.1:crates/aft-newcrate/Cargo.toml")) + + def test_retry_refuses_a_bump_that_changes_a_non_version_file(self) -> None: + fixes = self.prepare_retry() + self.env["PR_TEST_SYNC_EXTRA"] = "1" + result = self.retry(fixes) + self.assertNotEqual(result.returncode, 0) + self.assertIn("retry bump changes files other than versions and notes", result.stderr) + self.assertEqual(self.git("tag", "--list", "v1.0.1"), "") + def test_retry_refuses_fix_not_on_main(self) -> None: self.prepare_retry() self.git("checkout", "-qb", "unlanded")