From ac33a5ac9980569adeee2506c7d81ee2f22f83cc Mon Sep 17 00:00:00 2001 From: Mateusz Lewandowski Date: Thu, 29 Oct 2026 10:52:39 +0100 Subject: [PATCH] fix: preserve configured check execution and diagnostics --- CHANGELOG.md | 5 ++ src/ai_dev_tools/parsers/logs.py | 9 +- src/ai_dev_tools/utils/subprocess.py | 3 +- .../test_check_diagnostics_regressions.py | 84 +++++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_check_diagnostics_regressions.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d50a04..af7924b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +- Fix #125: Ignore zero-error summaries when selecting failure diagnostics while + preserving actual errors, including those printed by successful commands. +- Fix #126: Execute the PATH-resolved Windows executable for configured checks, + including cancellable checks, instead of relying on CreateProcess search order. + ## 1.3.1 - 2026-10-20 - Fix #111: Ship the measured check-duration correction missing from 1.3.0 and diff --git a/src/ai_dev_tools/parsers/logs.py b/src/ai_dev_tools/parsers/logs.py index bda9be4..ee90ec1 100644 --- a/src/ai_dev_tools/parsers/logs.py +++ b/src/ai_dev_tools/parsers/logs.py @@ -13,6 +13,7 @@ from ai_dev_tools.utils.subprocess import CommandResult ERROR_MARKERS = ("error", "failed", "failure", "traceback", "assertionerror", "exception") +ZERO_ERROR_SUMMARY_PATTERN = re.compile(r"\berrors?\s*:\s*0\b(?!\.\d)", re.IGNORECASE) ANSI_PATTERN = re.compile(r"\x1b\[[0-9;?]*[ -/]*[@-~]") PROGRESS_PATTERN = re.compile(r"\r[^\n]*") WARNING_PATTERN = re.compile(r"\bwarning\b", re.IGNORECASE) @@ -367,7 +368,13 @@ def _parsed_from_output( def _summary_parts(output: str) -> dict[str, object]: lines = [line.strip() for line in clean_output(output).splitlines() if line.strip()] grouped = Counter(lines) - errors = [line for line in lines if any(marker in line.lower() for marker in ERROR_MARKERS)] + errors = [ + line + for line in lines + if any( + marker in ZERO_ERROR_SUMMARY_PATTERN.sub("", line).lower() for marker in ERROR_MARKERS + ) + ] frames = _project_frames("\n".join(lines)) test_counts = parse_test_counts(output) tests_total = sum(test_counts.values()) diff --git a/src/ai_dev_tools/utils/subprocess.py b/src/ai_dev_tools/utils/subprocess.py index 32b5340..a44f977 100644 --- a/src/ai_dev_tools/utils/subprocess.py +++ b/src/ai_dev_tools/utils/subprocess.py @@ -155,4 +155,5 @@ def _windows_batch_command(command: list[str]) -> list[str]: comspec = os.environ.get("COMSPEC", "cmd.exe") executable_command = [resolved, *command[1:]] return [comspec, "/d", "/c", *executable_command] - return command + # CreateProcess may search the parent interpreter's directory before PATH. + return [resolved, *command[1:]] diff --git a/tests/unit/test_check_diagnostics_regressions.py b/tests/unit/test_check_diagnostics_regressions.py new file mode 100644 index 0000000..e65bf83 --- /dev/null +++ b/tests/unit/test_check_diagnostics_regressions.py @@ -0,0 +1,84 @@ +import os +import shutil +import subprocess +import sys +import venv +from pathlib import Path +from threading import Event + +import pytest + +from ai_dev_tools.parsers.logs import parse_tool_output +from ai_dev_tools.runners.check import run_check +from ai_dev_tools.utils.subprocess import _resolve_executable, run_command + + +@pytest.mark.parametrize( + "output", + [ + "Errors: 0", + "Documentation errors: 0. External URLs and heading anchors not checked.", + "ERRORS: 0\nEverything checked", + ], +) +def test_zero_error_summary_has_no_failure(output: str) -> None: + result = parse_tool_output("python check.py", output) + assert result["status"] == "success" + assert result["first_failure"] is None + assert result["first_failure_reason"] is None + + +@pytest.mark.parametrize( + "output", + [ + "Errors: 1", + "Errors: 01", + "Errors: 0.5", + "Errors: 0; validation failed", + "Errors: 0\nException: broken", + "Errors: 0x10", + "Errors: 0unknown", + ], +) +@pytest.mark.parametrize("exit_code", [0, 1]) +def test_real_diagnostics_are_retained(output: str, exit_code: int) -> None: + result = parse_tool_output("python check.py", output, exit_code) + assert result["first_failure"] is not None + assert result["first_failure_reason"] is not None + + +def test_configured_check_zero_errors(tmp_path: Path) -> None: + (tmp_path / ".ai-dev-tools.toml").write_text( + "[commands]\nlint = 'python check.py'\n", encoding="utf-8" + ) + (tmp_path / "check.py").write_text("print('Errors: 0')\n", encoding="utf-8") + report = run_check(tmp_path, "full", use_cache=False) + assert report.status == "success" + result = report.summary["results"][0] + assert result["exit_code"] == 0 + assert result["first_failure"] is None + assert result["first_failure_reason"] is None + + +@pytest.mark.skipif(sys.platform != "win32", reason="Windows executable search order") +@pytest.mark.parametrize("cancellable", [False, True]) +def test_windows_executes_path_selected_python( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, cancellable: bool +) -> None: + environment = tmp_path / "selected environment" + venv.EnvBuilder(with_pip=False).create(environment) + monkeypatch.setenv("PATH", str(environment / "Scripts") + os.pathsep + os.environ["PATH"]) + resolved = shutil.which("python") + assert resolved is not None + probe = ["-c", "import sys; print(sys.executable)"] + expected = subprocess.check_output([resolved, *probe], text=True).strip() + _resolve_executable.cache_clear() + try: + result = run_command( + ["python", *probe], tmp_path, cancel_event=Event() if cancellable else None + ) + assert result.exit_code == 0 + assert result.stdout.strip() == expected + assert result.command == ["python", *probe] + finally: + _resolve_executable.cache_clear()