Repository navigation
feat(returns): --by-group partial report on unvaluable scopes (#1850 §4) - #1852
Conversation
6c83db0 to
d115ff6
Compare
Net-units valuation isolates scopes — each sums only its own accounts — so one group hitting an unvaluable input (an in-scope account with an elided posting, or a commodity with no price) no longer has to fail the whole report. This finishes the #1850 §4 CLI rendering that the net-units core (#1851) unblocked. Previously the `--by-group` path `?`-aborted on the first per-scope error (the #1849 seventh-review finding), nuking the TOTAL and every other group. Now each scope is computed independently and a failure becomes a row-level `n/a` marker with a stderr warning naming the group and reason, while the computable groups render their figures. Only if EVERY row (TOTAL included) is unvaluable does the report fail loudly — there is then nothing to show. - report_returns: build `Vec<GroupRow>` (Ok | Unvaluable{label, reason}) instead of `?`-aborting; warn per unavailable scope; bail only when all are unvaluable. - render_grouped: render `n/a` in every figure column for an unvaluable row (text/CSV); JSON keeps a stable schema — every row gains an `error` field (`null` when computed, the reason string when not) with `null` figures. - Tests: a direct render_grouped test (text + JSON schema) and an end-to-end report_returns --by-group test (one valuable group + one elided-in-scope group → partial render, TOTAL n/a, report succeeds). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
The render_grouped_marks_unvaluable_rows JSON check ended in a substring OR (... || json.contains "un-booked") — the reason text matched anywhere in the blob, so a malformed or misplaced error key would still pass green (the substring-proxy anti-pattern CLAUDE.md calls out). Parse the JSON and assert the error FIELD structurally: the computed row's error is null with figures present, the unvaluable row and the TOTAL carry the exact reason on error with every figure null — the stable schema a consumer actually branches on. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
Second review pass, finding [0]: the §4 partial render turned EVERY per-scope error non-fatal, including MissingPrice — so a --by-group report with one unpriceable group emitted an n/a row and exited 0, where the single-scope path (and origin/main) exited non-zero. CSV/text carry no error column, so a pipeline gating on exit status treated a silently-incomplete report as full success. Now report_returns still RENDERS the computable rows + n/a markers, then returns Err so the CLI exits non-zero — the incomplete-report signal for pipelines (JSON also carries a per-row `error` field; the exit code is the only machine-readable signal for CSV/text). Only a fully-computable report exits 0; an all-unvaluable report still bails before rendering as before. Tests: the end-to-end unit test now asserts the partial output is written AND the call returns Err; a new subprocess test (by_group_partial_report_renders_but_exits_nonzero) pins the actual non-zero exit + partial stdout + stderr reason. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
d115ff6 to
c19aa6d
Compare
📊 Benchmark Results
vs main branch (2026-07-23)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
Updates the report returns --by-group CLI path to tolerate per-scope “unvaluable” inputs by rendering a partial grouped report (with n/a rows) instead of aborting on the first failing scope, aligning with the net-units isolation work from #1851.
Changes:
- Add a
GroupRow(OkvsUnvaluable { label, reason }) pipeline to keep rendering computable groups while marking failing rows asn/aand warning on stderr. - Extend grouped rendering so text/CSV show
n/afigures for unvaluable rows, and JSON keeps a stable schema via a per-rowerrorfield andnullfigures. - Add/extend tests covering partial grouped rendering behavior (both renderer-level and CLI end-to-end).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/rustledger/src/cmd/report_cmd/returns.rs | Implements partial by-group computation/rendering with GroupRow, per-scope warnings, n/a rows, and JSON error field; adds unit tests for the new rendering semantics. |
| crates/rustledger/tests/report_returns_test.rs | Adds an end-to-end CLI regression test asserting partial grouped output is still produced when one group is unvaluable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… warning (copilot) The per-scope unavailable warning printed the raw returns-group label, which is user-controlled and can carry control chars / newlines (log/terminal injection — spoofed lines, escape sequences). Route it through sanitize_display, the same guard the grouping warnings already use. The error text is grammar-constrained (account names / currencies), so it needs no sanitizing. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
crates/rustledger/src/cmd/report_cmd/returns.rs:527
- The PR description states that a partial
report returns --by-grouprender (some groups computable, some unvaluable) should still succeed unless every row is unvaluable. However, the implementation currently returnsErr(non-zero exit) wheneverunvaluable > 0, and the new integration test asserts non-zero status. Please decide the intended contract (exit 0 with warnings + per-rowerrorfield vs exit non-zero for incomplete output) and align the behavior + tests + PR description accordingly, since this is a user-visible CLI/API behavior change.
if unvaluable > 0 {
anyhow::bail!(
"returns report is incomplete: {unvaluable} of {} {} could not be valued \
(see the n/a rows and the warnings above)",
rows.len(),
Summary
report returns --by-groupnow renders a partial report when a scope hits an unvaluable input, instead of aborting the whole report on the first error (#1850 §4). Stacked work; base is nowmain(#1851 merged).Behavior
n/arow with a stderrwarning:naming the reason, while the computable groups still report their figures.rledgerexits non-zero — an incomplete report is not a full success, so a script gating on the exit code (rledger … && …) stops rather than consuming a report with silentn/aholes. The partial output is written to stdout before the non-zero exit (pinned by theby_group_partial_report_renders_but_exits_nonzerosubprocess test). Only when every row is unvaluable is nothing rendered.errorfield (nullwhen computed, the reason string when not) withnullfigures on an unvaluable row — machine-distinguishable in all formats (CSV/text signal via the exit code +n/a).Changes
report_returns: buildVec<GroupRow>(Ok|Unvaluable { label, reason }) instead of?-aborting; warn per unavailable scope (label routed throughsanitize_display— it is user-controlledreturns-groupmetadata); returnErr(non-zero exit) when the report is partial; bail before rendering only when all rows are unvaluable.render_grouped:n/ain every figure column (text/CSV); JSON gains the stableerrorfield.render_grouped(text + structural JSONerror-field assertion), an end-to-endreport_returnsunit test (partial output written andErr), and a subprocess test pinning the non-zero exit + partial stdout + stderr reason.🤖 Generated with Claude Code