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

Function main

tests/windows/test_daemon_lifecycle.py:62–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60
61
62def main():
63 if len(sys.argv) < 2:
64 print("usage: python test_daemon_lifecycle.py <binary>")
65 return 2
66 binary = os.path.abspath(sys.argv[1])
67 if not os.path.exists(binary):
68 print("FAIL: binary not found: %s" % binary)
69 return 2
70
71 work = tempfile.mkdtemp(prefix="cbm_win_daemonctl_")
72 cache = os.path.join(work, "cache")
73 os.makedirs(cache, exist_ok=True)
74 daemon_pid = 0
75 try:
76 status_absent = run_cli(binary, cache, ["daemon", "status"])
77 if status_absent.returncode == 0 or "not running" not in output_text(status_absent):
78 print("RED: `daemon status` with no daemon should report not-running "
79 "and exit nonzero:\n%s" % output_text(status_absent)[:300])
80 return 1
81 print("PASS: status reports not-running before any daemon exists")
82
83 cold = run_cli(binary, cache, ["cli", "list_projects", "{}"])
84 cold_text = output_text(cold)
85 if cold.returncode != 0 or "daemon start" in cold_text:
86 print("RED: a cold one-shot cli command should succeed without default "
87 "startup chatter:\n%s" % cold_text[:400])
88 return 1
89 print("PASS: cold cli one-shot succeeded quietly")
90
91 # Use an isolated rendezvous namespace to guarantee a cold verbose call.
92 verbose_cache = os.path.join(work, "cache-verbose")
93 os.makedirs(verbose_cache, exist_ok=True)
94 verbose = run_cli(binary, verbose_cache,
95 ["cli", "--verbose", "list_projects", "{}"])
96 verbose_text = output_text(verbose)
97 if verbose.returncode != 0 or "daemon start" not in verbose_text:
98 print("RED: `cli --verbose` should expose the cold-start hint:\n%s"
99 % verbose_text[:400])
100 return 1
101 print("PASS: verbose cold cli exposed the startup-tax hint")
102
103 start = run_cli(binary, cache, ["daemon", "start"])
104 start_text = output_text(start)
105 pid_match = re.search(r"pid (\d+)", start_text)
106 daemon_pid = int(pid_match.group(1)) if pid_match else 0
107 if start.returncode != 0 or "permanent" not in start_text or not daemon_pid:
108 print("RED: `daemon start` should report a permanent daemon with a pid:\n%s"
109 % start_text[:400])
110 return 1
111 print("PASS: daemon start reported permanent pid %d" % daemon_pid)
112 # Only a UI build configures a UI, and only it can refuse to.
113 ui_build = "ui:" in start_text
114
115 warm = run_cli(binary, cache, ["cli", "list_projects", "{}"])
116 warm_text = output_text(warm)
117 if warm.returncode != 0 or "daemon start" in warm_text:
118 print("RED: a warm cli one-shot should recycle the daemon without the "
119 "cold-start hint:\n%s" % warm_text[:400])

Callers 1

Calls 3

run_cliFunction · 0.70
output_textFunction · 0.70
force_killFunction · 0.70

Tested by

no test coverage detected