()
| 65 | |
| 66 | |
| 67 | def main(): |
| 68 | if len(sys.argv) != 2: |
| 69 | print("usage: test_non_ascii_cache_dump.py <binary>") |
| 70 | return 2 |
| 71 | binary = os.path.abspath(sys.argv[1]) |
| 72 | if not os.path.exists(binary): |
| 73 | print(f"SETUP: binary not found: {binary}") |
| 74 | return 2 |
| 75 | |
| 76 | work = tempfile.mkdtemp(prefix="cbm_996_") |
| 77 | try: |
| 78 | repo = os.path.join(work, "ascii_repo") |
| 79 | os.makedirs(repo) |
| 80 | with open(os.path.join(repo, "math.ts"), "w", encoding="utf-8") as f: |
| 81 | f.write(MATH_TS) |
| 82 | |
| 83 | cache = os.path.join(work, NON_ASCII_CACHE_SEGMENT) |
| 84 | os.makedirs(cache) |
| 85 | |
| 86 | with McpServer(binary, cache_dir=cache) as s: |
| 87 | resp = s.call_tool("index_repository", {"repo_path": repo}) |
| 88 | text, err = McpServer.tool_text(resp) |
| 89 | if err: |
| 90 | print(f"FAIL: index_repository rpc error: {err}") |
| 91 | return 1 |
| 92 | text = text or "" |
| 93 | if '"error"' in text: |
| 94 | print(f"FAIL: index_repository into non-ASCII cache errored: {text[:300]}") |
| 95 | return 1 |
| 96 | if "phase" in text and "dump" in text and "error" in text.lower(): |
| 97 | print(f"FAIL: dump phase error: {text[:300]}") |
| 98 | return 1 |
| 99 | |
| 100 | # Non-vacuous readback: the DB must exist under the non-ASCII |
| 101 | # cache and answer queries. |
| 102 | project = None |
| 103 | try: |
| 104 | project = json.loads(text).get("project") |
| 105 | except (ValueError, AttributeError): |
| 106 | pass |
| 107 | if not project: |
| 108 | # TOON-shaped success output: fall back to list_projects. |
| 109 | lp = s.call_tool("list_projects", {}) |
| 110 | lp_text, _ = McpServer.tool_text(lp) |
| 111 | lp_text = lp_text or "" |
| 112 | for line in lp_text.splitlines(): |
| 113 | if "ascii_repo" in line: |
| 114 | project = line.split(",")[0].strip().strip('"') |
| 115 | break |
| 116 | if not project: |
| 117 | print("FAIL: could not determine project name after index") |
| 118 | return 1 |
| 119 | |
| 120 | count = graph_function_count(s, project) |
| 121 | if count < 1: |
| 122 | print(f"FAIL: readback from non-ASCII cache found {count} Function nodes") |
| 123 | return 1 |
| 124 |
no test coverage detected