From c837768242ebdc82e2227247564f451f07982e8e Mon Sep 17 00:00:00 2001 From: Huixin615 Date: Mon, 8 Jun 2026 00:58:05 +0800 Subject: [PATCH] test: fix flaky tests relying on /nonexistent/... path under container root Two tests in this module (test_returns_none_on_invalid_path and test_fallback_when_disk_write_fails) used paths like '/nonexistent/impossible/path' to trigger _externalize's OSError fallback. These paths are creatable when the test process runs as root inside the CI container: os.makedirs(..., exist_ok=True) successfully creates the entire chain under /, so the OSError branch is never hit and the tests fail. Reproducible on main independently of this PR. Switch to '/dev/null/cannot-mkdir-here'. /dev/null is a character device on both Linux and macOS, so os.makedirs always fails with NotADirectoryError regardless of privileges, reliably exercising the OSError fallback. --- backend/tests/test_tool_output_budget_middleware.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/tests/test_tool_output_budget_middleware.py b/backend/tests/test_tool_output_budget_middleware.py index 6e4cd3c0c..c8313973a 100644 --- a/backend/tests/test_tool_output_budget_middleware.py +++ b/backend/tests/test_tool_output_budget_middleware.py @@ -121,11 +121,17 @@ class TestExternalize: assert f.read() == "full content here" def test_returns_none_on_invalid_path(self): + # ``/dev/null`` is a character device on both Linux and macOS, so + # ``os.makedirs`` cannot create any subdirectory under it for any + # user (including root). The previously-used ``/nonexistent/...`` + # path was silently created by ``mkdir -p`` when the test process + # ran as root inside the CI container, which made this test fail + # in CI independently of the externalization logic under test. path = _externalize( "data", tool_name="test", tool_call_id="tc-1", - outputs_path="/nonexistent/path/that/should/not/exist", + outputs_path="/dev/null/cannot-mkdir-here", storage_subdir=".tool-results", ) assert path is None @@ -370,7 +376,7 @@ class TestWrapToolCallFallback: mw = ToolOutputBudgetMiddleware(config=config) content = "x" * 500 msg = _tm(content, name="tool") - req = _make_request(outputs_path="/nonexistent/impossible/path") + req = _make_request(outputs_path="/dev/null/cannot-mkdir-here") result = mw.wrap_tool_call(req, lambda _: msg)