Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- `impact`, `lineage` and `drift` refuse `--models` pointing to a folder with no `.sql` files with `status: error` and a `next_step` instead of reporting zero models or empty impact. Thanks to @shaw778! (#122, #147)
- `run --max-rows N` refuses a value below 0 with `status: error` and a `next_step`, exits 1, and skips estimating, running, or writing a receipt, while `--max-rows 0` stays valid (#119).

## 0.4.0 - 2026-11-11

Expand Down
5 changes: 5 additions & 0 deletions src/gulliver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ def _rehearse(settings: Settings, sql: str, connection: str | None, fractions: l
# -- run -------------------------------------------------------------------------------
def run(settings: Settings, sql: str, connection: str | None = None, max_rows: int | None = None,
allow_write: bool = False) -> dict[str, Any]:
if max_rows is not None and (isinstance(max_rows, bool) or not isinstance(max_rows, int) or max_rows < 0):
return _error(
f"--max-rows must be at least 0, got {max_rows}.",
"Pass a non-negative integer for --max-rows (0 returns row counts without preview rows).",
)
try:
return _run(settings, sql, connection, max_rows, allow_write)
except ConfigError as exc:
Expand Down
15 changes: 14 additions & 1 deletion tests/test_cli_and_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def test_cli_translate_output_file(tmp_path, capsys):
assert out.read_text(encoding="utf-8") == data["sql"]



def test_mcp_check_by_name_and_status_checks(demo_db, state, tmp_path, monkeypatch):
db_path = demo_db.replace("\\", "/")
monkeypatch.chdir(tmp_path)
Expand Down Expand Up @@ -155,3 +154,17 @@ def test_mcp_check_by_name_and_status_checks(demo_db, state, tmp_path, monkeypat
err_data = json.loads(err_res.content[0].text)
assert err_data.get("status") == "error"
assert "Unknown configured check" in err_data.get("error", "")


def test_cli_run_refuses_negative_max_rows_and_allows_zero(demo_db, state, capsys):
assert main(["--dsn", demo_db, "run", "--max-rows", "-5", "--json", "select count(*) from users"]) == 1
data = json.loads(capsys.readouterr().out)
assert data["status"] == "error" and "-5" in data["error"] and data["next_step"]

assert main(["--dsn", demo_db, "run", "--max-rows", "-2", "select count(*) from users"]) == 1
plain = json.loads(capsys.readouterr().out)
assert plain["status"] == "error" and "-2" in plain["error"]

assert main(["--dsn", demo_db, "run", "--max-rows", "0", "--json", "select count(*) from users"]) == 0
zero = json.loads(capsys.readouterr().out)
assert zero["status"] == "ok" and zero["preview"] == [] and zero["actual"]["rows"] == 1
16 changes: 16 additions & 0 deletions tests/test_flow_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,19 @@ def test_budget_defaults_are_sane():
b = Budget()
assert b.approval_over_usd < b.max_query_usd < b.day_usd
assert Connection("x", "duckdb").public_dict() == {"name": "x", "engine": "duckdb"}


def test_run_refuses_negative_max_rows_and_allows_zero(settings):
err = core.run(settings, GOOD, max_rows=-5)
assert err["status"] == "error"
assert "-5" in err["error"] and "--max-rows" in err["error"] and err["next_step"]
assert core.list_receipts(settings)["receipts"] == []

zero = core.run(settings, GOOD, max_rows=0)
assert zero["status"] == "ok"
assert zero["preview"] == []
assert zero["actual"]["rows"] == 8

over = core.run(settings, GOOD, max_rows=settings.budget.max_output_rows + 50)
assert over["status"] == "ok"
assert len(over["preview"]) <= settings.budget.max_output_rows
Loading