hyf

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

commit e34ba7dcbbecacd63645ee42eedfe663e0e2690a
parent 9c7fa5606ba4d9abd230eee2efeb4b057ad13372
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:49:07 +0000

core: interpret supply update operations

Diffstat:
Asrc/hyf_application/farm_changes.mojo | 33+++++++++++++++++++++++++++++++++
Mtests/test_application.mojo | 21+++++++++++++++++++++
2 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/hyf_application/farm_changes.mojo b/src/hyf_application/farm_changes.mojo @@ -0,0 +1,33 @@ +from std.collections import List, Optional + +from hyf_core.domain.supply_change import ProposedSupplyChange, proposed_change + + +def interpret_update_operation(verb: String) -> String: + var lowered = verb.lower() + if lowered == "another" or lowered == "more" or lowered == "added": + return "addition" + if lowered == "left" or lowered == "remaining": + return "remaining" + if lowered == "total": + return "replacement" + if lowered == "sold out" or lowered == "gone" or lowered == "withdrawn": + return "withdrawal" + if lowered == "actually" or lowered == "correction": + return "correction" + return "unresolved" + + +def interpret_update_change( + verb: String, target_kind: String, target_id: Optional[String] +) raises -> ProposedSupplyChange: + return proposed_change( + target_kind=target_kind, + target_id=target_id, + operation=interpret_update_operation(verb), + expected_revision=None, + ) + + +def operation_is_proposal() -> Bool: + return True diff --git a/tests/test_application.mojo b/tests/test_application.mojo @@ -82,3 +82,24 @@ def test_quantity_association_per_product_without_swap() raises: assert_true(not reported_quantity_is_unreserved_stock()) with assert_raises(): _ = associate_quantity("", 1, 0, "kg", "exact") + + +from hyf_application.farm_changes import ( + interpret_update_change, + interpret_update_operation, + operation_is_proposal, +) + + +def test_supply_update_operation_semantics() raises: + assert_equal(interpret_update_operation("another"), "addition") + assert_equal(interpret_update_operation("left"), "remaining") + assert_equal(interpret_update_operation("total"), "replacement") + assert_equal(interpret_update_operation("sold out"), "withdrawal") + assert_equal(interpret_update_operation("actually"), "correction") + assert_equal(interpret_update_operation("maybe"), "unresolved") + var addition = interpret_update_change("another", "listing", Optional[String]("b1")) + assert_equal(addition.operation, "addition") + var ambiguous = interpret_update_change("sold out", "listing", None) + assert_equal(ambiguous.operation, "unresolved") + assert_true(operation_is_proposal())