| 64 | return resp.get('ok'), resp.get('output', '') |
| 65 | |
| 66 | def run_tests(client, providers): |
| 67 | results = {"passed": 0, "failed": 0} |
| 68 | |
| 69 | def check(condition, msg): |
| 70 | if condition: |
| 71 | log_pass(msg) |
| 72 | results["passed"] += 1 |
| 73 | else: |
| 74 | log_fail(msg) |
| 75 | results["failed"] += 1 |
| 76 | return condition |
| 77 | |
| 78 | for provider in providers: |
| 79 | log_section(f"Testing with {provider.upper()}") |
| 80 | |
| 81 | # Create session |
| 82 | ok, output = client.send(f"create_session:/tmp/memory-test-{provider}") |
| 83 | if not ok: |
| 84 | log_fail(f"Failed to create session: {output}") |
| 85 | continue |
| 86 | session_id = json.loads(output)['session_id'] |
| 87 | check(ok, f"Created session: {session_id}") |
| 88 | |
| 89 | # Switch provider |
| 90 | ok, output = client.send(f"set_provider:{provider}", session_id) |
| 91 | check(ok, f"Switched to {provider}") |
| 92 | if ok: |
| 93 | state = json.loads(output) |
| 94 | log(f" Provider: {state['provider']}, Model: {state['model']}") |
| 95 | |
| 96 | # Test 1: Memory remember with tags |
| 97 | log("\n --- Memory Remember ---") |
| 98 | ok, output = client.send( |
| 99 | f'tool:memory {{"action":"remember","content":"User prefers {provider} for testing","tags":["test","provider-pref"]}}', |
| 100 | session_id) |
| 101 | check(ok and "Remembered" in output, "Remember with tags") |
| 102 | |
| 103 | # Extract memory ID |
| 104 | result = json.loads(output) if output.startswith('{') else {'output': output} |
| 105 | match = re.search(r'id: (mem_\d+_\d+)', result.get('output', output)) |
| 106 | mem_id = match.group(1) if match else None |
| 107 | if mem_id: |
| 108 | log(f" Memory ID: {mem_id}") |
| 109 | |
| 110 | # Test 2: Memory list |
| 111 | log("\n --- Memory List ---") |
| 112 | ok, output = client.send('tool:memory {"action":"list"}', session_id) |
| 113 | check(ok and provider in output, "List shows our memory") |
| 114 | |
| 115 | # Test 3: Memory search (keyword) |
| 116 | log("\n --- Memory Search (keyword) ---") |
| 117 | ok, output = client.send(f'tool:memory {{"action":"search","query":"{provider} testing"}}', session_id) |
| 118 | check(ok, f"Search for '{provider} testing'") |
| 119 | |
| 120 | # Test 3b: Enhanced recall with query (semantic search) |
| 121 | log("\n --- Enhanced Recall (semantic) ---") |
| 122 | ok, output = client.send( |
| 123 | f'tool:memory {{"action":"recall","query":"testing preferences","mode":"cascade"}}', |