diff --git a/.github/workflows/release-note-tests.yml b/.github/workflows/release-note-tests.yml index 81ca0689..f7e81b5f 100644 --- a/.github/workflows/release-note-tests.yml +++ b/.github/workflows/release-note-tests.yml @@ -5,6 +5,8 @@ on: paths: - 'scripts/append-patch-note.py' - 'scripts/test_append_patch_note.py' + - 'scripts/regen-release-notes.py' + - 'scripts/test_release_install_pinning.py' - '.github/workflows/patch-release.yml' - '.github/workflows/release-note-tests.yml' workflow_dispatch: @@ -22,3 +24,9 @@ jobs: persist-credentials: false - name: Test patch-note insertion without GitHub calls run: python3 -B -m unittest discover -s scripts -p test_append_patch_note.py -v + - name: Require snippet runtimes + run: | + command -v bash + command -v pwsh + - name: Test release installer version arguments offline + run: python3 -B scripts/test_release_install_pinning.py -v diff --git a/scripts/regen-release-notes.py b/scripts/regen-release-notes.py index e480b8a1..1a075159 100644 --- a/scripts/regen-release-notes.py +++ b/scripts/regen-release-notes.py @@ -5,8 +5,7 @@ link to the previous tag. Run with no args from anywhere in the repo. Writes one body file per -tag to /tmp/release-notes/, then `gh release edit --notes-file` -for each. +tag to /tmp/release-notes/. This script does not publish to GitHub. Skips no tags; for the very first release (v0.0.1) the changelog is "all commits up to this tag" since there's no previous tag. @@ -24,7 +23,7 @@ from collections import defaultdict from pathlib import Path -# Repo root — script lives in /tmp, repo path is fixed here for clarity. +# Resolve the repository root from this script location. REPO = Path(__file__).resolve().parent.parent OUT = Path("/tmp/release-notes") OUT.mkdir(parents=True, exist_ok=True) @@ -151,12 +150,12 @@ def install_section(version_with_v: str) -> str: **One-line (Linux/macOS):** ```bash -curl -fsSL https://github.com/OpenCoven/coven-code/releases/download/{version_with_v}/install.sh | bash +curl -fsSL https://github.com/OpenCoven/coven-code/releases/download/{version_with_v}/install.sh | bash -s -- --version {bare} ``` **One-line (Windows PowerShell):** ```powershell -irm https://github.com/OpenCoven/coven-code/releases/download/{version_with_v}/install.ps1 | iex +& ([scriptblock]::Create((irm https://github.com/OpenCoven/coven-code/releases/download/{version_with_v}/install.ps1))) -Version {bare} ``` **npm:** diff --git a/scripts/test_release_install_pinning.py b/scripts/test_release_install_pinning.py new file mode 100644 index 00000000..9f5ae0f8 --- /dev/null +++ b/scripts/test_release_install_pinning.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""Execute generated install snippets with inert, offline installer responses.""" +import ast +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(__file__).with_name("regen-release-notes.py") + + +def install_section(tag): + # Importing the module creates /tmp/release-notes; execute only its real function. + tree = ast.parse(SCRIPT.read_text()) + function = next(node for node in tree.body + if isinstance(node, ast.FunctionDef) and node.name == "install_section") + namespace = {} + exec(compile(ast.Module(body=[function], type_ignores=[]), str(SCRIPT), "exec"), namespace) + return namespace["install_section"](tag) + + +class ReleaseInstallPinning(unittest.TestCase): + def test_bash_installer_receives_release_version(self): + bash = shutil.which("bash") + if not bash: + self.skipTest("bash unavailable") + for tag in ("v0.0.1", "v0.0.17"): + with self.subTest(tag=tag), tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + (root / "bash").symlink_to(bash) + curl = root / "curl" + curl.write_text('#!' + bash + '\n' + 'printf "%s\\n" "$@" > "$REQUEST_LOG"\n' + 'printf \'printf "ARG:<%%s>\\\\n" "$@"\\n\'\n') + curl.chmod(0o700) + snippet = re.findall(r"```bash\n(.*?)\n```", install_section(tag), re.S)[0] + result = subprocess.run([bash, "-c", snippet], text=True, capture_output=True, + timeout=10, env={"HOME": temporary, "PATH": temporary, + "REQUEST_LOG": str(root / "request")}) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual((root / "request").read_text().splitlines(), + ["-fsSL", f"https://github.com/OpenCoven/coven-code/releases/download/{tag}/install.sh"]) + self.assertEqual(result.stdout.splitlines(), ["ARG:<--version>", f"ARG:<{tag[1:]}>"]) + + def test_powershell_installer_receives_release_version(self): + pwsh = shutil.which("pwsh") + if not pwsh: + self.skipTest("pwsh unavailable") + for tag in ("v0.0.1", "v0.0.17"): + with self.subTest(tag=tag), tempfile.TemporaryDirectory() as temporary: + snippet = re.search(r"```powershell\n(.*?)\n```", install_section(tag), re.S)[1] + script = Path(temporary) / "fixture.ps1" + script.write_text('''$ErrorActionPreference = 'Stop' +Import-Module Microsoft.PowerShell.Utility -ErrorAction Stop +$PSModuleAutoLoadingPreference = 'None' +function Invoke-RestMethod { throw 'Unexpected real HTTP request' } +function Invoke-WebRequest { throw 'Unexpected real HTTP request' } +function Invoke-FixtureInstaller([string]$Uri) { + [IO.File]::WriteAllText($env:REQUEST_LOG, $Uri) + return 'param([string]$Version) Write-Output "VERSION:<$Version>"' +} +Set-Alias -Name irm -Value Invoke-FixtureInstaller -Scope Script -Force +if ((Get-Command irm).CommandType -ne 'Alias' -or + (Get-Command irm).Definition -ne 'Invoke-FixtureInstaller' -or + (Get-Command Invoke-FixtureInstaller).CommandType -ne 'Function') { + throw 'Offline installer mock resolution failed' +} +''' + snippet + '\n') + result = subprocess.run([pwsh, "-NoProfile", "-NonInteractive", "-File", str(script)], + text=True, capture_output=True, timeout=45, + env={"HOME": temporary, "PATH": temporary, + "REQUEST_LOG": str(Path(temporary) / "request")}) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual((Path(temporary) / "request").read_text(), + f"https://github.com/OpenCoven/coven-code/releases/download/{tag}/install.ps1") + self.assertEqual(result.stdout.splitlines(), [f"VERSION:<{tag[1:]}>"]) + + def test_existing_pinned_alternatives(self): + section = install_section("v0.0.17") + self.assertIn("npm install -g @opencoven/coven-code@0.0.17", section) + self.assertIn("coven-code upgrade --version 0.0.17", section) + self.assertIn("coven-code --version", section) + + +if __name__ == "__main__": + unittest.main()