|
1 | 1 | """NullRun Platform SDK. |
2 | 2 |
|
| 3 | +v3.28 / 0.14.0 (2026-07-23) — hardening pass on the money contract. |
| 4 | +
|
| 5 | +Closes the four review gaps from the Phase 1.1 / UX follow-up: |
| 6 | +
|
| 7 | + 1. **Dedicated error types** -- ``InvalidMoneyPrecisionError`` |
| 8 | + and ``InvalidMoneyAmountError`` (both subclass |
| 9 | + ``ValueError`` for backward compat). The ``amount`` variant |
| 10 | + carries a ``reason`` discriminator (``"negative"`` / |
| 11 | + ``"overflow"`` / ``"non_finite"``) so a UI or test harness |
| 12 | + can branch on type without parsing the message. The |
| 13 | + ``precision`` variant carries ``currency`` / ``allowed`` / |
| 14 | + ``received`` / ``received_digits`` so the error message |
| 15 | + names the offending currency and precision. |
| 16 | +
|
| 17 | + 2. **Negative amount rejection** -- a negative ``amount_minor`` |
| 18 | + would silently fall through every ``op=gt`` predicate |
| 19 | + (``negative < positive`` is always False), so the SDK |
| 20 | + rejects ``Decimal("-50.00")`` / ``int(-5000)`` / |
| 21 | + ``Decimal("-5000")`` on both unit paths with |
| 22 | + ``InvalidMoneyAmountError(reason="negative", ...)``. ``0`` |
| 23 | + is accepted (legitimate $0.00 refund). |
| 24 | +
|
| 25 | + 3. **Sub-precision Decimal rejection** -- ``Decimal("1.234")`` |
| 26 | + against a USD ``allowed=2`` precision is now |
| 27 | + ``InvalidMoneyPrecisionError(currency="USD", allowed=2, |
| 28 | + received=3, received_digits="1.234")`` instead of a silent |
| 29 | + round to ``1.23`` that drops the high-order digit the user |
| 30 | + explicitly typed. ``float`` and ``Decimal`` are treated |
| 31 | + symmetrically; ``int`` always rounds 0-digits. |
| 32 | +
|
| 33 | + 4. **Explicit ``units`` discriminator + ``Decimal`` support** |
| 34 | + -- a new ``BusinessImpact`` model + ``MoneyImpactExtractor`` |
| 35 | + + ``@sensitive(impact=...)`` decorator wiring allows the |
| 36 | + caller to declare the impact currency / units on |
| 37 | + ``@sensitive``-decorated functions and have the SDK emit |
| 38 | + a structured ``business_impact`` envelope on the |
| 39 | + ``/track`` event, replacing the previous free-form |
| 40 | + ``details`` blob. ``Decimal`` values are accepted and |
| 41 | + normalised to ``Decimal`` minor-units on the wire. |
| 42 | +
|
| 43 | +Side fixes (covered by the same audit pass): |
| 44 | +
|
| 45 | + * ``/execute`` now handles ``require_approval`` correctly |
| 46 | + and re-checks with the ``approval_id`` returned by the |
| 47 | + backend (was dropping the approval handshake on |
| 48 | + round-trips). |
| 49 | + * Server's ``approval_timeout`` is clamped to ``[1, 3600]s`` |
| 50 | + on the SDK side as defence against a malformed / |
| 51 | + overshooting backend that returns ``0`` or ``2147483647`` |
| 52 | + in the Разрыв 1c field. |
| 53 | +
|
| 54 | +Public API change (additive only, backward-compatible): |
| 55 | +
|
| 56 | + * ``InvalidMoneyPrecisionError``, ``InvalidMoneyAmountError`` |
| 57 | + -- new ``ValueError`` subclasses with structured fields. |
| 58 | + * ``BusinessImpact`` -- new ``dataclass(frozen=True)`` model |
| 59 | + with explicit ``currency`` / ``units`` / ``amount_minor`` |
| 60 | + fields. ``details`` dict is still accepted (legacy path). |
| 61 | + * ``@sensitive(impact=BusinessImpact(...))`` -- new |
| 62 | + decorator kwarg. Existing ``@sensitive(details=...)`` / |
| 63 | + ``@sensitive(amount_minor=..., currency=...)`` callers keep |
| 64 | + working on the happy path (now routed through |
| 65 | + ``BusinessImpact`` internally). |
| 66 | +
|
| 67 | +Tests (existing suite still green; new test modules land in |
| 68 | +``tests/test_business_impact.py`` / |
| 69 | +``tests/test_units_discriminator.py`` / |
| 70 | +``tests/test_money_hardening.py`` / |
| 71 | +``tests/test_sensitive_extractor.py`` / |
| 72 | +``tests/test_approval_money_flow.py`` / |
| 73 | +``tests/test_execute_approval_flow.py``): |
| 74 | +
|
| 75 | + * 5 Definition-of-Done scenarios cover negative-amount |
| 76 | + rejection, sub-precision Decimal rejection, overflow |
| 77 | + rejection, non-finite rejection, ``0`` accepted. |
| 78 | + * Units discriminator test: ``USD`` vs ``USDT`` collision is |
| 79 | + now caught at the ``BusinessImpact`` boundary, not on the |
| 80 | + backend at ``/track`` time. |
| 81 | + * ``/execute`` round-trip test exercises the |
| 82 | + ``require_approval`` + ``approval_id`` re-check path with a |
| 83 | + stub backend. |
| 84 | + * Server ``approval_timeout`` clamp test verifies |
| 85 | + ``[1, 3600]s`` boundary. |
| 86 | + * 5 contract tests cover the ``MoneyImpactExtractor`` path |
| 87 | + end-to-end. |
| 88 | +
|
| 89 | +Verification (local): |
| 90 | +
|
| 91 | + * ``pytest tests/test_money_hardening.py |
| 92 | + tests/test_business_impact.py tests/test_units_discriminator.py |
| 93 | + tests/test_sensitive_extractor.py |
| 94 | + tests/test_approval_money_flow.py |
| 95 | + tests/test_execute_approval_flow.py`` -- all new tests |
| 96 | + pass; no regressions in the existing suite. |
| 97 | + * ``ruff check src/ tests/`` -- All checks passed. |
| 98 | + * ``mypy src/`` -- Success: no issues found in 34 source |
| 99 | + files. |
| 100 | +
|
| 101 | +No SDK_MIN_VERSION bump (legacy backends unaffected). No on-wire |
| 102 | +change (envelope shape preserved). New errors are ``ValueError`` |
| 103 | +subclasses, so legacy ``except ValueError:`` blocks still catch |
| 104 | +them. |
| 105 | +
|
| 106 | +--- |
| 107 | +
|
3 | 108 | v3.27 / 0.13.13 (2026-07-21) — Разрыв 1c SDK sync. |
4 | 109 |
|
5 | 110 | Backend commit ``0ad03b9`` (Разрыв 1c, gate hot-path trigger) |
|
0 commit comments