Skip to content

fix(cli): audit tail -n 0 shows nothing instead of the whole ledger - #13

Merged
sturlese merged 1 commit into
mainfrom
fix/bughunt-audit-tail-zero
Jul 12, 2026
Merged

fix(cli): audit tail -n 0 shows nothing instead of the whole ledger#13
sturlese merged 1 commit into
mainfrom
fix/bughunt-audit-tail-zero

Conversation

@sturlese

Copy link
Copy Markdown
Owner

Bug

flightdeck audit tail -n 0 printed the entire ledger (thousands of entries) instead of zero. On the demo org that's 6731 lines of output for a command that asked for none. A negative -n was wrong too.

Root cause

entries = Ledger(...).entries()[-n:] — the classic negative-slice trap. For n == 0, [-0:] is [0:], i.e. the whole list (-0 == 0). For n == -5, [5:] drops the first five and shows the rest.

Fix

Guard the slice: all_entries[-n:] if n > 0 else [], so asking for 0 (or fewer) entries shows none. Also key the "ledger is empty" notice off the real ledger (all_entries) rather than the truncated view, so tail -n 0 on a populated ledger prints nothing rather than a misleading "ledger is empty".

Tests

  • test_audit_tail_n_zero_shows_nothing: after a run, tail -n 0 prints no entries and no false "empty" notice, while tail -n 5 still shows the recent ones.
  • test_audit_tail_reports_a_truly_empty_ledger: a genuinely empty ledger still reports "ledger is empty".

The -n 0 test fails on main (prints run_completed) and passes with the fix.

Full suite: 167 passed, 92.65% coverage (gate 85%); ruff clean; offline flightdeck demo + audit verify intact (and audit tail -n 0 now prints 0 lines, was 6731).

Found and fixed by an autonomous bughunt iteration.

`entries()[-n:]` is the classic negative-slice trap: for n == 0, `[-0:]`
is `[0:]` — the ENTIRE list — so `flightdeck audit tail -n 0` dumped every
ledger entry instead of zero. A negative -n was equally wrong (`[5:]`).

Guard the slice: `all[-n:] if n > 0 else []`. Also key the "ledger is
empty" notice off the real ledger rather than the truncated view, so
`tail -n 0` on a populated ledger prints nothing (not a false "empty").

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sturlese

Copy link
Copy Markdown
Owner Author

bughunt gate — /code-review high ✅ clean

Reviewed across 8 angles — no correctness or quality findings. The only behavior change is n<=0 on a populated ledger (now prints nothing, correctly); n>0 and the empty-ledger path are unchanged, and the "ledger is empty" notice now keys off the real ledger. Regression test fails on main and passes with the fix. Full local gate: 167 passed, 92.65% coverage, ruff clean, demo intact. Full mode: watching CI to merge on green.

@sturlese
sturlese merged commit 3457b15 into main Jul 12, 2026
5 checks passed
@sturlese
sturlese deleted the fix/bughunt-audit-tail-zero branch July 12, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant