max_local_operator_smoke.mojo (3120B)
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,"request_id":"max-local-operator-smoke-1","trace_id":"max-local-operator-smoke-1","capability":"query_rewrite","context":{"execution_mode_preference":"assisted","return_provenance":true,"deadline_ms":15000},"input":{"query":"local' 45 ' apples pickup this weekend"}}' 46 ) 47 48 49 def _assert_successful_provider_response(response: Value) raises: 50 if not response["ok"].bool_value(): 51 raise Error("MAX-local smoke response was not ok") 52 if response["meta"]["execution_mode"].string_value() != "assisted": 53 raise Error("MAX-local smoke did not use assisted execution") 54 if response["meta"]["backend"].string_value() != "provider_runtime": 55 raise Error("MAX-local smoke did not use provider_runtime") 56 if response["meta"]["provider"].string_value() != "max_local": 57 raise Error("MAX-local smoke did not use max_local provider") 58 if ( 59 response["meta"]["route"].string_value() 60 != max_local_query_rewrite_route() 61 ): 62 raise Error("MAX-local smoke route did not match derived route") 63 if response["output"]["rewritten_text"].string_value() == "": 64 raise Error("MAX-local smoke returned empty rewritten_text") 65 if _has_key(response["meta"], "fallback_kind"): 66 raise Error("MAX-local smoke unexpectedly returned fallback metadata") 67 if _has_key(response["meta"], "fallback_reason"): 68 raise Error("MAX-local smoke unexpectedly returned fallback metadata") 69 70 71 def main() raises: 72 var config_path = _require_config_path() 73 var response = run_stdio_entrypoint( 74 "src/main.mojo", 75 _smoke_request_json(), 76 "--config", 77 config_path, 78 ) 79 _assert_successful_provider_response(response) 80 print("ok")