Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

### Fixed
- `check` now refuses a negative `--min-rows` and a negative, NaN or infinite `--max-change` instead of silently passing or failing (#106).

## 0.4.0 - 2026-11-11

Data checks you define once in `gulliver.toml` and run in CI, a lint baseline for existing repos, rehearsal
Expand Down
4 changes: 4 additions & 0 deletions src/gulliver/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ def parse_spec(unique: list[str] | None = None, not_null: list[str] | None = Non
max_change_pct: float | None = None) -> CheckSpec:
"""Parse CLI-style strings: unique 'id' or 'a,b'; accepted 'status=new|paid'; range 'amount=0:1000';
fresh 'ts=24h'."""
if min_rows is not None and min_rows < 0:
raise ValueError(f"min_rows needs 0 or more, got {min_rows!r}")
if max_change_pct is not None and not (math.isfinite(max_change_pct) and max_change_pct >= 0):
raise ValueError(f"max_change needs a finite number, 0 or more, got {max_change_pct!r}")
spec = CheckSpec(min_rows=min_rows, max_change_pct=max_change_pct)
for u in unique or []:
spec.unique.append([c.strip() for c in u.split(",") if c.strip()])
Expand Down
15 changes: 15 additions & 0 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@
def _bounds(text):
return parse_spec(ranges=[f"amount={text}"]).ranges["amount"]

@pytest.mark.parametrize("value", [-1, -5])
def test_min_rows_refuses_negative(value):
with pytest.raises(ValueError, match=r"min_rows needs 0 or more"):
parse_spec(min_rows=value)

@pytest.mark.parametrize("value", [-5.0, float("nan"), float("inf"), float("-inf")])
def test_max_change_refuses_negative_or_non_finite(value):
with pytest.raises(ValueError, match=r"max_change needs a finite number"):
parse_spec(max_change_pct=value)



@pytest.mark.parametrize("text", ["nan:", ":inf", "-inf:", ":nan"])
def test_range_refuses_non_finite_bounds(text):
with pytest.raises(ValueError, match="finite"):
parse_spec(ranges=[f"amount={text}"])

def test_zero_thresholds_still_parse():
spec = parse_spec(min_rows=0, max_change_pct=0.0)
assert spec.min_rows == 0
assert spec.max_change_pct == 0.0

def test_range_refuses_a_non_number():
with pytest.raises(ValueError, match=r"range for 'amount' needs numbers, got 'abc'"):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli_and_mcp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import json

import pytest

from gulliver.cli import main
from gulliver.mcp_server import build_server, export_tools

Expand Down Expand Up @@ -99,6 +101,21 @@ def test_cli_translate_output_file(tmp_path, capsys):
assert out.read_text(encoding="utf-8") == data["sql"]


@pytest.mark.parametrize("extra, message", [
(["--min-rows", "-5"], "min_rows"),
(["--max-change", "-5"], "max_change"),
(["--max-change", "nan"], "max_change"),
(["--max-change", "inf"], "max_change"),
])
def test_check_refuses_invalid_thresholds(demo_db, capsys, extra, message):
code = main(["--dsn", demo_db, "--json", "check", "events", "--not-null", "event_id", *extra])
assert code == 1
assert message in capsys.readouterr().out


def test_check_accepts_zero_min_rows(demo_db):
assert main(["--dsn", demo_db, "--json", "check", "events", "--not-null", "event_id", "--min-rows", "0"]) == 0


def test_mcp_check_by_name_and_status_checks(demo_db, state, tmp_path, monkeypatch):
db_path = demo_db.replace("\\", "/")
Expand Down