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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model-hub): distinct close label for the catalog dialog; e2e allow-list for tier provenance (#1843)
Call Whitefc8dbe867e4b
diff --git a/ui/e2e/b-add-api-key.spec.ts b/ui/e2e/b-add-api-key.spec.tsindex a44d4b572..4cd173505 100644--- a/ui/e2e/b-add-api-key.spec.ts+++ b/ui/e2e/b-add-api-key.spec.ts@@ -197,18 +197,30 @@ test.describe('B · add an API-key source', () => {await expect(hub.sourceDetailDialog).toBeVisible({ timeout: 30_000 });const created = (await api.sources()).find((source) => source.display_name === name);- expect(created?.models.map((model) => model.id).sort()).toEqual(- inventory.map((model) => model.id).sort(),++ // assert-current: everything the upstream said about a model except its id+ // is discarded on the way to storage. The whole row is stated rather than+ // its key set, so each drop is asserted as a value and not merely as a name+ // that exists. `reasoning_efforts_source` is the one that matters: it is+ // #1836's tier provenance, product shape to record here rather than a leak+ // to strip, and `null` is the claim — the persisted schema also admits+ // `catalog` alongside an empty tier list, so a regression stamping it would+ // make the UI treat these tiers as managed and non-editable while a key+ // check still passed. A field arriving later fails this too.+ const byId = (one: { id: string }, other: { id: string }) => one.id.localeCompare(other.id);+ expect([...(created?.models ?? [])].sort(byId)).toEqual(+ inventory+ .map((model) => ({+ id: model.id,+ origin: 'discovered',+ display_name: null,+ reasoning_efforts: [],+ reasoning_efforts_source: null,+ discovered_at: expect.any(String),+ retired: false,+ }))+ .sort(byId),);- for (const model of created?.models ?? []) {- // assert-current: everything the upstream said about a model except its id- // is discarded on the way to storage.- expect(Object.keys(model).sort()).toEqual(- ['discovered_at', 'display_name', 'id', 'origin', 'reasoning_efforts', 'retired'],- );- expect(model.display_name).toBeNull();- expect(model.reasoning_efforts).toEqual([]);- }});test('B4 · a proven interface with no model list can still be added, on the record', async ({ hub, mock, api }) => {diff --git a/ui/scripts/travellingTokens.mjs b/ui/scripts/travellingTokens.mjsnew file mode 100644index 000000000..e12689530--- /dev/null+++ b/ui/scripts/travellingTokens.mjs@@ -0,0 +1,233 @@+// Which custom properties a class can actually resolve where it renders.+//+// `customPropertiesIn` answers "is this name declared anywhere", which is the+// question that let this defect ship. Every `--model-hub-guard-*` token was+// declared -- on `.model-hub-guard-dialog` -- so the token layer looked whole.+// But `GuardImpact` and `GuardGapList` are the shared evidence body for a+// guarded Model Hub mutation, and three of the four dialogs that mount them are+// not that dialog. In those three the `var()` named a property no ancestor+// declares, which is invalid at computed-value time, so the declaration drew+// nothing: `gap` fell back to `normal`, `font-size` to the inherited size, and+// the count's `padding` to zero. Not a pill missing a margin -- "Hops that will+// be removed2 hops" in one unbroken run.+//+// A rendered test cannot catch it. jsdom computes no cascade and loads no+// stylesheet, so `getComputedStyle` there reports the inline truth and agrees+// with itself in every root. The only place the mistake exists is the+// stylesheet's scope graph, so that is what gets read.+//+// The property asserted is self-sufficiency, not a list of tokens: a class that+// travels resolves every name it consumes from itself or from a scope every+// element inherits. A token added to such a class later is covered without+// editing anything, and a token parked back on a dialog root fails here rather+// than in a screenshot nobody takes.+//+// "Resolves" is the whole difficulty, and it is not "is declared somewhere".+// A declaration counts only where it is in force, so both halves of its reach+// are compared against the use: which subtree its selector claims, and which+// conditions its enclosing at-rules put on it. A rule that answers only the+// first half sanctions exactly the kind of scope this file exists to catch.++// A selector that matches the document root itself, so a custom property+// declared there is inherited by every element regardless of where it mounts.+// The whole selector has to match, not its prefix. A qualified root reaches+// every element only while its qualifier holds, which is a narrower promise+// than the one being consumed: `[data-theme="dark"]` names an attribute this+// repo also sets on nested elements (`AppWindow.tsx:259`,+// `AppsEditorPage.tsx:114`, `confirm-dialog.tsx:108`), and even on `<html>` it+// is one half of a theme pair, so a token declared only there is missing+// wherever the other half applies. Such tokens resolve because a `:root` base+// declares them and the themed block overrides it -- and that base is what+// this looks for.+const DOCUMENT_ROOT = /^(:root|html|body|\*)$/;++// An at-rule whose body applies only when its condition holds. A declaration+// inside one is in force for a use only if the use is inside it too, so the+// chain is compared rather than discarded -- 72 token declarations and 19 uses+// in this project sit under `@media`, so the difference is not hypothetical.+// `@layer` and `@theme` are deliberately absent: they set precedence and+// origin, not whether the body applies. An at-rule spelled some new way counts+// as unconditional, a miss rather than a false positive -- the same bias as+// the fallback rule below.+const CONDITIONAL = new Set(['media', 'supports', 'container', 'scope', 'document']);++// `var(--x)` on an undeclared name draws nothing; `var(--x, 6px)` draws 6px.+// The second is not this defect, so the fallback is what decides whether a use+// counts -- otherwise every deliberately-optional token reads as a violation+// and the gate fails correct CSS.+const UNGUARDED_USE = /var\(\s*(--[\w-]+)\s*\)/g;++function insideTheme(node) {+ for (let at = node.parent; at; at = at.parent) {+ if (at.type === 'atrule' && at.name === 'theme') return true;+ }+ return false;+}++// Every condition standing between a node and the stylesheet, innermost first.+// Params are whitespace-collapsed so one query spelled two ways still reads as+// one condition.+function conditionsOn(node) {+ const chain = [];+ for (let at = node.parent; at; at = at.parent) {+ if (at.type === 'atrule' && CONDITIONAL.has(at.name)) {+ chain.push(`@${at.name} ${at.params.replace(/\s+/g, ' ').trim()}`);+ }+ }+ return chain;+}++// Whether any of `chains` describes a declaration that is in force wherever a+// use guarded by `conditions` applies. That holds when every condition on the+// declaration also guards the use: the use cannot apply without them, so the+// declaration cannot be missing. An unconditional declaration has an empty+// chain and so is in force everywhere, which is the ordinary case.+function inForce(chains, conditions) {+ return (chains ?? []).some((chain) => chain.every((one) => conditions.includes(one)));+}++// The leftmost compound of a selector is the only part that says which subtree+// a rule belongs to. `.guard-label > span` and `.guard-hop strong` are the+// travelling body styling its own descendants, so their tokens are the+// travelling body's problem; `.catalog-dialog .guard-label` would be a rule+// about one dialog and is deliberately none of this fold's business.+function firstCompound(selector) {+ let depth = 0;+ for (let index = 0; index < selector.length; index += 1) {+ const character = selector[index];+ if (character === '(' || character === '[') depth += 1;+ else if (character === ')' || character === ']') depth -= 1;+ else if (depth === 0 && ' >+~'.includes(character)) return selector.slice(0, index);+ }+ return selector;+}++// `:not(.model-hub-guard-dialog)` names a class it excludes, so the+// parenthesised groups come out before the class names go in.+function classesOf(compound) {+ const bare = compound.replace(/\([^)]*\)/g, '');+ return [...bare.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)].map((match) => match[1]);+}++/**+ * Every class name a component renders, read from its own source.+ *+ * The component is the authority on this, not a list kept next to the check: a+ * class it stops rendering stops being asserted, and one it starts rendering+ * starts. Only `className` is read, so a class named in a comment or a log line+ * is not mistaken for one that ships.+ */+function classesRenderedBy(source) {+ const found = new Set();+ const attribute = /className\s*=\s*/g;++ for (let match = attribute.exec(source); match; match = attribute.exec(source)) {+ let cursor = match.index + match[0].length;+ let end = cursor;++ if (source[cursor] === '{') {+ // Read the whole expression, so `cn('a', flag && 'b')` contributes both.+ let depth = 0;+ for (; end < source.length; end += 1) {+ if (source[end] === '{') depth += 1;+ else if (source[end] === '}') {+ depth -= 1;+ if (depth === 0) { end += 1; break; }+ }+ }+ } else {+ const quote = source[cursor];+ if (quote !== '"' && quote !== "'" && quote !== '`') continue;+ end = source.indexOf(quote, cursor + 1) + 1;+ if (end === 0) continue;+ }++ const expression = source.slice(cursor, end);+ for (const literal of expression.matchAll(/["'`]([^"'`]*)["'`]/g)) {+ for (const name of literal[1].split(/\s+/)) if (name) found.add(name);+ }+ }++ return found;+}++/**+ * The tokens ``classNames`` consume but cannot resolve where they render.+ *+ * ``sheets`` is the materialised `eachStylesheet` walk -- materialised because+ * this needs two passes over the same trees, and a generator gives one.+ * Returns one entry per unresolvable use, naming the class whose subtree+ * consumes it and the origin to report, so a failure reads as an instruction.+ */+function unscopedTokens(sheets, classNames) {+ const travelling = new Set(classNames);+ // Both keyed to the conditions the declaration was made under, because a+ // name being declared somewhere is not the question -- that is what+ // `customPropertiesIn` answers, and what let this defect ship.+ const inheritable = new Map();+ const declaredOn = new Map();+ const record = (into, key, conditions) => {+ if (!into.has(key)) into.set(key, []);+ into.get(key).push(conditions);+ };++ for (const [, root] of sheets) {+ // A registered name resolves to its initial value everywhere, so a use of+ // one is not this defect. A registration carrying no initial value under+ // `syntax: "*"` does draw nothing, which this treats as resolvable and so+ // will not report -- a miss rather than a false positive, on the same+ // grounds `customProperties.mjs` records the name at all.+ root.walkAtRules('property', (rule) => record(inheritable, rule.params.trim(), conditionsOn(rule)));++ root.walkDecls((declaration) => {+ if (!declaration.prop.startsWith('--')) return;++ const owner = declaration.parent;+ const conditions = conditionsOn(declaration);+ const fromRoot = owner.type === 'rule'+ && owner.selectors.some((one) => DOCUMENT_ROOT.test(one.trim()));+ if (insideTheme(declaration) || fromRoot) record(inheritable, declaration.prop, conditions);+ if (owner.type !== 'rule') return;++ for (const one of owner.selectors) {+ const selector = one.trim();+ for (const name of classesOf(selector)) {+ // Only a declaration on the class ITSELF is inherited by the whole+ // subtree. One on `.guard-label > span` reaches that span's children+ // and no sibling, so counting it would sanction a scope narrower than+ // the one being consumed.+ if (selector !== `.${name}`) continue;+ record(declaredOn, `${name}|${declaration.prop}`, conditions);+ }+ }+ });+ }++ const unresolved = [];+ for (const [origin, root] of sheets) {+ root.walkDecls((declaration) => {+ const owner = declaration.parent;+ if (owner.type !== 'rule') return;++ const used = [...declaration.value.matchAll(UNGUARDED_USE)].map((match) => match[1]);+ if (used.length === 0) return;++ const conditions = conditionsOn(declaration);+ for (const one of owner.selectors) {+ const selector = one.trim();+ for (const name of classesOf(firstCompound(selector))) {+ if (!travelling.has(name)) continue;+ for (const property of used) {+ if (inForce(inheritable.get(property), conditions)) continue;+ if (inForce(declaredOn.get(`${name}|${property}`), conditions)) continue;+ unresolved.push({ className: name, property, origin, selector, declaration: declaration.prop });+ }+ }+ }+ });+ }++ return unresolved;+}++export { classesRenderedBy, firstCompound, unscopedTokens };diff --git a/ui/scripts/travellingTokens.test.mjs b/ui/scripts/travellingTokens.test.mjsnew file mode 100644index 000000000..919ff0229--- /dev/null+++ b/ui/scripts/travellingTokens.test.mjs@@ -0,0 +1,253 @@+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++import { describe, expect, it } from 'vitest';++import postcss from 'postcss';++import { eachStylesheet } from './stylesheets.mjs';+import { classesRenderedBy, firstCompound, unscopedTokens } from './travellingTokens.mjs';++const UI_ROOT = fileURLToPath(new URL('../', import.meta.url));++// The components whose styling has to survive being mounted somewhere else.+// This is the one thing the stylesheet cannot know and the check cannot derive:+// a class is only "travelling" because more than one dialog renders it, which+// is a fact about the React tree. So it is stated once, as the subject of the+// check -- and the classes themselves are then read out of these files, so the+// enumeration ends here rather than being copied into an assertion.+//+// Add a component to this list when it becomes shared. Both of these are: they+// are the evidence body of a guarded Model Hub mutation, and `SourceDetailPanel`,+// `SourceMutationReport`, `BackendModelCatalogDialog`, `AddApiKeyDialog` and+// `RouteChainDialog` each mount them under a different root class.+const TRAVELLING_COMPONENTS = [+ 'src/components/settings/models/GuardImpact.tsx',+ 'src/components/settings/models/GuardGapList.tsx',+];++// The body's outer wrapper has no component of its own: every caller writes the+// `<div className="model-hub-guard-body">` itself, so no single file's+// `className` values name it the way the two components above name theirs.+// Hence the name here. One name covers every caller, present and future,+// because what gets asserted is a property of the class -- it resolves its+// tokens from itself or from an inherited scope -- and that holds under+// whichever root a caller mounts it in.+const TRAVELLING_WRAPPERS = ['model-hub-guard-body'];++// Every shipped source, so a class can be asked who renders it. Tests are+// excluded: a class named only by an assertion does not ship.+function* shippedSources(directory) {+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {+ const at = path.join(directory, entry.name);+ if (entry.isDirectory()) yield* shippedSources(at);+ else if (/\.tsx?$/.test(entry.name) && !/\.test\.tsx?$/.test(entry.name)) {+ yield fs.readFileSync(at, 'utf8');+ }+ }+}++describe('firstCompound', () => {+ it('keeps the whole selector when nothing follows the subject', () => {+ expect(firstCompound('.model-hub-guard-label')).toBe('.model-hub-guard-label');+ });++ it('stops at every combinator, so a descendant rule is attributed to its subject', () => {+ for (const combinator of [' ', ' > ', ' + ', ' ~ ', '>']) {+ expect(firstCompound(`.a${combinator}span`)).toBe('.a');+ }+ });++ it('does not mistake a combinator inside a functional or attribute part for the end', () => {+ expect(firstCompound('.a:not(.b > .c)[data-x="y > z"] span')).toBe('.a:not(.b > .c)[data-x="y > z"]');+ });+});++describe('classesRenderedBy', () => {+ it('reads a plain literal, a helper call and a conditional alike', () => {+ const source = [+ 'const a = <div className="one two" />;',+ "const b = <div className={cn('three', flag && 'four')} />;",+ 'const c = <div className={`five`} />;',+ ].join('\n');++ expect(classesRenderedBy(source)).toEqual(new Set(['one', 'two', 'three', 'four', 'five']));+ });++ it('ignores a class name that is only talked about', () => {+ const source = '// .model-hub-guard-label is styled elsewhere\nconst tip = ".model-hub-guard-hop";';++ expect(classesRenderedBy(source)).toEqual(new Set());+ });+});++describe('unscopedTokens', () => {+ const sheetsOf = (css) => [['inline', postcss.parse(css)]];++ it('accepts a token the class declares on itself', () => {+ const sheets = sheetsOf('.travels { --gap: 6px; gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('accepts a token from a scope every element inherits', () => {+ for (const scope of [':root', 'html', 'body', '*']) {+ const sheets = sheetsOf(`${scope} { --gap: 6px } .travels { gap: var(--gap); }`);++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ }+ });++ it('reports a token only a qualified root declares, because the other half has none', () => {+ // A themed root reaches every element only while that theme applies, so it+ // cannot answer for a use that applies always.+ for (const scope of ['[data-theme="light"]', ':root:not([data-theme="dark"])', 'html[data-theme="dark"]']) {+ const sheets = sheetsOf(`${scope} { --gap: 6px } .travels { gap: var(--gap); }`);++ expect(unscopedTokens(sheets, ['travels'])).toHaveLength(1);+ }+ });++ it('accepts a themed override once a root base declares the same token', () => {+ // The project's own shape: `:root` states the value, the theme overrides it.+ const sheets = sheetsOf(':root { --gap: 6px } [data-theme="dark"] { --gap: 8px } .travels { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('accepts a token the class declares on itself and a descendant consumes', () => {+ const sheets = sheetsOf('.travels { --pad: 8px } .travels > span { padding: var(--pad); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('reports a token only some ancestor declares, naming the class and the property', () => {+ const sheets = sheetsOf('.host { --gap: 6px } .travels { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([+ { className: 'travels', property: '--gap', origin: 'inline', selector: '.travels', declaration: 'gap' },+ ]);+ });++ it('reports it for a descendant of the class too', () => {+ const sheets = sheetsOf('.host { --pad: 8px } .travels > span { padding: var(--pad); }');++ expect(unscopedTokens(sheets, ['travels'])).toHaveLength(1);+ });++ it('leaves a rule about one host alone, because that rule is not travelling', () => {+ const sheets = sheetsOf('.host { --gap: 6px } .host .travels { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('accepts a use that carries a fallback, which draws something either way', () => {+ const sheets = sheetsOf('.host { --gap: 6px } .travels { gap: var(--gap, 6px); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('says nothing about a class that does not travel', () => {+ const sheets = sheetsOf('.host { --gap: 6px } .stays-put { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('reports a token the class declares only inside a query the use does not share', () => {+ const sheets = sheetsOf('@media (min-width: 600px) { .travels { --gap: 6px } } .travels { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toHaveLength(1);+ });++ it('accepts it when the use stands under the same query', () => {+ const sheets = sheetsOf('@media (min-width: 600px) { .travels { --gap: 6px } .travels { gap: var(--gap); } }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('accepts a use nested deeper than the declaration it relies on', () => {+ // The use cannot apply without the query that guards the declaration, so+ // the declaration cannot be missing where the use is.+ const sheets = sheetsOf(+ '@media (min-width: 600px) { .travels { --gap: 6px } @supports (gap: 1px) { .travels { gap: var(--gap); } } }',+ );++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });++ it('reports an inherited scope that is itself conditional, registration included', () => {+ // The same miss as a class token: `:root`, `@theme` and `@property` each+ // promise every element, and a query around any of them takes that back.+ for (const declared of [+ ':root { --gap: 6px }',+ '@theme { --gap: 6px }',+ '@property --gap { syntax: "*"; inherits: true; initial-value: 6px }',+ ]) {+ const sheets = sheetsOf(`@media print { ${declared} } .travels { gap: var(--gap); }`);++ expect(unscopedTokens(sheets, ['travels'])).toHaveLength(1);+ }+ });++ it('treats a layer as no condition at all, because its body always applies', () => {+ const sheets = sheetsOf('@layer base { .travels { --gap: 6px } } .travels { gap: var(--gap); }');++ expect(unscopedTokens(sheets, ['travels'])).toEqual([]);+ });+});++describe('the shared guard body', () => {+ const sheets = [...eachStylesheet(UI_ROOT)];+ const travelling = new Set(TRAVELLING_WRAPPERS);+ for (const relative of TRAVELLING_COMPONENTS) {+ for (const name of classesRenderedBy(fs.readFileSync(path.join(UI_ROOT, relative), 'utf8'))) {+ travelling.add(name);+ }+ }++ it('names only wrappers the product still renders', () => {+ // The other half of the subject check below. A wrapper no file renders any+ // more is a name nobody checks, so it fails here rather than sitting in the+ // list looking like coverage.+ const rendered = new Set();+ for (const source of shippedSources(path.join(UI_ROOT, 'src'))) {+ for (const name of classesRenderedBy(source)) rendered.add(name);+ }++ for (const wrapper of TRAVELLING_WRAPPERS) expect(rendered).toContain(wrapper);+ });++ it('renders classes this project styles, so the check has a subject', () => {+ // Without this the assertion below passes by asking about nothing, which is+ // how a check outlives the thing it checks. `readFileSync` already fails+ // loudly if a component moves; this covers the quieter half, where the+ // files still parse but nothing recognisable comes out of them.+ expect(travelling.size).toBeGreaterThan(0);++ // Not every class needs a rule here: these components also render Tailwind+ // utilities (`flex-1`, `min-w-0`), which are generated at build time and+ // carry no custom properties, and `unscopedTokens` never reaches a class no+ // rule takes as its subject. So the requirement is that the project styles+ // some of what they render -- not all of it.+ const styled = new Set();+ for (const [, root] of sheets) {+ root.walkRules((rule) => {+ for (const one of rule.selectors) {+ for (const name of travelling) if (one.includes(`.${name}`)) styled.add(name);+ }+ });+ }+ expect(styled.size).toBeGreaterThan(0);+ });++ it('resolves every token it consumes wherever a caller mounts it', () => {+ // The four roots are `.model-hub-guard-dialog`, `.model-hub-catalog-dialog`,+ // `.model-hub-add-key-dialog` and `.model-hub-route-dialog`. None of them is+ // named here on purpose: a token resolvable from the class itself or from+ // `:root` is resolvable under all four and under a fifth nobody has written+ // yet, which is the property that makes the body shared rather than the+ // guard dialog's.+ expect(unscopedTokens(sheets, travelling)).toEqual([]);+ });+});diff --git a/ui/src/components/settings/models/BackendModelCatalogDialog.test.tsx b/ui/src/components/settings/models/BackendModelCatalogDialog.test.tsxindex 9dcbebe74..9c2afe1c4 100644--- a/ui/src/components/settings/models/BackendModelCatalogDialog.test.tsx+++ b/ui/src/components/settings/models/BackendModelCatalogDialog.test.tsx@@ -126,6 +126,36 @@ describe('BackendModelCatalogDialog', () => {expect(screen.getByLabelText('搜索名称或模型 ID')).toBeTruthy();});+ it.each([+ ['en', { corner: 'Close', footer: 'Cancel' }],+ ['zh', { corner: '关闭', footer: '取消' }],+ ] as const)('names the corner and footer exits apart in %s', async (language, exit) => {+ await i18n.changeLanguage(language);+ vi.spyOn(modelsApi, 'getAgentSources').mockResolvedValue(agent([model('alpha')]));+ const user = userEvent.setup();+ const { onClose } = renderDialog();++ // The model id is the one string here no locale rewrites.+ await screen.findByText('alpha');++ // Both ways out leave without saving, which is why they were once given the+ // same word — and why that word named neither. `getByRole` is singular, so+ // each line below also asserts the name it asks for reaches nothing else in+ // the dialog; the pair then has to be two controls rather than one found+ // twice. A screen reader is under the same constraint: one word announced+ // for the corner and the footer alike describes the dialog as having a+ // single exit, and offers no way to say which one is being read.+ const dialog = within(screen.getByRole('dialog'));+ const exits = [+ dialog.getByRole('button', { name: exit.corner }),+ dialog.getByRole('button', { name: exit.footer }),+ ];+ expect(new Set(exits).size).toBe(exits.length);++ for (const control of exits) await user.click(control);+ expect(onClose).toHaveBeenCalledTimes(exits.length);+ });+it('shows the catalog and nothing else — no source, route, fallback or mapping control', async () => {vi.spyOn(modelsApi, 'getAgentSources').mockResolvedValue(agent([model('alpha')], {routes: { alpha: { hops: [{ source_id: 'src_a', model_id: 'alpha' }] } },@@ -962,9 +992,10 @@ describe('BackendModelCatalogDialog', () => {await screen.findByRole('checkbox', { name: /Backup relay/ });// Either control the picker offers to leave is the same answer, and the- // dialog treats it as one: 「add none of these」.- const [dismiss] = within(screen.getByRole('dialog', { name: 'Add Claude Code models' }))- .getAllByRole('button', { name: 'Cancel' });+ // dialog treats it as one: 「add none of these」. Asked of one name, since+ // the corner control answers to 「Close」 and only the footer to this.+ const dismiss = within(screen.getByRole('dialog', { name: 'Add Claude Code models' }))+ .getByRole('button', { name: 'Cancel' });await user.click(dismiss);// The row and its promise go together. What is left is the list the server@@ -1004,11 +1035,11 @@ describe('BackendModelCatalogDialog', () => {// promise: what remains is the list the server already holds, so there is// nothing to save — the surest statement that the refused projection// cannot go out again. Asked back at the catalog, since the door closed- // the picker on its way out; the editor's own control is named for it,- // because the catalog behind it carries that word too.+ // the picker on its way out; scoped to the editor, whose footer is the+ // one control in it that carries this word.expect((await screen.findByLabelText('Model') as HTMLInputElement).value).toBe('');- const [leave] = within(screen.getByRole('dialog', { name: 'Add model' }))- .getAllByRole('button', { name: 'Cancel' });+ const leave = within(screen.getByRole('dialog', { name: 'Add model' }))+ .getByRole('button', { name: 'Cancel' });await user.click(leave);await waitFor(() => expect(screen.queryByText('GLM 5.2')).toBeNull());expect(screen.getByRole('button', { name: 'Save' }).hasAttribute('disabled')).toBe(true);diff --git a/ui/src/components/settings/models/BackendModelCatalogDialog.tsx b/ui/src/components/settings/models/BackendModelCatalogDialog.tsxindex 10d3a89ca..f2d433849 100644--- a/ui/src/components/settings/models/BackendModelCatalogDialog.tsx+++ b/ui/src/components/settings/models/BackendModelCatalogDialog.tsx@@ -950,7 +950,7 @@ export const BackendModelCatalogDialog: React.FC<{><DialogContentmobileSheetHeight="tall"- closeLabel={t('settings.models.gateway.catalog.cancel') as string}+ closeLabel={t('common.close') as string}className="model-hub-catalog-dialog flex h-[min(642px,calc(100dvh-32px))] w-[min(680px,calc(100vw-32px))] max-w-[680px] flex-col gap-0 overflow-hidden rounded-[14px] border-border-strong bg-surface p-0 shadow-[var(--model-hub-dialog-shadow)] max-md:w-full max-md:max-w-none max-md:rounded-t-2xl max-md:p-0 max-md:pt-2"onEscapeKeyDown={(event) => { if (busy || grabbedId) event.preventDefault(); }}onPointerDownOutside={(event) => { if (busy) event.preventDefault(); }}diff --git a/ui/src/components/settings/models/BackendModelEditorDialog.test.tsx b/ui/src/components/settings/models/BackendModelEditorDialog.test.tsxindex ab59f5e1a..a7f62266f 100644--- a/ui/src/components/settings/models/BackendModelEditorDialog.test.tsx+++ b/ui/src/components/settings/models/BackendModelEditorDialog.test.tsx@@ -650,13 +650,19 @@ describe('BackendModelEditorDialog', () => {await user.type(modelField(), 'abandoned');// The header close and the footer button are the same decision, so both- // discard the draft rather than one of them saving it.- const cancels = screen.getAllByRole('button', { name: 'Cancel' });- expect(cancels).toHaveLength(2);- await user.click(cancels[0]);- await user.click(cancels[1]);-- expect(onCancel).toHaveBeenCalledTimes(2);+ // discard the draft rather than one of them saving it. They are still two+ // controls, so they answer to two names: each `getByRole` below is singular+ // and throws if the name it asks for reaches more than one of them, which+ // is what sharing 「Cancel」 did — a screen reader announcing it twice named+ // neither, and a by-name locator could not address either.+ const exits = [+ screen.getByRole('button', { name: 'Close' }),+ screen.getByRole('button', { name: 'Cancel' }),+ ];+ expect(new Set(exits).size).toBe(exits.length);+ for (const exit of exits) await user.click(exit);++ expect(onCancel).toHaveBeenCalledTimes(exits.length);expect(onCommit).not.toHaveBeenCalled();});});diff --git a/ui/src/components/settings/models/BackendModelEditorDialog.tsx b/ui/src/components/settings/models/BackendModelEditorDialog.tsxindex 2a9b13bfe..9de327444 100644--- a/ui/src/components/settings/models/BackendModelEditorDialog.tsx+++ b/ui/src/components/settings/models/BackendModelEditorDialog.tsx@@ -419,7 +419,7 @@ export const BackendModelEditorDialog: React.FC<{<Dialog open={open} onOpenChange={(next) => { if (!next) onCancel(); }}><DialogContentmobileSheetHeight="tall"- closeLabel={t('settings.models.gateway.modelEditor.cancel') as string}+ closeLabel={t('common.close') as string}className="model-hub-model-editor flex h-[min(660px,calc(100dvh-32px))] w-[min(720px,calc(100vw-32px))] max-w-[720px] flex-col gap-0 overflow-hidden rounded-[14px] border-border-strong bg-surface p-0 shadow-[var(--model-hub-dialog-shadow)] max-md:w-full max-md:max-w-none max-md:rounded-t-2xl max-md:p-0 max-md:pt-2"><DialogHeader className="model-hub-model-editor-head shrink-0 justify-center border-b border-border">diff --git a/ui/src/components/settings/models/BackendModelPickerDialog.test.tsx b/ui/src/components/settings/models/BackendModelPickerDialog.test.tsxindex 1cd2e23fd..edd580231 100644--- a/ui/src/components/settings/models/BackendModelPickerDialog.test.tsx+++ b/ui/src/components/settings/models/BackendModelPickerDialog.test.tsx@@ -254,12 +254,18 @@ describe('BackendModelPickerDialog', () => {const { onCancel, onAdd } = renderPicker();await user.click(await screen.findByRole('checkbox', { name: 'gpt-6' }));- const exits = screen.getAllByRole('button', { name: 'Cancel' });+ // Every way out is the same way out, and each one is still addressable on+ // its own: the corner control is named for what it is rather than borrowing+ // the footer's word, so neither name reaches both. `getByRole` is singular+ // and enforces that — sharing 「Cancel」 made each of these throw.+ const exits = [+ screen.getByRole('button', { name: 'Close' }),+ screen.getByRole('button', { name: 'Cancel' }),+ ];+ expect(new Set(exits).size).toBe(exits.length);for (const exit of exits) await user.click(exit);- // Every way out is the same way out: the corner control borrows the- // footer's label rather than inventing a second word for it, and neither- // one takes the picks with it.+ // And neither one takes the picks with it.expect(onCancel).toHaveBeenCalledTimes(exits.length);expect(onAdd).not.toHaveBeenCalled();});diff --git a/ui/src/components/settings/models/BackendModelPickerDialog.tsx b/ui/src/components/settings/models/BackendModelPickerDialog.tsxindex f263ab1fa..3ce96e1a7 100644--- a/ui/src/components/settings/models/BackendModelPickerDialog.tsx+++ b/ui/src/components/settings/models/BackendModelPickerDialog.tsx@@ -168,7 +168,7 @@ export const BackendModelPickerDialog: React.FC<{<Dialog open={open} onOpenChange={(next) => { if (!next) onCancel(); }}><DialogContentmobileSheetHeight="tall"- closeLabel={t('settings.models.gateway.catalog.cancel') as string}+ closeLabel={t('common.close') as string}className="model-hub-catalog-dialog model-hub-picker flex h-[min(642px,calc(100dvh-32px))] w-[min(680px,calc(100vw-32px))] max-w-[680px] flex-col gap-0 overflow-hidden rounded-[14px] border-border-strong bg-surface p-0 shadow-[var(--model-hub-dialog-shadow)] max-md:w-full max-md:max-w-none max-md:rounded-t-2xl max-md:p-0 max-md:pt-2"><DialogHeader className="model-hub-catalog-head shrink-0 justify-center border-b border-border">diff --git a/ui/src/components/settings/models/modelHubSurface.css b/ui/src/components/settings/models/modelHubSurface.cssindex 2733e8167..b6a5b7130 100644--- a/ui/src/components/settings/models/modelHubSurface.css+++ b/ui/src/components/settings/models/modelHubSurface.css@@ -1185,6 +1185,24 @@}.model-hub-guard-overlay { background: var(--model-hub-scrim); }+/* Only the chrome's metrics. The head, title, subtitle, close, foot and action+ are this dialog's own furniture and render nowhere else, so they resolve here.+ The evidence BODY below is a different kind of thing: `GuardImpact` and+ `GuardGapList` are shared, and they mount inside four separate dialogs — this+ one, the catalog dialog's in-row removal confirmation, the Add-key replace+ phase, and the route chain's guard phase. A body token declared here reached+ exactly one of them; in the other three `var()` named a property no ancestor+ declares, which is invalid at computed-value time, so the declaration drew+ nothing: the label lost its gap AND its size, and the count lost its padding+ AND its size, which is not a pill missing a margin but 「Hops that will be+ removed2 hops」 in one unbroken run at the inherited font.++ It is the argument `.model-hub-route-selector` makes further up, arrived at+ from the other side. There a popover is portalled out of its dialog and+ inherits nothing; here nothing is portalled — the body is simply mounted+ somewhere else, which the stylesheet cannot see and the token scope must not+ assume. So each body class carries what it and its descendants consume, and a+ caller may mount it under any root at all. */.model-hub-guard-dialog {--model-hub-guard-width: 520px;--model-hub-guard-radius: 14px;@@ -1195,28 +1213,6 @@--model-hub-guard-subtitle-size: 10.5px;--model-hub-guard-close-size: 27px;--model-hub-guard-close-icon-size: 15px;- --model-hub-guard-body-padding: 20px;- --model-hub-guard-body-gap: 14px;- --model-hub-guard-label-gap: 6px;- --model-hub-guard-label-size: 10.5px;- --model-hub-guard-count-padding-y: 3px;- --model-hub-guard-count-padding-x: 8px;- --model-hub-guard-count-size: 10px;- --model-hub-guard-list-padding: 8px;- --model-hub-guard-list-gap: 6px;- --model-hub-guard-list-radius: 10px;- --model-hub-guard-hop-height: 52px;- --model-hub-guard-hop-padding-x: 10px;- --model-hub-guard-hop-gap: 10px;- --model-hub-guard-hop-radius: 8px;- --model-hub-guard-hop-name-size: 12px;- --model-hub-guard-hop-detail-gap: 3px;- --model-hub-guard-hop-detail-size: 10.5px;- --model-hub-guard-hint-gap: 7px;- --model-hub-guard-hint-size: 11.5px;- --model-hub-guard-hint-line: 17px;- --model-hub-guard-hint-icon-size: 13px;- --model-hub-guard-hint-icon-offset: 2px;--model-hub-guard-foot-padding-y: 14px;--model-hub-guard-foot-padding-x: 20px;--model-hub-guard-foot-gap: 8px;@@ -1240,14 +1236,77 @@.model-hub-guard-subtitle { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: var(--model-hub-guard-subtitle-size); }.model-hub-guard-close { width: var(--model-hub-guard-close-size); height: var(--model-hub-guard-close-size); color: var(--model-hub-ink-59); }.model-hub-guard-close svg { width: var(--model-hub-guard-close-icon-size); height: var(--model-hub-guard-close-icon-size); }-.model-hub-guard-body { padding: var(--model-hub-guard-body-padding); display: flex; flex-direction: column; gap: var(--model-hub-guard-body-gap); }-.model-hub-guard-label { display: flex; align-items: center; justify-content: flex-start; gap: var(--model-hub-guard-label-gap); color: var(--model-hub-ink-73); font-size: var(--model-hub-guard-label-size); font-weight: 700; }+/* The travelling body. Each class declares the metrics it and its own+ selector-descendants consume, so none of them depends on where a caller+ mounted it — not on the guard dialog, and not on each other either: a hop+ outside a list still measures like a hop. */+.model-hub-guard-body {+ --model-hub-guard-body-padding: 20px;+ --model-hub-guard-body-gap: 14px;+ padding: var(--model-hub-guard-body-padding);+ display: flex;+ flex-direction: column;+ gap: var(--model-hub-guard-body-gap);+}+.model-hub-guard-label {+ --model-hub-guard-label-gap: 6px;+ --model-hub-guard-label-size: 10.5px;+ --model-hub-guard-count-padding-y: 3px;+ --model-hub-guard-count-padding-x: 8px;+ --model-hub-guard-count-size: 10px;+ display: flex;+ align-items: center;+ justify-content: flex-start;+ gap: var(--model-hub-guard-label-gap);+ color: var(--model-hub-ink-73);+ font-size: var(--model-hub-guard-label-size);+ font-weight: 700;+}.model-hub-guard-label > span { padding: var(--model-hub-guard-count-padding-y) var(--model-hub-guard-count-padding-x); border: 1px solid var(--border); border-radius: 999px; background: var(--model-hub-wash-0a); color: var(--muted); font-size: var(--model-hub-guard-count-size); font-weight: 600; }-.model-hub-guard-list { padding: var(--model-hub-guard-list-padding); display: flex; flex-direction: column; gap: var(--model-hub-guard-list-gap); border: 1px solid var(--border); border-radius: var(--model-hub-guard-list-radius); background: var(--background); }-.model-hub-guard-hop { min-height: var(--model-hub-guard-hop-height); padding: 0 var(--model-hub-guard-hop-padding-x); display: flex; align-items: center; gap: var(--model-hub-guard-hop-gap); border: 1px solid var(--border); border-radius: var(--model-hub-guard-hop-radius); background: var(--model-hub-wash-08); }+.model-hub-guard-list {+ --model-hub-guard-list-padding: 8px;+ --model-hub-guard-list-gap: 6px;+ --model-hub-guard-list-radius: 10px;+ padding: var(--model-hub-guard-list-padding);+ display: flex;+ flex-direction: column;+ gap: var(--model-hub-guard-list-gap);+ border: 1px solid var(--border);+ border-radius: var(--model-hub-guard-list-radius);+ background: var(--background);+}+.model-hub-guard-hop {+ --model-hub-guard-hop-height: 52px;+ --model-hub-guard-hop-padding-x: 10px;+ --model-hub-guard-hop-gap: 10px;+ --model-hub-guard-hop-radius: 8px;+ --model-hub-guard-hop-name-size: 12px;+ --model-hub-guard-hop-detail-gap: 3px;+ --model-hub-guard-hop-detail-size: 10.5px;+ min-height: var(--model-hub-guard-hop-height);+ padding: 0 var(--model-hub-guard-hop-padding-x);+ display: flex;+ align-items: center;+ gap: var(--model-hub-guard-hop-gap);+ border: 1px solid var(--border);+ border-radius: var(--model-hub-guard-hop-radius);+ background: var(--model-hub-wash-08);+}.model-hub-guard-hop strong { display: block; color: color-mix(in srgb, var(--foreground) 70.2%, transparent); font-size: var(--model-hub-guard-hop-name-size); font-weight: 600; }.model-hub-guard-hop span span { margin-top: var(--model-hub-guard-hop-detail-gap); display: block; color: var(--model-hub-muted-b3); font-family: 'JetBrains Mono', monospace; font-size: var(--model-hub-guard-hop-detail-size); }-.model-hub-guard-hint { display: flex; align-items: flex-start; gap: var(--model-hub-guard-hint-gap); color: var(--model-hub-ink-73); font-size: var(--model-hub-guard-hint-size); line-height: var(--model-hub-guard-hint-line); }+.model-hub-guard-hint {+ --model-hub-guard-hint-gap: 7px;+ --model-hub-guard-hint-size: 11.5px;+ --model-hub-guard-hint-line: 17px;+ --model-hub-guard-hint-icon-size: 13px;+ --model-hub-guard-hint-icon-offset: 2px;+ display: flex;+ align-items: flex-start;+ gap: var(--model-hub-guard-hint-gap);+ color: var(--model-hub-ink-73);+ font-size: var(--model-hub-guard-hint-size);+ line-height: var(--model-hub-guard-hint-line);+}.model-hub-guard-hint svg { width: var(--model-hub-guard-hint-icon-size); height: var(--model-hub-guard-hint-icon-size); margin-top: var(--model-hub-guard-hint-icon-offset); flex: none; color: var(--model-hub-ink-59); }.model-hub-guard-foot { padding: var(--model-hub-guard-foot-padding-y) var(--model-hub-guard-foot-padding-x); display: flex; align-items: center; justify-content: flex-end; gap: var(--model-hub-guard-foot-gap); border-top: 1px solid var(--border); background: var(--model-hub-wash-05); }.model-hub-guard-action { height: auto; padding: var(--model-hub-guard-action-padding-y) var(--model-hub-guard-action-padding-x); border-radius: var(--model-hub-guard-action-radius); font-size: var(--model-hub-guard-action-size); font-weight: 600; }