Skip to content

fix(card): warm pinned variants under the key the card route reads - #17

Merged
LangerSword merged 2 commits into
LangerSword:mainfrom
saswatdutta1310:bot/fix-pinned-card-variant-warm-issue-5
Nov 26, 2026
Merged

LangerSword merged 2 commits into
LangerSword:mainfrom
saswatdutta1310:bot/fix-pinned-card-variant-warm-issue-5

Conversation

@saswatdutta1310

@saswatdutta1310 saswatdutta1310 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5

Problem

POST /api/cache-image always wrote cardpng:v10:<login>::, while GET /api/card-image/[username] reads cardpng:v10:<login>:<country>:<team> for pinned embeds. A visitor opening /<login>?country=nl&team=FER captured a real PNG and stored it in a key no variant request reads. Live probe before this fix:

/torvalds.png        200   x-og-cache: r2-hit
/torvalds.png?country=nl&team=FER   404   x-og-cache: miss-empty

Root cause

The cache-key shape was duplicated in two places with different inputs; the writer had no variant fields at all. History (532b531, 1a1b3a6) shows pinned variants are deliberately separate cached objects, so this is a missing writer, not intentional design.

Fix

  • New lib/og/cardCacheKey.ts: one key builder used by both routes. It normalises country with normalizeCountry() and team with pickTeam(), so ?country=NL and ?country=nl share one object; invalid overrides and full team names collapse to the plain key instead of minting a variant holding plain bytes.
  • app/api/card-image/[username]/route.tsx and app/api/cache-image/route.ts: both call the shared helper.
  • components/WarmOnView.tsx: accepts country / team and sends them with the card warm request; effect dependencies updated.
  • app/[username]/page.tsx: passes the explicit query values (sp.country, sp.team), not the resolved displayFlag or cookie prefs. The embed read path only knows the query string, so passing displayFlag warmed :nl:FER for a ?team=FER visit while that embed read ::FER. An independent review caught this gap; it is fixed here.

Acceptance coverage

  • A page opened with ?country=nl&team=FER warms the matching variant key.
  • The variant URL reads exactly the key the warm writes (pinned, raw-vs-normalised, team-only, and no-query cases).
  • The plain object keeps its own key and is not evicted by a variant.
  • Invalid / full-name team input falls back to the plain key.
  • Route tests added for both keys and the default fallback behaviour.
  • A warm is skipped when a cookie-selected variant is not expressed in the query.

Owner's two design questions from the issue thread are answered in this comment: resolved values are canonical, and team pins stay code-only.

Verification

Run locally on this branch:

npm test        -> 10 files, 50 tests passed
npx tsc --noEmit -> clean
npm run lint    -> 0 errors (3 pre-existing warnings)
npm run build   -> succeeded

The regression test was proven to fail with the old hardcoded write key restored (sabotage run: 3/3 failures), then pass with the fix.

Follow-up fix for the owner's P1 review: canWarmQueryVariant() in lib/prefs.ts skips the client warm when a cookie supplies a variant the query does not express, so captured bytes cannot be stored under a key whose OG render differs. Three tests cover the cookie-team, cookie-country and fully-expressed cases.

Disclosure

  • AI-assisted: authored with Hermes Agent. A second-context independent review found the implicit-flag / team-only parity gap described above; it was fixed and re-verified before this PR.
  • No secrets, tokens, or credentials are in the diff. No repository settings changed, no merge performed.
  • Not verified here: no production deployment, no real R2 write (the tests mock the store), no browser E2E of html-to-image capture, and CI had not run when this PR was opened. CI state will be reported from live checks, not assumed.

Risk and exclusions

Low risk: key derivation only; no render tree, styling, or auth path changed. The plain cardpng:v10:<login>:: key is unchanged, so existing embeds and the server warmer keep working. Existing cached variants under old raw-string keys are not migrated; they will be re-warmed on next view. No drive-by cleanup, no marketing files touched. The separate security issue #3 is intentionally out of scope.

@LangerSword LangerSword left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verdict: no blocking issue found.

Repo: LangerSword/gitone. PR #17: warm pinned card variants under the key the card route reads. Head: ca900ea.

I read all six changed files at the PR head, the issue #5 thread, and current origin/main. I ran npm test -- --run (10 files, 47 tests pass) and npx tsc --noEmit (clean). I also restored the old hardcoded write key; 4 of the 5 new tests failed, so the regression tests bite. Live checks show test passing, with eslint and rook skipped.

The shared key helper is used on both routes. Country and team normalize to the same values for raw query strings and resolved page values. Invalid team input falls back to the plain key. The tests cover the default key, pinned flag and team, raw-vs-normalised parity, team-only parity, and plain-versus-variant separation.

One product question, not a blocker: the page can resolve country and team from cookies when the query is absent (app/[username]/page.tsx:105-111). WarmOnView sends only explicit query values (components/WarmOnView.tsx:67). A visitor with a stored team who opens ?country=nl can capture an FER livery into the :nl: key, while the OG route renders that key without a team. Skip the warm when a cookie-selected variant is not represented in the query, or decide that this case is acceptable. I did not see a test for it, and I am not treating it as a merge blocker.

The PR body still leaves "Route tests added" unchecked although the file adds five tests. Tick it when convenient.

Initial draft by me; final wording written with Hermes Agent.

@saswatdutta1310

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for running the sabotage check yourself. Noted: CI test passes, eslint and rook skipped, and the head is still ca900ea with no new commits.

On the cookie-selected variant question: calling it acceptable for this PR, with the reason recorded here. That mismatch is pre-existing — before this change WarmOnView sent only kind=card&login=..., so a reader with a stored FER livery already captured that rendered card into the plain :: key that the OG route renders without a team. This PR narrows warms to explicit query variants; it does not introduce the cookie case, and it makes the common no-query plain flow correct again. A proper fix would need the OG read path to know cookie prefs, which unfurlers never send, or would mean skipping client warming for every returning reader with a saved pref. That is a product decision larger than this key fix — happy to open a separate issue for it if you want.

Also noted on the stale checkbox: all five route tests are present in tests/card-variant-warm.test.ts; the acceptance line in the body is simply unticked. I have not edited the PR body since opening it.

@LangerSword LangerSword left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verdict: no_ship.

Repo: LangerSword/gitone. PR #17: warm pinned card variants under the key the card route reads. Head: ca900ea. This review supersedes my earlier COMMENT review; GitHub does not let me remove it.

What I checked: all six changed files at ca900ea, issue #5 thread, current origin/main, and the PR's three checks. I ran npm test -- --run (10 files, 47 tests pass) and npx tsc --noEmit (clean). I also restored the old hardcoded write key; 4 of the 5 new tests failed, so the regression tests bite. Live checks show test passing, with eslint and rook skipped.

Should fix before merge:

P1|components/WarmOnView.tsx:67|high|The warm URL carries only explicit query values, but the captured DOM can carry a cookie-selected variant. See the inline comment.

Non-blocking:

P3|PR body|low|The acceptance checklist leaves "Route tests added" unchecked although the file adds five tests. Tick it or explain why it stays open.

Test gap: the route tests compare key strings only. They do not compare stored bytes with what the OG route renders for that key. Add a case with a cookie-selected team plus a country-only query, and assert the warm is skipped or the stored bytes match the route's render input.

Initial draft by me; final wording written with Hermes Agent.

Comment thread components/WarmOnView.tsx Resolved
@saswatdutta1310

Copy link
Copy Markdown
Contributor Author

Addressed the P1 and P3 from your CHANGES_REQUESTED review.

P1: added canWarmQueryVariant() in lib/prefs.ts and wired it into app/[username]/page.tsx — the card warm is now skipped whenever a cookie supplies a country or team that the query does not also express. That removes the path where the DOM carried an FER livery into :nl:. Three new tests cover cookie-selected team with a country-only query, cookie-selected country with a team-only query, and the fully-expressed/no-pref cases.

P3: ticked the route-tests box, added the cookie-skip acceptance line, and updated the verification count to 50 tests in the PR body.

Fix commit 1fb0550 is pushed to the same branch; head is now 1fb0550. Local re-check: 50/50 tests, tsc clean, lint 0 errors, build green. Please re-review when you get a chance.

@LangerSword
LangerSword dismissed their stale review November 26, 2026 22:04

Addressed by head 1fb0550; approving the current delta.

@LangerSword LangerSword left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verdict: ship.

Repo: LangerSword/gitone. PR #17: warm pinned card variants under the key the card route reads. Head: 1fb0550.

I reviewed the new delta at 1fb0550. It adds canWarmQueryVariant and skips the client warm when a cookie-selected variant is absent from the query. That closes the P1 from my earlier review. I reran npm test -- --run (10 files, 50 tests pass) and npx tsc --noEmit (clean). Live checks at the old head had test passing and the two bot checks skipped; I found no new check report after the push.

I found nothing outside issue #5 scope in the six changed files. The key helper is used by both routes, normalisation is shared, the plain key stays separate, and the new warm-eligibility tests cover the cookie case. The unchecked test box in the PR body is the only remaining nit and does not affect the code.

Initial draft by me; final wording written with Hermes Agent.

@LangerSword
LangerSword merged commit 5d3dab6 into LangerSword:main Nov 26, 2026
3 checks passed
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.

Warm pinned card variants or stop advertising them

2 participants