diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a3e1b0..8e95384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `--strict` flag on `agentcost analyze`: log parse failures exit non-zero instead of being reported as zero usage (#83) ### Fixed +- `budget set --quiet` (and `-q`) now suppresses per-period budget output while still saving the configured thresholds (#188) - `ClaudeCodeParser`, `CodexParser`, `OpenCodeParser` and `HermesParser` no longer crash on UTF-16 or other non-UTF-8 logs: all five parsers now share one encoding-fallback reader, so one such file cannot abort a directory scan (#182) - BOM-less UTF-16 logs (`utf-16-le` / `utf-16-be`) are now decoded by the shared encoding-fallback reader instead of being read as NUL-filled UTF-8 and silently yielding zero usages (#185) - CI failure on Python 3.10 due to missing `tomllib` stdlib module (#26) diff --git a/src/agentcost/cli.py b/src/agentcost/cli.py index 6dcefd7..758eed9 100644 --- a/src/agentcost/cli.py +++ b/src/agentcost/cli.py @@ -616,12 +616,12 @@ def budget(action, daily, weekly, monthly, as_sarif, quiet=False): save_budget_config(daily, weekly, monthly) if not quiet: console.print("[green]Budget thresholds saved to ~/.agentcost/config.toml[/green]") - if daily: - console.print(f" Daily: ${daily:.2f}") - if weekly: - console.print(f" Weekly: ${weekly:.2f}") - if monthly: - console.print(f" Monthly: ${monthly:.2f}") + if daily: + console.print(f" Daily: ${daily:.2f}") + if weekly: + console.print(f" Weekly: ${weekly:.2f}") + if monthly: + console.print(f" Monthly: ${monthly:.2f}") elif action == "show": config = load_budget_config() if not config: diff --git a/tests/test_quiet_mode.py b/tests/test_quiet_mode.py index badca43..2753dfd 100644 --- a/tests/test_quiet_mode.py +++ b/tests/test_quiet_mode.py @@ -7,6 +7,7 @@ import pytest from agentcost.cli import cli +from agentcost.budget import load_budget_config @pytest.fixture @@ -106,3 +107,32 @@ def test_compare_quiet(sample_claude_log: Path): data = json.loads(result.output) assert isinstance(data, list) assert len(data) > 0 + + +@pytest.mark.parametrize("quiet_flag", ["--quiet", "-q"]) +@pytest.mark.parametrize("thresholds", [ + {"daily": 5.0}, + {"daily": 5.0, "weekly": 25.0, "monthly": 100.0}, +]) +def test_budget_set_quiet(tmp_path, monkeypatch, quiet_flag, thresholds): + monkeypatch.setattr("agentcost.budget.CONFIG_DIR", tmp_path) + monkeypatch.setattr("agentcost.budget.CONFIG_FILE", tmp_path / "config.toml") + monkeypatch.chdir(tmp_path) + runner = CliRunner() + args = ["budget", "set"] + for period, amount in thresholds.items(): + args.extend([f"--{period}", str(amount)]) + + normal = runner.invoke(cli, args) + assert normal.exit_code == 0 + assert "Budget thresholds saved" in normal.output + for period, amount in thresholds.items(): + assert f"{period.title()}: ${amount:.2f}" in normal.output + expected_config = (tmp_path / "config.toml").read_bytes() + (tmp_path / "config.toml").unlink() + + quiet = runner.invoke(cli, args + [quiet_flag]) + assert quiet.exit_code == normal.exit_code + assert quiet.output == "" + assert (tmp_path / "config.toml").read_bytes() == expected_config + assert load_budget_config() == thresholds