From 16fd94558342c55da748bba65b69dc05afdf1886 Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Sun, 1 Nov 2026 10:06:28 -0600 Subject: [PATCH] ci(scripts): run update-nixpkgs-inputs contract tests in CI + cover the 127 fallback (#603) --- .github/workflows/scripts-test.yml | 47 +++++++++++++++++++++ scripts/tests/test_update_nixpkgs_inputs.py | 30 ++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/scripts-test.yml diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.yml new file mode 100644 index 0000000000..7a7799bad9 --- /dev/null +++ b/.github/workflows/scripts-test.yml @@ -0,0 +1,47 @@ +name: scripts-test + +on: + push: + branches: [main] + paths: + - "scripts/update-nixpkgs-inputs.py" + - "scripts/update-nixpkgs-inputs.sh" + - "pkgs/id/scripts/update-nixpkgs-inputs.py" + - "pkgs/id/scripts/update-nixpkgs-inputs.sh" + - "scripts/tests/test_update_nixpkgs_inputs.py" + - ".github/workflows/scripts-test.yml" + pull_request: + paths: + - "scripts/update-nixpkgs-inputs.py" + - "scripts/update-nixpkgs-inputs.sh" + - "pkgs/id/scripts/update-nixpkgs-inputs.py" + - "pkgs/id/scripts/update-nixpkgs-inputs.sh" + - "scripts/tests/test_update_nixpkgs_inputs.py" + - ".github/workflows/scripts-test.yml" + +permissions: + contents: read + +# Same concurrency contract as research-workflow.yml: push-to-main runs +# are keyed by run_id so every merged tree gets its own completed run; +# pull-request runs share a per-ref group so a new push supersedes the +# stale one. +concurrency: + group: scripts-test-${{ github.event_name == 'push' && github.run_id || github.ref }} + cancel-in-progress: true + +jobs: + update-nixpkgs-inputs-contract: + name: "basic: scripts-test (${{ matrix.python-version }})" + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + matrix: + python-version: ["3.12", "3.14"] + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 + with: + python-version: ${{ matrix.python-version }} + - name: Run update-nixpkgs-inputs contract tests (#603) + run: python3 -m unittest discover -s scripts/tests -p 'test_update_nixpkgs_inputs.py' -v diff --git a/scripts/tests/test_update_nixpkgs_inputs.py b/scripts/tests/test_update_nixpkgs_inputs.py index c941285873..75bca18be7 100644 --- a/scripts/tests/test_update_nixpkgs_inputs.py +++ b/scripts/tests/test_update_nixpkgs_inputs.py @@ -88,9 +88,12 @@ class ScriptTree: with a stub `nix` (and a stub `uv`, so the .py shebang executes the body under python3) on PATH. The stub nix appends one line to a counter file per invocation and exits with the configured status. + With `interpreter_missing=True` there is no uv stub and no uv on + PATH, so direct execution fails 127, and a python3 shim pointing at + the running interpreter serves the wrapper's fallback. """ - def __init__(self, src_dir: Path, nix_status: int): + def __init__(self, src_dir: Path, nix_status: int, interpreter_missing: bool = False): self._tmp = tempfile.TemporaryDirectory() base = Path(self._tmp.name) self.repo_dir = base / "repo" @@ -108,6 +111,19 @@ def __init__(self, src_dir: Path, nix_status: int): f'echo call >> "{self.counter}"\n' f"exit {nix_status}\n", ) + if interpreter_missing: + # No uv stub and a PATH with no uv on it: the .py shebang + # (`env -S uv run --script`) cannot find its interpreter, so + # the wrapper's direct-execution attempt exits 127. The + # python3 shim keeps the wrapper's fallback interpreter + # hermetic — a host python3 may live outside /usr/bin:/bin + # (e.g. on NixOS) and must not leak into the 127 setup. + _write_executable( + self.bin / "python3", + f'#!/bin/sh\nexec {sys.executable} "$@"\n', + ) + self.env = dict(os.environ, PATH=f"{self.bin}:/usr/bin:/bin") + return # The .py shebang is `env -S uv run --script`; this stub makes # the wrapper's direct-execution attempt run the body under # python3, so wrapper behaviour is testable without uv. @@ -208,6 +224,18 @@ def _check_copy(self, label: str, src_dir: Path): self.assertEqual(tree.nix_calls(), 1) finally: tree.cleanup() + with self.subTest(copy=label, case="missing interpreter (127) falls back to python3"): + tree = ScriptTree(src_dir, nix_status=1, interpreter_missing=True) + try: + # uv absent: the shebang interpreter cannot be found, so + # direct execution fails 127 — the other cannot-execute + # exit. Same contract as 126: fall back to python3 + # exactly once and propagate the genuine failure status. + r = tree.run_sh() + self.assertEqual(r.returncode, 1, r.stdout + r.stderr) + self.assertEqual(tree.nix_calls(), 1) + finally: + tree.cleanup() def test_root_copy(self): self._check_copy("root", COPIES["root"])