diff options
| author | Your Name <you@example.com> | 2026-05-19 01:10:06 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-19 01:10:06 +0530 |
| commit | 42902a36bc52e009a1e8d3c371741e30a9cb4c33 (patch) | |
| tree | 46db33710a3650b2267933a8375d3598af11319a /tests/integration | |
| parent | fe7c3be2fd9d464dbc837d1913409d2691bd50f5 (diff) | |
feat: ContextVM (MCP over Nostr) server with full integration
Complete CVM implementation: persistent WebSocket relay listener,
kind 25910 event subscription, MCP protocol handlers, CEP-6 announcements,
10 MCP tools, per-board hardware locks, WiFi EU regulatory fix.
Architecture:
- cvm_server.c: WS relay listener, kind 25910 subscription, MCP dispatch
- mcp_handler.c/h: 10 MCP tools (get_config, set_config, get_balance,
wallet_send, get_sessions, get_usage, set_payout, set_metric,
set_price, wallet_melt)
- Responses published via existing WS connection (not new TLS)
- Auth check: only owner npub accepted
- CEP-6: kinds 11316 (server), 11317 (tools), 10002 (relay list)
- WS ping/pong keepalive every 30s, 60s TLS read timeout
Critical fixes:
- WiFi country code DE (ESP-IDF defaults to CN, breaks EU APs)
- Subscription #p filter must be array not string
- Use-after-free: tags_str freed before nostr_event_to_json
- MCP responses via existing WS (ESP32 can't open multiple TLS)
- EVENT msg buffer underflow, WS frame masking, TLS write loop
Per-board hardware locks:
- Lock files in physical-router-test-automation/locks/
- lock-a/b/c, unlock-a/b/c targets in 3 Makefiles
- All hardware-touching targets require board lock
Verified on Board B via relay.primal.net:
- 282 unit tests passing (61 CVM + 60 MCP + 161 existing)
- MCP initialize roundtrip: PASS
- tools/list: PASS
- tools/call get_config: PASS
- tools/call get_balance: PASS
- tools/call set_price: PASS (write operation)
- CEP-6 announcements (11316, 11317, 10002): all accepted by relay
- WiFi STA connection (EnterSSID-2.4GHz): PASS with country code DE
- Board A WiFi confirmed hardware issue (not firmware)
Diffstat (limited to 'tests/integration')
| -rw-r--r-- | tests/integration/test-cvm.mjs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/integration/test-cvm.mjs b/tests/integration/test-cvm.mjs new file mode 100644 index 0000000..8deb6ec --- /dev/null +++ b/tests/integration/test-cvm.mjs | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | import { execSync } from 'child_process'; | ||
| 2 | |||
| 3 | const IP = process.env.TOLLGATE_IP || '10.192.45.1'; | ||
| 4 | const RELAYS = ['wss://relay.damus.io', 'wss://nos.lol']; | ||
| 5 | |||
| 6 | let passed = 0, failed = 0; | ||
| 7 | |||
| 8 | function assert(condition, test) { | ||
| 9 | if (condition) { console.log(` \u2713 ${test}`); passed++; } | ||
| 10 | else { console.log(` \u2717 ${test}`); failed++; } | ||
| 11 | } | ||
| 12 | |||
| 13 | function nak(args, timeout = 10000) { | ||
| 14 | try { | ||
| 15 | return execSync(`timeout ${timeout / 1000} nak ${args}`, { | ||
| 16 | encoding: 'utf8', | ||
| 17 | stdio: ['pipe', 'pipe', 'pipe'], | ||
| 18 | timeout | ||
| 19 | }).trim(); | ||
| 20 | } catch (e) { | ||
| 21 | return e.stdout ? e.stdout.trim() : ''; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | function sleep(ms) { return new Promise(r => setTimeout(r, ms)); } | ||
| 26 | |||
| 27 | async function runTests() { | ||
| 28 | console.log(`\n=== CVM Integration Tests (target: ${IP}) ===\n`); | ||
| 29 | |||
| 30 | const npub = nak(`key public a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2`); | ||
| 31 | const npubHex = npub.trim(); | ||
| 32 | console.log(`Board npub: ${npubHex}`); | ||
| 33 | |||
| 34 | const npubBech32 = nak(`encode npub ${npubHex}`).trim(); | ||
| 35 | console.log(`Board npub (bech32): ${npubBech32}`); | ||
| 36 | |||
| 37 | assert(npubHex.length === 64, 'npub hex is 64 chars'); | ||
| 38 | |||
| 39 | console.log('\n--- Test: Kind 11316 server announcement ---'); | ||
| 40 | for (const relay of RELAYS) { | ||
| 41 | console.log(` Querying ${relay}...`); | ||
| 42 | const result = nak(`req -k 11316 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 43 | if (result.length > 0) { | ||
| 44 | assert(result.includes('"kind"') || result.includes('11316'), | ||
| 45 | `Kind 11316 found on ${relay}`); | ||
| 46 | if (result.includes('TollGate')) { | ||
| 47 | assert(true, `Announcement contains "TollGate"`); | ||
| 48 | } | ||
| 49 | } else { | ||
| 50 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | console.log('\n--- Test: Kind 11317 tools list ---'); | ||
| 55 | for (const relay of RELAYS) { | ||
| 56 | const result = nak(`req -k 11317 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 57 | if (result.length > 0) { | ||
| 58 | assert(result.includes('"kind"') || result.includes('11317'), | ||
| 59 | `Kind 11317 found on ${relay}`); | ||
| 60 | if (result.includes('get_config') && result.includes('wallet_melt')) { | ||
| 61 | assert(true, `Tools list has expected tools`); | ||
| 62 | } | ||
| 63 | } else { | ||
| 64 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | console.log('\n--- Test: Kind 10002 relay list ---'); | ||
| 69 | for (const relay of RELAYS) { | ||
| 70 | const result = nak(`req -k 10002 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 71 | if (result.length > 0) { | ||
| 72 | assert(result.includes('"kind"') || result.includes('10002'), | ||
| 73 | `Kind 10002 found on ${relay}`); | ||
| 74 | } else { | ||
| 75 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | console.log('\n--- Test: API get_config (control check) ---'); | ||
| 80 | try { | ||
| 81 | const apiResult = execSync(`curl -s http://${IP}:2121/usage`, { encoding: 'utf8', timeout: 5000 }); | ||
| 82 | assert(apiResult.length > 0, 'API /usage responds (board is reachable)'); | ||
| 83 | } catch (e) { | ||
| 84 | console.log(' (API not reachable — board may be offline or not flashed yet)'); | ||
| 85 | } | ||
| 86 | |||
| 87 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 88 | process.exit(failed > 0 ? 1 : 0); | ||
| 89 | } | ||
| 90 | |||
| 91 | runTests().catch(e => { | ||
| 92 | console.error('Test error:', e.message); | ||
| 93 | process.exit(1); | ||
| 94 | }); | ||