From 137de03c7bc09a8e83ddb930298c69be393175a7 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 12 May 2026 19:17:21 +0000 Subject: [PATCH] Make AST regression tests CWD-independent and fail-loud Two robustness fixes to the workflow_id regression tests: 1. Resolve source-file paths relative to __file__ (repo_root = Path(__file__).resolve().parents[2]) instead of bare Path("main.py"). The bare form depends on the process CWD being the repo root, which made the tests flaky when run from tests-unit/, an IDE runner, or any other directory. Verified passing from three different CWDs (repo root, tests-unit/, /tmp). 2. Track matched_terminal_executing_send and assert it after the AST walk in TestTerminalExecutingResetInMainPy. Previously, if someone refactored the send_sync("executing", {...}) call to pass a local variable instead of an inline dict literal, the loop would simply find no match and the test would pass vacuously, losing its regression-protection value. Verified by temporarily refactoring main.py to use a variable payload: the test now fails with a clear message asking to update the regression test, and passes again once the inline dict is restored. --- .../test_workflow_id_in_ws_messages.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests-unit/execution_test/test_workflow_id_in_ws_messages.py b/tests-unit/execution_test/test_workflow_id_in_ws_messages.py index b98007b29..cf1ff71e9 100644 --- a/tests-unit/execution_test/test_workflow_id_in_ws_messages.py +++ b/tests-unit/execution_test/test_workflow_id_in_ws_messages.py @@ -138,7 +138,8 @@ class TestExecutionMessagePayloadsContainWorkflowId: def _assert_workflow_id_in_every_prompt_id_dict(self, file_path: str): from pathlib import Path - source = Path(file_path).read_text() + repo_root = Path(__file__).resolve().parents[2] + source = (repo_root / file_path).read_text() offenders = [] for node, keys in self._emitting_dicts(source): if "workflow_id" not in keys: @@ -241,7 +242,8 @@ class TestTerminalExecutingResetInMainPy: import ast from pathlib import Path - source = Path("main.py").read_text() + repo_root = Path(__file__).resolve().parents[2] + source = (repo_root / "main.py").read_text() tree = ast.parse(source) worker = next( @@ -262,6 +264,7 @@ class TestTerminalExecutingResetInMainPy: "in finally)." ) + matched_terminal_executing_send = False for node in ast.walk(worker): if not isinstance(node, ast.Call): continue @@ -276,6 +279,7 @@ class TestTerminalExecutingResetInMainPy: and isinstance(node.args[1], ast.Dict) ): continue + matched_terminal_executing_send = True payload = node.args[1] for key, value in zip(payload.keys, payload.values): if isinstance(key, ast.Constant) and key.value == "workflow_id": @@ -285,3 +289,9 @@ class TestTerminalExecutingResetInMainPy: "server.last_workflow_id; the executor clears it in its " "finally block. Use a locally captured workflow_id instead." ) + + assert matched_terminal_executing_send, ( + "main.py:prompt_worker no longer has an inline " + 'send_sync("executing", {...}) payload; update this regression test ' + "so it still verifies the terminal workflow_id source." + )