feat(mesh): route reserved control path to meshControl on upgrade

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-06-27 20:31:48 -05:00
1 parent 1174d14754
commit f151da4bd7
2 files changed
+29 -4

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest';
import WebSocket from 'ws';
import { createHttpServer, type MeshControl } from '../../src/http';
describe('mesh control upgrade', () => {
it('routes the reserved path to meshControl.handle and leaves wsRoutes intact', async () => {
let handled = false;
const meshControl: MeshControl = { path: '/__mesh__/control', handle: (ws) => { handled = true; ws.send('hi'); } };
const server = createHttpServer([], [], undefined, meshControl);
await new Promise<void>((r) => server.listen(0, r));
const port = (server.address() as any).port;
const client = new WebSocket(`ws://127.0.0.1:${port}/__mesh__/control`);
const msg = await new Promise<string>((res) => { client.on('message', (d) => res(d.toString())); });
expect(msg).toBe('hi');
expect(handled).toBe(true);
client.close(); server.close();
});
});