Skip to content

Fix report window default and double-escaped sender addresses#7

Merged
gmr merged 2 commits into
mainfrom
fix/report-previous-week-and-double-escape
Jul 13, 2026
Merged

Fix report window default and double-escaped sender addresses#7
gmr merged 2 commits into
mainfrom
fix/report-previous-week-and-double-escape

Conversation

@gmr

@gmr gmr commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Two fixes to the weekly report.

1. Default window is the previous full calendar week

The report defaulted to a trailing now() - 6 days span (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 reads Jul 6 – Jul 12, 2026 instead of Jul 7 – Jul 13, 2026.

  • --days N still selects a trailing N-day window ending today; --since a trailing window from a given date. The previous-week default only applies when neither flag is passed (--days default changed 7None).
  • _fetch_rows now 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's end date.

2. Double-escaped HTML entities in sender addresses

Some senders arrive already HTML-escaped (<jim@vidovation.com>). parseaddr then found no real address, so the display name held the escaped string and the template's autoescape re-encoded the & into <, rendering a literal <. _offenders now html.unescape()s the sender before parseaddr, so name/address split cleanly and autoescape encodes exactly once.

Testing

  • uv run coverage run -m pytest — 122 passed
  • uv run ruff check . — clean
  • Rendered end-to-end against the real action DB: correct week range, no double-escaped entities.

Added tests: test_render_defaults_to_previous_full_week, test_offenders_unescape_double_escaped_sender. Realigned two existing render tests whose injected now predated their record timestamps (they'd relied on the old absence of an upper bound).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Weekly reports now default to the previous full calendar week (Monday–Sunday) when no window is specified.
    • The report period can be controlled via a trailing day count or a start date; the rendered timestamp reflects the chosen window.
    • The CLI --days option now defaults to using the previous full calendar week when omitted.
  • Bug Fixes
    • Offender sender details now correctly handle HTML-escaped sender values.
    • Report filtering now applies an inclusive start/end date range rather than only a lower bound.

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>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ddc103b-bf51-4a79-91df-2b8acb3096e9

📥 Commits

Reviewing files that changed from the base of the PR and between ed1bcac and 53b0f2f.

📒 Files selected for processing (2)
  • tests/test_report.py
  • use_agent/report.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • use_agent/report.py
  • tests/test_report.py

📝 Walkthrough

Walkthrough

The 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.

Changes

Weekly report behavior

Layer / File(s) Summary
Calendar-week selection and bounded queries
use_agent/report.py, use_agent/cli.py, tests/test_report.py
The report defaults to the previous Monday–Sunday week, supports explicit overrides, queries an inclusive timestamp range, validates invalid windows, and updates related rendering tests.
Rendering context and sender normalization
use_agent/report.py, tests/test_report.py
Generated timestamps can be injected into the template context, and double-escaped sender values are decoded before offender parsing and grouping.

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
Loading

Possibly related PRs

  • gmr/use-agent#5: Introduced the weekly HTML reporting codepath that this change updates.

Poem

I’m a rabbit with a calendar bright,
Monday to Sunday, bounded just right.
Escaped little senders now bloom clear,
Fresh report timestamps hop near.
The weekly window is neatly drawn—
I nibble the tests from dusk to dawn!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: the default report window and sender address unescaping.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b7635c8 and ed1bcac.

📒 Files selected for processing (3)
  • tests/test_report.py
  • use_agent/cli.py
  • use_agent/report.py

Comment thread use_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>
@gmr

gmr commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

PR Monitoring Complete — Ready to Merge ✅

Automated monitoring finished. All exit criteria are met on head 53b0f2f:

  • CI/CD (E3): All checks passing — test (3.14) green.
  • Review threads (E2): 0 unresolved.
  • Automated reviewers (E4): CodeRabbit re-reviewed the current HEAD with 0 actionable comments.

Work done during monitoring

  • Pushed 53b0f2f — reject inverted report windows (start > end) with a covering test, addressing CodeRabbit feedback.
  • Resolved 1 CodeRabbit review thread with verification.

The two report fixes (previous-full-calendar-week default window; html.unescape() before parseaddr in report._offenders) are intact. No unrelated changes were introduced.

This PR is ready to merge.

@gmr gmr merged commit 8a902f9 into main Jul 13, 2026
2 checks passed
@gmr gmr deleted the fix/report-previous-week-and-double-escape branch July 13, 2026 17:04
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