Fix report window default and double-escaped sender addresses#7
Conversation
Two report fixes:
- Default the report window to the previous full calendar week
(last Monday through Sunday) instead of a trailing now()-6-days
span. --days N still selects a trailing N-day window ending
today, and --since a trailing window from a given date; the
previous-week default only applies when neither is passed.
Requires bounding _fetch_rows on the upper end so the fixed-end
week window no longer leaks in current-week rows, and decoupling
generatedAt (always "now") from the window end date.
- Unescape the sender in _offenders before parseaddr. Some senders
arrive already HTML-escaped ('<a@b.com>'), so parseaddr
found no address and the template's autoescape re-encoded the &,
rendering a literal '<'. html.unescape first lets parseaddr
split name/address and autoescape encode exactly once.
Verified end-to-end against the real action DB: the range now reads
"Jul 6 - Jul 12, 2026" and no double-escaped entities remain.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe report command and renderer now default to the previous full Monday–Sunday week, support bounded date windows, validate invalid ranges, preserve generation timestamps, and decode escaped sender values before offender grouping. ChangesWeekly report behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ReportCLI
participant ReportRender
participant ReportDatabase
participant ReportTemplate
ReportCLI->>ReportRender: pass optional days or since
ReportRender->>ReportDatabase: query processed_at within start and end
ReportDatabase-->>ReportRender: return bounded report rows
ReportRender->>ReportTemplate: render rows with generated timestamp
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@use_agent/report.py`:
- Around line 74-82: Validate the computed start_date and end_date immediately
after the since/days/default branches and before constructing timestamps or
querying. Reject any window where start_date is later than end_date, covering
zero or negative days and future since values, using the existing
validation/error mechanism.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 310d6d8d-d6c8-48e8-a57f-28e9fb895077
📒 Files selected for processing (3)
tests/test_report.pyuse_agent/cli.pyuse_agent/report.py
An inverted window (days<=0, or a future --since date) made start_date later than end_date, so the query silently returned no rows while the rendered range read backwards. Validate the computed dates and raise ValueError before building the timestamps. Addresses CodeRabbit review feedback on PR #7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR Monitoring Complete — Ready to Merge ✅Automated monitoring finished. All exit criteria are met on head
Work done during monitoring
The two report fixes (previous-full-calendar-week default window; This PR is ready to merge. |
Summary
Two fixes to the weekly report.
1. Default window is the previous full calendar week
The report defaulted to a trailing
now() - 6 daysspan (e.g. Tue–Mon). It now defaults to the previous full calendar week — last Monday through Sunday. Rendered against the real DB on Mon Jul 13, the range now readsJul 6 – Jul 12, 2026instead ofJul 7 – Jul 13, 2026.--days Nstill selects a trailing N-day window ending today;--sincea trailing window from a given date. The previous-week default only applies when neither flag is passed (--daysdefault changed7→None)._fetch_rowsnow bounds on the upper end too, so the fixed-end week window doesn't leak in current-week rows.generatedAt(always "now") is decoupled from the window'senddate.2. Double-escaped HTML entities in sender addresses
Some senders arrive already HTML-escaped (
<jim@vidovation.com>).parseaddrthen found no real address, so the display name held the escaped string and the template's autoescape re-encoded the&into&lt;, rendering a literal<._offendersnowhtml.unescape()s the sender beforeparseaddr, so name/address split cleanly and autoescape encodes exactly once.Testing
uv run coverage run -m pytest— 122 passeduv run ruff check .— cleanAdded tests:
test_render_defaults_to_previous_full_week,test_offenders_unescape_double_escaped_sender. Realigned two existing render tests whose injectednowpredated their record timestamps (they'd relied on the old absence of an upper bound).🤖 Generated with Claude Code
Summary by CodeRabbit
--daysoption now defaults to using the previous full calendar week when omitted.