Skip to content

Commit fc744ec

Browse files
fix: clean ConfigError handling on generation commands, reject negative budget caps, slim sdist
- commit/pr-summary/changelog now print a clean error for malformed or hand-edited config (including UnknownModelError mid-pipeline, a ConfigError subclass) instead of a raw traceback - budget_cap_usd rejects negative values at both entry points: config set and load_config (a negative cap permanently blocked generation) - sdist excludes docs/, .github/, uv.lock, .agents (drops ~2.5MB); templates and hook assets verified to still ship, .pre-commit-hooks.yaml kept - README: PyPI badges removed until first release, test count updated - 5 new tests: clean-error CLI paths for all three generation commands, negative-cap rejection at both layers
1 parent c81b3d0 commit fc744ec

6 files changed

Lines changed: 58 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ AI-assisted git commit messages, PR summaries, and changelogs — with caching,
44
cost control, and a human always in the loop before anything is committed.
55

66
[![CI](https://github.com/getdownandcode/gitmate/actions/workflows/ci.yml/badge.svg)](https://github.com/getdownandcode/gitmate/actions/workflows/ci.yml)
7-
[![PyPI](https://img.shields.io/pypi/v/gitmate-cli.svg)](https://pypi.org/project/gitmate-cli/)
8-
[![Python](https://img.shields.io/pypi/pyversions/gitmate-cli.svg)](https://pypi.org/project/gitmate-cli/)
9-
[![License](https://img.shields.io/pypi/l/gitmate-cli.svg)](LICENSE)
7+
![Python](https://img.shields.io/badge/python-3.11%2B-blue)
8+
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
109

1110
![gitmate demo](docs/demo.gif)
1211

@@ -171,7 +170,7 @@ size-only ordering, deliberately, with the reasoning recorded in the code.
171170
**Tests run against real git.** The suite never mocks the git binary —
172171
scratch repositories in `tmp_path` with real commits. Only the `LLMProvider`
173172
boundary is faked, because that's where our code ends and a vendor's begins.
174-
291 tests, `mypy --strict` clean, `ruff` clean.
173+
297 tests, `mypy --strict` clean, `ruff` clean.
175174

176175
## Development
177176

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ gitmate-hook = "gitmate.hooks:main"
6666

6767
# Internal build documentation; not needed by anyone who pip-installs.
6868
[tool.hatch.build.targets.sdist]
69-
exclude = ["plan.md", "AGENTS.md"]
69+
exclude = ["plan.md", "AGENTS.md", "docs", ".github", "uv.lock", ".agents", ".gitignore"]
7070

7171
# Import package differs from the distribution name (gitmate vs gitmate-cli).
7272
[tool.hatch.build.targets.wheel]

‎src/gitmate/cli.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ def commit(
6666
"""Generate a commit message for the staged diff and review before committing."""
6767
from gitmate.committer import commit_flow
6868

69-
code = commit_flow(yes=yes, console=console, secret_store=secret_store)
69+
try:
70+
code = commit_flow(yes=yes, console=console, secret_store=secret_store)
71+
except config_mod.ConfigError as exc:
72+
err_console.print(f"[red]error:[/red] {exc}")
73+
raise typer.Exit(1) from None
7074
if code != 0:
7175
raise typer.Exit(code)
7276

@@ -204,7 +208,7 @@ def pr_summary(
204208
copy_to_cb=copy,
205209
create_pr=create_pr,
206210
)
207-
except (GitCommandError, BudgetCapExceededError, GitHubCliError) as exc:
211+
except (GitCommandError, BudgetCapExceededError, GitHubCliError, config_mod.ConfigError) as exc:
208212
err_console.print(f"[red]error:[/red] {exc}")
209213
raise typer.Exit(1) from None
210214

@@ -257,7 +261,7 @@ def changelog(
257261
secret_store=secret_store,
258262
bypass_cache=bypass_cache,
259263
)
260-
except (GitCommandError, BudgetCapExceededError) as exc:
264+
except (GitCommandError, BudgetCapExceededError, config_mod.ConfigError) as exc:
261265
err_console.print(f"[red]error:[/red] {exc}")
262266
raise typer.Exit(1) from None
263267

@@ -426,8 +430,11 @@ def config_set(field: str, value: str) -> None:
426430

427431

428432
def _parse_budget(value: str) -> float:
429-
"""Parse a budget string, rejecting non-numeric input."""
433+
"""Parse a budget string, rejecting non-numeric or negative input."""
430434
try:
431-
return float(value)
435+
budget = float(value)
432436
except ValueError:
433437
raise typer.BadParameter(f"{value!r} is not a number.") from None
438+
if budget < 0:
439+
raise typer.BadParameter(f"'budget_cap_usd' must be non-negative (got {value!r}).")
440+
return budget

‎src/gitmate/config.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def load_config(path: Path | None = None) -> GitmateConfig:
168168
raise ConfigError(f"cannot parse {resolved}: 'budget_cap_usd' must be a number")
169169
else:
170170
cap = float(budget)
171+
if cap < 0:
172+
raise ConfigError(f"cannot parse {resolved}: 'budget_cap_usd' must be non-negative")
171173
globs = raw.get("ignore_globs", [])
172174
if not isinstance(globs, list) or not all(isinstance(g, str) for g in globs):
173175
raise ConfigError(f"cannot parse {resolved}: 'ignore_globs' must be a string list")

‎tests/test_cli.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,33 @@ def test_config_show_malformed_config_clean_error(tmp_config_dir: Path) -> None:
178178
assert "Traceback" not in result.output
179179

180180

181+
def test_commit_malformed_config_clean_error(tmp_config_dir: Path, git_repo: Path) -> None:
182+
config_path().parent.mkdir(parents=True, exist_ok=True)
183+
config_path().write_text("model = [invalid toml\n", encoding="utf-8")
184+
result = runner.invoke(cli.app, ["commit"])
185+
assert result.exit_code == 1
186+
assert "error:" in result.output
187+
assert "Traceback" not in result.output
188+
189+
190+
def test_pr_summary_malformed_config_clean_error(tmp_config_dir: Path, git_repo: Path) -> None:
191+
config_path().parent.mkdir(parents=True, exist_ok=True)
192+
config_path().write_text("model = [invalid toml\n", encoding="utf-8")
193+
result = runner.invoke(cli.app, ["pr-summary"])
194+
assert result.exit_code == 1
195+
assert "error:" in result.output
196+
assert "Traceback" not in result.output
197+
198+
199+
def test_changelog_malformed_config_clean_error(tmp_config_dir: Path, git_repo: Path) -> None:
200+
config_path().parent.mkdir(parents=True, exist_ok=True)
201+
config_path().write_text("model = [invalid toml\n", encoding="utf-8")
202+
result = runner.invoke(cli.app, ["changelog", "--from", "HEAD"])
203+
assert result.exit_code == 1
204+
assert "error:" in result.output
205+
assert "Traceback" not in result.output
206+
207+
181208
def test_debug_diff_git_command_error_clean_error(tmp_config_dir: Path, git_repo: Path) -> None:
182209
result = runner.invoke(cli.app, ["debug-diff", "--base", "nonexistent-branch"])
183210
assert result.exit_code == 1
@@ -226,6 +253,12 @@ def test_config_set_budget_fields_validation(tmp_config_dir: Path) -> None:
226253
assert "must be greater than" in res.output
227254

228255

256+
def test_config_set_rejects_negative_budget_cap(tmp_config_dir: Path) -> None:
257+
res = runner.invoke(cli.app, ["config", "set", "budget_cap_usd", "--", "-5"])
258+
assert res.exit_code != 0
259+
assert "non-negative" in res.output
260+
261+
229262
def test_commit_cli_no_staged_diff_exits_zero(git_repo: Path, tmp_config_dir: Path) -> None:
230263
result = runner.invoke(cli.app, ["commit"])
231264
assert result.exit_code == 0

‎tests/test_config.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ def test_budget_config_round_trip(tmp_config_dir: Path) -> None:
168168
assert loaded.template_overhead == 800
169169

170170

171+
def test_negative_budget_cap_rejected(tmp_config_dir: Path) -> None:
172+
config_path().parent.mkdir(parents=True, exist_ok=True)
173+
config_path().write_text("budget_cap_usd = -1.0\n", encoding="utf-8")
174+
with pytest.raises(ConfigError, match="must be non-negative"):
175+
load_config()
176+
177+
171178
@pytest.mark.parametrize("val", ['"big"', "true", "-100", "0"])
172179
def test_invalid_max_context_tokens_raises(tmp_config_dir: Path, val: str) -> None:
173180
config_path().parent.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)