Add a packaged-client runtime boundary so the shared UI can talk to local, desktop, remote, and VS Code runtimes through the right transport instead of assuming one same-origin web server. Centralize OpenChamber-owned API access behind RuntimeAPIs, runtimeFetch, and runtime URL helpers, while keeping official OpenCode traffic on the SDK path. Support runtime switching, remote host selection, desktop client credentials, and headless connection links for pairing packaged clients with remote OpenChamber servers. Harden the new auth model by moving long-lived client tokens out of browser URLs, introducing short-lived scoped URL tokens for browser-owned transports, restricting URL-token access to explicit readable/realtime routes, and making client-token management session-scoped or self-scoped as appropriate. Update browser-owned assets and preview proxy flows to work with the split runtime model, including authenticated project icons, preview token propagation, CSP-safe preview bridge injection, and preview proxy auth that survives short-lived URL-token expiry. Tighten Electron security boundaries for packaged clients by gating privileged preload state to trusted origins and requiring explicit confirmation before connect deep-links import or switch remote runtimes. Also refresh agent guidance and project skills so future runtime/API, auth, preview, UI, CLI, settings, locale, and drag-to-reorder work follows the new architecture.
61 lines
2.4 KiB
JavaScript
61 lines
2.4 KiB
JavaScript
import { describe, expect, it } from 'bun:test';
|
|
import express from 'express';
|
|
import request from 'supertest';
|
|
import { createStaticRoutesRuntime } from './static-routes-runtime.js';
|
|
|
|
const createRuntime = () => createStaticRoutesRuntime({
|
|
fs: { existsSync: () => false },
|
|
path: { join: (...parts) => parts.join('/'), resolve: (value) => value, sep: '/' },
|
|
process: { env: {} },
|
|
__dirname: '/server',
|
|
express,
|
|
resolveProjectDirectory: () => '',
|
|
buildOpenCodeUrl: () => '',
|
|
getOpenCodeAuthHeaders: () => ({}),
|
|
readSettingsFromDiskMigrated: async () => ({}),
|
|
normalizePwaAppName: (value) => value,
|
|
normalizePwaOrientation: (value) => value,
|
|
});
|
|
|
|
describe('static routes runtime', () => {
|
|
it('returns API-only HTML fallback for browser UI routes', async () => {
|
|
const app = express();
|
|
createRuntime().registerApiOnlyFallbackRoutes(app);
|
|
|
|
const response = await request(app).get('/sessions/abc').set('Accept', 'text/html');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.text).toContain('OpenChamber is running in headless mode');
|
|
expect(response.text).toContain('Open it from the OpenChamber desktop or mobile app');
|
|
expect(response.text).toContain('openchamber connect-url --help');
|
|
expect(response.text).toContain('Copy command');
|
|
});
|
|
|
|
it('returns API-only info JSON for JSON clients', async () => {
|
|
const app = express();
|
|
createRuntime().registerApiOnlyFallbackRoutes(app);
|
|
|
|
const response = await request(app).get('/sessions/abc').set('Accept', 'application/json');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(response.body).toEqual({
|
|
ok: true,
|
|
mode: 'api-only',
|
|
message: 'OpenChamber is running in API-only mode',
|
|
});
|
|
});
|
|
|
|
it('does not intercept API, auth, or health routes in API-only mode', async () => {
|
|
const app = express();
|
|
createRuntime().registerApiOnlyFallbackRoutes(app);
|
|
|
|
const api = await request(app).get('/api/version');
|
|
const auth = await request(app).get('/auth/session');
|
|
const health = await request(app).get('/health');
|
|
|
|
expect(api.body).not.toEqual({ ok: true, mode: 'api-only', message: 'OpenChamber is running in API-only mode' });
|
|
expect(auth.body).not.toEqual({ ok: true, mode: 'api-only', message: 'OpenChamber is running in API-only mode' });
|
|
expect(health.body).not.toEqual({ ok: true, mode: 'api-only', message: 'OpenChamber is running in API-only mode' });
|
|
});
|
|
});
|