Skip to content

feat(stats): make milestone computation pluggable via strategy#308

Merged
Amund211 merged 1 commit into
mainfrom
feat/pluggable-milestone-strategy
Jun 30, 2026
Merged

feat(stats): make milestone computation pluggable via strategy#308
Amund211 merged 1 commit into
mainfrom
feat/pluggable-milestone-strategy

Conversation

@Amund211

Copy link
Copy Markdown
Owner

Summary

Extracts the milestone-value selection in computeStatProgression into a pluggable MilestoneStrategy(value, trendingUpward, stat) => number — while leaving the time-to-reach math (cubic solver for index, linear algebra for ratios, etc.) untouched.

The built-in nextNaturalMilestone reproduces today's behavior exactly: next prestige for stars, next whole number for fkdr/kdr, next round number scaled to order of magnitude for everything else. It's wired as an optional trailing param on computeStatProgression (defaulting to nextNaturalMilestone), so callers can swap in a different scheme without touching the solvers.

Contract: a strategy must return a value strictly greater than value when trending up, and strictly less when trending down — the solvers rely on this to keep daysUntilMilestone non-negative and correctly signed.

Why

We want to be able to choose different milestone schemes in different places — in particular snappier, finer-grained milestones, which we'll use in #256. This PR is just the pluggable seam (the default preserves current behavior); the alternate "snappier" strategy and where it gets selected land in #256.

Tests

Built red-green; two new test families in progression.unit.test.ts:

  • nextNaturalMilestone unit tests — stars/quotient/round-number, up & down, power-of-ten boundaries, non-positive clamp, and a strict-monotonic contract check.
  • Strategy injection tests on computeStatProgression — assert the injected strategy receives the expected (value, trendingUpward, stat) per stat type (including the dividend key finalKills in the infinite-ratio path), and that its returned milestone is respected for simple linear / quotient / index / stars cases (with daysUntilMilestone recomputed accordingly).

pnpm test:unit562 passing (34 new; the prior suite is unchanged and green, confirming the default preserves behavior). pnpm tsc and oxlint/oxfmt clean on the changed files.

🤖 Generated with Claude Code

Extract the milestone-VALUE choice in computeStatProgression into a
pluggable MilestoneStrategy (value, trendingUpward, stat) => number,
leaving the time-to-reach math untouched. The built-in
nextNaturalMilestone reproduces today's behavior exactly: next prestige
for stars, next whole number for fkdr/kdr, next round number otherwise.

The strategy is an optional param on computeStatProgression (defaulting
to nextNaturalMilestone) so callers can swap in different milestone
schemes per place.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 30, 2026 19:31
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rainbow with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92b5181
Status: ✅  Deploy successful!
Preview URL: https://602cc685.rainbow-ctx.pages.dev
Branch Preview URL: https://feat-pluggable-milestone-str.rainbow-ctx.pages.dev

View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes milestone target selection in computeStatProgression pluggable via a MilestoneStrategy callback, while keeping the existing time-to-reach solvers unchanged. It introduces a default nextNaturalMilestone strategy intended to preserve existing milestone behavior and adds unit tests covering both the default strategy and strategy injection.

Changes:

  • Added MilestoneStrategy and default nextNaturalMilestone, and threaded an optional strategy parameter through computeStatProgression (and internal quotient/index paths).
  • Replaced hard-coded milestone selection logic for quotient, index, stars, and linear counters with calls to the strategy.
  • Added new unit tests for nextNaturalMilestone and for strategy injection behavior in computeStatProgression.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/stats/progression.ts Introduces MilestoneStrategy/nextNaturalMilestone and applies the strategy throughout milestone selection in progression computations.
src/stats/progression.unit.test.ts Adds unit tests for the default milestone strategy and for injected-strategy behavior in computeStatProgression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/stats/progression.ts
Comment thread src/stats/progression.ts
Comment thread src/stats/progression.unit.test.ts
Comment thread src/stats/progression.ts
@Amund211 Amund211 merged commit bacdd87 into main Jun 30, 2026
9 checks passed
@Amund211 Amund211 deleted the feat/pluggable-milestone-strategy branch June 30, 2026 19:39
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