Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/scripts-test.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 29 additions & 1 deletion scripts/tests/test_update_nixpkgs_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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"])
Expand Down
Loading