wishforge-ide/apps/ide/collaboration/test/client-factory.test.cjs
eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

56 lines
2.3 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert/strict');
const { collaborationBase, normalizeAuthMetadata, createPrefixTransport } = require('../client-factory.cjs');
test('collaboration URLs remain within the authenticated workspace and same origin', () => {
const location = 'https://ide.example/workspaces/alpha/index.html';
assert.equal(
collaborationBase('https://ide.example/workspaces/alpha/collaboration/', location).pathname,
'/workspaces/alpha/collaboration/',
);
for (const url of [
'https://external.example/workspaces/alpha/collaboration/',
'https://ide.example/workspaces/beta/collaboration/',
'https://ide.example/socket.io/',
'https://ide.example/workspaces/alpha/collaboration/?token=secret',
])
assert.throws(() => collaborationBase(url, location));
});
test('simple display-name form URL cannot escape the workspace basepath', () => {
const meta = normalizeAuthMetadata({
providers: [
{ type: 'form', name: 'unverified', endpoint: '/api/login/simple' },
{ type: 'web', name: 'github', endpoint: 'https://external.example' },
],
});
assert.equal(meta.providers.length, 1);
assert.equal(
new URL(meta.providers[0].endpoint, 'https://ide.example/workspaces/alpha/collaboration/').pathname,
'/workspaces/alpha/collaboration/api/login/simple',
);
assert.throws(() => normalizeAuthMetadata({ providers: [], loginPageUrl: 'https://external.example/login' }));
});
test('Socket.IO uses origin namespace plus a workspace-specific Engine.IO path', () => {
let observed;
const socket = {};
const adapter = createPrefixTransport(
{
io: (...args) => {
observed = args;
return socket;
},
SocketIoTransport: class {
constructor(value) {
this.socket = value;
}
},
},
'https://ide.example/workspaces/alpha/collaboration/',
);
const transport = adapter.createTransport('ignored', { 'x-oct-jwt': 'room-token' });
assert.equal(transport.socket, socket);
assert.equal(observed[0], 'https://ide.example');
assert.equal(observed[1].path, '/workspaces/alpha/collaboration/socket.io');
assert.deepEqual(observed[1].transports, ['polling', 'websocket']);
assert.equal(observed[1].extraHeaders['x-oct-jwt'], 'room-token');
});