Skip to content

Commit 2bc9f01

Browse files
tonydziclaude
andcommitted
test(mcp): pin the per-call answer file so the race can actually fail a test
The scoping fix in #8 is correct, but none of the five unit tests that shipped with it distinguish a per-call temp file from a single shared path: each makes one sequential call and asserts the round-trip, which a fixed path satisfies identically. Reverting run_recall to a shared ROOT_DIR/_shared_answer.txt left all 12 tests in the file green. This test records the BRAIN_ANSWER_OUT value across two calls and asserts the paths differ and neither file survives. Verified both ways: red on the reverted shared-path version ("both calls shared one answer file: ..."), green on main, 62 passed overall. Assisted-by: claude-code/claude-opus-5[1m] Machine: ZBOOKG8-2023PAL Account: dzyatkovskiy.a2@gmail.com Operator: robot:contrib-watch-daily Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3ce7061 commit 2bc9f01

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎tests/test_mcp_server.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "examples"))
1010
from mcp_server import handle_request, TOOLS, SERVER_INFO
11+
import mcp_server
1112

1213

1314

@@ -148,3 +149,34 @@ def mock_run(*args, **kwargs):
148149
assert "timed out after 60 seconds" in res
149150

150151

152+
def test_run_recall_answer_file_is_unique_per_call_and_cleaned_up(tmp_path, monkeypatch):
153+
"""The scoped answer file must differ between calls and must not survive them.
154+
155+
Regression guard for the shared-answer-file race. The unit tests that shipped with
156+
the scoping fix all pass against a single fixed path too, so none of them actually
157+
pinned the behaviour; this one fails if the path stops being per-call or is left
158+
behind on disk.
159+
"""
160+
recorder = tmp_path / "paths.log"
161+
stub = tmp_path / "stub_record.py"
162+
stub.write_text(
163+
"\n".join(
164+
[
165+
"import os",
166+
"out = os.environ['BRAIN_ANSWER_OUT']",
167+
"open(r'{rec}', 'a', encoding='utf-8').write(out + chr(10))",
168+
"open(out, 'w', encoding='utf-8').write('BUNDLE')",
169+
]
170+
).format(rec=recorder),
171+
encoding="utf-8",
172+
)
173+
monkeypatch.setattr(mcp_server, "BRAIN_ASK_SCRIPT", stub)
174+
175+
assert "BUNDLE" in mcp_server.run_recall("first query")
176+
assert "BUNDLE" in mcp_server.run_recall("second query")
177+
178+
used = [l.strip() for l in recorder.read_text(encoding="utf-8").splitlines() if l.strip()]
179+
assert len(used) == 2, used
180+
assert used[0] != used[1], f"both calls shared one answer file: {used[0]}"
181+
for p in used:
182+
assert not Path(p).exists(), f"answer file left behind: {p}"

0 commit comments

Comments
 (0)