Skip to content

Commit 58fb945

Browse files
authored
Merge pull request #1958 from ilyabrykau-orca/fix/windows-guards-setup-retry
fix(ci): gate Windows guard setups on the index response, not list_projects stats
2 parents ae5de7f + 947e52d commit 58fb945

4 files changed

Lines changed: 138 additions & 49 deletions

File tree

‎tests/windows/mcp_stdio.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,34 @@ def close(self):
148148
self.proc.kill()
149149
except Exception:
150150
pass
151+
152+
153+
def wait_projects_with_stats(server, timeout=90.0, poll=1.0):
154+
"""Poll list_projects until a project row carries node/edge counts.
155+
156+
index_repository returns when the pipeline finishes, but the project
157+
stats are published asynchronously; on slow CI runners the first
158+
list_projects can observe the registration row before its counts land
159+
(`nodes` absent/None). That window is environmental, not a product
160+
regression (#1952), so wait it out instead of failing setup on it.
161+
162+
Returns (projects, last_text): the parsed project list (possibly [])
163+
and the last raw list_projects payload for diagnostics.
164+
"""
165+
deadline = time.time() + timeout
166+
last_txt = ""
167+
while True:
168+
resp = server.call_tool("list_projects", {}, timeout=60)
169+
txt, err = server.tool_text(resp)
170+
projects = []
171+
if not err and txt:
172+
last_txt = txt
173+
try:
174+
projects = json.loads(txt).get("projects") or []
175+
except ValueError:
176+
projects = []
177+
if projects and projects[0].get("nodes") is not None:
178+
return projects, last_txt
179+
if time.time() >= deadline:
180+
return projects, last_txt
181+
time.sleep(poll)

‎tests/windows/test_cli_non_ascii_arg.py‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import subprocess
3232
import sys
3333
import tempfile
34+
import time
3435

3536
MATH_TS = (
3637
"export function add(a: number, b: number): number { return a + b; }\n"
@@ -67,13 +68,24 @@ def main():
6768
# CLI path itself works and isolating the failure to argv encoding.
6869
ascii_repo = os.path.join(work, "ascii_repo")
6970
make_fixture(ascii_repo)
70-
env = dict(os.environ)
71-
env["CBM_CACHE_DIR"] = os.path.join(work, "cache_ascii")
72-
ctrl = subprocess.run(
73-
[binary, "cli", "index_repository",
74-
json.dumps({"repo_path": ascii_repo})],
75-
capture_output=True, timeout=120, env=env)
76-
ctrl_out = (ctrl.stdout or b"").decode("utf-8", "replace")
71+
# The control is setup, not the surface under test: a cold runner can
72+
# lose the first one-shot to coordination-daemon startup latency
73+
# (#1952). One retry against a fresh cache separates that from a real
74+
# CLI indexing failure.
75+
ctrl_out = ""
76+
for attempt in ("cache_ascii", "cache_ascii_retry"):
77+
env = dict(os.environ)
78+
env["CBM_CACHE_DIR"] = os.path.join(work, attempt)
79+
ctrl = subprocess.run(
80+
[binary, "cli", "index_repository",
81+
json.dumps({"repo_path": ascii_repo})],
82+
capture_output=True, timeout=120, env=env)
83+
ctrl_out = (ctrl.stdout or b"").decode("utf-8", "replace")
84+
if '"nodes"' in ctrl_out:
85+
break
86+
print("SETUP: ASCII control attempt %r did not index via CLI:\n%s"
87+
% (attempt, ctrl_out[:300]))
88+
time.sleep(2)
7789
if '"nodes"' not in ctrl_out:
7890
print("SETUP FAIL: ASCII control did not index via CLI:\n%s" %
7991
ctrl_out[:300])

‎tests/windows/test_hook_augment.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import subprocess
3232
import sys
3333
import tempfile
34+
import time
3435

3536
SYMBOL = "someIndexedSymbol"
3637
SRC = "export function %s(a: number): number { return a + 1; }\n" % SYMBOL
@@ -63,9 +64,19 @@ def main():
6364

6465
# repo_path / cwd in the forward-slash drive form Claude Code passes.
6566
repo_fwd = repo.replace("\\", "/")
66-
idx = run_cli(binary, cache, ["cli", "index_repository",
67-
json.dumps({"repo_path": repo_fwd})])
68-
idx_out = (idx.stdout or b"").decode("utf-8", "replace")
67+
# Setup, not the surface under test: retry once so a cold runner's
68+
# coordination-daemon startup latency (#1952) is not misread as a
69+
# broken CLI index. Reindexing the same cache is idempotent.
70+
idx_out = ""
71+
for attempt in (1, 2):
72+
idx = run_cli(binary, cache, ["cli", "index_repository",
73+
json.dumps({"repo_path": repo_fwd})])
74+
idx_out = (idx.stdout or b"").decode("utf-8", "replace")
75+
if '"nodes"' in idx_out:
76+
break
77+
print("SETUP: index attempt %d did not run:\n%s"
78+
% (attempt, idx_out[:300]))
79+
time.sleep(2)
6980
if '"nodes"' not in idx_out:
7081
print("SETUP FAIL: index did not run:\n%s" % idx_out[:300])
7182
return 2
@@ -88,10 +99,17 @@ def main():
8899
# first — the supported way to keep hooks armed outside MCP sessions —
89100
# and retire it afterwards (with a kill-by-pid backstop so a stuck stop
90101
# can never hang CI).
91-
start = run_cli(binary, cache, ["daemon", "start"], timeout=60)
92-
start_out = (start.stdout or b"").decode("utf-8", "replace")
93-
print("daemon start rc=%d %r" % (start.returncode, start_out[:120]))
94-
if start.returncode != 0:
102+
start_out = ""
103+
rc = 1
104+
for attempt in (1, 2):
105+
start = run_cli(binary, cache, ["daemon", "start"], timeout=60)
106+
start_out = (start.stdout or b"").decode("utf-8", "replace")
107+
rc = start.returncode
108+
print("daemon start attempt %d rc=%d %r" % (attempt, rc, start_out[:120]))
109+
if rc == 0:
110+
break
111+
time.sleep(2)
112+
if rc != 0:
95113
print("SETUP FAIL: permanent daemon did not start")
96114
return 2
97115
pid_match = re.search(r"pid (\d+)", start_out)

‎tests/windows/test_non_ascii_path.py‎

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import tempfile
3535

3636
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
37-
from mcp_stdio import McpServer # noqa: E402
37+
from mcp_stdio import McpServer, wait_projects_with_stats # noqa: E402
3838

3939
MATH_TS = (
4040
"export function add(a: number, b: number): number { return a + b; }\n"
@@ -246,6 +246,37 @@ def make_fixture(root):
246246
f.write(text.encode("utf-8")) # exact bytes, identical across copies
247247

248248

249+
def no_project_error(index_txt, repo, cache):
250+
"""Assemble the venue diagnostics for an index that left no project row.
251+
252+
The count summary cannot explain a venue-specific empty listing; carry the
253+
index response, the cache contents and the supervisor's worker logs (the
254+
only record of the pipeline's own error) into the CI log.
255+
"""
256+
try:
257+
cache_entries = sorted(os.listdir(cache))
258+
except OSError as exc:
259+
cache_entries = ["<listdir failed: %s>" % exc]
260+
log_tails = []
261+
logs_dir = os.path.join(cache, "logs")
262+
if os.path.isdir(logs_dir):
263+
for log_name in sorted(os.listdir(logs_dir)):
264+
try:
265+
with open(os.path.join(logs_dir, log_name), "rb") as lf:
266+
tail = lf.read()[-800:].decode("utf-8", "replace")
267+
log_tails.append("%s: %s" % (log_name, tail))
268+
except OSError as exc:
269+
log_tails.append("%s: <unreadable: %s>" % (log_name, exc))
270+
try:
271+
repo_entries = sorted(os.listdir(repo))
272+
except OSError as exc:
273+
repo_entries = ["<listdir failed: %s>" % exc]
274+
return {"error": "no project listed after index; index said %r; "
275+
"cache holds %r; repo holds %r; worker logs: %s"
276+
% (index_txt[:400], cache_entries, repo_entries,
277+
" | ".join(log_tails) or "<none>")}
278+
279+
249280
def index_and_count(binary, repo, cache):
250281
"""Index `repo` into an isolated cache and return label-resolved counts."""
251282
os.makedirs(cache, exist_ok=True)
@@ -255,42 +286,29 @@ def index_and_count(binary, repo, cache):
255286
index_txt, err = s.tool_text(resp)
256287
if err:
257288
return {"error": "index tools/call error: %r" % err}
258-
lp = s.call_tool("list_projects", {}, timeout=60)
259-
lp_txt, _ = s.tool_text(lp)
260-
projects = json.loads(lp_txt).get("projects") or []
261-
if not projects:
262-
# The count summary cannot explain a venue-specific empty listing;
263-
# carry the index response and the cache contents into the log.
264-
try:
265-
cache_entries = sorted(os.listdir(cache))
266-
except OSError as exc:
267-
cache_entries = ["<listdir failed: %s>" % exc]
268-
# The supervisor's worker logs carry the actual pipeline error.
269-
log_tails = []
270-
logs_dir = os.path.join(cache, "logs")
271-
if os.path.isdir(logs_dir):
272-
for log_name in sorted(os.listdir(logs_dir)):
273-
try:
274-
with open(os.path.join(logs_dir, log_name), "rb") as lf:
275-
tail = lf.read()[-800:].decode("utf-8", "replace")
276-
log_tails.append("%s: %s" % (log_name, tail))
277-
except OSError as exc:
278-
log_tails.append("%s: <unreadable: %s>" % (log_name, exc))
279-
try:
280-
repo_entries = sorted(os.listdir(repo))
281-
except OSError as exc:
282-
repo_entries = ["<listdir failed: %s>" % exc]
283-
return {"error": "no project listed after index; index said %r; "
284-
"cache holds %r; repo holds %r; worker logs: %s"
285-
% (index_txt[:400], cache_entries, repo_entries,
286-
" | ".join(log_tails) or "<none>")}
287-
p = projects[0]
288-
out = {"name": p.get("name"), "nodes": p.get("nodes"),
289-
"edges": p.get("edges")}
289+
# The index response itself carries the synchronous, authoritative
290+
# counts ("nodes"/"edges"). list_projects publishes its stats columns
291+
# asynchronously — on some venues never within a one-shot session — so
292+
# gating on it misreads a healthy index as a setup failure (#1952).
293+
try:
294+
summary = json.loads(index_txt)
295+
except ValueError:
296+
summary = {}
297+
out = {"name": summary.get("project"), "nodes": summary.get("nodes"),
298+
"edges": summary.get("edges")}
299+
if out["nodes"] is None:
300+
# Payload without counts: fall back to list_projects, polled
301+
# because its stats row can trail the index on slow runners.
302+
projects, _ = wait_projects_with_stats(s)
303+
if not projects:
304+
return no_project_error(index_txt, repo, cache)
305+
p = projects[0]
306+
out = {"name": p.get("name"), "nodes": p.get("nodes"),
307+
"edges": p.get("edges")}
290308
# Definition-level counts prove the parser ran (not just discovery).
291309
# query_graph defaults to TOON text; this scripted consumer requests
292310
# format="json" ({"columns":[...],"rows":[["<n>"]],...}) explicitly.
293-
name = p.get("name")
311+
name = out["name"]
294312
defs = 0
295313
for label in ("Function", "Class", "Method"):
296314
q = "MATCH (n:%s) RETURN count(n)" % label
@@ -331,7 +349,17 @@ def main():
331349

332350
ascii_repo = os.path.join(work, "ascii_repo")
333351
make_fixture(ascii_repo)
334-
base = index_and_count(binary, ascii_repo, os.path.join(work, "c_ascii"))
352+
# The baseline is setup, not the surface under test: a cold runner can
353+
# lose the first index to daemon startup latency (#1952). One retry
354+
# against a fresh cache separates that environmental window from a
355+
# real indexing failure before the guard declares a precondition skip.
356+
base = {}
357+
for attempt in ("c_ascii", "c_ascii_retry"):
358+
base = index_and_count(binary, ascii_repo, os.path.join(work, attempt))
359+
if not base.get("error") and base.get("nodes"):
360+
break
361+
print("SETUP: ASCII baseline attempt %r did not index: %r"
362+
% (attempt, base))
335363
if base.get("error") or not base.get("nodes"):
336364
print("SETUP FAIL: ASCII baseline did not index: %r" % base)
337365
return 2

0 commit comments

Comments
 (0)