commit 60abdb01a4ec3bd2df11b27bfc1110984d514619
parent f758321c4c3e014e44d1d1219ef7cb0f300e5cf9
Author: triesap <tyson@radroots.org>
Date: Wed, 23 Sep 2026 21:11:48 +0000
test: characterize runtime config compatibility
- Pin the applied two-level runtime and assisted table forms.
- Pin dotted, three-level, array-of-tables and inline forms as ignored.
- Pin every removed max_local route syntax and the deep-inline gap.
- Pin invalid scalar, cross-field and compiled-default behavior.
Diffstat:
1 file changed, 268 insertions(+), 0 deletions(-)
diff --git a/tests/test_runtime_paths.mojo b/tests/test_runtime_paths.mojo
@@ -212,6 +212,274 @@ def test_startup_context_rejects_missing_root_unknown_flag_and_flag_as_value() r
)
+# ── H010 runtime TOML compatibility characterization ────────────────────────
+
+
+from std.pathlib import Path
+from safe_tempdir import SafeTempDir
+from hyf_runtime.config import load_runtime_config
+
+
+def _load_toml(
+ temp_dir: String, name: String, text: String
+) raises -> HyfLoadedRuntimeConfig:
+ var path = temp_dir + "/" + name + ".toml"
+ Path(path).write_text(text)
+ return load_runtime_config(path)
+
+
+def _assert_compiled_defaults(config: HyfLoadedRuntimeConfig) raises:
+ assert_true(not config.effective.runtime.allow_assisted)
+ assert_equal(config.effective.assisted.provider, "")
+ assert_true(not config.effective.assisted.max_local.enabled)
+ assert_equal(config.effective.assisted.max_local.base_url, "")
+ assert_equal(config.effective.assisted.max_local.request_timeout_ms, 0)
+
+
+def _assert_route_rejected(
+ config: HyfLoadedRuntimeConfig, message: String
+) raises:
+ assert_equal(config.load_state, "invalid")
+ assert_equal(config.load_error, message)
+
+
+def _assert_form_ignored(config: HyfLoadedRuntimeConfig) raises:
+ assert_equal(config.load_state, "loaded")
+ assert_true(not config.effective.assisted.max_local.enabled)
+ assert_equal(config.effective.assisted.max_local.base_url, "")
+ assert_equal(config.effective.assisted.max_local.request_timeout_ms, 0)
+
+
+comptime ASSISTED_HEADER = (
+ '[runtime]\nallow_assisted = true\n[assisted]\nprovider = "max_local"\n'
+)
+
+
+def test_toml_compatibility_supported_table_forms_are_equivalent() raises:
+ # H010: the two-level tables the loader applies are `[runtime]` and
+ # `[assisted]`; blank lines and trailing comments are equivalent.
+ with SafeTempDir() as temp_dir:
+ var plain = _load_toml(temp_dir, "plain", ASSISTED_HEADER)
+ var commented = _load_toml(
+ temp_dir,
+ "commented",
+ (
+ "# leading comment\n\n[runtime]\n"
+ "allow_assisted = true # trailing\n\n"
+ '[assisted]\nprovider = "max_local"\n'
+ ),
+ )
+ assert_equal(plain.load_state, "loaded")
+ assert_equal(commented.load_state, "loaded")
+ assert_true(plain.effective.runtime.allow_assisted)
+ assert_equal(plain.effective.assisted.provider, "max_local")
+ assert_true(commented.effective.runtime.allow_assisted)
+ assert_equal(commented.effective.assisted.provider, "max_local")
+
+
+def test_toml_compatibility_ignored_forms_are_characterized() raises:
+ # H010: current loader limitation, characterized not repaired. Dotted keys,
+ # three-level tables and array-of-tables headers load without error but do
+ # not apply their values, so `assisted.max_local.*` cannot be configured
+ # from a TOML artifact today.
+ with SafeTempDir() as temp_dir:
+ var dotted = _load_toml(
+ temp_dir,
+ "dotted",
+ (
+ 'assisted.provider = "max_local"\n'
+ "assisted.max_local.enabled = true\n"
+ 'assisted.max_local.base_url = "http://127.0.0.1:8080"\n'
+ "runtime.allow_assisted = true\n"
+ ),
+ )
+ var deep = _load_toml(
+ temp_dir,
+ "deep",
+ ASSISTED_HEADER
+ + "[assisted.max_local]\nenabled = true\n"
+ 'base_url = "http://127.0.0.1:8080"\n'
+ 'health_url = "http://127.0.0.1:8080/health"\n'
+ 'model = "m"\nrequest_timeout_ms = 15000\n',
+ )
+ var array_header = _load_toml(
+ temp_dir, "array", '[[assisted]]\nprovider = "max_local"\n'
+ )
+ var typesafe = _load_toml(
+ temp_dir,
+ "typesafe",
+ ASSISTED_HEADER
+ + "[assisted.typesafe]\nenabled = true\n"
+ 'base_url = "https://api.typesafe.ai"\n'
+ 'model = "jev-1.13.0"\nrequest_timeout_ms = 15000\n',
+ )
+ _assert_form_ignored(dotted)
+ _assert_form_ignored(deep)
+ _assert_form_ignored(array_header)
+ _assert_form_ignored(typesafe)
+ assert_true(not typesafe.effective.assisted.typesafe.enabled)
+ # The array-of-tables form drops the two-level provider key as well.
+ assert_true(not array_header.effective.runtime.allow_assisted)
+ assert_equal(array_header.effective.assisted.provider, "")
+ # The dotted form does not apply the two-level runtime/assisted keys.
+ assert_true(not dotted.effective.runtime.allow_assisted)
+ assert_equal(dotted.effective.assisted.provider, "")
+ # The two-level keys around a three-level table still apply.
+ assert_true(deep.effective.runtime.allow_assisted)
+ assert_equal(deep.effective.assisted.provider, "max_local")
+
+
+def test_toml_compatibility_inline_tables_are_characterized() raises:
+ # H010: inline table forms are characterized. An inline table of tables is
+ # accepted and ignored; an inline table carrying a string field fails the
+ # TOML bridge with the current bounded error.
+ with SafeTempDir() as temp_dir:
+ var inline_scalar = _load_toml(
+ temp_dir, "inline_scalar", "runtime = { allow_assisted = true }\n"
+ )
+ assert_equal(inline_scalar.load_state, "loaded")
+ assert_true(not inline_scalar.effective.runtime.allow_assisted)
+ var inline_tables = _load_toml(
+ temp_dir,
+ "inline_tables",
+ 'assisted = { max_local = { enabled = true, route = "/x" } }\n',
+ )
+ assert_equal(inline_tables.load_state, "loaded")
+ assert_true(not inline_tables.effective.assisted.max_local.enabled)
+ var inline_string = _load_toml(
+ temp_dir,
+ "inline_string",
+ 'assisted = { provider = "max_local" }\n',
+ )
+ assert_equal(inline_string.load_state, "invalid")
+ assert_equal(inline_string.load_error, "Empty JSON value")
+
+
+def test_toml_compatibility_rejects_removed_route_syntaxes() raises:
+ # H010: every syntax of the removed `assisted.max_local.route` the guard
+ # recognizes is rejected with the contractual message. The deep inline form
+ # is not recognized today and loads with the key ignored: recorded as a
+ # characterized gap for the config owner, not repaired here (product source
+ # is outside this slice).
+ var message = (
+ "assisted.max_local.route has been removed; provider route is derived"
+ " by HYF"
+ )
+ with SafeTempDir() as temp_dir:
+ var table = _load_toml(
+ temp_dir, "route_table", '[assisted.max_local]\nroute = "/v1"\n'
+ )
+ var dotted = _load_toml(
+ temp_dir, "route_dotted", 'assisted.max_local.route = "/v1"\n'
+ )
+ var quoted = _load_toml(
+ temp_dir, "route_quoted", '[assisted."max_local"]\nroute = "/v1"\n'
+ )
+ var inline = _load_toml(
+ temp_dir, "route_inline", 'assisted.max_local = { route = "/v1" }\n'
+ )
+ _assert_route_rejected(table, message)
+ _assert_route_rejected(dotted, message)
+ _assert_route_rejected(quoted, message)
+ _assert_route_rejected(inline, message)
+ var deep_inline = _load_toml(
+ temp_dir,
+ "route_deep",
+ 'assisted = { max_local = { route = "/v1" } }\n',
+ )
+ assert_equal(deep_inline.load_state, "loaded")
+ assert_equal(deep_inline.load_error, "")
+
+
+def test_toml_compatibility_unknown_keys_and_defaults_are_characterized() raises:
+ # H010: unknown keys anywhere are accepted without error, a missing artifact
+ # leaves the compiled defaults active, and an invalid artifact falls back to
+ # those same compiled defaults.
+ with SafeTempDir() as temp_dir:
+ var unknown_top = _load_toml(
+ temp_dir, "unknown_top", "unknown = true\n"
+ )
+ assert_equal(unknown_top.load_state, "loaded")
+ assert_equal(unknown_top.load_error, "")
+ var unknown_table = _load_toml(
+ temp_dir,
+ "unknown_table",
+ '[assisted]\nunknown = "value"\n[runtime]\nunknown_number = 3\n',
+ )
+ assert_equal(unknown_table.load_state, "loaded")
+ assert_equal(unknown_table.load_error, "")
+ var missing = load_runtime_config(temp_dir + "/absent.toml")
+ assert_equal(missing.load_state, "not_found")
+ assert_true(not missing.artifact_present)
+ assert_true(missing.compiled_defaults_active)
+ _assert_compiled_defaults(unknown_top)
+ _assert_compiled_defaults(unknown_table)
+ _assert_compiled_defaults(missing)
+ var invalid = _load_toml(
+ temp_dir, "invalid_defaults", '[service]\ntransport = "udp"\n'
+ )
+ assert_equal(invalid.load_state, "invalid")
+ assert_true(invalid.compiled_defaults_active)
+ _assert_compiled_defaults(invalid)
+ assert_equal(invalid.effective.service.transport, "stdio")
+
+
+def test_toml_compatibility_rejects_invalid_scalar_and_cross_field_forms() raises:
+ # H010: invalid scalar values, cross-field combinations and a malformed
+ # header preserve their current bounded error categories/messages.
+ with SafeTempDir() as temp_dir:
+ var transport = _load_toml(
+ temp_dir, "transport", '[service]\ntransport = "udp"\n'
+ )
+ assert_equal(transport.load_state, "invalid")
+ assert_equal(transport.load_error, "service.transport must be 'stdio'")
+ var mode = _load_toml(
+ temp_dir, "mode", '[runtime]\ndefault_execution_mode = "assisted"\n'
+ )
+ assert_equal(mode.load_state, "invalid")
+ assert_equal(
+ mode.load_error,
+ (
+ "runtime.default_execution_mode must be 'deterministic' in the"
+ " foundation wave"
+ ),
+ )
+ var provider = _load_toml(
+ temp_dir,
+ "provider",
+ (
+ "[runtime]\nallow_assisted = true\n[assisted]\n"
+ 'provider = "other"\n'
+ ),
+ )
+ assert_equal(provider.load_state, "invalid")
+ assert_equal(
+ provider.load_error,
+ (
+ "assisted.provider must be 'max_local' or 'typesafe' when"
+ " runtime.allow_assisted is true"
+ ),
+ )
+ var whitespace = _load_toml(
+ temp_dir,
+ "whitespace",
+ (
+ "[runtime]\nallow_assisted = true\n[assisted]\n"
+ 'provider = " max_local"\n'
+ ),
+ )
+ assert_equal(whitespace.load_state, "invalid")
+ assert_equal(
+ whitespace.load_error,
+ "assisted.provider must not include leading or trailing whitespace",
+ )
+ var header = _load_toml(
+ temp_dir, "header", '[assisted\nprovider = "max_local"\n'
+ )
+ assert_equal(header.load_state, "invalid")
+ assert_true(header.load_error.startswith("Invalid TOML table header"))
+
+
def main() raises:
TestSuite.discover_tests[__functions_in_module()]().run()