2 * Test script to verify command execution works end-to-end
3 * Tests the execute_script functionality added to agent v2
6const WebSocket = require('ws');
8// Agent UUID from the VM
9const agentUuid = '2c3e2d7a-c521-4844-b44b-a30b4c2ec4d8';
10const wsUrl = 'wss://rmm-psa-backend-t9f7k.ondigitalocean.app/api/ws';
12console.log('Connecting to WebSocket as backend...');
13const ws = new WebSocket(`${wsUrl}?agent_uuid=${agentUuid}`);
16 console.log('ā
Connected to WebSocket');
18 // Send a test script execution
20 type: 'execute_script',
21 execution_id: 'test-' + Date.now(),
22 script_id: 'test-script-1',
23 code: 'echo "Hello from Agent v2!"; echo "Current directory: $PWD"; whoami'
26 console.log('\nš¤ Sending command execution:', testCommand);
27 ws.send(JSON.stringify(testCommand));
29 // Timeout after 30 seconds
31 console.log('\nā±ļø Test timeout - closing connection');
37ws.on('message', (data) => {
39 const message = JSON.parse(data.toString());
41 switch (message.type) {
43 console.log(`š Output [${message.execution_id}]:`, message.line);
46 case 'script_complete':
47 console.log(`ā
Script completed [${message.execution_id}] - Exit code: ${message.exit_code}`);
55 console.log(`ā Script error [${message.execution_id}]:`, message.error);
63 console.log('šØ Received:', message.type);
66 console.error('Error parsing message:', err);
70ws.on('error', (error) => {
71 console.error('ā WebSocket error:', error.message);
76 console.log('š Connection closed');