()
| 28 | |
| 29 | |
| 30 | def main(): |
| 31 | if len(sys.argv) >= 2: |
| 32 | binary = sys.argv[1] |
| 33 | else: |
| 34 | # Default: look for build artifact relative to this script's directory |
| 35 | script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 36 | repo_root = os.path.dirname(script_dir) |
| 37 | binary = os.path.join(repo_root, "build", "c", "codebase-memory-mcp") |
| 38 | |
| 39 | if not os.path.isfile(binary): |
| 40 | print(f"FAIL: binary not found at {binary}") |
| 41 | sys.exit(1) |
| 42 | |
| 43 | if not os.access(binary, os.X_OK): |
| 44 | print(f"FAIL: binary not executable: {binary}") |
| 45 | sys.exit(1) |
| 46 | |
| 47 | proc = subprocess.Popen( |
| 48 | [binary], |
| 49 | stdin=subprocess.PIPE, |
| 50 | stdout=subprocess.PIPE, |
| 51 | stderr=subprocess.DEVNULL, |
| 52 | ) |
| 53 | |
| 54 | try: |
| 55 | # Write all 3 messages in one call and close stdin to signal EOF |
| 56 | stdout_data, _ = proc.communicate(input=MESSAGES, timeout=TIMEOUT_S) |
| 57 | except subprocess.TimeoutExpired: |
| 58 | proc.kill() |
| 59 | proc.wait() |
| 60 | print( |
| 61 | f"FAIL: server did not respond within {TIMEOUT_S}s " |
| 62 | f"(poll/getline buffering bug not fixed)" |
| 63 | ) |
| 64 | sys.exit(1) |
| 65 | |
| 66 | output = stdout_data.decode("utf-8", errors="replace") |
| 67 | |
| 68 | # Expect exactly 2 JSON responses: id:1 (initialize) and id:2 (tools/list). |
| 69 | # notifications/initialized has no id and produces no response. |
| 70 | lines = [ln.strip() for ln in output.splitlines() if ln.strip()] |
| 71 | import json as _json |
| 72 | json_lines = [] |
| 73 | for ln in lines: |
| 74 | try: |
| 75 | json_lines.append(_json.loads(ln)) |
| 76 | except _json.JSONDecodeError: |
| 77 | pass |
| 78 | |
| 79 | ids = {obj.get("id") for obj in json_lines if "id" in obj} |
| 80 | if 1 not in ids: |
| 81 | print("FAIL: missing initialize response (id:1) in server output") |
| 82 | print(f"Server output was:\n{output!r}") |
| 83 | sys.exit(1) |
| 84 | if 2 not in ids: |
| 85 | print("FAIL: missing tools/list response (id:2) in server output") |
| 86 | print(f"Server output was:\n{output!r}") |
| 87 | sys.exit(1) |
no test coverage detected