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.
127 lines
4.3 KiB
JavaScript
127 lines
4.3 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import path from 'path';
|
|
import { pathToFileURL } from 'url';
|
|
|
|
import { isModuleCliExecution, normalizeCliEntryPath } from './cli-entry.js';
|
|
import { parseArgs } from './cli.js';
|
|
|
|
describe('cli args', () => {
|
|
it('accepts legacy daemon flags as no-ops', () => {
|
|
expect(parseArgs(['serve', '--daemon']).removedFlagErrors).toEqual([]);
|
|
expect(parseArgs(['serve', '-d']).removedFlagErrors).toEqual([]);
|
|
});
|
|
|
|
it('parses explicit connect-url server overrides', () => {
|
|
const parsed = parseArgs(['connect-url', '--server', 'https://openchamber.example.com', '--port', '3002']);
|
|
|
|
expect(parsed.command).toBe('connect-url');
|
|
expect(parsed.options.server).toBe('https://openchamber.example.com');
|
|
expect(parsed.options.port).toBe(3002);
|
|
});
|
|
|
|
it('parses connect-url server-url alias', () => {
|
|
const parsed = parseArgs(['connect-url', '--server-url=http://homebridge:3002']);
|
|
|
|
expect(parsed.options.server).toBe('http://homebridge:3002');
|
|
});
|
|
|
|
it('parses connect-url api-only help', () => {
|
|
const parsed = parseArgs(['connect-url', '--api-only', '--help']);
|
|
|
|
expect(parsed.command).toBe('connect-url');
|
|
expect(parsed.options.apiOnly).toBe(true);
|
|
expect(parsed.helpRequested).toBe(true);
|
|
});
|
|
|
|
it('parses startup api-only option', () => {
|
|
const parsed = parseArgs(['startup', 'enable', '--api-only', '--port', '3002']);
|
|
|
|
expect(parsed.command).toBe('startup');
|
|
expect(parsed.startupAction).toBe('enable');
|
|
expect(parsed.options.apiOnly).toBe(true);
|
|
expect(parsed.options.port).toBe(3002);
|
|
});
|
|
|
|
it('parses tunnel auto-start server options', () => {
|
|
const parsed = parseArgs(['tunnel', 'start', '--port', '3002', '--api-only', '--lan', '--ui-password', 'secret']);
|
|
|
|
expect(parsed.command).toBe('tunnel');
|
|
expect(parsed.subcommand).toBe('start');
|
|
expect(parsed.options.port).toBe(3002);
|
|
expect(parsed.options.apiOnly).toBe(true);
|
|
expect(parsed.options.host).toBe('0.0.0.0');
|
|
expect(parsed.options.uiPassword).toBe('secret');
|
|
});
|
|
|
|
it('maps --lan to wildcard bind host', () => {
|
|
const parsed = parseArgs(['serve', '--lan', '--port', '3002']);
|
|
|
|
expect(parsed.options.host).toBe('0.0.0.0');
|
|
expect(parsed.options.lan).toBe(true);
|
|
});
|
|
|
|
it('supports --hostname as top-level bind alias', () => {
|
|
const parsed = parseArgs(['serve', '--hostname', '0.0.0.0']);
|
|
|
|
expect(parsed.options.host).toBe('0.0.0.0');
|
|
});
|
|
|
|
it('keeps --hostname for tunnel commands', () => {
|
|
const parsed = parseArgs(['tunnel', 'start', '--hostname', 'app.example.com']);
|
|
|
|
expect(parsed.options.hostname).toBe('app.example.com');
|
|
expect(parsed.options.host).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('cli entry detection', () => {
|
|
const modulePath = '/tmp/openchamber/bin/cli.js';
|
|
const moduleUrl = pathToFileURL(modulePath).href;
|
|
|
|
it('resolves symlinked entry paths before comparing', () => {
|
|
const symlinkPath = '/usr/local/bin/openchamber';
|
|
const realpath = (filePath) => {
|
|
if (filePath === path.resolve(symlinkPath)) {
|
|
return modulePath;
|
|
}
|
|
return filePath;
|
|
};
|
|
|
|
expect(isModuleCliExecution(symlinkPath, moduleUrl, realpath)).toBe(true);
|
|
});
|
|
|
|
it('falls back to resolved paths when realpath fails', () => {
|
|
const realpath = () => {
|
|
throw new Error('realpath unavailable');
|
|
};
|
|
|
|
expect(isModuleCliExecution(modulePath, moduleUrl, realpath)).toBe(true);
|
|
});
|
|
|
|
it('returns false for non-matching entry path', () => {
|
|
expect(isModuleCliExecution('/tmp/other-cli.js', moduleUrl)).toBe(false);
|
|
});
|
|
|
|
it('returns false for empty entry path', () => {
|
|
expect(isModuleCliExecution('', moduleUrl)).toBe(false);
|
|
});
|
|
|
|
it('returns false when module url is not provided', () => {
|
|
expect(isModuleCliExecution(modulePath)).toBe(false);
|
|
});
|
|
|
|
it('accepts wrapper binary name fallback when requested', () => {
|
|
const wrapperPath = '/home/user/.local/bin/openchamber';
|
|
expect(isModuleCliExecution(wrapperPath, moduleUrl, undefined, 'openchamber')).toBe(true);
|
|
});
|
|
|
|
it('normalizes direct paths when realpath fails', () => {
|
|
const unresolvedPath = './packages/web/bin/cli.js';
|
|
const realpath = () => {
|
|
throw new Error('no symlink resolution');
|
|
};
|
|
|
|
expect(normalizeCliEntryPath(unresolvedPath, realpath)).toBe(path.resolve(unresolvedPath));
|
|
});
|
|
});
|