Repository navigation
chore(lint): extract Python pre-commit gate table into tools/lint/precommit_gates.py - #1699
Conversation
There was a problem hiding this comment.
Code Review
This pull request consolidates several individual Python-based pre-commit checks into a single declarative runner script, tools/lint/precommit_gates.py, and updates the pre-commit hook configuration, Bazel build files, and documentation accordingly. It also introduces unit tests for the new runner. The review feedback suggests defining a REPO_ROOT constant and passing it as the working directory (cwd) to all command executions in precommit_gates.py to ensure the script runs reliably when invoked from subdirectories.
87be222 to
5c5fb1a
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces precommit_gates.py, a new declarative runner for Python-based pre-commit linting tasks, which consolidates and simplifies the existing logic in the .githooks/pre-commit script. The changes include updated Bazel build rules and comprehensive unit tests for the new runner. The reviewer provided actionable feedback to improve debuggability by ensuring that standard error output is displayed when git commands fail, along with a corresponding update to the unit tests to verify this behavior.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the pre-commit git hook by consolidating several individual Python-based lint checks (such as legacy imports, examples coverage, matrix contract, agent doc paths, file naming, and UI selector contract) into a single declarative runner script, tools/lint/precommit_gates.py. The pre-commit hook now calls this consolidated script instead of running each check individually. Additionally, Bazel build targets and comprehensive unit tests have been added for the new runner, and the tools documentation has been updated. There are no review comments to address, and I have no additional feedback to provide.
…commit_gates.py - Replace the six duplicated Python lint wrapper functions in `.githooks/pre-commit` with a declarative `PYTHON_GATES` table and CLI runner (`tools/lint/precommit_gates.py --mode fix|check`). - Add hermetic unit tests in `tools/lint/precommit_gates_test.py` and document the module in `tools/README.md`. TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
…EPO_ROOT Comment links: - #1699 (comment) - #1699 (comment) - #1699 (comment) TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
…line failure paths Comment links: - #1699 (comment) - #1699 (comment) TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
46bb9f2 to
67061d0
Compare
AntonTyb
left a comment
There was a problem hiding this comment.
Multi-Specialist Review Summary (Round 1 · 67061d061d)
- Convergence Verdict:
APPROVE_WITH_NON_BLOCKING_POLISH(S_1 = 1) - Inline Review Threads Opened:
0(Zero-ThreadAPPROVEpolicy:1non-blocking notes collapsed below so automated merge/Grain loops are not disrupted) - Scoped Human Review Lenses:
CONTROL_PLANE_CI_OR_LINTER_EDIT,INLINE_LINT_SUPPRESSION_ADDED
PR #1699 cleanly extracts the six standalone Python pre-commit gates from .githooks/pre-commit into a declarative PYTHON_GATES table and stdlib-only runner in tools/lint/precommit_gates.py, with matching Bazel targets (tools/lint/BUILD.bazel), unit tests (tools/lint/precommit_gates_test.py), documentation (tools/README.md), and all CI checks passing. All five prior gemini-code-assist review threads (REPO_ROOT resolution, cwd=REPO_ROOT propagation, and git diff --cached stderr logging/test assertion) are verified fixed at HEAD 67061d061d. Only one non-blocking Medium test-coverage suggestion remains: adding a mode="check" unit test case when baseline_path is configured to guard the ctx.mode != "fix" check in _update_baseline. Because the diff modifies the protected .githooks/pre-commit control-plane file (CONTROL_PLANE_CI_OR_LINTER_EDIT) and adds one # noqa: E402 suppression (INLINE_LINT_SUPPRESSION_ADDED), scoped human sign-off is required before merge.
Non-blocking polish & follow-up notes (1 items — no action required to merge)
C1 · [Medium · Non-Blocking] Add check-mode boundary test for baseline_path gates to verify --update-baseline is skipped (tools/lint/precommit_gates_test.py:117)
test_baseline_error_paths_and_unchanged and test_runs_and_updates_baseline_when_changed_in_fix_mode only exercise baseline_path with mode="fix", while test_records_failure_on_nonzero_script_exit uses mode="check" with baseline_path=None. As a result, the ctx.mode != "fix" guard in _update_baseline (tools/lint/precommit_gates.py:146) that prevents check mode from invoking --update-baseline or git add is untested.
Consider adding a check-mode case to verify exec_cmd is called only once when baseline_path is set:
ctx_check = gates.RunContext(mode="check")
with (
mock.patch.object(
gates, "exec_cmd", return_value=subprocess.CompletedProcess([], 0, "", "")
) as chk_exec,
mock.patch("sys.stdout", new_callable=io.StringIO),
):
gates.run_python_gate(ctx_check, gate)
self.assertFalse(ctx_check.failed)
chk_exec.assert_called_once()
Summary
Replace the six duplicated Python lint wrapper functions in
.githooks/pre-commitwith a declarativePYTHON_GATEStable and CLI runner intools/lint/precommit_gates.py, backed by hermetic unit tests intools/lint/precommit_gates_test.py.Motivation & Context
.githooks/pre-commitrepeated identicalXMC_BYPASS_VENV=1 python3 ...error-handling, mode-gating, and failure-reporting blocks across all six standalone Python lint checks. Moving those gates into a typed Python module eliminates copy-paste Bash boilerplate, enables standardunittest+ Bazel test coverage, and lays the shared git/execution primitives for the remaining pre-commit migration slices.Key Changes
tools/lint/precommit_gates.py: AddPythonGate,PYTHON_GATES,RunContext,exec_cmd(handlingOSErrorfail-closed with returncode127and stderr logging),git_staged_paths(printing git stderr before exiting1),staged_paths_match,_update_baseline(checking--update-baseline,git diff, andgit addreturn codes),run_python_gate, andmain()(--mode fix|check, settingXMC_BYPASS_VENV=1).tools/lint/precommit_gates_test.py&tools/lint/BUILD.bazel: Addprecommit_gates_libandprecommit_gates_testcoveringRunContext.fail, real-subprocess and missing-binaryexec_cmdbehavior, git diff error stderr propagation (--no-renames), fix-modeAM/Dtrigger skipping, baseline unchanged/failure/lowering paths, non-zero failure propagation, andmain()..githooks/pre-commit: Replacecheck_legacy_imports,check_examples_coverage,check_matrix_contract,check_agent_doc_paths,check_file_naming, andcheck_ui_selector_contractwithcheck_python_gatesinvokingtools/lint/precommit_gates.py --mode "${MODE}".tools/README.md: Documenttools/lint/precommit_gates.pyunder section 7 (tools/lint/).Assumptions
precommit_gates.pywithXMC_BYPASS_VENV=1and Python 3.11+ standard-library modules allows pre-commit hooks to execute before./tools/common/venvis provisioned — pre-commit is documented to bypass the Python venv wrapper — failing to stick to stdlib imports would break developers running hooks without an initialized virtualenv.Verification & Testing
ruff format --check,ruff check,mypy --config-file pyproject.toml,bazel test --test_output=errors //tools/lint:precommit_gates_test,./.githooks/pre-commit(fix mode on commit),python3 tools/analyze_diff_size.py --base-ref origin/main, and full./.githooks/pre-commit --check+bazel test //cmd/ui:ui_unit_tests+node --test .github/scripts/*.test.json top of the stack.precommit_gates_testand all 6 affected//tools/lint:*_testtargets passed on commit (214prod lines /234test lines,threshold_exceeded: false); full stack verification passed on the top branch.Related Issues / Bugs
N/A
TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c