hyf

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

commit 072f69f74644b662a95c416f0c245b6240242c0e
parent 17fe887d4406f9a5bdf6da047f7790f9e74ec62c
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:52:54 +0000

core: validate and index supplied lots

Diffstat:
Asrc/hyf_application/match_index.mojo | 36++++++++++++++++++++++++++++++++++++
Mtests/test_application.mojo | 35+++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/hyf_application/match_index.mojo b/src/hyf_application/match_index.mojo @@ -0,0 +1,36 @@ +from std.collections import List + + +def index_supplied_lots( + lot_ids: List[String], revisions: List[String] +) raises -> List[String]: + if len(lot_ids) != len(revisions): + raise Error("lot ids and revisions must align") + if len(lot_ids) == 0: + raise Error("matching requires at least one supplied lot") + var keys = List[String]() + var seen_ids = List[String]() + var seen_revisions = List[String]() + for index in range(len(lot_ids)): + var lot = String(lot_ids[index]) + var rev = String(revisions[index]) + if String(lot).strip().byte_length() == 0 or String(rev).strip().byte_length() == 0: + raise Error("supplied lot requires id and revision") + var key = lot + "@" + rev + for existing in keys: + if existing == key: + raise Error("duplicate supplied lot revision: " + key) + var id_seen = False + for known in seen_ids: + if known == lot: + id_seen = True + if id_seen: + raise Error("conflicting revisions for lot: " + lot) + seen_ids.append(String(lot)) + seen_revisions.append(String(rev)) + keys.append(String(key)) + return keys^ + + +def duplicate_records_double_stock() -> Bool: + return False diff --git a/tests/test_application.mojo b/tests/test_application.mojo @@ -354,3 +354,38 @@ def test_match_input_scope_and_lot_validation() raises: with assert_raises(): _ = validate_supplied_lots(dupes) assert_true(not caller_name_is_authentication()) + + +from hyf_application.match_index import ( + duplicate_records_double_stock, + index_supplied_lots, +) + + +def test_index_supplied_lots_rejects_duplicates_and_conflicts() raises: + var ids = List[String]() + ids.append("lot-1") + ids.append("lot-2") + var revisions = List[String]() + revisions.append("l1") + revisions.append("l1") + assert_equal(len(index_supplied_lots(ids, revisions)), 2) + + var dup_ids = List[String]() + dup_ids.append("lot-1") + dup_ids.append("lot-1") + var dup_revs = List[String]() + dup_revs.append("l1") + dup_revs.append("l1") + with assert_raises(): + _ = index_supplied_lots(dup_ids, dup_revs) + + var conflict_ids = List[String]() + conflict_ids.append("lot-1") + conflict_ids.append("lot-1") + var conflict_revs = List[String]() + conflict_revs.append("l1") + conflict_revs.append("l2") + with assert_raises(): + _ = index_supplied_lots(conflict_ids, conflict_revs) + assert_true(not duplicate_records_double_stock())