hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit 40206b4f63e4dd3f7def1267f2a677a3d1676a0d
parent 5747fc98cf717c5064d6acc1e403baa444466053
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:01:02 +0000

core: add authoritative supply snapshot views

Diffstat:
Asrc/hyf_core/domain/snapshot.mojo | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/test_domain.mojo | 18++++++++++++++++++
2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/src/hyf_core/domain/snapshot.mojo b/src/hyf_core/domain/snapshot.mojo @@ -0,0 +1,52 @@ +from hyf_core.domain.product import ProductRef +from hyf_core.domain.units import unit_dimension + + +@fieldwise_init +struct SupplySnapshot(Copyable, Movable): + var lot_id: String + var revision: String + var supplier_id: String + var product: ProductRef + var unreserved_state: String + var unreserved_value: Int + var unreserved_scale: Int + var unit: String + var dimension: String + + +def supply_snapshot( + lot_id: String, + revision: String, + supplier_id: String, + product: ProductRef, + unreserved_state: String, + unreserved_value: Int, + unreserved_scale: Int, + unit: String, +) raises -> SupplySnapshot: + if lot_id.strip() == "" or revision.strip() == "" or supplier_id.strip() == "": + raise Error("snapshot requires lot id, revision and supplier id") + if unreserved_state != "known" and unreserved_state != "unknown": + raise Error("unreserved state must be 'known' or 'unknown'") + if unreserved_scale < 0 or unreserved_scale > 9: + raise Error("unreserved scale must be between 0 and 9") + return SupplySnapshot( + lot_id=String(lot_id), + revision=String(revision), + supplier_id=String(supplier_id), + product=product.copy(), + unreserved_state=String(unreserved_state), + unreserved_value=unreserved_value, + unreserved_scale=unreserved_scale, + unit=String(unit), + dimension=String(unit_dimension(unit)), + ) + + +def snapshot_unreserved_known(snapshot: SupplySnapshot) -> Bool: + return snapshot.unreserved_state == "known" + + +def snapshot_identity(snapshot: SupplySnapshot) -> String: + return snapshot.lot_id + "@" + snapshot.revision diff --git a/tests/test_domain.mojo b/tests/test_domain.mojo @@ -449,3 +449,21 @@ def test_demand_lines_and_condition_strength() raises: assert_true(not missing_information_is_prohibition()) with assert_raises(): _ = condition("grade", "maybe", Optional[String]("x")) + + +from hyf_core.domain.snapshot import ( + SupplySnapshot, + snapshot_identity, + snapshot_unreserved_known, + supply_snapshot, +) + + +def test_supply_snapshot_revisions_and_unknown_unreserved() raises: + var tomatoes = resolved_product("Roma tomatoes", "tomato.roma") + var known = supply_snapshot("lot-1", "l1", "farm-1", tomatoes, "known", 50, 0, "kg") + var other_revision = supply_snapshot("lot-1", "l2", "farm-1", tomatoes, "known", 30, 0, "kg") + assert_true(snapshot_unreserved_known(known)) + assert_true(snapshot_identity(known) != snapshot_identity(other_revision)) + var unknown = supply_snapshot("lot-2", "l1", "farm-1", tomatoes, "unknown", 0, 0, "kg") + assert_true(not snapshot_unreserved_known(unknown))