Open-source skills for designing and reviewing software with AI agents
Python agent-skillsai-agentsantigravityclaude-codeclaude-code-pluginclaude-skillscodexcodex-plugincoding-agentscontext-engineeringdeveloper-toolsgeminillmmulti-agentprompt-engineeringspec-driven-development
refactor(releases): clarify validation and function contracts
Oliver66af316f9fa4
diff --git a/scripts/prepare_release.py b/scripts/prepare_release.pyindex 1d8618c..439648a 100644--- a/scripts/prepare_release.py+++ b/scripts/prepare_release.py@@ -11,7 +11,18 @@ from pack_plugin import builddef version_for_tag(root: Path, tag: str) -> str:- """Require a normal vMAJOR.MINOR.PATCH tag matching every shipped manifest."""+ """Returns the tag version after validating all shipped manifests.++ Args:+ root: Repository root containing the portable and host manifests.+ tag: Release tag in vMAJOR.MINOR.PATCH format, without leading zeroes.++ Returns:+ The version without the leading v.++ Raises:+ ValueError: The tag is invalid or a manifest version does not match it.+ """if not re.fullmatch(r"v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)", tag):raise ValueError("Tag must be vMAJOR.MINOR.PATCH without leading zeroes")version = tag[1:]@@ -24,9 +35,22 @@ def version_for_tag(root: Path, tag: str) -> str:def prepare(root: Path, tag: str, output: Path, commit: str) -> None:- """Build into a new directory; never overwrite a previous candidate."""+ """Builds runtime archives, checksums, and draft notes in a new directory.++ Args:+ root: Repository root containing the runtime sources and manifests.+ tag: Release tag matching every shipped manifest version.+ output: New destination directory; an existing candidate is never replaced.+ commit: Caller-declared source identity as 40 lowercase hexadecimal digits.+ This function does not verify that it identifies the source checkout.++ Raises:+ ValueError: The tag, manifest versions, commit, or runtime inputs are invalid.+ FileExistsError: The destination already exists.+ OSError: Reading sources, building archives, or writing output fails.+ """version = version_for_tag(root, tag)- if not re.fullmatch(r"[0-9a-f]{40}", commit):+ if len(commit) != 40 or any(char not in "0123456789abcdef" for char in commit):raise ValueError("Source commit must be a full Git SHA")output.mkdir(parents=True, exist_ok=False)checksums = []diff --git a/tests/unit/test_releases.py b/tests/unit/test_releases.pyindex 204d486..d55d4bb 100644--- a/tests/unit/test_releases.py+++ b/tests/unit/test_releases.py@@ -62,9 +62,13 @@ def test_prepare_exact_archives(release: dict, tmp_path: Path) -> None:release["prepare"](ROOT, f"v{version}", destination, commit)-def test_reject_invalid_commit_without_writing(release: dict, tmp_path: Path) -> None:[email protected]("commit", ["HEAD", "a" * 39, "a" * 41, "A" * 40,+ "g" * 40, "a" * 39 + "\n", "1" * 40])+def test_reject_invalid_commit_without_writing(+ release: dict, tmp_path: Path, commit: str,+) -> None:version = json.loads((ROOT / "plugin.json").read_text())["version"]destination = tmp_path / "release"with pytest.raises(ValueError, match="Git SHA"):- release["prepare"](ROOT, f"v{version}", destination, "HEAD")+ release["prepare"](ROOT, f"v{version}", destination, commit)assert not destination.exists()