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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/ai_dev_tools/parsers/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/ai_dev_tools/utils/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]]
84 changes: 84 additions & 0 deletions tests/unit/test_check_diagnostics_regressions.py
Original file line number Diff line number Diff line change
@@ -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()
Loading