Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): preserve catalog drafts after touch selection (#1919)

Call White47300bfb81ec
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index fe350feae..d6ca02e45 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -51,6 +51,12 @@ jobs:
npm run typecheck:tests
npm test
+ - name: Test model catalog browser interactions
+ working-directory: ui
+ run: |
+ npx playwright install --with-deps chromium
+ npm run test:model-catalog
+
build-linux-artifacts:
runs-on: ubuntu-latest
steps:
diff --git a/ui/e2e/model-catalog/README.md b/ui/e2e/model-catalog/README.md
new file mode 100644
index 000000000..0ad44e16f
--- /dev/null
+++ b/ui/e2e/model-catalog/README.md
@@ -0,0 +1,24 @@
+# Model Catalog Interaction Regression
+
+Run `npm run test:model-catalog` from `ui/` after installing the pinned Chromium
+binary with `npx playwright install chromium`. CI runs this in `ui-checks`.
+The suite follows the existing
+isolated UI fixture pattern and never starts or contacts Avibe or a backend CLI.
+Only `modelsApi` is replaced with in-memory reads/writes. The catalog, picker,
+editor, Radix dialogs and browser pointer/focus behavior are real.
+
+All three backends run in English and Chinese with desktop mouse and mobile
+touch input. Cases verify picker additions, save/readback, child Cancel/Escape/
+outside dismissal, editor commit, custom-editor handoff and catalog cancellation.
+The host unmounts the catalog on close, matching `SettingsModelsPage`.
+
+This consumes the shared `MH-MENU-COMPOSE-001` addition workflow. It guards the
+React ownership of portalled child dialogs: a delayed touch click must not be
+classified as outside the catalog after the child closes. Mouse-only and JSDOM
+tests do not reproduce that browser event timing. Backend persistence and routing
+contracts remain covered by their existing tests; this is not live acceptance.
+
+The live `playwright.config.ts` excludes this fixture directory. The consuming
+`scripts/modelCatalogDiscovery.test.mjs` checks both real configs with `--list`:
+live discovery excludes the fixture, while isolated discovery retains all 36
+scenario-labelled cases. Collection starts no browser, web server or fixture.
diff --git a/ui/e2e/model-catalog/catalog.spec.ts b/ui/e2e/model-catalog/catalog.spec.ts
new file mode 100644
index 000000000..01bc31184
--- /dev/null
+++ b/ui/e2e/model-catalog/catalog.spec.ts
@@ -0,0 +1,99 @@
+import { expect, test, type Locator, type Page } from '@playwright/test';
+import { hub } from '../support/copy';
+import type { BackendModel, BackendModelsPut } from '../../src/components/settings/models/types';
+
+const savedState = async (page: Page): Promise<{ saved: BackendModel[]; writes: BackendModelsPut[] }> =>
+ JSON.parse(await page.getByTestId('saved').innerText());
+
+for (const backend of ['claude', 'codex', 'opencode']) {
+ for (const lang of ['en', 'zh'] as const) {
+ test.describe(`${backend}/${lang}`, () => {
+ const text = (key: string, vars?: Record<string, string | number>) => hub(`gateway.${key}`, vars, lang);
+ const grip = (page: Page, model: string) => page.getByRole('button', { name: text('catalog.reorder', { model }), exact: true });
+ test.beforeEach(async ({ page }) => {
+ await page.route('**/api/**', (route) => route.abort());
+ await page.goto(`/e2e/model-catalog/fixture.html?backend=${backend}&lang=${lang}`);
+ await page.getByRole('button', { name: 'Manage models', exact: true }).click();
+ await expect(grip(page, 'Existing model')).toBeVisible();
+ });
+
+ test('MH-MENU-COMPOSE-001: keeps picker additions until the catalog is saved', async ({ page, isMobile }, testInfo) => {
+ const activate = (locator: Locator) => isMobile ? locator.tap() : locator.click();
+ const initial = await savedState(page);
+ await activate(page.getByRole('button', { name: text('catalog.add'), exact: true }));
+ await activate(page.getByRole('checkbox', { name: /claude-candidate-alpha/ }));
+ await activate(page.getByRole('checkbox', { name: /claude-candidate-beta/ }));
+ await activate(page.getByRole('button', { name: text('picker.confirm', { count: 2 }), exact: true }));
+
+ await expect(page.getByRole('dialog')).toHaveCount(1);
+ await expect(grip(page, 'claude-candidate-alpha')).toBeVisible();
+ await expect(grip(page, 'claude-candidate-beta')).toBeVisible();
+ expect(await savedState(page)).toEqual(initial);
+ await page.screenshot({ path: testInfo.outputPath('added-draft.png'), scale: 'css' });
+ await activate(page.getByRole('button', { name: text('catalog.save'), exact: true }));
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ const result = await savedState(page);
+ expect(result.saved.map((model) => model.id)).toEqual(['claude-existing-model', 'claude-candidate-alpha', 'claude-candidate-beta']);
+ expect(result.saved[0]).toEqual(initial.saved[0]);
+ expect(result.writes).toHaveLength(1);
+ expect(result.writes[0].baseline).toEqual(initial.saved);
+ expect(result.writes[0].expected_suppliers).toEqual({ 'claude-candidate-alpha': [], 'claude-candidate-beta': [] });
+ await activate(page.getByRole('button', { name: 'Manage models', exact: true }));
+ await expect(grip(page, 'claude-candidate-beta')).toBeVisible();
+ });
+
+ test('MH-MENU-COMPOSE-001: dismisses only the picker or editor and preserves the unsaved draft', async ({ page, isMobile }) => {
+ const activate = (locator: Locator) => isMobile ? locator.tap() : locator.click();
+ const initial = await savedState(page);
+ await activate(page.getByRole('button', { name: text('catalog.add'), exact: true }));
+ await activate(page.getByRole('checkbox', { name: /claude-candidate-alpha/ }));
+ await activate(page.getByRole('button', { name: text('picker.confirm', { count: 1 }), exact: true }));
+ await expect(grip(page, 'claude-candidate-alpha')).toBeVisible();
+
+ for (const exit of ['cancel', 'escape', 'outside'] as const) {
+ await activate(page.getByRole('button', { name: text('catalog.add'), exact: true }));
+ await expect(page.getByRole('checkbox', { name: /claude-candidate-beta/ })).toBeVisible();
+ // Raw Escape/coordinate input has no locator actionability wait.
+ await page.getByRole('dialog').filter({ has: page.getByRole('checkbox', { name: /claude-candidate-beta/ }) })
+ .evaluate(async (node) => { await Promise.all(node.getAnimations().map((animation) => animation.finished)); });
+ if (exit === 'cancel') await activate(page.getByRole('button', { name: text('catalog.cancel'), exact: true }));
+ else if (exit === 'escape') await page.keyboard.press('Escape');
+ else if (isMobile) await page.touchscreen.tap(5, 5);
+ else await page.mouse.click(5, 5);
+ await expect(grip(page, 'claude-candidate-alpha')).toBeVisible();
+ await expect(page.getByRole('dialog')).toHaveCount(1);
+ }
+
+ await activate(page.getByRole('button', { name: text('catalog.edit', { model: 'Existing model' }), exact: true }));
+ await activate(page.getByRole('button', { name: text('modelEditor.cancel'), exact: true }));
+ await expect(grip(page, 'claude-candidate-alpha')).toBeVisible();
+ await activate(page.getByRole('button', { name: text('catalog.edit', { model: 'Existing model' }), exact: true }));
+ await page.getByLabel(text('modelEditor.displayName.label'), { exact: true }).fill('Edited name');
+ await activate(page.getByRole('button', { name: text('modelEditor.apply'), exact: true }));
+ await expect(grip(page, 'Edited name')).toBeVisible();
+ await expect(grip(page, 'claude-candidate-alpha')).toBeVisible();
+ expect(await savedState(page)).toEqual(initial);
+ await activate(page.getByRole('button', { name: text('catalog.cancel'), exact: true }));
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ expect(await savedState(page)).toEqual(initial);
+ });
+
+ test('MH-MENU-COMPOSE-001: hands the picker to the custom editor without dismissing the catalog', async ({ page, isMobile }) => {
+ const activate = (locator: Locator) => isMobile ? locator.tap() : locator.click();
+ const initial = await savedState(page);
+ await activate(page.getByRole('button', { name: text('catalog.add'), exact: true }));
+ await activate(page.getByRole('button', { name: text('picker.custom'), exact: true }));
+ await page.getByLabel(text('modelEditor.id.label'), { exact: true }).fill('claude-custom-model');
+ await activate(page.getByRole('button', { name: text('modelEditor.add'), exact: true }));
+ await expect(grip(page, 'claude-custom-model')).toBeVisible();
+ expect(await savedState(page)).toEqual(initial);
+ await activate(page.getByRole('button', { name: text('catalog.save'), exact: true }));
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ const result = await savedState(page);
+ expect(result.saved.map((model) => model.id)).toEqual(['claude-existing-model', 'claude-custom-model']);
+ expect(result.writes).toHaveLength(1);
+ expect(result.writes[0].expected_suppliers).toBeUndefined();
+ });
+ });
+ }
+}
diff --git a/ui/e2e/model-catalog/fixture.html b/ui/e2e/model-catalog/fixture.html
new file mode 100644
index 000000000..48b2d395d
--- /dev/null
+++ b/ui/e2e/model-catalog/fixture.html
@@ -0,0 +1,2 @@
+<!doctype html>
+<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Model catalog fixture</title></head><body><div id="root"></div><script type="module" src="./fixture.tsx"></script></body></html>
diff --git a/ui/e2e/model-catalog/fixture.tsx b/ui/e2e/model-catalog/fixture.tsx
new file mode 100644
index 000000000..c78f41b08
--- /dev/null
+++ b/ui/e2e/model-catalog/fixture.tsx
@@ -0,0 +1,55 @@
+import { useState } from 'react';
+import { createRoot } from 'react-dom/client';
+import { createInstance } from 'i18next';
+import { I18nextProvider } from 'react-i18next';
+import en from '../../src/i18n/en.json';
+import zh from '../../src/i18n/zh.json';
+import '../../src/index.css';
+import '../../src/components/settings/models/modelHubSurface.css';
+import { BackendModelCatalogDialog } from '../../src/components/settings/models/BackendModelCatalogDialog';
+import { blankBackendModel } from '../../src/components/settings/models/backendCatalog';
+import { modelsApi } from '../../src/components/settings/models/modelsApi';
+import type { AgentBackend, AgentSupply, BackendModel, BackendModelsPut } from '../../src/components/settings/models/types';
+
+const params = new URLSearchParams(location.search);
+const backend = params.get('backend') as AgentBackend;
+const language = createInstance();
+await language.init({ lng: params.get('lang') ?? 'en', resources: { en: { translation: en }, zh: { translation: zh } }, interpolation: { escapeValue: false } });
+let saved: BackendModel[] = [{ ...blankBackendModel(), id: 'claude-existing-model', display_name: 'Existing model', context_window: 200000 }];
+const writes: BackendModelsPut[] = [];
+const supply = (): AgentSupply => ({
+ backend, cli_present: true, mode: 'hub', menu_kind: backend === 'opencode' ? 'open' : 'fixed',
+ sources: { order: [], eligibility: [] }, routes: {}, builtin_models: [], menu: null, catalog_models: saved,
+});
+
+// Only the API boundary is replaced; Radix portals, focus, touch events and
+// catalog draft/commit consumers are the shipped components.
+modelsApi.getAgentSources = async () => supply();
+modelsApi.getAgentModelCandidates = async () => ({
+ builtin: [], in_list: [],
+ providers: ['claude-candidate-alpha', 'claude-candidate-beta'].map((id) => ({
+ id, display_name: null, reasoning_efforts: [], suppliers: [], origin: 'provider' as const,
+ ...(backend === 'opencode' ? { native_protocol: 'anthropic' as const } : {}),
+ })),
+});
+modelsApi.searchModelsDev = async () => [];
+modelsApi.putAgentModels = async (target, input) => {
+ if (target !== backend) throw new Error('Wrong backend');
+ writes.push(input);
+ saved = input.models;
+ return supply();
+};
+
+export function Fixture() {
+ const [open, setOpen] = useState(false);
+ const [, setRevision] = useState(0);
+ return <I18nextProvider i18n={language}>
+ <button type="button" onClick={() => setOpen(true)}>Manage models</button>
+ <output data-testid="saved">{JSON.stringify({ saved, writes })}</output>
+ {open && <BackendModelCatalogDialog open backend={backend} canReadSources sourceNames={{}}
+ onClose={() => setOpen(false)} onSaved={() => setRevision((value) => value + 1)}
+ onObserved={() => {}} catalogWrite={{ pending: false, track: async (work) => work() }} />}
+ </I18nextProvider>;
+}
+
+createRoot(document.getElementById('root')!).render(<Fixture />);
diff --git a/ui/e2e/model-catalog/tsconfig.json b/ui/e2e/model-catalog/tsconfig.json
new file mode 100644
index 000000000..279617553
--- /dev/null
+++ b/ui/e2e/model-catalog/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.app.json",
+ "compilerOptions": { "types": ["vite/client", "node"] },
+ "include": ["*.ts", "*.tsx", "../../playwright.model-catalog.config.ts", "../../agentation.d.ts"],
+ "exclude": []
+}
diff --git a/ui/package.json b/ui/package.json
index 316b1790b..e0996f32d 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -21,6 +21,7 @@
"e2e:headed": "playwright test --headed",
"test:chat-paging": "tsc -p e2e/chat-paging/tsconfig.json --noEmit && playwright test --config playwright.chat-paging.config.ts",
"test:inbox-return": "tsc -p e2e/inbox-return/tsconfig.json --noEmit && playwright test --config playwright.inbox-return.config.ts",
+ "test:model-catalog": "tsc -p e2e/model-catalog/tsconfig.json --noEmit && playwright test --config playwright.model-catalog.config.ts",
"validate:catalog": "node scripts/validate-scenario-catalog.mjs",
"validate:theme": "node scripts/validate-theme.mjs"
},
diff --git a/ui/playwright.config.ts b/ui/playwright.config.ts
index fd704869a..e8b33f2fd 100644
--- a/ui/playwright.config.ts
+++ b/ui/playwright.config.ts
@@ -16,7 +16,7 @@ import { BASE_URL } from './e2e/support/env';
export default defineConfig({
testDir: './e2e',
- testIgnore: ['**/chat-paging/**', '**/inbox-return/**'],
+ testIgnore: ['**/chat-paging/**', '**/inbox-return/**', '**/model-catalog/**'],
outputDir: './e2e/.artifacts/test-results',
// Every spec mutates shared instance state (sources, agent modes, the
// runtime switch). Parallel workers would race on it, so the suite is serial
diff --git a/ui/playwright.model-catalog.config.ts b/ui/playwright.model-catalog.config.ts
new file mode 100644
index 000000000..065bc2c70
--- /dev/null
+++ b/ui/playwright.model-catalog.config.ts
@@ -0,0 +1,18 @@
+import { defineConfig, devices } from '@playwright/test';
+
+export default defineConfig({
+ testDir: './e2e/model-catalog',
+ outputDir: './e2e/.artifacts/model-catalog',
+ workers: 1,
+ retries: 0,
+ use: { baseURL: 'http://127.0.0.1:5201', trace: 'retain-on-failure' },
+ webServer: {
+ command: 'npm run dev -- --host 127.0.0.1 --port 5201 --strictPort',
+ env: { VIBE_UI_BACKEND: 'http://127.0.0.1:9' },
+ url: 'http://127.0.0.1:5201/e2e/model-catalog/fixture.html?backend=opencode',
+ },
+ projects: [
+ { name: 'desktop', use: { ...devices['Desktop Chrome'] } },
+ { name: 'mobile', use: { ...devices['iPhone 13'], browserName: 'chromium' } },
+ ],
+});
diff --git a/ui/scripts/modelCatalogDiscovery.test.mjs b/ui/scripts/modelCatalogDiscovery.test.mjs
new file mode 100644
index 000000000..b1dc601cf
--- /dev/null
+++ b/ui/scripts/modelCatalogDiscovery.test.mjs
@@ -0,0 +1,44 @@
+import { execFileSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+import { expect, test } from 'vitest';
+
+const uiRoot = fileURLToPath(new URL('..', import.meta.url));
+const collectedSpecs = (suite) => [
+ ...(suite.specs ?? []),
+ ...(suite.suites ?? []).flatMap(collectedSpecs),
+];
+
+function collect(config) {
+ // List mode loads the real config/specs but never starts fixtures or webServer.
+ const report = JSON.parse(execFileSync(process.execPath, [
+ 'node_modules/@playwright/test/cli.js', 'test', '--config', config,
+ '--list', '--reporter=json',
+ ], {
+ cwd: uiRoot,
+ env: {
+ ...process.env,
+ VIBE_E2E_BASE_URL: 'http://127.0.0.1:9',
+ VIBE_E2E_DESTRUCTIVE_TARGET: 'http://127.0.0.1:9',
+ },
+ encoding: 'utf8',
+ timeout: 30_000,
+ maxBuffer: 8 * 1024 * 1024,
+ }));
+ expect(report.errors).toEqual([]);
+ return collectedSpecs(report);
+}
+
+test('live E2E discovery never collects the model catalog fixture', () => {
+ const specs = collect('playwright.config.ts');
+ expect(specs.length).toBeGreaterThan(0);
+ expect(specs.filter((spec) => spec.file.startsWith('model-catalog/'))).toEqual([]);
+}, 35_000);
+
+test('isolated catalog discovery retains all scenario-labelled browser cases', () => {
+ const specs = collect('playwright.model-catalog.config.ts');
+ expect(specs.flatMap((spec) => spec.tests)).toHaveLength(36);
+ for (const spec of specs) {
+ expect(spec.title).toContain('MH-MENU-COMPOSE-001');
+ expect(spec.file).toBe('catalog.spec.ts');
+ }
+}, 35_000);
diff --git a/ui/src/components/settings/models/BackendModelCatalogDialog.tsx b/ui/src/components/settings/models/BackendModelCatalogDialog.tsx
index a10cc406c..c26fa3d46 100644
--- a/ui/src/components/settings/models/BackendModelCatalogDialog.tsx
+++ b/ui/src/components/settings/models/BackendModelCatalogDialog.tsx
@@ -1101,60 +1101,61 @@ export const BackendModelCatalogDialog: React.FC<{
</Button>
</div>
</DialogFooter>
+ {/* Portals keep their visual layers, but must be descendants of this
+ content so Radix treats their delayed touch clicks as inside. */}
+ {picking && (
+ <BackendModelPickerDialog
+ open
+ backend={backend}
+ listedIds={offerable(takenIds, picking.seed)}
+ seedPicked={picking.seed}
+ // 「Add none of these」 — the same answer as confirming with nothing
+ // picked, and the same call, because a re-ask the user dismisses has
+ // declined every id it seeded. An ordinary add seeds nothing, so this
+ // still just closes.
+ onCancel={() => addCandidates([])}
+ onAdd={addCandidates}
+ // The editor is the other door an id becomes a row through, so leaving
+ // by it answers this picker's two standing questions in the same order
+ // every other exit answers them, through the same call.
+ //
+ // `addCandidates([])` first, for the same reason Cancel makes that
+ // call: walking out through the editor confirms none of a re-ask's
+ // seeded ids, and a seeded projection this dialog keeps is one the
+ // next Save would send as if it had been agreed.
+ //
+ // Then the id, resolved BEFORE the row lookup and through the rule the
+ // editor itself commits under (`backendModelId`, which `draftWithId`
+ // applies there). The lookup is a total function of the id, so the id
+ // it is asked about has to be the one the row would be saved as: asked
+ // about a typed `foo` it finds the user's saved `foo`,
+ // and the editor — resolving the id only on commit — would then write
+ // a blank row onto it, dropping the limits, modalities, capabilities
+ // and name they had described. The resolver is idempotent, so the
+ // editor re-applying it to this seed changes nothing.
+ onCustom={(typed) => {
+ addCandidates([]);
+ const seedId = backendModelId(typed);
+ const existing = heldRowFor(seedId, draftRef.current, baselineRef.current?.models ?? []);
+ setEditing(existing ? { model: existing } : { model: null, seedId });
+ }}
+ />
+ )}
+
+ {editing && (
+ <BackendModelEditorDialog
+ open
+ backend={backend}
+ model={editing.model}
+ seedId={editing.seedId}
+ takenIds={takenIds}
+ effortSuggestions={effortSuggestions}
+ onCancel={() => setEditing(null)}
+ onCommit={commitEdit}
+ />
+ )}
</DialogContent>
</Dialog>
-
- {picking && (
- <BackendModelPickerDialog
- open
- backend={backend}
- listedIds={offerable(takenIds, picking.seed)}
- seedPicked={picking.seed}
- // 「Add none of these」 — the same answer as confirming with nothing
- // picked, and the same call, because a re-ask the user dismisses has
- // declined every id it seeded. An ordinary add seeds nothing, so this
- // still just closes.
- onCancel={() => addCandidates([])}
- onAdd={addCandidates}
- // The editor is the other door an id becomes a row through, so leaving
- // by it answers this picker's two standing questions in the same order
- // every other exit answers them, through the same call.
- //
- // `addCandidates([])` first, for the same reason Cancel makes that
- // call: walking out through the editor confirms none of a re-ask's
- // seeded ids, and a seeded projection this dialog keeps is one the
- // next Save would send as if it had been agreed.
- //
- // Then the id, resolved BEFORE the row lookup and through the rule the
- // editor itself commits under (`backendModelId`, which `draftWithId`
- // applies there). The lookup is a total function of the id, so the id
- // it is asked about has to be the one the row would be saved as: asked
- // about a typed `foo` it finds the user's saved `foo`,
- // and the editor — resolving the id only on commit — would then write
- // a blank row onto it, dropping the limits, modalities, capabilities
- // and name they had described. The resolver is idempotent, so the
- // editor re-applying it to this seed changes nothing.
- onCustom={(typed) => {
- addCandidates([]);
- const seedId = backendModelId(typed);
- const existing = heldRowFor(seedId, draftRef.current, baselineRef.current?.models ?? []);
- setEditing(existing ? { model: existing } : { model: null, seedId });
- }}
- />
- )}
-
- {editing && (
- <BackendModelEditorDialog
- open
- backend={backend}
- model={editing.model}
- seedId={editing.seedId}
- takenIds={takenIds}
- effortSuggestions={effortSuggestions}
- onCancel={() => setEditing(null)}
- onCommit={commitEdit}
- />
- )}
</>
);
};