Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3,6 +3,7 @@
## Unreleased

### Added
- Receipt listing filters by `--action` and `--connection`, combined with `--status` before applying `--limit` (#93).
- `gulliver rules --format markdown|json` prints a generated rule table (markdown) or the same JSON as `--json`; the README Scale lint rules table is generated from it (#18).
- `gulliver spend -o/--output PATH` and `gulliver top -o/--output PATH` write the report as UTF-8 and print a one-line confirmation (#19).
- Opt-in `check --samples N` / MCP `samples` (0-20) reports guarded offending values and row counts for failed unique, accepted-values and range checks. Each extra query is budget-gated and logged; blocked or failed samples leave the check result intact (#48, #49).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ gulliver preflight SQL estimate + lint + gate, no execution
gulliver rehearse SQL [--fractions 0.01,0.03,0.1] [--sample largest|all] [--method auto|system|bernoulli]
gulliver run SQL [--max-rows N] [--allow-write]
gulliver receipt [ID|latest] [--format markdown|json] [-o PATH]
gulliver receipt --list [--limit N] [--status STATUS] [--json]
gulliver receipt --list [--limit 20] [--status S] [--action A] [--connection C] [--json]
gulliver approve ID [--note TEXT] (human only)
gulliver demo [PATH] create a demo DuckDB database
gulliver lineage --models DIR | --manifest FILE
Expand Down
4 changes: 3 additions & 1 deletion src/gulliver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def add_parser(name: str, **kwargs: Any) -> argparse.ArgumentParser:
p.add_argument("--list", action="store_true", help="List recent receipts instead of showing one")
p.add_argument("--limit", type=int, default=20, help="Maximum receipts to list (default: 20)")
p.add_argument("--status", help="Only list receipts with this status, e.g. needs_approval")
p.add_argument("--action", help="Only list receipts with this action, e.g. run or rehearse")
p.add_argument("--format", choices=["markdown", "json"], default="markdown")
p.add_argument("-o", "--output", metavar="PATH", help="Also write the receipt (in --format) to PATH")

Expand Down Expand Up @@ -591,7 +592,8 @@ def csv(text: str | None) -> list[str] | None:
if args.list:
if args.receipt_id != "latest":
parser.error("receipt --list does not take a receipt ID")
result = core.list_receipts(settings, limit=args.limit, status=args.status)
result = core.list_receipts(settings, limit=args.limit, status=args.status,
action=args.action, connection=args.connection)
if result.get("status") == "ok" and not args.json:
for rec in result["receipts"]:
print(f"{rec['receipt_id']} {rec['created_at']} {rec['action']} "
Expand Down
7 changes: 6 additions & 1 deletion src/gulliver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ def get_receipt(settings: Settings, receipt_id: str, fmt: str = "markdown") -> d
"next_step": "Show this markdown to the human."}


def list_receipts(settings: Settings, limit: int = 20, status: str | None = None) -> dict[str, Any]:
def list_receipts(settings: Settings, limit: int = 20, status: str | None = None,
action: str | None = None, connection: str | None = None) -> dict[str, Any]:
"""Return a compact summary of recent receipts.

The full receipt stays in the store; list output is intentionally limited to
Expand All @@ -758,6 +759,10 @@ def list_receipts(settings: Settings, limit: int = 20, status: str | None = None
receipts = _store(settings).receipts()
if status is not None:
receipts = [rec for rec in receipts if rec.get("status") == status]
if action is not None:
receipts = [rec for rec in receipts if rec.get("action") == action]
if connection is not None:
receipts = [rec for rec in receipts if rec.get("connection") == connection]

summaries = []
for rec in receipts[:limit]:
Expand Down
58 changes: 58 additions & 0 deletions tests/test_receipt_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json

import pytest

from gulliver import core
from gulliver.cli import main
from gulliver.store import Store


@pytest.fixture
def receipts(settings):
store = Store(settings.state_dir)
records = [
("old-run", "run", "ok", "warehouse"),
("other-connection", "run", "ok", "local"),
("other-status", "run", "block", "warehouse"),
("new-run", "run", "ok", "warehouse"),
("newest-preflight", "preflight", "ok", "warehouse"),
]
for i, (receipt_id, action, status, connection) in enumerate(records):
store.save_receipt({
"receipt_id": f"gv-20260101-00000{i}-{receipt_id}", "action": action,
"status": status, "connection": connection,
"created_at": f"2026-01-01T00:00:0{i}+00:00", "sql": "select 1", "preview": [{"private": "row"}],
})
return settings


@pytest.mark.parametrize("filters, expected", [
({"action": "run"}, ["new-run", "other-status", "other-connection", "old-run"]),
({"connection": "local"}, ["other-connection"]),
({"action": "run", "connection": "warehouse", "status": "ok"}, ["new-run", "old-run"]),
({"action": "missing"}, []),
({"connection": "missing"}, []),
])
def test_receipt_filters_combine_and_preserve_summary_only(receipts, capsys, filters, expected):
result = core.list_receipts(receipts, **filters)
assert result["status"] == "ok"
assert [rec["receipt_id"].split("-", 3)[3] for rec in result["receipts"]] == expected
assert all("preview" not in rec for rec in result["receipts"])
args = ["receipt", "--list", "--json"]
for key, value in filters.items():
args.extend([f"--{key}", value])
assert main(args) == 0
result = json.loads(capsys.readouterr().out)
assert [rec["receipt_id"].split("-", 3)[3] for rec in result["receipts"]] == expected


def test_receipt_limit_is_applied_after_all_filters(receipts, capsys):
filters = {"action": "run", "connection": "warehouse", "status": "ok"}
result = core.list_receipts(receipts, limit=1, **filters)
assert [rec["receipt_id"].split("-", 3)[3] for rec in result["receipts"]] == ["new-run"]
assert main(["receipt", "--list", "--action", "run", "--connection", "warehouse",
"--status", "ok", "--limit", "1"]) == 0
output = capsys.readouterr().out
assert "new-run" in output
assert "old-run" not in output
assert "preflight" not in output