The preview panel worked by proxying a dev server through OpenChamber's own origin and rewriting the HTML that came back. Anything the rewriter did not anticipate broke, and pages that refuse to be embedded never loaded at all. This deletes the proxy (-1604 lines and its tests) and merges the preview and browser panels into one surface backed by a real Chromium view. What the panel is now - A `<webview>` in its own session partition: logins and cookies persist, hot reload works because nothing is rewritten, DevTools are one click away. - Annotation: pick one element, drag a region, or draw freehand, write a note, and it reaches chat with a screenshot of the visible page with the marks on it. - Toolbar: hard reload, page zoom, device sizes, a light/dark switch that applies to the page rather than the app, and cookie/cache clearing scoped to the panel alone. - Several pages at once, each tab showing the page's own favicon, and an address bar that suggests pages already visited in this project. - Dev servers are listed from what is actually listening on the machine, checked against what a project announced, so a server is offered no matter how it was started. One that is still starting is waited for instead of failing. Remote dev servers The desktop app binds a local port and pipes raw bytes to the OpenChamber host over the existing authenticated connection, so the page keeps its own origin at the root of its own host. The reachable set is exactly what discovery reports and is re-checked per connection, so an authenticated client cannot dial arbitrary local services on the host. Links and redirects to another loopback port stay on the machine that served the page. A tunnel that cannot be opened is reported; it is never replaced by the plain loopback URL, which would answer from the user's own machine under a remote address. Agent control Browser actions are a separate `openchamber_web` tool: open, snapshot, click, type, scroll, inspect computed styles, resize between mobile/tablet/desktop, and capture a screenshot into `.openchamber/screenshots/` in the project. The existing `openchamber` tool keeps sessions, worktrees and scheduled tasks. Each has its own setting in the new Settings -> General -> OpenChamber Tools section, and the plugin is not injected at all when both are off. Capability belongs to the connected client, not to configuration: a client declares on its event stream that it can drive a page, which only a Chromium host does. Exactly one client performs each request — it claims the request before acting, and the first claim wins — because deciding by whose result arrives first would be too late for a click that already happened. No client listening is answered immediately with an explanation rather than a timeout. Runtime boundaries Web tabs get a plain iframe that can display a page but not inspect one. The VS Code extension no longer offers the surface at all, since nothing that makes the panel worth having works there. Mobile is unaffected. Native boundary Camera, microphone, location and device-picker requests from panel pages are denied — Electron grants them by default when no handler is set, and the panel loads whatever address the user types. Page capture, appearance emulation and storage clearing verify that their target belongs to the panel's own session instead of trusting a web-contents id from the renderer. Persisted state Stored `preview` tabs migrate to `browser` (v13 -> v14). Context panel tab limits are now per surface, so filling one surface no longer evicts another's tabs. Address history is stored per project and per runtime. Documentation `preview.mdx` and `desktop-browser.mdx` rewritten across all locales, the agent tool settings path corrected, new `DOCUMENTATION.md` for the browser-control broker and the dev tunnel, and the `ui-api-decoupling` skill updated where it still described the deleted proxy.
206 lines
8.6 KiB
TypeScript
206 lines
8.6 KiB
TypeScript
import { beforeEach, describe, expect, test } from 'bun:test';
|
|
import { CONTEXT_SURFACES, sortContextSurfaces } from '../lib/surfaces/registry';
|
|
import { useUIStore } from './useUIStore';
|
|
|
|
beforeEach(() => {
|
|
useUIStore.setState({ contextPanelByDirectory: {}, contextRailOrder: [] });
|
|
});
|
|
|
|
describe('useUIStore context panel tabs', () => {
|
|
test('updates readOnly when an existing chat tab is reopened', () => {
|
|
const directory = '/repo';
|
|
|
|
useUIStore.getState().openContextPanelTab(directory, {
|
|
mode: 'chat',
|
|
dedupeKey: 'session:ses_1',
|
|
label: 'Session',
|
|
readOnly: true,
|
|
});
|
|
|
|
useUIStore.getState().openContextPanelTab(directory, {
|
|
mode: 'chat',
|
|
dedupeKey: 'session:ses_1',
|
|
label: 'Session',
|
|
readOnly: false,
|
|
});
|
|
|
|
const tabs = useUIStore.getState().contextPanelByDirectory[directory]?.tabs ?? [];
|
|
expect(tabs).toHaveLength(1);
|
|
expect(tabs[0]?.readOnly).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('useUIStore openContextSurface', () => {
|
|
const directory = '/repo';
|
|
|
|
test('opens a fresh singleton tab when none of that mode exists', () => {
|
|
useUIStore.getState().openContextSurface(directory, 'diff');
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.isOpen).toBe(true);
|
|
expect(state?.tabs.map((tab) => tab.mode)).toEqual(['diff']);
|
|
});
|
|
|
|
test('activates the existing tab of the requested mode instead of duplicating it', () => {
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'diff' });
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'file', targetPath: '/repo/a.ts' });
|
|
|
|
useUIStore.getState().openContextSurface(directory, 'diff');
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.tabs.filter((tab) => tab.mode === 'diff')).toHaveLength(1);
|
|
expect(state?.activeTabId).toBe('diff');
|
|
expect(state?.isOpen).toBe(true);
|
|
});
|
|
|
|
test('toggles the panel closed when the requested mode is already active and open', () => {
|
|
useUIStore.getState().openContextSurface(directory, 'diff');
|
|
useUIStore.getState().openContextSurface(directory, 'diff');
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.isOpen).toBe(false);
|
|
expect(state?.tabs.map((tab) => tab.mode)).toEqual(['diff']);
|
|
});
|
|
|
|
test('does nothing for content-driven modes without existing content', () => {
|
|
useUIStore.getState().openContextSurface(directory, 'chat');
|
|
|
|
expect(useUIStore.getState().contextPanelByDirectory[directory]).toBe(undefined);
|
|
});
|
|
|
|
test('opens an empty editor tab that a real file later replaces', () => {
|
|
useUIStore.getState().openContextSurface(directory, 'file');
|
|
|
|
let state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.isOpen).toBe(true);
|
|
expect(state?.tabs.map((tab) => tab.mode)).toEqual(['file']);
|
|
expect(state?.tabs[0]?.targetPath).toBe(null);
|
|
|
|
useUIStore.getState().openContextFile(directory, '/repo/a.ts');
|
|
|
|
state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.tabs.filter((tab) => tab.mode === 'file')).toHaveLength(1);
|
|
expect(state?.tabs.find((tab) => tab.mode === 'file')?.targetPath).toBe('/repo/a.ts');
|
|
});
|
|
|
|
test('activates the most recently touched tab of a content-driven mode', () => {
|
|
useUIStore.getState().openContextFile(directory, '/repo/a.ts');
|
|
useUIStore.getState().openContextFile(directory, '/repo/b.ts');
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'diff' });
|
|
|
|
useUIStore.getState().openContextSurface(directory, 'file');
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
const activeTab = state?.tabs.find((tab) => tab.id === state.activeTabId);
|
|
expect(activeTab?.mode).toBe('file');
|
|
expect(activeTab?.targetPath).toBe('/repo/b.ts');
|
|
});
|
|
});
|
|
|
|
describe('useUIStore closeContextPanelTab surface stability', () => {
|
|
const directory = '/repo';
|
|
|
|
test('closing an active file tab activates another file tab, not another surface', () => {
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'terminal' });
|
|
useUIStore.getState().openContextFile(directory, '/repo/a.ts');
|
|
useUIStore.getState().openContextFile(directory, '/repo/b.ts');
|
|
|
|
const stateBefore = useUIStore.getState().contextPanelByDirectory[directory];
|
|
const activeTabId = stateBefore?.activeTabId as string;
|
|
useUIStore.getState().closeContextPanelTab(directory, activeTabId);
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
const activeTab = state?.tabs.find((tab) => tab.id === state.activeTabId);
|
|
expect(activeTab?.mode).toBe('file');
|
|
expect(activeTab?.targetPath).toBe('/repo/a.ts');
|
|
expect(state?.isOpen).toBe(true);
|
|
});
|
|
|
|
test('closing the last tab of the active surface closes the panel', () => {
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'terminal' });
|
|
useUIStore.getState().openContextFile(directory, '/repo/a.ts');
|
|
|
|
const stateBefore = useUIStore.getState().contextPanelByDirectory[directory];
|
|
useUIStore.getState().closeContextPanelTab(directory, stateBefore?.activeTabId as string);
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.isOpen).toBe(false);
|
|
expect(state?.tabs.map((tab) => tab.mode)).toEqual(['terminal']);
|
|
});
|
|
|
|
test('closing an inactive tab keeps the active tab untouched', () => {
|
|
useUIStore.getState().openContextFile(directory, '/repo/a.ts');
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'terminal' });
|
|
|
|
const state0 = useUIStore.getState().contextPanelByDirectory[directory];
|
|
const fileTab = state0?.tabs.find((tab) => tab.mode === 'file');
|
|
useUIStore.getState().closeContextPanelTab(directory, fileTab?.id as string);
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.activeTabId).toBe('terminal');
|
|
expect(state?.isOpen).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('useUIStore per-surface panel widths', () => {
|
|
const directory = '/repo';
|
|
|
|
test('setContextPanelWidth stores a clamped manual width for one mode only', () => {
|
|
useUIStore.getState().openContextPanelTab(directory, { mode: 'diff' });
|
|
useUIStore.getState().setContextPanelWidth(directory, 'diff', 700);
|
|
useUIStore.getState().setContextPanelWidth(directory, 'git', 100);
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
expect(state?.widthByMode.diff).toBe(700);
|
|
expect(state?.widthByMode.git).toBe(380);
|
|
expect(state?.widthByMode.browser).toBe(undefined);
|
|
});
|
|
});
|
|
|
|
describe('useUIStore contextRailOrder', () => {
|
|
test('setContextRailOrder drops empty and duplicate ids', () => {
|
|
useUIStore.getState().setContextRailOrder(['diff', 'diff', '', 'editor']);
|
|
expect(useUIStore.getState().contextRailOrder).toEqual(['diff', 'editor']);
|
|
});
|
|
|
|
test('sortContextSurfaces applies persisted order and appends missing surfaces', () => {
|
|
const ordered = sortContextSurfaces(['browser', 'unknown-id', 'diff']);
|
|
const ids = ordered.map((surface) => surface.id);
|
|
|
|
expect(ids.slice(0, 2)).toEqual(['browser', 'diff']);
|
|
// Assert against the registry itself so this test cannot go stale when a
|
|
// surface is added or removed.
|
|
expect(new Set(ids)).toEqual(new Set(CONTEXT_SURFACES.map((surface) => surface.id)));
|
|
expect(ids).toHaveLength(CONTEXT_SURFACES.length);
|
|
});
|
|
});
|
|
|
|
describe('context panel tab limits', () => {
|
|
test('a surface filling up never evicts another surface tab', () => {
|
|
const directory = '/repo';
|
|
useUIStore.getState().openContextDiff(directory, 'src/app.ts');
|
|
|
|
for (let index = 0; index < 20; index += 1) {
|
|
useUIStore.getState().openContextPreview(directory, `http://localhost:${3000 + index}/`);
|
|
}
|
|
|
|
const tabs = useUIStore.getState().contextPanelByDirectory[directory]?.tabs ?? [];
|
|
// The diff tab is not on screen while browsing, so losing it would be a
|
|
// disappearance the user never saw happen.
|
|
expect(tabs.some((tab) => tab.mode === 'diff')).toBe(true);
|
|
expect(tabs.filter((tab) => tab.mode === 'browser').length).toBeLessThan(20);
|
|
});
|
|
|
|
test('keeps the tab that was just opened', () => {
|
|
const directory = '/repo';
|
|
for (let index = 0; index < 20; index += 1) {
|
|
useUIStore.getState().openContextPreview(directory, `http://localhost:${3000 + index}/`);
|
|
}
|
|
|
|
const state = useUIStore.getState().contextPanelByDirectory[directory];
|
|
const tabs = state?.tabs ?? [];
|
|
expect(tabs.some((tab) => tab.id === state?.activeTabId)).toBe(true);
|
|
expect(tabs.some((tab) => tab.targetPath === 'http://localhost:3019/')).toBe(true);
|
|
});
|
|
});
|