Commit 91bf0c5
fix(ai): clamp a negative balance, refresh stale comments, test the formatters (PR #34 review)
All three review points were real.
1. creditBalance() could render a negative ("-2 left"). An overage pushes the
remaining balance below zero in the ledger, and the dollar formatter this
replaced clamped at $0.00 — that clamp was lost in the port. Restored.
(The same comment also flagged creditCost() rounding sub-0.05 costs to "0";
that half was already fixed in 7d6c711, which added the "<0.1" floor.)
2. The comment block above the helpers still described the deleted money()
behaviour ("$0.00" / "<$0.01"), and the response-bar comment still read
"model · $cost · $left". Both now describe credits.
3. The helpers had no tests, in a repo that already extracts and tests shipped
chat.html functions. Added creditFormat.test.js on the narrativeUi/shHighlight
pattern — it EXTRACTS the real functions from chat.html rather than copying
them, and asserts MICROS_PER_CREDIT is still 10000 so the editor can't drift
from the website's conversion. To make extraction work, toCredits and
creditBalance became multi-line (the convention slices to "\n }").
Verified: 23 suites, 0 failures; creditFormat is 7 cases. Both fixes are
mutation-checked — removing the clamp fails, and restoring the unary + fails.
The suite also caught an arithmetic error in my own first draft ($0.70 is 70
credits, not 7.0), which is a fair advertisement for the reviewer's point.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7d6c711 commit 91bf0c5
2 files changed
Lines changed: 124 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2419 | 2419 | | |
2420 | 2420 | | |
2421 | 2421 | | |
2422 | | - | |
2423 | | - | |
2424 | | - | |
2425 | | - | |
2426 | | - | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
2427 | 2426 | | |
2428 | | - | |
2429 | | - | |
2430 | | - | |
2431 | | - | |
2432 | | - | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
2433 | 2442 | | |
2434 | 2443 | | |
2435 | 2444 | | |
2436 | 2445 | | |
2437 | | - | |
2438 | | - | |
2439 | | - | |
2440 | 2446 | | |
2441 | 2447 | | |
2442 | 2448 | | |
2443 | | - | |
| 2449 | + | |
2444 | 2450 | | |
2445 | 2451 | | |
2446 | 2452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
0 commit comments