MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main

Function main

tests/windows/test_cli_non_ascii_arg.py:50–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48
49
50def main():
51 if len(sys.argv) < 2:
52 print("usage: python test_cli_non_ascii_arg.py <binary>")
53 return 2
54 binary = os.path.abspath(sys.argv[1])
55 if not os.path.exists(binary):
56 print("FAIL: binary not found: %s" % binary)
57 return 2
58
59 work = tempfile.mkdtemp(prefix="cbm_win_cliarg_")
60 try:
61 # Non-ASCII repo directory (created via the OS wide API → really exists).
62 repo = os.path.join(work, "café_日本語_repo")
63 make_fixture(repo)
64 cache = os.path.join(work, "cache")
65 os.makedirs(cache, exist_ok=True)
66
67 # Sanity: an ASCII control path must index through the CLI, proving the
68 # CLI path itself works and isolating the failure to argv encoding.
69 ascii_repo = os.path.join(work, "ascii_repo")
70 make_fixture(ascii_repo)
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 ctrl_err = ""
77 for attempt in ("cache_ascii", "cache_ascii_retry"):
78 env = dict(os.environ)
79 env["CBM_CACHE_DIR"] = os.path.join(work, attempt)
80 ctrl = subprocess.run(
81 [binary, "cli", "index_repository",
82 json.dumps({"repo_path": ascii_repo})],
83 capture_output=True, timeout=120, env=env)
84 ctrl_out = (ctrl.stdout or b"").decode("utf-8", "replace")
85 ctrl_err = (ctrl.stderr or b"").decode("utf-8", "replace")
86 if '"nodes"' in ctrl_out:
87 break
88 # Full stdout AND stderr: the reason lives on stderr (daemon
89 # spawn/handshake diagnostics), and a head slice of stdout only
90 # ever showed the allocator preamble.
91 print("SETUP: ASCII control attempt %r did not index via CLI (rc=%s):\n"
92 "stdout:\n%s\nstderr:\n%s"
93 % (attempt, ctrl.returncode, ctrl_out, ctrl_err))
94 time.sleep(2)
95 if '"nodes"' not in ctrl_out:
96 print("SETUP FAIL: ASCII control did not index via CLI:\nstdout:\n%s\nstderr:\n%s"
97 % (ctrl_out, ctrl_err))
98 return 2
99
100 env2 = dict(os.environ)
101 env2["CBM_CACHE_DIR"] = cache
102 # Exercise the DEFAULT (supervisor-enabled) path, not in-process. The non-ASCII
103 # repo path must survive BOTH the argv read (main() wide command line) AND the
104 # supervisor -> worker spawn (CreateProcessW). The suite runner sets
105 # CBM_INDEX_SUPERVISOR=0 for determinism across the other guards; forcing it OFF
106 # here would run in-process and mask the spawn-boundary half of #423/#20, so we
107 # drop the override and let the supervisor wrap the worker as it does for users.

Callers 1

Calls 2

make_fixtureFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected