You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(hooks): pin the pre-push interpreter fallback (floor-only when pytest is unavailable) #21351
The pre-push hook's interpreter resolution gained a fallback in PR #21278 (review at head 1b37fae10d): it first asks the shared resolver for an interpreter that can import pytest and, when none qualifies, accepts any interpreter that meets the .python-version floor. No test pins this behaviour, and the comment block above the resolution in tools/git-hooks/pre-push still describes the earlier "must import pytest" contract in places.
The fallback was added after six tests in repo_tests/pre_push_no_open_pr_cap_19397_test.py failed on a merge train: they run the hook in a sandbox whose python3 meets the floor but has no pytest.
Acceptance criteria
A test runs the hook with an interpreter that meets the floor but cannot import pytest, on a push that selects no tests, and asserts the push proceeds.
A test runs the hook with no interpreter meeting the floor and asserts the push is blocked with a message naming the required version.
A test asserts that a push which does select tests is blocked (not silently passed) when pytest cannot be imported, unless the documented unrunnable-override variable is set.
The comment above the resolution block in tools/git-hooks/pre-push describes the preferred-then-floor behaviour.
Source
Non-blocking findings of the independent review on PR #21278. Parent: #21163.
Addition from the second independent review of PR #21278 (head 17bc23ce6e), same theme — tests that cannot tell "the rule fired" from "the interpreter was not found":
pipeline-scripts/check-pre-commit-hook-pr_hook_ext_test.py asserts only returncode == 1. It passed for the wrong reason before (the resolver failed, not the rule). It should also assert that the resolver's "no Python" message is absent from stderr, so a resolver failure can never satisfy it again.
Context: that review also found three negative gate tests in repo_tests/doc_index_worktree_contamination_16934_test.py had been passing vacuously because the fixture's copied hook never reached its gates; the fixture is corrected in #21278.
Two further non-blocking findings on the hook interpreter guard repo_tests/hook_interpreter_resolver_21163_test.py, from review of the merge train carrying PR #21278:
Detect a quoted executable: exec "python3" -m tools.lint.check_x resolves python3 on PATH, but _QUOTED strips "python3" before _BARE runs (_code_of_line, ~L74-80), so bare_invocations misses it. Add a positive control while keeping quoted messages exempt.
Reach for interpreter-prefixed language: system entries: hook_scripts() (~L129) uses e.split()[0], which is bash for bash autobot-infrastructure/shared/tests/test_ssot_config_lib.sh, so that script (outside the hook directories) is never inspected. Resolve the script operand and add a reach control. Today that script has no bare python/pytest invocation.
repo_tests/hook_interpreter_resolver_21163_test.py_code / _SHELL_C: the bash -c body is extracted from the raw line, so echo ok # bash -c 'python3 -V' (comment) or a quoted message containing bash -c ... is judged as an invocation (false positive). Extract -c bodies only from executable text and add a negative control next to the positive one. (review thread on PR chore(merge-train): #21275 #21278 #21232 #21203 #21335)
same file, _code_of_line / _QUOTED: Bash ANSI-C strings ($'label\'#') are not consumed as a unit, so echo $'a\'#' && python3 x.py has its tail dropped as a comment and bare_invocations misses python3 (false negative). Consume the full $'...' string with escapes before comment stripping and add a control for it. (review thread on PR chore(merge-train): #21275 #21278 #21232 #21203 #21335)
Activity
mrveiss commentedon Nov 12, 2026
Addition from the second independent review of PR #21278 (head
17bc23ce6e), same theme — tests that cannot tell "the rule fired" from "the interpreter was not found":pipeline-scripts/check-pre-commit-hook-pr_hook_ext_test.pyasserts onlyreturncode == 1. It passed for the wrong reason before (the resolver failed, not the rule). It should also assert that the resolver's "no Python" message is absent from stderr, so a resolver failure can never satisfy it again.Context: that review also found three negative gate tests in
repo_tests/doc_index_worktree_contamination_16934_test.pyhad been passing vacuously because the fixture's copied hook never reached its gates; the fixture is corrected in #21278.mrveiss commentedon Nov 12, 2026
Two further non-blocking findings on the hook interpreter guard
repo_tests/hook_interpreter_resolver_21163_test.py, from review of the merge train carrying PR #21278:exec "python3" -m tools.lint.check_xresolvespython3on PATH, but_QUOTEDstrips"python3"before_BAREruns (_code_of_line, ~L74-80), sobare_invocationsmisses it. Add a positive control while keeping quoted messages exempt.language: systementries:hook_scripts()(~L129) usese.split()[0], which isbashforbash autobot-infrastructure/shared/tests/test_ssot_config_lib.sh, so that script (outside the hook directories) is never inspected. Resolve the script operand and add a reach control. Today that script has no bare python/pytest invocation.mrveiss commentedon Nov 12, 2026
repo_tests/hook_interpreter_resolver_21163_test.py_code/_SHELL_C: thebash -cbody is extracted from the raw line, soecho ok # bash -c 'python3 -V'(comment) or a quoted message containingbash -c ...is judged as an invocation (false positive). Extract-cbodies only from executable text and add a negative control next to the positive one. (review thread on PR chore(merge-train): #21275 #21278 #21232 #21203 #21335)_code_of_line/_QUOTED: Bash ANSI-C strings ($'label\'#') are not consumed as a unit, soecho $'a\'#' && python3 x.pyhas its tail dropped as a comment andbare_invocationsmissespython3(false negative). Consume the full$'...'string with escapes before comment stripping and add a control for it. (review thread on PR chore(merge-train): #21275 #21278 #21232 #21203 #21335)