Skip to content

refactor(email): use the shared WEEKS_PER_ROW in the life PDF grid - #5187

Merged
tyler-dane merged 1 commit into
mainfrom
claude/kind-dirac-ksh9h9
Nov 9, 2026
Merged

tyler-dane merged 1 commit into
mainfrom
claude/kind-dirac-ksh9h9

Conversation

@tyler-dane

Copy link
Copy Markdown
Contributor

What and why

The reflection life PDF renders the same week grid as the web Life View, and its own comment says so ("Keep the Life View grid, with a plain white background for the attachment"). LifeGrid.tsx derives that grid from the exported WEEKS_PER_ROW, but reflection-life-image.ts hardcoded 52 for both the row length and the dot index, while already importing DEFAULT_LIFESPAN and getCompletedLifeWeeks from that same @core/life/life-math module.

That left one divergent copy of a domain constant, and it is a live coupling rather than a cosmetic one: the percentage line printed in the same attachment comes from reflectionLifeProgress -> getTotalLifeDots -> WEEKS_PER_ROW. A change to WEEKS_PER_ROW would silently desync the grid drawn in the PDF from the percentage printed beside it, with no test catching it, because the test re-encoded the same literals as 79 * 52.

This uses the shared constant in both expressions and derives the test's expected rect count from DEFAULT_LIFESPAN * WEEKS_PER_ROW instead. Behavior preserving: WEEKS_PER_ROW is 52, so the rendered PDF is byte-identical. Deliberately unchanged: the renderer still uses DEFAULT_LIFESPAN for the row count rather than a user lifespan, since reflection emails do not carry one.

Found by a tech-debt sweep of the last 7 days of merges. It was the only genuine finding; bun knip and bun lint are clean, and the providerVersion and date-picker-keys clusters from this week have already converged on shared helpers.

Verify

VERDICT: FAIL from bun run verify --strict, on a pre-existing environmental failure only.

Checks run: type-check, lint, knip (all pass), test:backend:fast.

PRE-EXISTING: test:backend:fast fails 13 tests in GET /api/config and SSE Server (Timeout waiting for SSE event, 500 GET /api/events/stream). This sandbox has no compass.yaml, which AGENTS.md lists as required for backend, auth, MongoDB, sync and SSE. Verify does not baseline test:backend automatically, so I ran it on a clean origin/main tree: 13 failures there too, the same suites. This diff touches only an SVG grid constant in the email package and adds no new failures.

FLAKY: none.

bun test packages/backend/src/email/reflection-life-image.test.ts: 4 pass, 0 fail.


Generated by Claude Code

The reflection life PDF renders the same week grid as the web Life View,
and its own comment says so ("Keep the Life View grid"). LifeGrid.tsx
derives that grid from the exported WEEKS_PER_ROW, but the PDF renderer
hardcoded 52 for both the row length and the dot index while already
importing DEFAULT_LIFESPAN and getCompletedLifeWeeks from the same
module.

That left one divergent copy of a domain constant: the attachment's
percentage line comes from reflectionLifeProgress -> getTotalLifeDots ->
WEEKS_PER_ROW, so a change to WEEKS_PER_ROW would silently desync the
grid drawn in the PDF from the percentage printed beside it.

Use the shared constant in both expressions, and stop the test
re-encoding the same literals as 79 * 52.

Behavior preserving: WEEKS_PER_ROW is 52.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmwVQGU4sTAu5rbJPLsEbE
@tyler-dane
tyler-dane enabled auto-merge November 9, 2026 11:12

Copy link
Copy Markdown
Contributor Author

Tech-debt sweep, 2026-11-02 to 2026-11-09 (50 merges)

Addressed: 1 item — the WEEKS_PER_ROW divergence in this PR.

Examined and deliberately left alone, so the next sweep does not redo them:

Area Why it is not debt
providerVersion normalization (#5121, #5126, #5128) Converged on a shared NullableProviderEventVersionReadSchema used by both EventReadSchema and DeletionMarkerReadSchema, with the legacy-empty rationale in comments. #5146 already did the sharing.
Date-picker key utils (#5146, #5184) date-picker-keys.util.ts owns key semantics, eventFormDateFieldKeys.util.ts owns form-specific closed-field behavior that needs the field text. That split is the point of #5184; collapsing it would recouple them.
date-picker-keyboard-dom.util.ts Clunky by nature (CSS-class queries, requestAnimationFrame, a bounded scroll loop), but it is wrestling react-datepicker internals. The mess is load-bearing; refactoring it blind risks keyboard/focus regressions for no behavior gain.
reflection-life-image.ts typography churn (6 PRs) Iterative visual design on a 132-line renderer, not structural debt.
Repo-wide bun knip reports no unused files or exports; bun lint passes all rules.

A note worth raising, since it concerns this sweep more than this PR: 8 of the week's 50 merges were tech-debt refactors, and 5 of them rework the same date-picker hint cluster. LifeBirthDateField.tsx and EventFormDateField.tsx were each touched 4 times in 7 days; useDatePickerSidebarHints.ts and date-picker-keyboard-dom.util.ts 3 times each. The titles track the pattern: #5146 shares the helpers, #5174 folds "leftover copies", #5178 folds "the duplication", #5184 moves the semantics, #5186 folds "leftover hint copies" again.

Each of those is individually defensible, but in aggregate they are churn on code that was already fine, carrying real review and regression cost for no user-visible change. The honest read of this week is that there was roughly one thing worth fixing, not eight. Recommend either narrowing this routine to mechanically-verifiable findings (knip/lint/type signal, drifted shared constants) or dropping its cadence, rather than letting it keep finding something to do in the same files. Happy to leave the date-picker cluster off the sweep list entirely if you prefer.


Generated by Claude Code

@tyler-dane
tyler-dane added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 4840e95 Nov 9, 2026
28 checks passed
@tyler-dane
tyler-dane deleted the claude/kind-dirac-ksh9h9 branch November 9, 2026 11:21
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.

2 participants