hyf

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

max_local_operator_smoke.mojo (3143B)


      1 from std.sys import argv
      2 
      3 from json import Value
      4 
      5 from hyf_assist.contract import max_local_query_rewrite_route
      6 from stdio_process_helper import run_stdio_entrypoint
      7 
      8 comptime _CONFIG_EQUALS_PREFIX = "--config="
      9 comptime _CONFIG_EQUALS_PREFIX_BYTE_LENGTH = 9
     10 
     11 
     12 def _has_key(value: Value, key: String) -> Bool:
     13     for candidate in value.object_keys():
     14         if candidate == key:
     15             return True
     16     return False
     17 
     18 
     19 def _require_config_path() raises -> String:
     20     var raw_args = argv()
     21     var index = 1
     22     while index < len(raw_args):
     23         var arg = String(raw_args[index])
     24         if arg == "--config":
     25             if index + 1 >= len(raw_args):
     26                 raise Error("--config requires a path")
     27             var value = String(String(raw_args[index + 1]).strip())
     28             if value == "" or value.startswith("-"):
     29                 raise Error("--config requires a path")
     30             return value^
     31         if arg.startswith(_CONFIG_EQUALS_PREFIX):
     32             var value = String(
     33                 String(arg[byte = _CONFIG_EQUALS_PREFIX_BYTE_LENGTH :]).strip()
     34             )
     35             if value == "":
     36                 raise Error("--config requires a path")
     37             return value^
     38         raise Error("unknown smoke argument '" + arg + "'")
     39     raise Error("MAX-local smoke requires --config <path>")
     40 
     41 
     42 def _smoke_request_json() -> String:
     43     return (
     44         '{"version":1,'
     45         '"request_id":"max-local-operator-smoke-1",'
     46         '"trace_id":"max-local-operator-smoke-1",'
     47         '"capability":"query_rewrite",'
     48         '"context":{"execution_mode_preference":"assisted","return_provenance":true,"deadline_ms":15000},'
     49         '"input":{"query":"local apples pickup this weekend"}}'
     50     )
     51 
     52 
     53 def _assert_successful_provider_response(response: Value) raises:
     54     if not response["ok"].bool_value():
     55         raise Error("MAX-local smoke response was not ok")
     56     if response["meta"]["execution_mode"].string_value() != "assisted":
     57         raise Error("MAX-local smoke did not use assisted execution")
     58     if response["meta"]["backend"].string_value() != "provider_runtime":
     59         raise Error("MAX-local smoke did not use provider_runtime")
     60     if response["meta"]["provider"].string_value() != "max_local":
     61         raise Error("MAX-local smoke did not use max_local provider")
     62     if response["meta"]["route"].string_value() != max_local_query_rewrite_route():
     63         raise Error("MAX-local smoke route did not match derived route")
     64     if response["output"]["rewritten_text"].string_value() == "":
     65         raise Error("MAX-local smoke returned empty rewritten_text")
     66     if _has_key(response["meta"], "fallback_kind"):
     67         raise Error("MAX-local smoke unexpectedly returned fallback metadata")
     68     if _has_key(response["meta"], "fallback_reason"):
     69         raise Error("MAX-local smoke unexpectedly returned fallback metadata")
     70 
     71 
     72 def main() raises:
     73     var config_path = _require_config_path()
     74     var response = run_stdio_entrypoint(
     75         "src/main.mojo",
     76         _smoke_request_json(),
     77         "--config",
     78         config_path,
     79     )
     80     _assert_successful_provider_response(response)
     81     print("ok")