hyf

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

commit f60e5cbf78be22df7275c165520882789634fd54
parent 072f69f74644b662a95c416f0c245b6240242c0e
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:53:16 +0000

core: implement product and substitution checks

Diffstat:
Asrc/hyf_application/match_checks.mojo | 26++++++++++++++++++++++++++
Mtests/test_application.mojo | 23+++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/hyf_application/match_checks.mojo b/src/hyf_application/match_checks.mojo @@ -0,0 +1,26 @@ +from std.collections import List + +from hyf_core.domain.eligibility import ConstraintAssessment, constraint_assessment +from hyf_core.domain.price import Price, price_compare, price_is_known +from hyf_core.domain.product import ProductRef, product_is_resolved, product_matches +from hyf_core.domain.quantity import Quantity, quantity_compare + + +def check_product( + need_product: ProductRef, lot_product: ProductRef, substitution_permitted: Bool +) raises -> ConstraintAssessment: + if not product_is_resolved(need_product) or not product_is_resolved(lot_product): + return constraint_assessment( + "product", "unknown", True, "product_unresolved" + ) + if product_matches(need_product, lot_product): + return constraint_assessment("product", "pass", True, "product_match") + if substitution_permitted: + return constraint_assessment( + "product", "unknown", True, "substitution_not_permitted" + ) + return constraint_assessment("product", "fail", True, "product_mismatch") + + +def semantic_score_can_rescue_product() -> Bool: + return False diff --git a/tests/test_application.mojo b/tests/test_application.mojo @@ -389,3 +389,26 @@ def test_index_supplied_lots_rejects_duplicates_and_conflicts() raises: with assert_raises(): _ = index_supplied_lots(conflict_ids, conflict_revs) assert_true(not duplicate_records_double_stock()) + + +from hyf_application.match_checks import ( + check_product, + semantic_score_can_rescue_product, +) +from hyf_core.domain.product import resolved_product, unresolved_product + + +def test_product_and_substitution_check() raises: + var tomato = resolved_product("tomatoes", "tomato") + var roma = resolved_product("roma tomatoes", "tomato") + pass_check = check_product(tomato, roma, False) + assert_equal(pass_check.result, "pass") + var carrot = resolved_product("carrots", "carrot") + fail_check = check_product(tomato, carrot, False) + assert_equal(fail_check.result, "fail") + assert_equal(fail_check.reason, "product_mismatch") + var substitution = check_product(tomato, carrot, True) + assert_equal(substitution.result, "unknown") + var unknown = check_product(unresolved_product("mystery"), roma, False) + assert_equal(unknown.result, "unknown") + assert_true(not semantic_score_can_rescue_product())