Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

tests: wait for late writers before removing temporary workspaces

justrachd19140b6fe0e
diff --git a/scripts/test-acp-startup.py b/scripts/test-acp-startup.py
index 71d2a195..80019096 100644
--- a/scripts/test-acp-startup.py
+++ b/scripts/test-acp-startup.py
@@ -34,7 +34,10 @@ def main():
}}))
env = {"HOME": str(root), "PATH": str(shim) + ":/usr/bin:/bin", "TERM": "dumb",
"LMSTUDIO_API_KEY": "fixture", "GRAFF_MCP_CONFIG": str(config),
- "GRAFF_BOOT_DEBUG": "1", "GRAFF_NO_ADOPT": "1", "GRAFF_NO_TELEMETRY": "1", "GRAFF_FLEET": "off"}
+ "GRAFF_BOOT_DEBUG": "1", "GRAFF_NO_ADOPT": "1", "GRAFF_NO_TELEMETRY": "1", "GRAFF_FLEET": "off",
+ # The fixture servers run this Python; on macOS it caches stdlib
+ # bytecode under $HOME, racing the temporary directory's removal.
+ "PYTHONDONTWRITEBYTECODE": "1"}
with (root / "stderr").open("w") as stderr:
child = subprocess.Popen([str(binary), "acp", "--yolo", "--model", "lmstudio"],
cwd=root, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
diff --git a/scripts/test-json-cancel.py b/scripts/test-json-cancel.py
index 54180160..a6f1a171 100644
--- a/scripts/test-json-cancel.py
+++ b/scripts/test-json-cancel.py
@@ -122,6 +122,22 @@ def stream_http(port, path, body, events):
conn.close()
+def wait_for_children(pid, timeout=10.0):
+ """Wait until `pid` has no child processes. A serve session closed with
+ DELETE exits on its own and writes its session and trajectory files on the
+ way out; removing the workspace before then races those writes."""
+ deadline = time.monotonic() + timeout
+ while time.monotonic() < deadline:
+ try:
+ alive = subprocess.run(["pgrep", "-P", str(pid)], capture_output=True).returncode == 0
+ except FileNotFoundError:
+ time.sleep(1.0)
+ return
+ if not alive:
+ return
+ time.sleep(0.05)
+
+
def main():
server = http.server.ThreadingHTTPServer(("127.0.0.1", 1234), Mock)
server.daemon_threads = True
@@ -245,6 +261,7 @@ def main():
http_json(port, "DELETE", f"/v1/sessions/{session_id}")
except OSError:
pass
+ wait_for_children(serve.pid)
if serve.poll() is None:
serve.terminate()
try: