Skip to content

Demo: simplify money() with round() — CI catches a half-cent bug - #6

Draft
NailKarimov wants to merge 1 commit into
mainfrom
demo/simplify-money-rounding
Draft

NailKarimov wants to merge 1 commit into
mainfrom
demo/simplify-money-rounding

Conversation

@NailKarimov

@NailKarimov NailKarimov commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Important

This is a demo pull request. It stays open on purpose and is never merged.
It shows how the suite and CI react to a realistic change that looks harmless in review.

The change

money() rounds every amount to cents. This PR "simplifies" it:

-    return value.quantize(CENT, rounding=ROUND_HALF_UP)
+    return round(value, 2)

It reads as a clean refactor, the linters and mypy pass, and the diff is three lines. But Python's round() on a
Decimal uses banker's rounding (half to even), while a till rounds half up. Every amount that ends in
exactly half a cent now rounds the other way.

What the tests say

  • 76 of 77 tests pass, including every hand-written pricing test: none of their baskets has an exact half cent.
  • The Hypothesis oracle test fails. It generates thousands of baskets and compares the service with an
    independent implementation of the price rules. It shrinks the failure to the smallest case:
    two items at 0.01 with the SAVE25 coupon. 25 % of 0.02 is 0.005: the oracle gives a 0.01 discount, the service now
    gives 0.00, and the customer pays 5.01 instead of 5.00.

Where to look

  1. Checks tab: the test job is red; its summary has the verdict and the failing test, and the annotation
    points at the line of the test that caught it, with the shrunk example.
  2. The comment below, written by CI: passed, failed, time, and the shrunk example.

Planted bug M1 in scripts/mutants.py is the same mistake; the mutation check
shows that only the property-based test catches it.

Decision

Do not merge. Keep quantize(CENT, rounding=ROUND_HALF_UP).


Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwMkm9aNCkt1zWgTtAG3xw
@NailKarimov NailKarimov added demo Kept open on purpose to show CI behaviour; never merged do not merge Must not be merged labels Oct 26, 2026 — with Claude
@github-actions

Copy link
Copy Markdown

Test results

❌ Do not merge

Passed Failed Skipped Time
76 1 0 11.8 s
Failed test Where First assertion line
test_pricing::test_service_pricing_agrees_with_the_independent_oracle tests/property/test_pricing.py:61 basket: [('0.01', 2)], coupon: SAVE25 · service: {'items': '0.02', 'discount': '0.00', 'shipping': '4.99', 'total': '5.01'} · oracle: {'items': '0.02', 'discount': '0.01', 'shipping': '4.99', 'total': '5.00'}

Full log and Hypothesis output: run 40409112932.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

demo Kept open on purpose to show CI behaviour; never merged do not merge Must not be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants