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

Function main

tests/windows/test_hook_augment.py:50–174  ·  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_hook_augment.py <binary>")
53 return 2
54 # Claude's exec-form hook preserves this string exactly. On Windows, keep
55 # the forward-slash spelling that previously crossed Git Bash incorrectly.
56 binary = os.path.abspath(sys.argv[1]).replace("\\", "/")
57 if not os.path.exists(binary):
58 print("FAIL: binary not found: %s" % binary)
59 return 2
60
61 # macOS resolves /tmp through a symlink; the daemon's secure path walk
62 # accepts the canonical root-owned sticky parent at /private/tmp.
63 temp_parent = "/private/tmp" if sys.platform == "darwin" else None
64 work = tempfile.mkdtemp(prefix="cbm_win_hook_", dir=temp_parent)
65 cache = None
66 daemon_pid = 0
67 daemon_started = False
68 try:
69 repo = os.path.join(work, "repo")
70 os.makedirs(os.path.join(repo, "src"), exist_ok=True)
71 with open(os.path.join(repo, "src", "m.ts"), "wb") as f:
72 f.write(SRC.encode("utf-8"))
73 cache = os.path.join(work, "cache")
74 os.makedirs(cache, exist_ok=True)
75 os.makedirs(os.path.join(cache, "runtime"), mode=0o700, exist_ok=True)
76
77 # The CLI and hooks share the mandatory daemon. Start the supported
78 # permanent mode before indexing so every product-surface command uses
79 # the same isolated cache and daemon cohort.
80 # Retry once: a cold runner's daemon startup latency (#1952) is setup
81 # noise, not the surface under test.
82 start_out = ""
83 rc = 1
84 for attempt in (1, 2):
85 start = run_cli(binary, cache, ["daemon", "start"], timeout=60)
86 start_out = (start.stdout or b"").decode("utf-8", "replace")
87 start_err = (start.stderr or b"").decode("utf-8", "replace")
88 rc = start.returncode
89 print("daemon start attempt %d rc=%d stdout=%r stderr=%r" %
90 (attempt, rc, start_out[:120], start_err[:500]))
91 if rc == 0:
92 break
93 time.sleep(2)
94 if rc != 0:
95 print("SETUP FAIL: permanent daemon did not start")
96 return 2
97 daemon_started = True
98 pid_match = re.search(r"pid (\d+)", start_out)
99 daemon_pid = int(pid_match.group(1)) if pid_match else 0
100
101 # repo_path / cwd in the forward-slash drive form Claude Code passes.
102 repo_fwd = repo.replace("\\", "/")
103 # Setup, not the surface under test: retry once so a cold runner's
104 # coordination-daemon startup latency (#1952) is not misread as a
105 # broken CLI index. Reindexing the same cache is idempotent.
106 idx_out = ""
107 idx_err = ""

Callers 1

Calls 5

strFunction · 0.85
run_cliFunction · 0.70
openFunction · 0.50
writeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected