Skip to content

fix(plans): prefill non-preset weekly and monthly ramps as custom in Edit - #1183

Merged
cristim merged 1 commit into
mainfrom
fix/edit-prefill-custom-ramp
Oct 20, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/edit-prefill-custom-ramp

Conversation

@cristim

@cristim cristim commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #1156

Opening Edit on a plan whose stored ramp is weekly at a percent other than 25 (or monthly other than 10) pre-selected Immediate. The inline preview then showed one step, and Save would have rewritten the plan's ramp to immediate.

21da8497 replaces the inline if-chain in editPlan with a small pure helper, rampRadioValue, and a PRESET_RAMPS table:

  • an immediate ramp maps to Immediate;
  • a ramp maps to a preset radio only if its type, percent and interval all match (weekly-25pct = weekly/25/7, monthly-10pct = monthly/10/30, from internal/config/types.go:272-283);
  • everything else maps to Custom, with the stored percent and interval pre-filled.

Round-trip check against the backend

buildRampSchedule / buildCustomRampSchedule (internal/api/types.go:~850-891) compute custom steps as int(100/pct). Next-execution and step dates depend only on percent and interval, the same as for the presets. A weekly 20%/7d plan saved as custom keeps 5 steps on the same dates, and monthly 5%/30d keeps 20.

The inline preview (plan-schedule-intent.ts:30, Math.floor) already counts steps the same way as the backend (internal/api/types.go:882). The only Math.ceil is in generatePlanName (plans.ts:1882), which affects only the auto-generated name of a new plan whose percent does not divide 100.

Tests

test.each over 7 stored ramps (radio, custom fields, preview steps):

Stored ramp Radio Custom fields Preview steps
weekly 20%/7d custom 20, 7 5
monthly 5%/30d custom 5, 30 20
weekly 25%/14d custom 25, 14 4
monthly 10%/15d custom 10, 15 10
weekly 25%/7d weekly-25pct - 4
monthly 10%/30d monthly-10pct - 10
immediate immediate - 1

Verification evidence is posted as PR comments.

🤖 Generated with Claude Code

…Edit

Edit mapped a stored ramp to a preset radio by type and percent only, and
sent every other weekly or monthly ramp (e.g. weekly 20%, monthly 5%) to
"immediate", so the form and preview showed one step and Save would have
rewritten the schedule. A ramp now matches a preset only when type, percent
and interval all match; every other non-immediate ramp is prefilled as custom
with its stored percent and interval.

Closes #1156

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cristim cristim added effort/xs Trivial / one-liner impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm type/bug Defect urgency/this-sprint Within the current sprint labels Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 1 second for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 65ea77e0-d1fd-44d4-841e-0fd4467b275b
📥 Commits

Reviewing files that changed from the base of the PR and between 5a95420 and 21da849.

📒 Files selected for processing: 3
  • frontend/src/__tests__/plans.test.ts
  • frontend/src/plans.ts
  • frontend/tests-e2e/plan-schedule-preview.spec.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Merge gate at 21da8497b5ed1116bbc191c0f1055c18c7f59ddf

Two independent reviewers (cold brief, non-author) both approve 21da8497.

Review 1: APPROVE

Checked against the backend source of truth:

  • the presets (internal/config/types.go:272-283);
  • buildCustomRampSchedule (int(100/pct));
  • GetNextPurchaseDate;
  • the Save serialization for each radio.

Every mapping case was traced:

  • non-preset weekly/monthly ramps map to Custom with the stored values;
  • exact presets map to their preset radios;
  • immediate maps to Immediate whatever the percent;
  • a stored custom ramp with preset-equal values stays Custom;
  • an unknown or missing type maps to Custom.

Mutations:

  • Killed: interval check dropped, percent check dropped, preset interval changed, immediate early return removed, the old fallback to immediate restored.
  • Survived (nits, no test mixes them): the type check, and the || 20 prefill fallback.

Medium finding, not a regression, filed as #1184: Save keeps percent and interval but stores custom, so rampScheduleShapeUnchanged refuses even a rename of an in-progress plan with 409. Before this PR the same plans also got 409, because the form sent immediate.

Review 2: APPROVE

  • Bug reproduced: recreating the old logic makes 4 of the 7 new cases fail.
  • Preview: it follows the prefill (5, 20, 4, 10, 4, 10 and 1 steps).
  • e2e: the Edit case is meaningful.
  • PR body corrected: the preview already floors like the backend; only generatePlanName rounds up.
  • List-label mismatch: filed as fix(plans): plan list ramp label ignores percent/interval and disagrees with Edit #1185. The plans list labels a stored weekly 20% plan as "Weekly 20%" while Edit shows Custom.
  • Nit: the custom panel's show/hide is not asserted.

Local verification (macOS, exact head)

  • npm ci, npm run build, npm run lint (0 errors) and npx jest pass: 109 suites, 3469 passed, 1 skipped.
  • tests-e2e/plan-schedule-preview.spec.ts passes 6/6, including a new Edit case for a weekly 20% plan.

CI: green at this SHA. Threads: none open. CodeRabbit is waived as a merge gate.

@cristim
cristim merged commit 3b420c3 into main Oct 20, 2026
27 checks passed
@cristim
cristim deleted the fix/edit-prefill-custom-ramp branch October 20, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(plans): Edit pre-selects Immediate for weekly/monthly ramps with non-preset percents

1 participant