Commit 4aea625
committed
fix(calc): reject weight-unit and NaN finenesses instead of silently haircutting (om-t0fs)
Adversarial review, two CONFIRMED findings — both the same silent-garbage class
this bead already fixed for the 1.0 = full-melt case.
Finding 2 — a DECIMAL point laundered a weight into a junk haircut. The weight
rule only guarded BARE numbers, but "0.4 oz" / ".9 oz" have a decimal point, so
finenessFraction treated them as marked and discarded the trailing unit as
annotation: "0.4 oz" -> 0.40 -> 40% bucket -> factor 0.80 (main returned 1.0),
silently, no anomaly. "40 grain" was protected; "0.4 oz" was not — inconsistent
by construction. Now a weight-unit token (oz, ozt, g, gram(s), gr, grain(s))
ANYWHERE in the tail makes the whole string unparseable, marked or not, so it
takes the conservative branch AND raises the fineness anomaly. Non-unit
annotation is untouched: ".900 coin", "90% (worn)", "80% (CAD)", "22k .9167"
still parse.
Finding 4 — NaN escaped the range check. ParseFloat("nan") is a valid NaN, not
an error, and `f <= 0 || f > 1` is false for NaN (every comparison is), so
"nan%" classified as a parsed fraction -> factor 1.0, no anomaly. Inverted the
accept test to `!(f > 0 && f <= 1)`, which is true for NaN and +Inf, routing
both to conservative + anomaly.
Tests: +TestWeightUnitFinenessIsAnomaly (weight strings + nan% -> conservative
factor AND one fineness anomaly each), +TestMarkedFinenessAnnotationStillParses
(the over-rejection boundary: marked finenesses with non-unit annotation still
parse, no anomaly), plus cases in the finenessFraction and buybackFactor tables.
No existing test weakened.
AC7 unchanged: /api/summary over sample-data is byte-identical to the pre-review
branch, and vs main still differs only by the additive "anomalies": [].1 parent 94d1987 commit 4aea625
2 files changed
Lines changed: 109 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
234 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
235 | 248 | | |
236 | 249 | | |
237 | 250 | | |
| |||
283 | 296 | | |
284 | 297 | | |
285 | 298 | | |
286 | | - | |
287 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
288 | 306 | | |
289 | 307 | | |
290 | 308 | | |
291 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
292 | 323 | | |
293 | 324 | | |
294 | 325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
458 | 468 | | |
459 | 469 | | |
460 | 470 | | |
| |||
533 | 543 | | |
534 | 544 | | |
535 | 545 | | |
| 546 | + | |
| 547 | + | |
536 | 548 | | |
537 | 549 | | |
538 | 550 | | |
539 | 551 | | |
540 | 552 | | |
541 | 553 | | |
542 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
543 | 567 | | |
544 | 568 | | |
545 | 569 | | |
| |||
641 | 665 | | |
642 | 666 | | |
643 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
0 commit comments