This commit is contained in:
Chris Tate
2026-01-10 13:08:22 -06:00
parent ff05842fd8
commit 93374638eb
9 changed files with 416 additions and 404 deletions
+12 -12
View File
@@ -33,7 +33,7 @@ async function waitForSocket(maxAttempts = 30): Promise<boolean> {
debug('Socket found after', i * 100, 'ms');
return true;
}
await new Promise(r => setTimeout(r, 100));
await new Promise((r) => setTimeout(r, 100));
}
debug('Socket not found after', maxAttempts * 100, 'ms');
return false;
@@ -49,7 +49,7 @@ export async function ensureDaemon(): Promise<void> {
debug('Daemon already running');
return;
}
debug('Starting daemon...');
const daemonPath = path.join(__dirname, 'daemon.js');
const child = spawn(process.execPath, [daemonPath], {
@@ -58,13 +58,13 @@ export async function ensureDaemon(): Promise<void> {
env: { ...process.env, VEB_DAEMON: '1', VEB_SESSION: session },
});
child.unref();
// Wait for socket to be created
const ready = await waitForSocket();
if (!ready) {
throw new Error('Failed to start daemon');
}
debug(`Daemon started for session "${session}"`);
}
@@ -74,23 +74,23 @@ export async function ensureDaemon(): Promise<void> {
export async function sendCommand(command: Record<string, unknown>): Promise<Response> {
const socketPath = getSocketPath();
debug('Sending command:', JSON.stringify(command));
return new Promise((resolve, reject) => {
let resolved = false;
let buffer = '';
const startTime = Date.now();
const socket = net.createConnection(socketPath);
socket.on('connect', () => {
debug('Connected to daemon, sending command...');
socket.write(JSON.stringify(command) + '\n');
});
socket.on('data', (data) => {
buffer += data.toString();
debug('Received data:', buffer.length, 'bytes');
// Try to parse complete JSON from buffer
const newlineIdx = buffer.indexOf('\n');
if (newlineIdx !== -1) {
@@ -106,14 +106,14 @@ export async function sendCommand(command: Record<string, unknown>): Promise<Res
}
}
});
socket.on('error', (err) => {
debug('Socket error:', err.message);
if (!resolved) {
reject(new Error(`Connection error: ${err.message}`));
}
});
socket.on('close', () => {
debug('Socket closed, resolved:', resolved, 'buffer:', buffer.length);
if (!resolved && buffer.trim()) {
@@ -127,7 +127,7 @@ export async function sendCommand(command: Record<string, unknown>): Promise<Res
reject(new Error('Connection closed without response'));
}
});
// Timeout after 15 seconds (allows for 10s Playwright timeout + overhead)
setTimeout(() => {
if (!resolved) {