@openchamber/web 1.14.1 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.test.js +8 -0
- package/bin/lib/DOCUMENTATION.md +3 -0
- package/bin/lib/cli-args.js +10 -0
- package/bin/lib/commands-connect-url.js +169 -22
- package/dist/assets/{DiagramView-Cb58svCq.js → DiagramView-HR2xZxJ8.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-sm01Q7R7.js +11 -0
- package/dist/assets/{MultiRunWindow-BPSxV_B7.js → MultiRunWindow-DlFUaNQK.js} +1 -1
- package/dist/assets/OnboardingScreen-DVRz82mJ.js +1 -0
- package/dist/assets/{SessionSwitcherDropdown-4FWg9xMC.js → SessionSwitcherDropdown-DvoOalMY.js} +1 -1
- package/dist/assets/SettingsWindow-CkInZcj7.js +1 -0
- package/dist/assets/{TerminalView-fTYjnQkh.js → TerminalView-D_9BAjtv.js} +3 -3
- package/dist/assets/es-cjUissX4.js +15 -0
- package/dist/assets/fr-DqbXnTdK.js +13 -0
- package/dist/assets/index-Dg0nmvQU.css +1 -0
- package/dist/assets/index-ltrmNGAf.js +2 -0
- package/dist/assets/ja-Cetyq6Eg.js +15 -0
- package/dist/assets/ko-DtunWisP.js +15 -0
- package/dist/assets/main-BC0m8s1v.js +236 -0
- package/dist/assets/main-DzNa8r0N.js +2 -0
- package/dist/assets/miniChat-BRYDE-Se.js +2 -0
- package/dist/assets/mobile-C3QJVA97.js +2 -0
- package/dist/assets/pl-DctGLgve.js +15 -0
- package/dist/assets/pt-BR-CXPhf78S.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-CVFbDC5A.js +2 -0
- package/dist/assets/renderMobileApp-wkBjh5WR.js +16 -0
- package/dist/assets/runtimeEndpointReset-C42u8PvG.js +167 -0
- package/dist/assets/uk-Bdrc-kqF.js +15 -0
- package/dist/assets/{useAppFontEffects-BUUJYbAZ.js → useAppFontEffects-DzBg8hrC.js} +123 -119
- package/dist/assets/{vendor-.bun-C6iL44L9.js → vendor-.bun-BE757pvp.js} +1 -1
- package/dist/assets/zh-CN-CeCVKrHP.js +15 -0
- package/dist/assets/zh-TW-CoqiQING.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +130 -1
- package/server/lib/client-auth/pairing.js +308 -0
- package/server/lib/client-auth/pairing.test.js +142 -0
- package/server/lib/client-auth/remote-clients.js +65 -3
- package/server/lib/notifications/apns-runtime.js +9 -16
- package/server/lib/opencode/bootstrap-runtime.js +10 -0
- package/server/lib/opencode/core-routes.js +246 -6
- package/server/lib/opencode/core-routes.test.js +248 -9
- package/server/lib/opencode/network-runtime.js +14 -1
- package/server/lib/opencode/network-runtime.test.js +29 -9
- package/server/lib/opencode/proxy.js +47 -6
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +11 -0
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/package-manager.js +18 -5
- package/server/lib/relay/DOCUMENTATION.md +78 -0
- package/server/lib/relay/cross-compat.test.js +135 -0
- package/server/lib/relay/e2ee.js +341 -0
- package/server/lib/relay/e2ee.test.js +124 -0
- package/server/lib/relay/host-client.js +389 -0
- package/server/lib/relay/host-client.test.js +280 -0
- package/server/lib/relay/identity.js +73 -0
- package/server/lib/relay/identity.test.js +78 -0
- package/server/lib/relay/service.js +247 -0
- package/server/lib/relay/signing-key.js +50 -0
- package/server/lib/relay/tunnel-codec.js +373 -0
- package/server/lib/relay/tunnel-codec.test.js +58 -0
- package/server/lib/relay/tunnel-host.js +462 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +6 -0
- package/server/lib/ui-auth/ui-auth.js +10 -0
- package/server/opencode-proxy.test.js +38 -0
- package/dist/assets/MarkdownRendererImpl-D2yCDL5A.js +0 -7
- package/dist/assets/OnboardingScreen-Sl-6JgaP.js +0 -1
- package/dist/assets/SettingsWindow-CY8q4msv.js +0 -1
- package/dist/assets/es-bWcuDy_2.js +0 -15
- package/dist/assets/fr-DzRs3OzV.js +0 -13
- package/dist/assets/index-KnWk9fmM.css +0 -1
- package/dist/assets/index-ZJTzZ0_U.js +0 -2
- package/dist/assets/ja-BqUX_UD3.js +0 -15
- package/dist/assets/ko-BQo10SNx.js +0 -15
- package/dist/assets/main-BDoqLlQB.js +0 -236
- package/dist/assets/main-DUGyTrDt.js +0 -2
- package/dist/assets/miniChat-DNDiX8GA.js +0 -2
- package/dist/assets/mobile-DnghtOCb.js +0 -2
- package/dist/assets/pl-Bgx_ATJT.js +0 -15
- package/dist/assets/pt-BR-B1yXRvoX.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BB4C1K7t.js +0 -2
- package/dist/assets/renderMobileApp-CZgaXKi5.js +0 -16
- package/dist/assets/runtimeEndpointReset-By39StyB.js +0 -167
- package/dist/assets/uk-C9k8SP8q.js +0 -15
- package/dist/assets/zh-CN-Bri-Vo5y.js +0 -15
- package/dist/assets/zh-TW-DAUGzmYG.js +0 -15
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import request from 'supertest';
|
|
4
4
|
import { registerAuthAndAccessRoutes, registerCommonRequestMiddleware, registerServerStatusRoutes } from './core-routes.js';
|
|
5
5
|
|
|
6
6
|
describe('core-routes', () => {
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
vi.useRealTimers();
|
|
9
|
+
});
|
|
10
|
+
|
|
7
11
|
it('should call gracefulShutdown with exitProcess: true on /api/system/shutdown', async () => {
|
|
8
12
|
const app = express();
|
|
9
13
|
let shutdownOpts = null;
|
|
@@ -225,6 +229,206 @@ describe('core-routes', () => {
|
|
|
225
229
|
}
|
|
226
230
|
});
|
|
227
231
|
|
|
232
|
+
const createPairingRouteApp = (overrides = {}) => {
|
|
233
|
+
const app = express();
|
|
234
|
+
const dependencies = {
|
|
235
|
+
express,
|
|
236
|
+
tunnelAuthController: {
|
|
237
|
+
classifyRequestScope: () => 'local',
|
|
238
|
+
requireTunnelSession: vi.fn(),
|
|
239
|
+
getTunnelSessionFromRequest: vi.fn(),
|
|
240
|
+
clearTunnelSessionCookie: vi.fn(),
|
|
241
|
+
exchangeBootstrapToken: vi.fn(),
|
|
242
|
+
},
|
|
243
|
+
uiAuthController: {
|
|
244
|
+
resolveAuthContext: vi.fn(async () => ({ type: 'session', token: 'session-token' })),
|
|
245
|
+
requireAuth: vi.fn((_req, _res, next) => next()),
|
|
246
|
+
requireSessionAuth: vi.fn((_req, _res, next) => next()),
|
|
247
|
+
handleSessionStatus: vi.fn(),
|
|
248
|
+
handleSessionCreate: vi.fn(),
|
|
249
|
+
handleUrlAuthToken: vi.fn(),
|
|
250
|
+
handlePasskeyStatus: vi.fn(),
|
|
251
|
+
handlePasskeyAuthenticationOptions: vi.fn(),
|
|
252
|
+
handlePasskeyAuthenticationVerify: vi.fn(),
|
|
253
|
+
handlePasskeyRegistrationOptions: vi.fn(),
|
|
254
|
+
handlePasskeyRegistrationVerify: vi.fn(),
|
|
255
|
+
handlePasskeyList: vi.fn(),
|
|
256
|
+
handlePasskeyRevoke: vi.fn(),
|
|
257
|
+
handleResetAuth: vi.fn(),
|
|
258
|
+
},
|
|
259
|
+
remoteClientAuthRuntime: {
|
|
260
|
+
listClients: vi.fn(async () => []),
|
|
261
|
+
createClient: vi.fn(),
|
|
262
|
+
revokeClient: vi.fn(),
|
|
263
|
+
purgeRevokedClients: vi.fn(),
|
|
264
|
+
},
|
|
265
|
+
clientPairingRuntime: {
|
|
266
|
+
createPairingSession: vi.fn(async () => ({ pairing: { id: 'pair_1', secret: 'secret', expiresAt: '2099-01-01T00:00:00.000Z', fingerprint: 'ABCD-1234' } })),
|
|
267
|
+
cancelPairingSession: vi.fn(async () => ({ cancelled: true })),
|
|
268
|
+
redeemPairingSession: vi.fn(async () => ({
|
|
269
|
+
pairing: { fingerprint: 'ABCD-1234' },
|
|
270
|
+
client: { id: 'client-1', label: 'Phone', authMethod: 'pairing' },
|
|
271
|
+
token: 'oc_client_token',
|
|
272
|
+
})),
|
|
273
|
+
},
|
|
274
|
+
readSettingsFromDiskMigrated: vi.fn(async () => ({})),
|
|
275
|
+
normalizeTunnelSessionTtlMs: vi.fn(),
|
|
276
|
+
...overrides,
|
|
277
|
+
};
|
|
278
|
+
registerAuthAndAccessRoutes(app, dependencies);
|
|
279
|
+
return { app, dependencies };
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
it('creates pairing sessions behind owner auth and returns no-store payload data', async () => {
|
|
283
|
+
const { app, dependencies } = createPairingRouteApp();
|
|
284
|
+
|
|
285
|
+
const response = await request(app)
|
|
286
|
+
.post('/api/client-auth/pairing/sessions')
|
|
287
|
+
.set('Host', 'runtime.example')
|
|
288
|
+
.send({ label: 'Pair phone', allowedClientKinds: ['mobile'] })
|
|
289
|
+
.expect(201);
|
|
290
|
+
|
|
291
|
+
expect(response.headers['cache-control']).toBe('no-store');
|
|
292
|
+
expect(response.body.pairing).toMatchObject({ id: 'pair_1', secret: 'secret' });
|
|
293
|
+
expect(response.body.server.candidates).toEqual([{ type: 'lan', url: 'http://runtime.example', priority: 10 }]);
|
|
294
|
+
expect(dependencies.clientPairingRuntime.createPairingSession).toHaveBeenCalledWith({
|
|
295
|
+
label: 'Pair phone',
|
|
296
|
+
allowedClientKinds: ['mobile'],
|
|
297
|
+
createdByClientId: null,
|
|
298
|
+
usesRelay: false,
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('advertises the caller-supplied serverUrl as the direct candidate over the request origin', async () => {
|
|
303
|
+
const { app } = createPairingRouteApp();
|
|
304
|
+
|
|
305
|
+
const response = await request(app)
|
|
306
|
+
.post('/api/client-auth/pairing/sessions')
|
|
307
|
+
.set('Host', 'runtime.example')
|
|
308
|
+
.send({ label: 'Pair phone', serverUrl: 'http://192.168.1.20:2606' })
|
|
309
|
+
.expect(201);
|
|
310
|
+
|
|
311
|
+
expect(response.body.server.candidates).toEqual([
|
|
312
|
+
{ type: 'lan', url: 'http://192.168.1.20:2606', priority: 10 },
|
|
313
|
+
]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('folds in a relay candidate when the host relay is enabled', async () => {
|
|
317
|
+
const relayCandidate = {
|
|
318
|
+
type: 'relay',
|
|
319
|
+
relayUrl: 'wss://relay.example/ws',
|
|
320
|
+
serverId: 'srv_1',
|
|
321
|
+
hostEncPubJwk: { kty: 'EC', crv: 'P-256', x: 'aaa', y: 'bbb' },
|
|
322
|
+
priority: 30,
|
|
323
|
+
};
|
|
324
|
+
const { app } = createPairingRouteApp({ getRelayPairingCandidate: vi.fn(async () => relayCandidate) });
|
|
325
|
+
|
|
326
|
+
const response = await request(app)
|
|
327
|
+
.post('/api/client-auth/pairing/sessions')
|
|
328
|
+
.set('Host', 'runtime.example')
|
|
329
|
+
.send({ label: 'Pair phone' })
|
|
330
|
+
.expect(201);
|
|
331
|
+
|
|
332
|
+
expect(response.body.server.candidates).toEqual([
|
|
333
|
+
{ type: 'lan', url: 'http://runtime.example', priority: 10 },
|
|
334
|
+
relayCandidate,
|
|
335
|
+
]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('still returns the direct candidate when the relay candidate lookup throws', async () => {
|
|
339
|
+
const { app } = createPairingRouteApp({
|
|
340
|
+
getRelayPairingCandidate: vi.fn(async () => { throw new Error('relay status read failed'); }),
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const response = await request(app)
|
|
344
|
+
.post('/api/client-auth/pairing/sessions')
|
|
345
|
+
.set('Host', 'runtime.example')
|
|
346
|
+
.send({ label: 'Pair phone' })
|
|
347
|
+
.expect(201);
|
|
348
|
+
|
|
349
|
+
expect(response.body.server.candidates).toEqual([{ type: 'lan', url: 'http://runtime.example', priority: 10 }]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('requires owner auth before creating or cancelling pairing sessions', async () => {
|
|
353
|
+
const { app, dependencies } = createPairingRouteApp({
|
|
354
|
+
uiAuthController: {
|
|
355
|
+
resolveAuthContext: vi.fn(async () => null),
|
|
356
|
+
requireAuth: vi.fn((_req, res) => res.status(401).json({ error: 'Unauthorized' })),
|
|
357
|
+
requireSessionAuth: vi.fn((_req, res) => res.status(401).json({ error: 'Unauthorized' })),
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
await request(app).post('/api/client-auth/pairing/sessions').send({}).expect(401);
|
|
362
|
+
await request(app).delete('/api/client-auth/pairing/sessions/pair_1').expect(401);
|
|
363
|
+
expect(dependencies.clientPairingRuntime.createPairingSession).not.toHaveBeenCalled();
|
|
364
|
+
expect(dependencies.clientPairingRuntime.cancelPairingSession).not.toHaveBeenCalled();
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('redeems pairing sessions with no-store response and generic errors', async () => {
|
|
368
|
+
const { app, dependencies } = createPairingRouteApp();
|
|
369
|
+
|
|
370
|
+
const response = await request(app)
|
|
371
|
+
.post('/api/client-auth/pairing/redeem')
|
|
372
|
+
.set('Host', 'runtime.example')
|
|
373
|
+
.send({ pairingId: 'pair_1', secret: 'secret', clientKind: 'mobile', deviceName: 'Phone' })
|
|
374
|
+
.expect(200);
|
|
375
|
+
|
|
376
|
+
expect(response.headers['cache-control']).toBe('no-store');
|
|
377
|
+
expect(response.body).toMatchObject({
|
|
378
|
+
ok: true,
|
|
379
|
+
server: { label: 'OpenChamber', url: 'http://runtime.example', fingerprint: 'ABCD-1234' },
|
|
380
|
+
client: { id: 'client-1', authMethod: 'pairing' },
|
|
381
|
+
clientToken: 'oc_client_token',
|
|
382
|
+
});
|
|
383
|
+
expect(dependencies.clientPairingRuntime.redeemPairingSession).toHaveBeenCalledWith(expect.objectContaining({
|
|
384
|
+
pairingId: 'pair_1',
|
|
385
|
+
secret: 'secret',
|
|
386
|
+
clientKind: 'mobile',
|
|
387
|
+
deviceName: 'Phone',
|
|
388
|
+
}));
|
|
389
|
+
|
|
390
|
+
dependencies.clientPairingRuntime.redeemPairingSession.mockRejectedValueOnce(new Error('Invalid or expired pairing session'));
|
|
391
|
+
await request(app)
|
|
392
|
+
.post('/api/client-auth/pairing/redeem')
|
|
393
|
+
.send({ pairingId: 'pair_2', secret: 'wrong' })
|
|
394
|
+
.expect(400, { error: 'Invalid or expired pairing session' });
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('rate limits pairing redeem attempts by socket address and pairingId, then resets after the window', async () => {
|
|
398
|
+
vi.useFakeTimers();
|
|
399
|
+
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
|
|
400
|
+
const { app, dependencies } = createPairingRouteApp();
|
|
401
|
+
app.set('trust proxy', true);
|
|
402
|
+
dependencies.clientPairingRuntime.redeemPairingSession.mockRejectedValue(new Error('Invalid or expired pairing session'));
|
|
403
|
+
|
|
404
|
+
// The X-Forwarded-For headers below are deliberate spoof attempts: the rate
|
|
405
|
+
// limiter buckets by socket address (not forwarded headers), so rotating the
|
|
406
|
+
// header must NOT reset the counter or evade the lockout.
|
|
407
|
+
for (let index = 0; index < 10; index += 1) {
|
|
408
|
+
await request(app)
|
|
409
|
+
.post('/api/client-auth/pairing/redeem')
|
|
410
|
+
.set('X-Forwarded-For', `203.0.113.${index}`)
|
|
411
|
+
.send({ pairingId: 'pair_rate', secret: `wrong-${index}` })
|
|
412
|
+
.expect(400, { error: 'Invalid or expired pairing session' });
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const locked = await request(app)
|
|
416
|
+
.post('/api/client-auth/pairing/redeem')
|
|
417
|
+
.set('X-Forwarded-For', '203.0.113.10')
|
|
418
|
+
.send({ pairingId: 'pair_rate', secret: 'wrong-locked' })
|
|
419
|
+
.expect(429, { error: 'Invalid or expired pairing session' });
|
|
420
|
+
expect(locked.headers['retry-after']).toBe('300');
|
|
421
|
+
expect(dependencies.clientPairingRuntime.redeemPairingSession).toHaveBeenCalledTimes(10);
|
|
422
|
+
|
|
423
|
+
vi.setSystemTime(new Date('2026-01-01T00:05:01Z'));
|
|
424
|
+
await request(app)
|
|
425
|
+
.post('/api/client-auth/pairing/redeem')
|
|
426
|
+
.set('X-Forwarded-For', '203.0.113.10')
|
|
427
|
+
.send({ pairingId: 'pair_rate', secret: 'wrong-after-reset' })
|
|
428
|
+
.expect(400, { error: 'Invalid or expired pairing session' });
|
|
429
|
+
expect(dependencies.clientPairingRuntime.redeemPairingSession).toHaveBeenCalledTimes(11);
|
|
430
|
+
});
|
|
431
|
+
|
|
228
432
|
it('should let preview proxy credentials reach preview proxy validation', async () => {
|
|
229
433
|
const app = express();
|
|
230
434
|
const requireAuth = vi.fn((_req, res) => res.status(401).type('text/plain').send('Authentication required'));
|
|
@@ -364,11 +568,9 @@ describe('client auth routes', () => {
|
|
|
364
568
|
|
|
365
569
|
const listedAfterPurge = await request(app).get('/api/client-auth/clients');
|
|
366
570
|
expect(listedAfterPurge.body.clients).toHaveLength(0);
|
|
367
|
-
expect(dependencies.testHooks.requireSessionAuth).toHaveBeenCalled();
|
|
368
|
-
expect(dependencies.testHooks.requireAuth).not.toHaveBeenCalled();
|
|
369
571
|
});
|
|
370
572
|
|
|
371
|
-
it('
|
|
573
|
+
it('scopes non-desktop client credentials to list and revoke only themselves', async () => {
|
|
372
574
|
const app = express();
|
|
373
575
|
let authContext = { type: 'session' };
|
|
374
576
|
const dependencies = createDependencies({
|
|
@@ -383,20 +585,57 @@ describe('client auth routes', () => {
|
|
|
383
585
|
.post('/api/client-auth/clients')
|
|
384
586
|
.send({ label: 'Other device' });
|
|
385
587
|
|
|
386
|
-
|
|
588
|
+
// A regular (non-desktop-local) client token only sees and manages itself.
|
|
589
|
+
authContext = { type: 'client', clientId: other.body.client.id, client: other.body.client };
|
|
387
590
|
|
|
388
591
|
const listed = await request(app).get('/api/client-auth/clients');
|
|
389
592
|
expect(listed.status).toBe(200);
|
|
390
|
-
expect(listed.body.clients).toEqual([
|
|
593
|
+
expect(listed.body.clients).toEqual([other.body.client]);
|
|
391
594
|
|
|
392
|
-
const denied = await request(app).delete(`/api/client-auth/clients/${
|
|
595
|
+
const denied = await request(app).delete(`/api/client-auth/clients/${current.body.client.id}`);
|
|
393
596
|
expect(denied.status).toBe(403);
|
|
394
597
|
expect(denied.body.revoked).toBe(false);
|
|
395
598
|
|
|
396
|
-
const
|
|
599
|
+
const deniedPurge = await request(app).delete('/api/client-auth/clients');
|
|
600
|
+
expect(deniedPurge.status).toBe(403);
|
|
601
|
+
|
|
602
|
+
const revoked = await request(app).delete(`/api/client-auth/clients/${other.body.client.id}`);
|
|
603
|
+
expect(revoked.status).toBe(200);
|
|
604
|
+
expect(revoked.body.revoked).toBe(true);
|
|
605
|
+
expect(revoked.body.client.id).toBe(other.body.client.id);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('lets the local desktop client list and revoke every device', async () => {
|
|
609
|
+
const app = express();
|
|
610
|
+
let authContext = { type: 'session' };
|
|
611
|
+
const dependencies = createDependencies({
|
|
612
|
+
resolveAuthContext: async () => authContext,
|
|
613
|
+
});
|
|
614
|
+
registerAuthAndAccessRoutes(app, dependencies);
|
|
615
|
+
|
|
616
|
+
const desktop = await request(app)
|
|
617
|
+
.post('/api/client-auth/clients')
|
|
618
|
+
.send({ label: 'OpenChamber Desktop', clientKind: 'desktop-local' });
|
|
619
|
+
const other = await request(app)
|
|
620
|
+
.post('/api/client-auth/clients')
|
|
621
|
+
.send({ label: 'Other device' });
|
|
622
|
+
|
|
623
|
+
// The trusted desktop shell client manages all devices like a UI session.
|
|
624
|
+
authContext = { type: 'client', clientId: desktop.body.client.id, client: desktop.body.client };
|
|
625
|
+
|
|
626
|
+
const listed = await request(app).get('/api/client-auth/clients');
|
|
627
|
+
expect(listed.status).toBe(200);
|
|
628
|
+
const listedIds = listed.body.clients.map((client) => client.id).sort();
|
|
629
|
+
expect(listedIds).toEqual([desktop.body.client.id, other.body.client.id].sort());
|
|
630
|
+
|
|
631
|
+
const revoked = await request(app).delete(`/api/client-auth/clients/${other.body.client.id}`);
|
|
397
632
|
expect(revoked.status).toBe(200);
|
|
398
633
|
expect(revoked.body.revoked).toBe(true);
|
|
399
|
-
expect(revoked.body.client.id).toBe(
|
|
634
|
+
expect(revoked.body.client.id).toBe(other.body.client.id);
|
|
635
|
+
|
|
636
|
+
const purged = await request(app).delete('/api/client-auth/clients');
|
|
637
|
+
expect(purged.status).toBe(200);
|
|
638
|
+
expect(purged.body.purged).toBe(1);
|
|
400
639
|
});
|
|
401
640
|
|
|
402
641
|
it('allows only the local desktop client token to create remote client tokens', async () => {
|
|
@@ -2,8 +2,21 @@ export const createOpenCodeNetworkRuntime = (deps) => {
|
|
|
2
2
|
const {
|
|
3
3
|
state,
|
|
4
4
|
getOpenCodeAuthHeaders,
|
|
5
|
+
configuredOpenCodeHostname = '127.0.0.1',
|
|
5
6
|
} = deps;
|
|
6
7
|
|
|
8
|
+
const resolveConnectHostname = () => {
|
|
9
|
+
const raw = typeof configuredOpenCodeHostname === 'string' ? configuredOpenCodeHostname.trim() : '';
|
|
10
|
+
const hostname = raw || '127.0.0.1';
|
|
11
|
+
if (hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]') {
|
|
12
|
+
return '127.0.0.1';
|
|
13
|
+
}
|
|
14
|
+
if (hostname.startsWith('[') && hostname.endsWith(']')) {
|
|
15
|
+
return hostname;
|
|
16
|
+
}
|
|
17
|
+
return hostname.includes(':') ? `[${hostname}]` : hostname;
|
|
18
|
+
};
|
|
19
|
+
|
|
7
20
|
const normalizeApiPrefix = (prefix) => {
|
|
8
21
|
if (!prefix) {
|
|
9
22
|
return '';
|
|
@@ -77,7 +90,7 @@ export const createOpenCodeNetworkRuntime = (deps) => {
|
|
|
77
90
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
78
91
|
const prefix = normalizeApiPrefix(prefixOverride !== undefined ? prefixOverride : '');
|
|
79
92
|
const fullPath = `${prefix}${normalizedPath}`;
|
|
80
|
-
const base = state.openCodeBaseUrl ?? `http
|
|
93
|
+
const base = state.openCodeBaseUrl ?? `http://${resolveConnectHostname()}:${state.openCodePort}`;
|
|
81
94
|
return `${base}${fullPath}`;
|
|
82
95
|
};
|
|
83
96
|
|
|
@@ -2,36 +2,56 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { createOpenCodeNetworkRuntime } from './network-runtime.js';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const originalFetch = globalThis.fetch;
|
|
6
|
+
|
|
7
|
+
const createRuntime = (overrides = {}) => createOpenCodeNetworkRuntime({
|
|
6
8
|
state: {
|
|
7
9
|
openCodePort: 4096,
|
|
8
10
|
openCodeBaseUrl: null,
|
|
9
11
|
openCodeApiPrefix: '',
|
|
10
12
|
openCodeApiPrefixDetected: false,
|
|
11
13
|
openCodeApiDetectionTimer: null,
|
|
14
|
+
...overrides.state,
|
|
12
15
|
},
|
|
13
16
|
getOpenCodeAuthHeaders: () => ({}),
|
|
17
|
+
configuredOpenCodeHostname: overrides.configuredOpenCodeHostname,
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
describe('OpenCode network runtime', () => {
|
|
17
21
|
afterEach(() => {
|
|
18
22
|
vi.useRealTimers();
|
|
19
|
-
|
|
23
|
+
globalThis.fetch = originalFetch;
|
|
20
24
|
});
|
|
21
25
|
|
|
22
|
-
it('
|
|
23
|
-
vi.
|
|
24
|
-
vi.setSystemTime(0);
|
|
25
|
-
vi.stubGlobal('fetch', vi.fn(async () => {
|
|
26
|
+
it('returns false when readiness fetch rejects', async () => {
|
|
27
|
+
globalThis.fetch = vi.fn(async () => {
|
|
26
28
|
throw new Error('offline');
|
|
27
|
-
})
|
|
29
|
+
});
|
|
28
30
|
|
|
29
31
|
const runtime = createRuntime();
|
|
30
32
|
const readyPromise = runtime.waitForReady('http://127.0.0.1:4096', 1);
|
|
31
33
|
|
|
32
|
-
await vi.advanceTimersByTimeAsync(100);
|
|
33
34
|
await expect(readyPromise).resolves.toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('builds managed OpenCode URLs against IPv4 loopback by default', () => {
|
|
38
|
+
const runtime = createRuntime();
|
|
39
|
+
|
|
40
|
+
expect(runtime.buildOpenCodeUrl('/provider')).toBe('http://127.0.0.1:4096/provider');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('keeps external OpenCode base URLs authoritative', () => {
|
|
44
|
+
const runtime = createRuntime({
|
|
45
|
+
state: { openCodeBaseUrl: 'http://remote.example:4096' },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(runtime.buildOpenCodeUrl('/provider')).toBe('http://remote.example:4096/provider');
|
|
49
|
+
});
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
it('normalizes wildcard and IPv6 OpenCode bind hosts for local connects', () => {
|
|
52
|
+
expect(createRuntime({ configuredOpenCodeHostname: '0.0.0.0' }).buildOpenCodeUrl('/provider'))
|
|
53
|
+
.toBe('http://127.0.0.1:4096/provider');
|
|
54
|
+
expect(createRuntime({ configuredOpenCodeHostname: '::1' }).buildOpenCodeUrl('/provider'))
|
|
55
|
+
.toBe('http://[::1]:4096/provider');
|
|
36
56
|
});
|
|
37
57
|
});
|
|
@@ -181,6 +181,7 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
181
181
|
os,
|
|
182
182
|
path,
|
|
183
183
|
OPEN_CODE_READY_GRACE_MS,
|
|
184
|
+
LONG_REQUEST_TIMEOUT_MS,
|
|
184
185
|
getRuntime,
|
|
185
186
|
getOpenCodeAuthHeaders,
|
|
186
187
|
buildOpenCodeUrl,
|
|
@@ -291,11 +292,46 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
291
292
|
return externalBase;
|
|
292
293
|
}
|
|
293
294
|
|
|
294
|
-
|
|
295
|
-
|
|
295
|
+
return FALLBACK_PROXY_TARGET;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const normalizeProxyTimeout = (value) => {
|
|
299
|
+
return Number.isFinite(value) && value > 0 ? value : 4 * 60 * 1000;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const PROXY_REQUEST_TIMEOUT_MS = normalizeProxyTimeout(LONG_REQUEST_TIMEOUT_MS);
|
|
303
|
+
const PROXY_TIMEOUT_MARKER = Symbol('openchamberProxyTimedOut');
|
|
304
|
+
|
|
305
|
+
const isProxyTimeoutError = (error) => {
|
|
306
|
+
const code = typeof error?.code === 'string' ? error.code : '';
|
|
307
|
+
const message = typeof error?.message === 'string' ? error.message.toLowerCase() : '';
|
|
308
|
+
return code === 'ETIMEDOUT'
|
|
309
|
+
|| code === 'ESOCKETTIMEDOUT'
|
|
310
|
+
|| message.includes('timeout')
|
|
311
|
+
|| message.includes('timed out');
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const sendProxyErrorResponse = (res, statusCode) => {
|
|
315
|
+
if (!res || res.headersSent || res.writableEnded || typeof res.status !== 'function') {
|
|
316
|
+
return false;
|
|
296
317
|
}
|
|
318
|
+
res.status(statusCode).json({ error: statusCode === 504 ? 'OpenCode upstream timed out' : 'OpenCode service unavailable' });
|
|
319
|
+
return true;
|
|
320
|
+
};
|
|
297
321
|
|
|
298
|
-
|
|
322
|
+
const applyProxyResponseDeadline = (req, res, next) => {
|
|
323
|
+
const timeout = setTimeout(() => {
|
|
324
|
+
req[PROXY_TIMEOUT_MARKER] = true;
|
|
325
|
+
if (sendProxyErrorResponse(res, 504)) {
|
|
326
|
+
res.once('finish', () => req.destroy?.());
|
|
327
|
+
}
|
|
328
|
+
}, PROXY_REQUEST_TIMEOUT_MS);
|
|
329
|
+
timeout.unref?.();
|
|
330
|
+
|
|
331
|
+
const clear = () => clearTimeout(timeout);
|
|
332
|
+
res.once('finish', clear);
|
|
333
|
+
res.once('close', clear);
|
|
334
|
+
next();
|
|
299
335
|
};
|
|
300
336
|
|
|
301
337
|
const forwardSseRequest = async (req, res) => {
|
|
@@ -665,6 +701,8 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
665
701
|
target: resolveProxyTarget(),
|
|
666
702
|
changeOrigin: true,
|
|
667
703
|
pathRewrite: { '^/api': '' },
|
|
704
|
+
timeout: PROXY_REQUEST_TIMEOUT_MS,
|
|
705
|
+
proxyTimeout: PROXY_REQUEST_TIMEOUT_MS,
|
|
668
706
|
// Dynamic target — port can change after restart
|
|
669
707
|
router: () => resolveProxyTarget(),
|
|
670
708
|
on: {
|
|
@@ -700,11 +738,13 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
700
738
|
}
|
|
701
739
|
}
|
|
702
740
|
},
|
|
703
|
-
error: (err,
|
|
741
|
+
error: (err, req, res) => {
|
|
704
742
|
console.error('[proxy] OpenCode proxy error:', err.message);
|
|
705
|
-
if (
|
|
706
|
-
|
|
743
|
+
if (req?.[PROXY_TIMEOUT_MARKER]) {
|
|
744
|
+
return;
|
|
707
745
|
}
|
|
746
|
+
const statusCode = isProxyTimeoutError(err) ? 504 : 503;
|
|
747
|
+
sendProxyErrorResponse(res, statusCode);
|
|
708
748
|
},
|
|
709
749
|
},
|
|
710
750
|
});
|
|
@@ -724,5 +764,6 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
724
764
|
next();
|
|
725
765
|
});
|
|
726
766
|
|
|
767
|
+
app.use('/api', applyProxyResponseDeadline);
|
|
727
768
|
app.use('/api', apiProxy);
|
|
728
769
|
};
|
|
@@ -181,6 +181,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
181
181
|
if (typeof candidate.desktopKeepAwakeEnabled === 'boolean') {
|
|
182
182
|
result.desktopKeepAwakeEnabled = candidate.desktopKeepAwakeEnabled;
|
|
183
183
|
}
|
|
184
|
+
if (typeof candidate.desktopMinimizeToTrayEnabled === 'boolean') {
|
|
185
|
+
result.desktopMinimizeToTrayEnabled = candidate.desktopMinimizeToTrayEnabled;
|
|
186
|
+
}
|
|
184
187
|
if (typeof candidate.desktopUiPassword === 'string') {
|
|
185
188
|
result.desktopUiPassword = candidate.desktopUiPassword.trim();
|
|
186
189
|
}
|
|
@@ -100,6 +100,17 @@ describe('settings helpers', () => {
|
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
it('accepts desktopMinimizeToTrayEnabled as a persisted shared setting', () => {
|
|
104
|
+
const helpers = createTestHelpers();
|
|
105
|
+
|
|
106
|
+
expect(helpers.sanitizeSettingsUpdate({ desktopMinimizeToTrayEnabled: true })).toEqual({
|
|
107
|
+
desktopMinimizeToTrayEnabled: true,
|
|
108
|
+
});
|
|
109
|
+
expect(helpers.sanitizeSettingsUpdate({ desktopMinimizeToTrayEnabled: false })).toEqual({
|
|
110
|
+
desktopMinimizeToTrayEnabled: false,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
103
114
|
it('accepts desktopUiPassword as a persisted shared setting', () => {
|
|
104
115
|
const helpers = createTestHelpers();
|
|
105
116
|
|
|
@@ -139,6 +139,7 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
|
|
139
139
|
: null;
|
|
140
140
|
const iconBackground = normalizeIconBackground(candidate.iconBackground);
|
|
141
141
|
const color = typeof candidate.color === 'string' ? candidate.color.trim() : '';
|
|
142
|
+
const defaultModel = typeof candidate.defaultModel === 'string' ? candidate.defaultModel.trim() : '';
|
|
142
143
|
const addedAt = Number.isFinite(candidate.addedAt) ? Number(candidate.addedAt) : null;
|
|
143
144
|
const lastOpenedAt = Number.isFinite(candidate.lastOpenedAt)
|
|
144
145
|
? Number(candidate.lastOpenedAt)
|
|
@@ -158,6 +159,7 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
|
|
158
159
|
...(icon ? { icon } : {}),
|
|
159
160
|
...(iconBackground ? { iconBackground } : {}),
|
|
160
161
|
...(color ? { color } : {}),
|
|
162
|
+
...(defaultModel && defaultModel.includes('/') ? { defaultModel } : {}),
|
|
161
163
|
...(Number.isFinite(addedAt) && addedAt >= 0 ? { addedAt } : {}),
|
|
162
164
|
...(Number.isFinite(lastOpenedAt) && lastOpenedAt >= 0 ? { lastOpenedAt } : {}),
|
|
163
165
|
};
|
|
@@ -12,6 +12,7 @@ const PACKAGE_NAME = '@openchamber/web';
|
|
|
12
12
|
const PACKAGE_PATH_SEGMENTS = PACKAGE_NAME.split('/');
|
|
13
13
|
const NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}`;
|
|
14
14
|
const CHANGELOG_URL = 'https://raw.githubusercontent.com/btriapitsyn/openchamber/main/CHANGELOG.md';
|
|
15
|
+
const GITHUB_RELEASES_URL = 'https://github.com/openchamber/openchamber/releases';
|
|
15
16
|
let cachedDetectedPm = null;
|
|
16
17
|
|
|
17
18
|
function getSpawnSyncBaseOptions() {
|
|
@@ -29,7 +30,7 @@ function getOpenChamberConfigDir() {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
function sanitizeInstallScope(scope) {
|
|
32
|
-
if (scope === 'desktop-electron' || scope === 'vscode' || scope === 'web') return scope;
|
|
33
|
+
if (scope === 'desktop-electron' || scope === 'vscode' || scope === 'web' || scope === 'mobile-capacitor') return scope;
|
|
33
34
|
return 'web';
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -65,7 +66,7 @@ function mapArch(value) {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
function normalizeAppType(value) {
|
|
68
|
-
if (value === 'web' || value === 'desktop-electron' || value === 'vscode') return value;
|
|
69
|
+
if (value === 'web' || value === 'desktop-electron' || value === 'vscode' || value === 'mobile-capacitor') return value;
|
|
69
70
|
return 'web';
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -75,7 +76,7 @@ function normalizeDeviceClass(value) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
function normalizePlatform(value) {
|
|
78
|
-
if (value === 'macos' || value === 'windows' || value === 'linux' || value === 'web') return value;
|
|
79
|
+
if (value === 'macos' || value === 'windows' || value === 'linux' || value === 'web' || value === 'android' || value === 'ios') return value;
|
|
79
80
|
return mapPlatform(process.platform);
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -89,8 +90,9 @@ async function checkForUpdatesFromApi(currentVersion, options = {}) {
|
|
|
89
90
|
const appType = normalizeAppType(options.appType);
|
|
90
91
|
const hostPlatform = mapPlatform(process.platform);
|
|
91
92
|
const hostArch = mapArch(process.arch);
|
|
92
|
-
const
|
|
93
|
-
const
|
|
93
|
+
const shouldTrustClientPlatform = appType === 'vscode' || appType === 'mobile-capacitor';
|
|
94
|
+
const platform = shouldTrustClientPlatform ? normalizePlatform(options.platform) : hostPlatform;
|
|
95
|
+
const arch = shouldTrustClientPlatform ? normalizeArch(options.arch) : hostArch;
|
|
94
96
|
const payload = {
|
|
95
97
|
appType,
|
|
96
98
|
deviceClass: normalizeDeviceClass(options.deviceClass),
|
|
@@ -120,11 +122,19 @@ async function checkForUpdatesFromApi(currentVersion, options = {}) {
|
|
|
120
122
|
const versionComparison = compareVersions(data.latestVersion, currentVersion);
|
|
121
123
|
if (versionComparison < 0) return null;
|
|
122
124
|
|
|
125
|
+
const releaseUrl = `${GITHUB_RELEASES_URL}/tag/v${data.latestVersion}`;
|
|
126
|
+
const downloadUrl = typeof data.downloadUrl === 'string'
|
|
127
|
+
? data.downloadUrl
|
|
128
|
+
: typeof data.download?.url === 'string'
|
|
129
|
+
? data.download.url
|
|
130
|
+
: undefined;
|
|
123
131
|
return {
|
|
124
132
|
available: Boolean(data.updateAvailable) && versionComparison > 0,
|
|
125
133
|
version: data.latestVersion,
|
|
126
134
|
currentVersion,
|
|
127
135
|
body: typeof data.releaseNotes === 'string' ? data.releaseNotes : undefined,
|
|
136
|
+
releaseUrl: typeof data.releaseNotesUrl === 'string' ? data.releaseNotesUrl : releaseUrl,
|
|
137
|
+
downloadUrl: appType === 'mobile-capacitor' ? (downloadUrl || releaseUrl) : undefined,
|
|
128
138
|
nextSuggestedCheckInSec:
|
|
129
139
|
typeof data.nextSuggestedCheckInSec === 'number' && Number.isFinite(data.nextSuggestedCheckInSec)
|
|
130
140
|
? data.nextSuggestedCheckInSec
|
|
@@ -721,6 +731,7 @@ export async function checkForUpdates(options = {}) {
|
|
|
721
731
|
const currentVersion = options.currentVersion || getCurrentVersion();
|
|
722
732
|
const pm = detectPackageManager();
|
|
723
733
|
const appType = normalizeAppType(options.appType);
|
|
734
|
+
const platform = normalizePlatform(options.platform);
|
|
724
735
|
|
|
725
736
|
if (currentVersion !== 'unknown') {
|
|
726
737
|
const remote = await checkForUpdatesFromApi(currentVersion, options);
|
|
@@ -760,6 +771,8 @@ export async function checkForUpdates(options = {}) {
|
|
|
760
771
|
version: latestVersion,
|
|
761
772
|
currentVersion,
|
|
762
773
|
body: changelog,
|
|
774
|
+
releaseUrl: `${GITHUB_RELEASES_URL}/tag/v${latestVersion}`,
|
|
775
|
+
downloadUrl: appType === 'mobile-capacitor' && platform === 'android' ? `${GITHUB_RELEASES_URL}/tag/v${latestVersion}` : undefined,
|
|
763
776
|
packageManager: pm,
|
|
764
777
|
// Show our CLI command, not raw package manager command
|
|
765
778
|
updateCommand: 'openchamber update',
|