Remove the rounding hook that bypasses the quote cap
An inherited calculate method calls a reseller override after the cap check. That override recomputes the discount, so the supposed fixed algorithm no longer enforces its own invariant.
- Focused work estimate
- 3h + prerequisites
- Priority in the scenario
- High
- Engineering practice
- Inheritance refactoring · Domain invariants · Regression analysis
Estimated field mix
- Backend70%
- Quality engineering30%
Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.
Pattern topics
- Template MethodRefactor
Constrain or replace the inherited algorithm hooks so a reseller extension cannot undo a discount cap after validation.
- StrategyApply
Move the variable discount calculation into a narrow composed operation whose result is checked by the common quoting pipeline.
Review it, then add it to your workspace.
The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.
Project context
A fictional equipment-rental service supports direct customers and two reseller contracts. Pricing now lives in a long conditional with subclasses left over from a discontinued campaign. Build a local TypeScript quoting module and synthetic fixtures; no starter repository, real charges, tax advice, or payment connection is supplied. Amounts use integer cents and the exercise supports USD only.
Setup prerequisites
- Pure functions
- Object composition
- Integer arithmetic
Preceding work
Complete these dependencies, or supply their agreed outputs before taking this ticket.
- PPOLICY-101 · Capture the reseller examples before splitting the pricing branch
- PPOLICY-102 · Stop incomplete quote requests reaching the calculator
- PPOLICY-103 · Add a capped volume contract without editing the existing rules
- PPOLICY-104 · Share quote assembly between the portal and nightly import
- PPOLICY-105 · Keep calculation and explanation revisions in the same contract family
Acceptance criteria
- Make the order explicit: validate, evaluate the selected rule, apply its declared cap, then derive the final amount and explanation.
- No extension point can change the applied amount after the final invariant check.
- Replace the unsafe Template Method hook with a narrower composed operation or justify a sealed algorithm with constrained inputs.
Implementation constraints
- Preserve published rule revision behavior where valid; represent the defective synthetic revision explicitly instead of rewriting issued quote fixtures.
Verification to include
- Reproduce the subclass cap bypass and show the corrected pipeline respects the cap.
- Supply an extension returning a negative or over-subtotal discount and verify a typed failure.
Deliverables
- Pipeline refactor and cap-bypass regression
Rollout and recovery
Compare old and corrected revision outputs in a local replay; activate a new revision only after listing intentional differences.
Value of the work
For the engineer: Practice choosing, testing, and removing object-design abstractions around versioned business rules and tenant isolation.
For the team: Review changes that let a team introduce a contract without silently changing existing quotes, together with the maintenance costs of the chosen design.
Evidence boundaries
Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.
Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.