Skip to content

Commit 52ce518

Browse files
committed
test(capture-dispatch): the dispatch tests own their capture root on every platform (#693)
TestCaptureDispatch patched CORTEX_CLAUDE_DIR in os.environ, but capture_dispatch reads CLAUDE_DIR once at import, so the patch never reached dispatch(). On a platform without the resident worker (native Windows), test_spawn_or_transport_failure_is_logged_and_telemetried took the spool path: it wrote a spool file into the suite's shared capture root and started a real detached drainer. That file is the one test_capture_drain found before writing (issue #693). - setUp also patches capture_dispatch.CLAUDE_DIR to the test's temporary root. - The transport-failure test pins is_supported to True: it targets deliver(). - New test: with is_supported False and the drainer mocked, the spool file lands under the test root and the shared root is unchanged. It fails without the CLAUDE_DIR patch. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018kyZYqW7pSQ4T95ysn4nRg
1 parent b65030b commit 52ce518

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

‎tests_py/hooks/test_capture_dispatch.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def setUp(self):
2626
from mcp_server.core import telemetry
2727

2828
self.dispatch = capture_dispatch
29+
# The variable above reaches child processes only: capture_dispatch read
30+
# CLAUDE_DIR at import, so the spool path of an unsupported platform
31+
# (Windows) wrote to the suite's shared root (issue #693).
32+
mock.patch.object(
33+
capture_dispatch, "CLAUDE_DIR", Path(self.temporary.name)
34+
).start()
2935
self.record = mock.patch.object(telemetry, "record").start()
3036

3137
def tearDown(self):
@@ -52,8 +58,14 @@ def test_hook_transmits_the_exact_previous_payload_without_inference(self):
5258
self.assertIn("persistence pending", log.call_args.args[0])
5359

5460
def test_spawn_or_transport_failure_is_logged_and_telemetried(self):
55-
with mock.patch.object(
56-
self.dispatch, "deliver", side_effect=OSError("fixture spawn failed")
61+
# the resident-worker path on every platform: without the pin, Windows
62+
# took the spool path and started a real detached drainer (issue #693)
63+
supported = mock.patch.object(self.dispatch, "is_supported", return_value=True)
64+
with (
65+
supported,
66+
mock.patch.object(
67+
self.dispatch, "deliver", side_effect=OSError("fixture spawn failed")
68+
),
5769
):
5870
with mock.patch.object(
5971
self.dispatch.time, "monotonic", side_effect=[4.0, 4.25]
@@ -65,6 +77,22 @@ def test_spawn_or_transport_failure_is_logged_and_telemetried(self):
6577
"capture_skipped", latency_ms=250.0, ok=False, skipped=True
6678
)
6779

80+
def test_spool_path_writes_only_under_the_test_root(self):
81+
from mcp_server.infrastructure import capture_spool
82+
from mcp_server.infrastructure.config import CLAUDE_DIR
83+
84+
shared = capture_spool.spool_directory(CLAUDE_DIR)
85+
before = capture_spool.pending(shared)
86+
unsupported = mock.patch.object(
87+
self.dispatch, "is_supported", return_value=False
88+
)
89+
with unsupported, mock.patch.object(self.dispatch, "spawn_drainer") as spawn:
90+
self.assertTrue(self.dispatch.dispatch(payload()))
91+
local = capture_spool.spool_directory(Path(self.temporary.name))
92+
self.assertEqual(len(capture_spool.pending(local)), 1)
93+
self.assertEqual(capture_spool.pending(shared), before)
94+
spawn.assert_called_once_with(capture_spool.log_path(local))
95+
6896
def test_invalid_payload_never_reaches_spawn_or_transport(self):
6997
with mock.patch.object(self.dispatch, "deliver") as deliver:
7098
with self.assertLogs(self.dispatch.logger, level="ERROR"):

0 commit comments

Comments
 (0)