Skip to content

fix(rider): disable extend-contract button before click when rider is at the cap - #3169

Merged
NicolaiDolmer merged 4 commits into
mainfrom
fix/3164-contract-extend-cap-ux
Jul 31, 2026
Merged

NicolaiDolmer merged 4 commits into
mainfrom
fix/3164-contract-extend-cap-ux

Conversation

@NicolaiDolmer

Copy link
Copy Markdown
Owner

Hvad

Rytter-kortets "Forlæng kontrakt"-knap er nu deaktiveret med forklarende tekst når rytteren allerede står på #3143-kontraktloftet (current season + 3), i stedet for at spilleren først opdager det efter et klik der altid ville fejle med 409 contract_extension_cap_reached.

Refs #3164

Hvorfor

178 ryttere på 14 rigtige hold står præcis på loftet i dag (#3143, merged 30/7). Alle 14 managere rammer samme mur hver gang de prøver at forlænge — Sentry CYCLINGZONE-45 havde 5 hændelser / 4 spillere på 17 timer, og det fortsætter indtil UI'et matcher backend-reglen.

Triage-anbefalingen (fra issuet): backend-drevet flag i stedet for at frontend gentager currentSeason + 3-regnestykket klientsidet (samme drift-klasse som #3071/#3081/#3150). Konkret implementering: RiderManageActions (rytterprofilen) og TeamPage's RiderActionModal (holdsidens administrationspanel) henter nu den EKSISTERENDE GET /riders/:id/extend-quote-route stille ved mount i stedet for ved klik. Rapporterer den contract_extension_cap_reached, deaktiveres knappen (rytterprofil) hhv. "Forlæng"-fanen (holdside) og en forklarende linje vises — loft-tallet (errorParams.maxSeason) kommer 100% fra backend, ingen ny regnestykke-duplikering i frontend. Ingen ny route, ingen DB-ændring.

Test plan

  • Frontend build: npm run build --prefix frontend passerer
  • Backend tests: npm test --prefix backend passerer (4713/4714; det ene fejl var lib/economyEngine.test.js som en isoleret worker-thread-deserialiseringsflake i test-runneren — kører 102/102 grønt i isolation, urelateret til denne PR)
  • Lint: npm run lint --prefix frontend passerer (kun 4 præeksisterende loadAll-warnings, ingen af dem i rørte filer)
  • pwsh -File scripts/verify-local.ps1 (backend+frontend tests + frontend build) grøn
  • npx playwright test core-smoke.spec.js — 27/27 grøn på tværs af alle 3 projekter (desktop-chromium, mobile-chromium, mobile-webkit)
  • i18n: i18n-check-keys.mjs / i18n-check-icu-braces.mjs / i18n-check-duplicate-keys.mjs grønne (nye manage.extend.capped / actionModal.extend.capped-nøgler i alle 4 locale-filer)
  • node scripts/check-patch-notes-version.js grøn (ny top-version 7.77)
  • Manuel: se Brugerverifikation nedenfor
  • Regression: eksisterende extend-quote/extend-contract-kontrakt-tests (backend/lib/riderActionsRoutes.test.js, backend/lib/contractSeed.test.js) uændrede og stadig grønne — [bug] Intet loft på gentagne kontraktforlængelser — lav løn kan låses til sæson 11+ (academy og senior) #3143-loftet er IKKE rørt, kun hvornår/hvordan frontend læser dets svar

Brugerverifikation (KRÆVET)

  • Jeg har åbnet feature i prod eller preview-deploy og bekræftet at brugere ser forventet UI/data
  • Jeg har testet som authenticated user (ikke kun service_role / admin)
  • Hvis ikke testet end-to-end: forklar hvorfor

Hvad jeg verificerede konkret: Jeg er en udførende agent uden interaktiv adgang til prod/preview i denne opgave, så jeg har IKKE klikket funktionen igennem i en levende browser som authenticated user. Verifikationen er: (1) Playwright core-smoke.spec.js kører autentificerede flows gennem rytterprofil + holdside uden regressions på tværs af 3 projekter, (2) de eksisterende backend-kontrakt-tests for extend-quote/extend-contract (409 + errorParams.maxSeason) er uændrede og grønne, (3) frontend-build + lint er rene. Ejeren bør selv åbne en rytter på loftet (fx en af de 178 ryttere nævnt i #3164) på både rytterprofilen og holdsidens "Administrér"-modal i preview/prod og bekræfte at "Forlæng kontrakt" viser sig deaktiveret med forklarende tekst i stedet for at kunne klikkes.

Risk / auto-merge

  • auto-merge er kun sat hvis PR'en er lav-risiko og ikke kræver menneskelig beslutning
  • Dependency/security-impact er vurderet hvis package*.json, workflows, auth, DB eller upload-flow ændres

Ingen DB/schema/route-ændringer. Ren frontend-UX-ændring der genbruger en eksisterende, allerede testet backend-route. Lav risiko, men lades ikke auto-merge da UI-ændringer bør ejer-godkendes visuelt (se Brugerverifikation).

Filer rørt

Skærmbillede / video

Ikke vedhæftet — ingen interaktiv browser-adgang til preview i denne opgave. Se Brugerverifikation-sektionen ovenfor for hvad ejeren bør tjekke visuelt.


Close-out (efter merge til main)

… at the cap

Riders at the #3143 contract-extension cap (current season + 3) still
showed a normal, clickable "Extend contract" button — the 178 riders
across 14 teams standing exactly on the cap all hit a 409 only AFTER
clicking, since backend was the only place that knew the rule.

RiderManageActions and TeamPage's RiderActionModal now prefetch the
existing extend-quote response silently on mount and disable the
button + show an explanatory line when it reports
contract_extension_cap_reached, instead of frontend re-deriving
"current season + 3" itself. The cap rule stays backend-only.

Refs #3164

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cycling-zone Ready Ready Preview Jul 31, 2026 11:35am

Request Review

@supabase

supabase Bot commented Jul 31, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project ghwvkxzhsbbltzfnuhhz because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@NicolaiDolmer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 441e2365-50d8-4ad4-8a11-82f6e604be4a

📥 Commits

Reviewing files that changed from the base of the PR and between df4d90c and f4594de.

📒 Files selected for processing (7)
  • frontend/public/locales/da/rider.json
  • frontend/public/locales/da/team.json
  • frontend/public/locales/en/rider.json
  • frontend/public/locales/en/team.json
  • frontend/src/components/rider/RiderManageActions.jsx
  • frontend/src/data/patchNotes.js
  • frontend/src/pages/TeamPage.jsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@NicolaiDolmer
NicolaiDolmer enabled auto-merge (squash) July 31, 2026 10:47
@github-actions

Copy link
Copy Markdown
Contributor

🟡 Lighthouse (advisory — blokerer ikke)

Lab-måling af den byggede frontend (frontend/dist, desktop-preset, median af 3 runs). Scores svinger ±et par point på CI-hardware og uden prod-env — brug dem til at fange STORE fald, ikke som facit. Bundle-size er den hard gate (separat step). Autoritativ perf-måling: ugentlig prod-run + field-CWV i GA4.

Kategori Score
Performance 98
Accessibility 96
Best Practices 96
SEO 100

Fuld rapport-URL i job-artifact lighthouse-results.

@NicolaiDolmer
NicolaiDolmer merged commit 129393d into main Jul 31, 2026
34 checks passed
@NicolaiDolmer
NicolaiDolmer deleted the fix/3164-contract-extend-cap-ux branch July 31, 2026 11:42
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deploy verificeret LIVE — 129393d

  • Vercel deploy: success
  • Railway deploy: skipped (no backend changes)
  • Backend /health = 200
  • Backend /api/auctions (no auth) = 401 (auth gates virker)
  • Frontend root = 200

Du kan trygt lukke telefonen — det er live.

NicolaiDolmer added a commit that referenced this pull request Aug 3, 2026
…ose race window (#3186) (#3218)

Sentry CYCLINGZONE-45 kept logging rejected rider_extend_quote attempts even
after #3169's "disable when capped" fix, because the trigger button/tab was
only disabled AFTER the async cap-check resolved - a player who clicked
during that in-flight window (slow mobile network, or just a fast tap)
still reached a doomed request. 5 of 10 Sentry events post-dated #3169.

- backend/lib/contractSeed.js: new pure helper contractExtensionCapInfo()
  derives "X/3 extensions used" from the rider's current contract_end_season
  and currentSeason, without frontend re-deriving the "+3" cap formula.
- backend/routes/api.js: GET/POST extend-quote and extend-contract now send
  extensionCap in every branch (allowed and 409), so the counter is visible
  before the player acts, not only after a rejection.
- frontend RiderManageActions.jsx + TeamPage.jsx: trigger button/tab is now
  disabled for the ENTIRE async cap-check (not just once capped=true),
  closing the race window, and render an always-visible "Extensions used:
  X/3" / "Forlængelser brugt: X/3" line (EN+DA) alongside the existing
  disabled+explanation state.

Refs #3186

Co-authored-by: Nicolai Dolmer <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
NicolaiDolmer added a commit that referenced this pull request Aug 3, 2026
…ation (#3172) (#3222)

* fix(ci): isolate economyEngine.test.js to stop worker-IPC flake

backend/lib/economyEngine.test.js is by far the largest backend test
file (100+ tests, 6500+ lines, ~250KB) and its per-worker result
payload appears large enough to trip a known Node test-runner bug
(nodejs/node#64061, root-caused and fixed upstream in
nodejs/node#64706, merged 2026-07-26 but not yet in our pinned Node
24.x line) when many other test-file workers stream results back to
the parent process concurrently. Isolated runs were always
102/102 (now 103/103) green; the flake only ever showed up in the
full suite (#3169-CI, #3171-CI).

Add backend/scripts/run-tests.js: runs economyEngine.test.js alone
first, then every other backend test file exactly as before (same
flags, same default concurrency) via explicit relative file paths so
the two passes never overlap. Wire both npm test (backend/package.json
- the one permitted package.json edit) and scripts/verify-local.ps1
(which called `node --test` directly, bypassing npm entirely) through
this script so CI and local pre-push runs get the same protection.

No dependency or lockfile changes. Verified with 5 consecutive
`npm test` runs locally (103/103 + 4773/4773 every time, exit 0).

Refs #3172
Co-Authored-By: Claude <[email protected]>

* docs(learnings): postmortem for economyEngine.test.js worker-IPC flake

Refs #3172
Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Nicolai Dolmer <[email protected]>
Co-authored-by: Claude <[email protected]>
NicolaiDolmer added a commit that referenced this pull request Aug 14, 2026
…rejection (#3597) (#3694)

Sentry CYCLINGZONE-45 kept logging rejected rider_extend_quote calls after
#3186 - 8 events / 7 users on 3-9 Aug, this time across Chrome desktop, Edge
and Firefox desktop, not only iOS. Round three of the same symptom.

Root cause: the frontend derived its whole blocked-state from one signal -
"have we been REJECTED?" (extendCapped, set only by a 409
contract_extension_cap_reached). #3164/#3169 moved that check earlier, #3186
closed its in-flight race window, but both rounds kept the rejection-derived
flag as the only gate. Any state transition that leaves extendCapped === false
while capacity is actually 0 reopens the hole - and an ordinary successful
extension does exactly that: confirmExtend()'s success branch drops the used
quote (setExtendQuote(null)) and never touches extendCapped, while the mount
check is keyed on [rider.id], which does not change. If that extension consumed
the last allowed season, the button went gold and clickable again on a rider
whose next extend-quote is guaranteed to 409. One click, one Sentry event -
deterministic, hence the browser spread.

#3186 had already added extensionCap to the success branch, so the client knew
there were 0 left and displayed "Extensions used 3/3" - the number was just
never wired to the button.

- frontend/src/lib/extendCapGate.js: shared pure gate that blocks on the
  POSITIVE capacity number the backend already sends in every branch
  (extensionCap.remainingExtensions), with extendCapped as a fallback for
  responses that carry no extensionCap. A missing/null field means "unknown",
  not "0 left", so a response without the counter cannot deadlock the button.
- RiderManageActions.jsx + TeamPage.jsx gate on that same function, so the two
  surfaces cannot diverge again.
- RiderManageActions.jsx also resets extend state on rider change: the
  component is not remounted when navigating /riders/A -> /riders/B, so rider B
  used to inherit A's quote (panel showing A's salary terms) and A's
  extendCapped (B's button locked forever).
- openExtend()'s error branch now locks on a 409 too, as confirmExtend()
  already did.

Regression cover: rider-extend-cap-after-success.spec.js walks the player's
path (extend a rider with one extension left, require the button locked
afterwards, counter at 3/3, explanation visible, and no extend-quote reaching
the backend). Verified as a negative control - it fails against the old
disabled={extendCapped || extendLoading}. extendCapGate.test.js proves the gate
itself plus the contract that both surfaces use it.

No backend changes and no migrations - the extensionCap contract shipped with
#3186 and is now used as intended.

Postmortem: .claude/learnings/2026-08-14-extend-cap-gate-derived-from-rejection-not-capacity.md

Refs #3597

Co-authored-by: Nicolai Dolmer <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — f4594def Deployed Jul 31, 2026 by vercel[bot]
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