| 24 | } |
| 25 | |
| 26 | async function main() { |
| 27 | console.log(`Testing debug server at ${DEBUG_URL}\n`); |
| 28 | |
| 29 | // Test 1: Simple label only |
| 30 | console.log("1. Sending simple label..."); |
| 31 | const t1 = await sendLog("test-start"); |
| 32 | console.log(` Result: ${t1 ? "OK" : "FAILED"}`); |
| 33 | |
| 34 | // Test 2: Label with data object |
| 35 | console.log("2. Sending label with data..."); |
| 36 | const t2 = await sendLog("user-action", { userId: 123, action: "click", target: "button" }); |
| 37 | console.log(` Result: ${t2 ? "OK" : "FAILED"}`); |
| 38 | |
| 39 | // Test 3: Nested data |
| 40 | console.log("3. Sending nested data..."); |
| 41 | const t3 = await sendLog("api-response", { |
| 42 | status: 200, |
| 43 | body: { items: [1, 2, 3], meta: { page: 1, total: 100 } }, |
| 44 | }); |
| 45 | console.log(` Result: ${t3 ? "OK" : "FAILED"}`); |
| 46 | |
| 47 | // Test 4: Error simulation |
| 48 | console.log("4. Sending error data..."); |
| 49 | const t4 = await sendLog("error-caught", { |
| 50 | error: "Something went wrong", |
| 51 | stack: "Error: Something went wrong\n at main (test.ts:50:10)", |
| 52 | }); |
| 53 | console.log(` Result: ${t4 ? "OK" : "FAILED"}`); |
| 54 | |
| 55 | // Test 5: State change |
| 56 | console.log("5. Sending state change..."); |
| 57 | const t5 = await sendLog("state-updated", { |
| 58 | prevState: { count: 0, loading: true }, |
| 59 | nextState: { count: 5, loading: false }, |
| 60 | }); |
| 61 | console.log(` Result: ${t5 ? "OK" : "FAILED"}`); |
| 62 | |
| 63 | console.log("\n--- Summary ---"); |
| 64 | const passed = [t1, t2, t3, t4, t5].filter(Boolean).length; |
| 65 | console.log(`${passed}/5 tests passed`); |
| 66 | |
| 67 | if (passed === 5) { |
| 68 | console.log("\nAll logs sent successfully! Check .opencode/debug.log for entries."); |
| 69 | } else { |
| 70 | console.log("\nSome tests failed. Is the debug server running?"); |
| 71 | console.log(`Try: Start debug mode in OpenCode first, then run this test.`); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | main(); |