()
| 209 | return results |
| 210 | |
| 211 | def main(): |
| 212 | parser = argparse.ArgumentParser(description='Test jcode memory system') |
| 213 | parser.add_argument('--fresh', action='store_true', help='Start fresh server for testing') |
| 214 | parser.add_argument('--provider', choices=['claude', 'openai'], help='Test specific provider only') |
| 215 | parser.add_argument('--socket', help='Custom debug socket path') |
| 216 | args = parser.parse_args() |
| 217 | |
| 218 | providers = [args.provider] if args.provider else ['claude', 'openai'] |
| 219 | |
| 220 | proc = None |
| 221 | if args.fresh: |
| 222 | log_section("Starting fresh test server...") |
| 223 | test_socket = '/tmp/jcode-memory-test.sock' |
| 224 | debug_socket = test_socket.replace('.sock', '-debug.sock') |
| 225 | |
| 226 | for s in [test_socket, debug_socket]: |
| 227 | if os.path.exists(s): |
| 228 | os.remove(s) |
| 229 | |
| 230 | env = os.environ.copy() |
| 231 | env['JCODE_DEBUG_CONTROL'] = '1' |
| 232 | env['JCODE_SOCKET'] = test_socket |
| 233 | |
| 234 | proc = subprocess.Popen( |
| 235 | ['jcode', 'serve'], |
| 236 | env=env, |
| 237 | stdout=subprocess.PIPE, |
| 238 | stderr=subprocess.PIPE |
| 239 | ) |
| 240 | |
| 241 | for i in range(100): |
| 242 | if os.path.exists(debug_socket): |
| 243 | break |
| 244 | time.sleep(0.1) |
| 245 | else: |
| 246 | proc.terminate() |
| 247 | log_fail("Server failed to start") |
| 248 | sys.exit(1) |
| 249 | |
| 250 | log_pass(f"Server started (PID {proc.pid})") |
| 251 | socket_path = debug_socket |
| 252 | else: |
| 253 | socket_path = args.socket or '/run/user/1000/jcode-debug.sock' |
| 254 | if not os.path.exists(socket_path): |
| 255 | log_fail(f"Debug socket not found: {socket_path}") |
| 256 | log("Use --fresh to start a test server, or ensure jcode is running") |
| 257 | sys.exit(1) |
| 258 | |
| 259 | client = DebugSocketClient(socket_path) |
| 260 | |
| 261 | try: |
| 262 | client.connect() |
| 263 | results = run_tests(client, providers) |
| 264 | |
| 265 | log_section("TEST RESULTS") |
| 266 | total = results["passed"] + results["failed"] |
| 267 | log(f"Passed: {results['passed']}/{total}", GREEN if results["failed"] == 0 else YELLOW) |
| 268 | if results["failed"] > 0: |
no test coverage detected