hyf

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

commit 8da5b3128cebebd17d9be480064752e08fd4e635
parent 23555ddef0959a68a6588c96753c2b68fb0aba5f
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:58:27 +0000

runtime: implement persistent bounded request reading

Diffstat:
Mpixi.toml | 2++
Msrc/hyf_stdio/server.mojo | 27++++++++++++++++++---------
Atests/test_persistent_stdio.mojo | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/pixi.toml b/pixi.toml @@ -28,6 +28,7 @@ test-domain = "mojo -I src -I tests tests/test_domain.mojo" test-assist = "mojo -I src -I tests tests/test_assist.mojo" test-jev = "mojo -I src -I tests tests/test_jev.mojo" test-application = "mojo -I src -I tests tests/test_application.mojo" +test-stdio-session = "mojo -I src -I tests tests/test_persistent_stdio.mojo" test-spec = "mojo -I src -I tests tests/test_traceability.mojo" check-build = "mkdir -p .pixi/build && mojo build -I src src/main.mojo -o .pixi/build/hyfd" check-format = "sh tools/check_format.sh" @@ -44,6 +45,7 @@ test = { depends-on = [ "test-assist", "test-jev", "test-application", + "test-stdio-session", "test-provider-adapter", "test-spec", "test-architecture", diff --git a/src/hyf_stdio/server.mojo b/src/hyf_stdio/server.mojo @@ -1,4 +1,4 @@ -from std.collections import Optional +from std.collections import List, Optional from std.io.io import _fdopen from std.sys import stdin @@ -309,17 +309,26 @@ def run_stdio_server() raises: ) +def run_stdio_session( + frames: List[String], runtime_context: RuntimeStartupContext +) raises -> List[String]: + var responses = List[String]() + for frame in frames: + responses.append( + handle_request_line_with_runtime_context(frame, runtime_context) + ) + return responses^ + + def run_stdio_server_with_runtime_context( runtime_context: RuntimeStartupContext, ) raises: if stdin.isatty(): return - try: - var line = _read_request_line() - - print(handle_request_line_with_runtime_context(line, runtime_context)) - except e: - if String(e) == "EOF": - return - raise e^ + with _fdopen["r"](stdin) as input_file: + while True: + var line = input_file.readline() + if line == "": + break + print(handle_request_line_with_runtime_context(line, runtime_context)) diff --git a/tests/test_persistent_stdio.mojo b/tests/test_persistent_stdio.mojo @@ -0,0 +1,53 @@ +from std.collections import List +from std.tempfile import TemporaryDirectory +from std.testing import TestSuite, assert_equal, assert_true + +from fixture_assertions import load_scenario_request_json +from hyf_runtime.startup import ( + RuntimeStartupContext, + RuntimeStartupInput, + resolve_startup_context, +) +from hyf_stdio.server import run_stdio_session + + +def _context(temp_dir: String) raises -> RuntimeStartupContext: + return resolve_startup_context( + RuntimeStartupInput( + env_paths_profile="repo_local", + env_repo_local_base_root=temp_dir, + user_home="/home/unused", + argv=List[String](), + ) + ) + + +def test_persistent_session_processes_multiple_frames() raises: + with TemporaryDirectory() as temp_dir: + var context = _context(temp_dir) + var frames = List[String]() + frames.append(load_scenario_request_json("scenarios/status_ok.json")) + frames.append(load_scenario_request_json("scenarios/capabilities_ok.json")) + frames.append(load_scenario_request_json("scenarios/status_ok.json")) + var responses = run_stdio_session(frames, context) + assert_equal(len(responses), 3) + for response in responses: + assert_true(response.find('"ok":true') >= 0) + + +def test_session_recovers_from_malformed_frame() raises: + with TemporaryDirectory() as temp_dir: + var context = _context(temp_dir) + var frames = List[String]() + frames.append(load_scenario_request_json("scenarios/status_ok.json")) + frames.append("{not valid json") + frames.append(load_scenario_request_json("scenarios/status_ok.json")) + var responses = run_stdio_session(frames, context) + assert_equal(len(responses), 3) + assert_true(responses[0].find('"ok":true') >= 0) + assert_true(responses[1].find('invalid_request') >= 0) + assert_true(responses[2].find('"ok":true') >= 0) + + +def main() raises: + TestSuite.discover_tests[__functions_in_module()]().run()