commit bdc5e462c7a5970c14f6cfd44aa896c354d95410
parent 4c2e11761e0badc6f177eb2810039b914b19bd53
Author: triesap <tyson@radroots.org>
Date: Thu, 18 Jun 2026 17:50:02 -0700
runtime: reject removed max local route config
- catch quoted, dotted, commented-header, and inline-table route config forms
- keep provider route derived by HYF instead of startup config
- add stdio invalid-config regression coverage
Diffstat:
2 files changed, 123 insertions(+), 6 deletions(-)
diff --git a/src/hyf_runtime/config.mojo b/src/hyf_runtime/config.mojo
@@ -180,22 +180,94 @@ def _require_http_url(value: String, context: String) raises:
raise Error(context + " must use http or https")
+def _strip_toml_key_quotes(value: String) -> String:
+ var stripped = String(String(value).strip())
+ if stripped.byte_length() < 2:
+ return stripped^
+
+ var bytes = stripped.as_bytes()
+ var last_index = stripped.byte_length() - 1
+ if (
+ bytes[0] == UInt8(ord('"'))
+ and bytes[last_index] == UInt8(ord('"'))
+ ):
+ return String(stripped[byte=1:last_index])
+ if (
+ bytes[0] == UInt8(ord("'"))
+ and bytes[last_index] == UInt8(ord("'"))
+ ):
+ return String(stripped[byte=1:last_index])
+ return stripped^
+
+
+def _normalize_toml_key_path(key: String) -> String:
+ var normalized = String("")
+ for raw_part in key.split("."):
+ var part = _strip_toml_key_quotes(
+ String(String(raw_part).strip())
+ )
+ if normalized == "":
+ normalized = part
+ else:
+ normalized += "." + part
+ return normalized^
+
+
+def _inline_table_contains_route_key(value: String) -> Bool:
+ var table = String(String(value).strip())
+ var open_index = table.find("{")
+ if open_index < 0:
+ return False
+ var close_index = table.find("}")
+ if close_index < 0 or close_index <= open_index:
+ close_index = table.byte_length()
+
+ var body = String(table[byte=open_index + 1:close_index])
+ for raw_field in body.split(","):
+ var field = String(String(raw_field).strip())
+ var equals_index = field.find("=")
+ if equals_index < 0:
+ continue
+ var key = String(String(field[byte=0:equals_index]).strip())
+ if _normalize_toml_key_path(key) == "route":
+ return True
+ return False
+
+
def _reject_removed_max_local_route_config(config_text: String) raises:
var in_max_local = False
for raw_line in config_text.splitlines():
- var line = String(raw_line).strip()
+ var line = String(String(raw_line).strip())
if line == "" or line.startswith("#"):
continue
if line.startswith("["):
- in_max_local = line == "[assisted.max_local]"
- continue
- if not in_max_local:
+ var close_index = line.find("]")
+ if close_index < 0:
+ in_max_local = False
+ continue
+ var table_name = String(
+ String(line[byte=1:close_index]).strip()
+ )
+ in_max_local = (
+ _normalize_toml_key_path(table_name)
+ == "assisted.max_local"
+ )
continue
var equals_index = line.find("=")
if equals_index < 0:
continue
- var key = String(line[byte=0:equals_index]).strip()
- if key == "route":
+ var key = _normalize_toml_key_path(
+ String(String(line[byte=0:equals_index]).strip())
+ )
+ var value = String(String(line[byte=equals_index + 1:]).strip())
+ if (
+ (in_max_local and key == "route")
+ or key == "assisted.max_local.route"
+ or (
+ key == "assisted.max_local"
+ and _inline_table_contains_route_key(value)
+ )
+ ):
raise Error(
"assisted.max_local.route has been removed; provider route is derived by HYF"
)
diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo
@@ -1114,6 +1114,51 @@ def test_status_rejects_invalid_max_local_runtime_config() raises:
_assert_invalid_runtime_config_load_error(
prefix
+ provider
+ + '[assisted.max_local] # provider route is derived\n'
+ + 'enabled = true\n'
+ + 'base_url = "http://127.0.0.1:8000/v1"\n'
+ + 'health_url = "http://127.0.0.1:8000/health"\n'
+ + 'model = "max-local-query-rewrite"\n'
+ + 'route = "provider_runtime.query_rewrite.max_local"\n'
+ + 'request_timeout_ms = 15000\n',
+ "assisted.max_local.route",
+ )
+ _assert_invalid_runtime_config_load_error(
+ prefix
+ + provider
+ + max_local_header
+ + 'base_url = "http://127.0.0.1:8000/v1"\n'
+ + 'health_url = "http://127.0.0.1:8000/health"\n'
+ + 'model = "max-local-query-rewrite"\n'
+ + '"route" = "provider_runtime.query_rewrite.max_local"\n'
+ + 'request_timeout_ms = 15000\n',
+ "assisted.max_local.route",
+ )
+ _assert_invalid_runtime_config_load_error(
+ prefix
+ + provider
+ + 'assisted.max_local.route = "provider_runtime.query_rewrite.max_local"\n'
+ + max_local_header
+ + 'base_url = "http://127.0.0.1:8000/v1"\n'
+ + 'health_url = "http://127.0.0.1:8000/health"\n'
+ + 'model = "max-local-query-rewrite"\n'
+ + 'request_timeout_ms = 15000\n',
+ "assisted.max_local.route",
+ )
+ _assert_invalid_runtime_config_load_error(
+ prefix
+ + provider
+ + 'assisted.max_local = { enabled = true, '
+ + 'base_url = "http://127.0.0.1:8000/v1", '
+ + 'health_url = "http://127.0.0.1:8000/health", '
+ + 'model = "max-local-query-rewrite", '
+ + 'route = "provider_runtime.query_rewrite.max_local", '
+ + 'request_timeout_ms = 15000 }\n',
+ "assisted.max_local.route",
+ )
+ _assert_invalid_runtime_config_load_error(
+ prefix
+ + provider
+ max_local_header
+ 'base_url = "http://127.0.0.1:8000/v1"\n'
+ 'health_url = "http://127.0.0.1:8000/health"\n'