-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-debug-endpoint.js
More file actions
194 lines (153 loc) · 5.64 KB
/
test-debug-endpoint.js
File metadata and controls
194 lines (153 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* Test script for debug API endpoints
*/
const http = require('http');
const SERVER_URL = 'http://localhost:4000';
// Test circuit code
const sourceCode = `pub fn main(x: Field, y: pub Field) -> pub Field {
// Verify that x and y are both non-zero
assert(x != 0);
assert(y != 0);
// Compute the sum and verify it's greater than both inputs
let sum = x + y;
assert(sum as u64 > x as u64);
assert(sum as u64 > y as u64);
// Return the sum as proof output
sum
}`;
const inputs = {
x: "5",
y: "3"
};
async function makeRequest(method, path, body) {
return new Promise((resolve, reject) => {
const url = new URL(path, SERVER_URL);
const options = {
hostname: url.hostname,
port: url.port,
path: url.pathname,
method: method,
headers: {
'Content-Type': 'application/json',
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const json = JSON.parse(data);
resolve({ status: res.statusCode, data: json });
} catch (error) {
resolve({ status: res.statusCode, data });
}
});
});
req.on('error', (error) => {
reject(error);
});
if (body) {
req.write(JSON.stringify(body));
}
req.end();
});
}
async function testDebugAPI() {
console.log('🧪 Testing Debug API...\n');
try {
// Step 1: Start debug session
console.log('1️⃣ Starting debug session...');
const startResult = await makeRequest('POST', '/api/debug/start', {
sourceCode,
inputs
});
console.log(` Status: ${startResult.status}`);
console.log(` Response:`, JSON.stringify(startResult.data, null, 2));
if (!startResult.data.success) {
console.error('❌ Failed to start debug session');
return;
}
const sessionId = startResult.data.sessionId;
console.log(` ✅ Session ID: ${sessionId}\n`);
// Step 2: Execute a step command
console.log('2️⃣ Executing step command (next)...');
const stepResult = await makeRequest('POST', '/api/debug/step', {
sessionId,
command: 'next'
});
console.log(` Status: ${stepResult.status}`);
console.log(` Response:`, JSON.stringify(stepResult.data, null, 2));
if (stepResult.data.success) {
console.log(` ✅ Step executed successfully\n`);
} else {
console.log(` ❌ Step failed: ${stepResult.data.error}\n`);
}
// Step 3: Get variables
console.log('3️⃣ Fetching variables...');
const variablesResult = await makeRequest('GET', `/api/debug/variables/${sessionId}`, null);
console.log(` Status: ${variablesResult.status}`);
console.log(` Response:`, JSON.stringify(variablesResult.data, null, 2));
if (variablesResult.data.success) {
console.log(` ✅ Variables fetched: ${variablesResult.data.variables?.length || 0}\n`);
} else {
console.log(` ⚠️ Variables failed: ${variablesResult.data.error}\n`);
}
// Step 4: Get witness map
console.log('4️⃣ Fetching witness map...');
const witnessResult = await makeRequest('GET', `/api/debug/witness/${sessionId}`, null);
console.log(` Status: ${witnessResult.status}`);
console.log(` Response:`, JSON.stringify(witnessResult.data, null, 2));
if (witnessResult.data.success) {
console.log(` ✅ Witness entries: ${witnessResult.data.witnesses?.length || 0}\n`);
} else {
console.log(` ⚠️ Witness failed: ${witnessResult.data.error}\n`);
}
// Step 5: Get opcodes
console.log('5️⃣ Fetching opcodes...');
const opcodesResult = await makeRequest('GET', `/api/debug/opcodes/${sessionId}`, null);
console.log(` Status: ${opcodesResult.status}`);
console.log(` Response:`, JSON.stringify(opcodesResult.data, null, 2));
if (opcodesResult.data.success) {
console.log(` ✅ Opcodes fetched: ${opcodesResult.data.opcodes?.length || 0}\n`);
} else {
console.log(` ⚠️ Opcodes failed: ${opcodesResult.data.error}\n`);
}
// Step 6: Terminate session
console.log('6️⃣ Terminating debug session...');
const deleteResult = await makeRequest('DELETE', `/api/debug/${sessionId}`, null);
console.log(` Status: ${deleteResult.status}`);
if (deleteResult.status === 204) {
console.log(` ✅ Session terminated successfully\n`);
} else {
console.log(` ❌ Failed to terminate session\n`);
}
console.log('✅ All tests completed!');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error(error.stack);
}
}
// Check if server is running
async function checkServer() {
try {
const result = await makeRequest('GET', '/api/debug/health', null);
console.log('✅ Server is running!\n');
return true;
} catch (error) {
console.error('❌ Server is not running. Please start it with: npm run start:dev');
console.error(` Error: ${error.message}\n`);
return false;
}
}
async function main() {
console.log('═══════════════════════════════════════════════════════════');
console.log(' Noir Playground - Debug API Test Suite');
console.log('═══════════════════════════════════════════════════════════\n');
const serverRunning = await checkServer();
if (serverRunning) {
await testDebugAPI();
}
}
main();