commit 1a3d20f47e13f01441f9b7375862603c71fff4c1
parent 91a45f720d9c6f33a64faefa61e5fcd125450fc2
Author: triesap <tyson@radroots.org>
Date: Mon, 21 Sep 2026 13:51:52 +0000
core: assemble reviewable typed buyer needs
Diffstat:
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/src/hyf_application/buyer_needs.mojo b/src/hyf_application/buyer_needs.mojo
@@ -0,0 +1,33 @@
+from std.collections import List
+
+from hyf_core.domain.demand import DemandLine
+from hyf_core.domain.execution import ExecutionMeta
+from hyf_core.domain.review import ReviewState
+
+
+@fieldwise_init
+struct BuyerNeedOutput(Copyable, Movable):
+ var demand_lines: List[DemandLine]
+ var review: ReviewState
+ var execution: ExecutionMeta
+
+
+def assemble_buyer_need(
+ lines: List[DemandLine], review: ReviewState, execution: ExecutionMeta
+) raises -> BuyerNeedOutput:
+ if len(lines) == 0:
+ raise Error("buyer need requires at least one demand line")
+ var copied = List[DemandLine]()
+ for line in lines:
+ copied.append(line.copy())
+ return BuyerNeedOutput(
+ demand_lines=copied^, review=review.copy(), execution=execution.copy()
+ )
+
+
+def needs_reparse_rewritten_text() -> Bool:
+ return False
+
+
+def buyer_need_creates_order() -> Bool:
+ return False
diff --git a/tests/test_application.mojo b/tests/test_application.mojo
@@ -283,3 +283,33 @@ def test_buyer_contradiction_detection() raises:
clean.append(condition("fulfillment", "mandatory", Optional[String]("delivery")))
clean.append(condition("fulfillment", "excluded", Optional[String]("pickup")))
assert_equal(len(detect_contradictions(clean)), 0)
+
+
+from hyf_application.buyer_needs import (
+ BuyerNeedOutput,
+ assemble_buyer_need,
+ buyer_need_creates_order,
+ needs_reparse_rewritten_text,
+)
+from hyf_core.domain.demand import DemandLine, demand_line
+from hyf_core.domain.execution import execution_meta
+from hyf_core.domain.product import resolved_product
+from hyf_core.domain.review import review_clear
+
+
+def test_assemble_reviewable_typed_buyer_need() raises:
+ var tomatoes = resolved_product("tomatoes", "tomato")
+ var conditions = List[Condition]()
+ conditions.append(condition("fulfillment", "mandatory", Optional[String]("delivery")))
+ var lines = List[DemandLine]()
+ lines.append(demand_line("l1", tomatoes, "known", 25, 0, conditions))
+ var output = assemble_buyer_need(
+ lines, review_clear(), execution_meta("complete", 0, None, None, None)
+ )
+ assert_equal(len(output.demand_lines), 1)
+ assert_true(not needs_reparse_rewritten_text())
+ assert_true(not buyer_need_creates_order())
+ with assert_raises():
+ _ = assemble_buyer_need(
+ List[DemandLine](), review_clear(), execution_meta("complete", 0, None, None, None)
+ )