From 36c16761824ee751721fd7d76c263980407f4c5f Mon Sep 17 00:00:00 2001 From: Mateusz Lewandowski Date: Tue, 20 Oct 2026 08:58:58 +0200 Subject: [PATCH 1/3] fix: validate context token budgets before dispatch --- CHANGELOG.md | 3 ++ src/ai_dev_tools/cli.py | 10 ++++++ tests/integration/test_token_budget_cli.py | 41 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/integration/test_token_budget_cli.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 200eea9..cb7351f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Fix #110: Reject invalid context token budgets with a concise usage error and + exit code 2, including supported categories, before generating artifacts. + - Fix #98: Detect tool versions using the resolved executable path, preserving subcommand arguments and avoiding mismatched Python versions on Windows. - Fix #99: Preserve measured per-check durations in reports instead of replacing diff --git a/src/ai_dev_tools/cli.py b/src/ai_dev_tools/cli.py index 4ccedca..8b9134d 100644 --- a/src/ai_dev_tools/cli.py +++ b/src/ai_dev_tools/cli.py @@ -379,6 +379,16 @@ def main(argv: list[str] | None = None) -> int: command_started = time.monotonic() parser = build_parser() args = parser.parse_args(_normalize_global_flags(argv)) + if args.command == "context" and args.context_command == "build": + from ai_dev_tools.context.tokens import CATEGORIES, parse_token_budgets + + try: + parse_token_budgets(tuple(args.token_budget)) + except ValueError as exc: + parser.error( + f"--token-budget: {exc}; expected category=N with a non-negative integer " + f"and no repeated categories; allowed categories: {', '.join(CATEGORIES)}" + ) project_root = args.project.resolve() startup_seconds = time.monotonic() - command_started if args.command == "mcp" and args.mcp_command == "serve": diff --git a/tests/integration/test_token_budget_cli.py b/tests/integration/test_token_budget_cli.py new file mode 100644 index 0000000..1d5fcc8 --- /dev/null +++ b/tests/integration/test_token_budget_cli.py @@ -0,0 +1,41 @@ +import os +import subprocess +import sys +from pathlib import Path + +import pytest + + +@pytest.mark.parametrize( + "budgets", + [ + ["6000"], + ["unknown=1"], + ["source=abc"], + ["source=-1"], + ["source=1", "source=2"], + ], +) +@pytest.mark.parametrize("json_output", [False, True]) +def test_invalid_token_budget_is_usage_error( + tmp_path: Path, budgets: list[str], json_output: bool +) -> None: + command = [ + sys.executable, "-m", "ai_dev_tools.cli", + "--project", str(tmp_path), "context", "build", + ] + for budget in budgets: + command.extend(["--token-budget", budget]) + if json_output: + command.append("--json") + result = subprocess.run( + command, capture_output=True, text=True, check=False, + env={**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[2] / "src")}, + ) + assert result.returncode == 2 + assert "--token-budget" in result.stderr + assert "category=N" in result.stderr + assert "allowed categories: source, diffs, tests, logs, maps, history" in result.stderr + assert "Traceback" not in result.stderr + assert not result.stdout + assert not (tmp_path / ".ai").exists() From a4ef7598c4b141e3d18024eac02d98e04b9cb112 Mon Sep 17 00:00:00 2001 From: Mateusz Lewandowski Date: Tue, 20 Oct 2026 09:05:56 +0200 Subject: [PATCH 2/3] fix: verify packaged check durations and prepare 1.3.1 --- CHANGELOG.md | 6 +++++ pyproject.toml | 2 +- scripts/test_installed_package.py | 37 ++++++++++++++++++++++++++++++- src/ai_dev_tools/__init__.py | 2 +- tests/unit/test_report.py | 2 +- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7351f..0d50a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 1.3.1 - 2026-10-20 + +- Fix #111: Ship the measured check-duration correction missing from 1.3.0 and + verify a real non-cached Ruff invocation through the installed release wheel. +- Include untracked source files in context and restore strict typing (#109). + - Fix #110: Reject invalid context token budgets with a concise usage error and exit code 2, including supported categories, before generating artifacts. diff --git a/pyproject.toml b/pyproject.toml index 27479ca..67f4d34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "ai-dev-cli-tools" -version = "1.3.0" +version = "1.3.1" description = "Cross-platform CLI helpers that give AI coding agents concise, deterministic development reports." readme = "README.md" requires-python = ">=3.11" diff --git a/scripts/test_installed_package.py b/scripts/test_installed_package.py index 144d3e4..a93565f 100644 --- a/scripts/test_installed_package.py +++ b/scripts/test_installed_package.py @@ -121,6 +121,39 @@ def _smoke_entrypoint(entrypoint: Path, cwd: Path) -> None: mcp_response = json.loads(mcp_result.stdout) if mcp_response.get("result", {}).get("serverInfo", {}).get("name") != "ai-dev-cli-tools": raise SmokeError("installed MCP entrypoint did not initialize") + _smoke_check_duration(entrypoint, cwd) + + +def _smoke_check_duration(entrypoint: Path, cwd: Path) -> None: + # Run real Ruff from the development environment through the installed wheel. + # The wheel's venv remains independent and contains no editable source install. + (cwd / "sample.py").write_text("value = 1\n", encoding="utf-8") + (cwd / ".ai-dev-tools.toml").write_text( + '[commands]\nlint = "python -m ruff check sample.py"\n', encoding="utf-8" + ) + result = _run( + [str(entrypoint), "--json", "check", "--mode", "fast", "--no-cache"], cwd, + env={ + **os.environ, + "PATH": str(Path(sys.executable).parent) + os.pathsep + os.environ.get("PATH", ""), + }, + ) + _assert_report_json(result.stdout, "check") + payload = json.loads(result.stdout) + checks = payload["summary"]["results"] + if len(checks) != 1: + raise SmokeError(f"expected one installed Ruff check, found {len(checks)}") + check = checks[0] + duration = check.get("duration_seconds", 0) + if check.get("cached") is not False or duration <= 0: + raise SmokeError("installed non-cached Ruff check lost measured subprocess duration") + aggregate = payload["summary"]["execution"]["aggregate_subprocess_seconds"] + if duration != aggregate: + raise SmokeError("installed per-check duration differs from subprocess aggregate") + saved = json.loads((cwd / ".ai/reports/check-fast-latest.json").read_text(encoding="utf-8")) + if saved["summary"]["results"][0]["duration_seconds"] != duration: + raise SmokeError("saved report lost installed check duration") + print(f"Installed Ruff duration verified: {duration}s") def _assert_report_json(output: str, command: str) -> None: @@ -137,7 +170,8 @@ def _assert_report_json(output: str, command: str) -> None: def _run( - command: list[str], cwd: Path, *, input_text: str | None = None + command: list[str], cwd: Path, *, input_text: str | None = None, + env: dict[str, str] | None = None, ) -> subprocess.CompletedProcess[str]: result = subprocess.run( command, @@ -147,6 +181,7 @@ def _run( errors="replace", capture_output=True, input=input_text, + env=env, shell=False, timeout=180, ) diff --git a/src/ai_dev_tools/__init__.py b/src/ai_dev_tools/__init__.py index 07b1de0..9ee8e51 100644 --- a/src/ai_dev_tools/__init__.py +++ b/src/ai_dev_tools/__init__.py @@ -1,3 +1,3 @@ """AI Dev CLI Tools.""" -__version__ = "1.3.0" +__version__ = "1.3.1" diff --git a/tests/unit/test_report.py b/tests/unit/test_report.py index 356f51c..20e0935 100644 --- a/tests/unit/test_report.py +++ b/tests/unit/test_report.py @@ -11,7 +11,7 @@ def test_report_schema_contains_required_fields(tmp_path: Path) -> None: ).finish() data = report.to_dict() assert data["schema_version"] == "1.1" - assert data["tool_version"] == "1.3.0" + assert data["tool_version"] == "1.3.1" assert data["status"] == "success" assert data["command"] == "scan" assert data["summary"] == {} From a62837496154e488fb49d63bdc097d9cfc4a2d1b Mon Sep 17 00:00:00 2001 From: Mateusz Lewandowski Date: Tue, 20 Oct 2026 09:08:47 +0200 Subject: [PATCH 3/3] ci: install pinned Ruff for release artifact regression check --- .github/workflows/release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 35d7d80..abf53f7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,9 @@ jobs: - name: Validate tag and source version run: python scripts/validate_release.py --tag "$GITHUB_REF_NAME" - name: Install release tooling - run: python -m pip install --upgrade build twine + run: | + python -m pip install --upgrade build twine + python -m pip install -c requirements-dev.lock ruff - name: Build wheel and source distribution run: python -m build - name: Validate distributions