mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-18 13:55:57 +00:00
* perf(renderer): cut the startup bundle by a third Every window parsed ~6.1 MB of JavaScript before the first render. The entry chunk carried all five UI locales, and the whole AI SDK chunk was preloaded even though the AI panel is lazy. - i18n: only English stays in the entry; other dictionaries load on demand (plus their same-base fallback, e.g. zh-TW -> zh-CN). index.tsx awaits the saved language before the first render, and I18nProvider re-renders when a runtime switch finishes loading. - AI runtime: aiStateSnapshots cleaned up chats through getAgentRuntime(), and the plugin AI/agent hosts created their runtimes on mount, which pulled the Catty harness and @ai-sdk providers into startup. Cleanup now goes through a light handle that the runtime registers (the reversible privacy flag and main-process privacy mapping are still cleared without a runtime), and both plugin hosts create their runtime on the first request, re-checking liveness after the async load. - Chunking: manualChunks' object form also moved Vite's dynamic-import preload helper into vendor-ai (the AI SDK itself uses import()), so the entry imported it from there and vendor-ai (649 KB) was preloaded on every launch. Vendor chunks now use the function form and the helper gets its own 1 KB chunk. - jsqr is loaded when a QR image is imported instead of with the host editor. - startupBundle.architecture.test.ts guards these invariants. Startup JS (index.html): 5.29 MB entry + 649 KB vendor-ai + 138 KB radix -> 3.80 MB entry + 1 KB helper + 174 KB radix (-35%). Startup harness, 2000 hosts, 10 runs, warm p50: loadURL -> renderer entry evaluated 321 -> 207 ms, loadURL -> renderer ready 481 -> 323 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(i18n): preload locale messages before static rendering * test(i18n): preload locales in remaining zh-CN UI tests Non-English dictionaries now load lazily, so I18nProvider can initially render English before its effect finishes loading zh-CN. Explicitly await loadLocaleMessages before rendering these localized UI tests to fix the remaining CI failures without timing-based waits or production changes. * chore: retrigger CI after locale preload fix Previous tip 38108ce66 was on the branch but the PR head stayed stuck on d49ad024e after a GitHub 500 during push. Empty commit to refresh the PR head and re-queue checks. * chore: retrigger CI after plugin-contract runner cancel --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
7.1 KiB
TypeScript
198 lines
7.1 KiB
TypeScript
import test, { before } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import React from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
|
|
import { ComposerModelPicker } from './ComposerModelPicker';
|
|
import { I18nProvider } from '../../application/i18n/I18nProvider';
|
|
import { loadLocaleMessages } from '../../application/i18n/messages';
|
|
|
|
// Non-English dictionaries load on demand; static rendering runs no effects.
|
|
before(async () => {
|
|
for (const locale of ['zh-CN', 'zh-TW', 'es', 'ru']) await loadLocaleMessages(locale);
|
|
});
|
|
|
|
for (const [locale, cachedLabel] of [
|
|
['en', 'Cached'],
|
|
['zh-CN', '缓存'],
|
|
['zh-TW', '快取'],
|
|
['es', 'En caché'],
|
|
['ru', 'Кэш'],
|
|
]) {
|
|
test(`cached catalog without a usable timestamp has a clean label in ${locale}`, () => {
|
|
for (const fetchedAt of [undefined, 'invalid-date']) {
|
|
const html = renderToStaticMarkup(
|
|
<I18nProvider locale={locale}>
|
|
<ComposerModelPicker
|
|
modelPresets={[{ id: 'saved-model', name: 'Saved model' }]}
|
|
selectedModelId="saved-model"
|
|
catalogSource="last-known-good"
|
|
catalogFetchedAt={fetchedAt}
|
|
prefs={{ recent: [], pinned: [] }}
|
|
onSelectModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>
|
|
</I18nProvider>,
|
|
);
|
|
assert.ok(html.includes(`title="${cachedLabel}"`));
|
|
assert.doesNotMatch(html, /\{time\}|ai\.chat\.modelCatalog/);
|
|
}
|
|
});
|
|
}
|
|
|
|
test('Catty picker keeps a single model list and hides other providers until the submenu opens', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ComposerModelPicker
|
|
providers={[
|
|
{
|
|
id: 'p1',
|
|
providerId: 'deepseek',
|
|
name: 'DeepSeek',
|
|
defaultModel: 'deepseek-v4-pro',
|
|
enabled: true,
|
|
},
|
|
{
|
|
id: 'p2',
|
|
providerId: 'openai',
|
|
name: 'OpenAI',
|
|
defaultModel: 'gpt-5.5',
|
|
enabled: true,
|
|
},
|
|
]}
|
|
selectedProviderId="p1"
|
|
selectedModelId="deepseek-v4-pro"
|
|
prefs={{ recent: [], pinned: [] }}
|
|
onSelectProviderModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>,
|
|
);
|
|
|
|
assert.match(html, /DeepSeek/);
|
|
assert.match(html, /placeholder="ai\.chat\.searchModels"/);
|
|
assert.match(html, /deepseek-v4-pro/);
|
|
assert.match(html, /aria-label="ai\.chat\.selectProvider"/);
|
|
assert.doesNotMatch(html, /OpenAI/);
|
|
assert.doesNotMatch(html, /w-\[128px\]/);
|
|
});
|
|
|
|
test('external agent picker lists presets without a provider column', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ComposerModelPicker
|
|
modelPresets={[
|
|
{ id: 'gpt-5.5', name: 'GPT-5.5' },
|
|
{ id: 'gpt-5.4', name: 'GPT-5.4' },
|
|
]}
|
|
selectedModelId="gpt-5.5"
|
|
prefs={{ recent: [{ modelId: 'gpt-5.5' }], pinned: [] }}
|
|
onSelectModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>,
|
|
);
|
|
|
|
assert.match(html, /GPT-5\.5/);
|
|
assert.match(html, /GPT-5\.4/);
|
|
assert.match(html, /ai\.chat\.recent/);
|
|
assert.doesNotMatch(html, /ai\.chat\.providers/);
|
|
});
|
|
|
|
test('custom model action is offered in provider-switcher and preset modes', () => {
|
|
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
|
// Custom ids are accepted regardless of mode (provider catalog or CLI
|
|
// presets) — #3534 wants manual model entry for external agents too.
|
|
assert.match(source, /const showCustom = Boolean\(\s*allowCustomEntry\s*&&\s*trimmedQuery/s);
|
|
assert.match(source, /resolveComposerEnterModelId/);
|
|
});
|
|
|
|
test('custom model action can be suppressed when the host locks the model', () => {
|
|
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
|
// Codex config-locked models override every selection on send; the host
|
|
// turns the action off so it never becomes a silent no-op.
|
|
assert.match(source, /allowCustomEntry = true/);
|
|
const html = renderToStaticMarkup(
|
|
<ComposerModelPicker
|
|
modelPresets={[{ id: 'gpt-5.5', name: 'GPT-5.5' }]}
|
|
selectedModelId="gpt-5.5"
|
|
prefs={{ recent: [], pinned: [] }}
|
|
allowCustomEntry={false}
|
|
onSelectModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>,
|
|
);
|
|
assert.doesNotMatch(html, /ai\.chat\.useCustomModel/);
|
|
});
|
|
|
|
test('reselecting a saved custom model preserves its custom provenance', () => {
|
|
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
|
// A saved custom id is appended to the preset list, so picking it from
|
|
// Recent has showCustom === false. The callback must keep the custom flag
|
|
// anyway, or the host overwrites the pref entry without it and
|
|
// resolveComposerCustomModelIds drops the model from the presets.
|
|
assert.match(source, /customPrefIds\.has\(modelId\.toLowerCase\(\)\)/);
|
|
});
|
|
|
|
test('external agent picker keeps preset rows truncation-friendly with a full-name tooltip', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ComposerModelPicker
|
|
modelPresets={[{ id: 'gpt-5.6-sol-very-long-preview-id', name: 'GPT-5.6 Sol (preview)' }]}
|
|
selectedModelId="gpt-5.6-sol-very-long-preview-id"
|
|
prefs={{ recent: [], pinned: [] }}
|
|
onSelectModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>,
|
|
);
|
|
|
|
assert.match(html, /title="GPT-5\.6 Sol \(preview\)"/);
|
|
});
|
|
|
|
test('external agent picker shows the loading row while the live catalog is pending', () => {
|
|
const html = renderToStaticMarkup(
|
|
<ComposerModelPicker
|
|
modelPresets={[]}
|
|
loading
|
|
selectedModelId={undefined}
|
|
prefs={{ recent: [], pinned: [] }}
|
|
onSelectModel={() => {}}
|
|
onTogglePinned={() => {}}
|
|
/>,
|
|
);
|
|
|
|
assert.match(html, /ai\.chat\.loadingModels/);
|
|
// With no presets the picker renders only the loading row; the host now
|
|
// keeps built-in presets visible during loading and passes them through.
|
|
assert.doesNotMatch(html, /gpt-5\.1/);
|
|
});
|
|
|
|
test('manual refresh button renders for any fetched catalog or warning and stays localized', () => {
|
|
const base = {
|
|
modelPresets: [{ id: 'm-1', name: 'M1' }],
|
|
selectedModelId: 'm-1',
|
|
prefs: { recent: [], pinned: [] },
|
|
onSelectModel: () => {},
|
|
onTogglePinned: () => {},
|
|
};
|
|
for (const [locale, refreshLabel] of [
|
|
['en', 'Refresh model list'],
|
|
['zh-CN', '刷新模型列表'],
|
|
['zh-TW', '重新整理模型清單'],
|
|
['es', 'Actualizar la lista de modelos'],
|
|
['ru', 'Обновить список моделей'],
|
|
]) {
|
|
const html = renderToStaticMarkup(
|
|
<I18nProvider locale={locale}>
|
|
<ComposerModelPicker {...base} catalogSource="last-known-good" onRefreshCatalog={() => {}} />
|
|
</I18nProvider>,
|
|
);
|
|
assert.ok(html.includes(`aria-label="${refreshLabel}"`));
|
|
}
|
|
|
|
// A plain preset list without a host refresh action stays buttonless.
|
|
assert.doesNotMatch(renderToStaticMarkup(<ComposerModelPicker {...base} />), /refreshModelList/);
|
|
|
|
// A degraded preset serve (warning, no source) still offers the refresh.
|
|
const warned = renderToStaticMarkup(
|
|
<ComposerModelPicker {...base} catalogWarning="live fetch failed" onRefreshCatalog={() => {}} />,
|
|
);
|
|
assert.match(warned, /aria-label="ai\.chat\.refreshModelList"/);
|
|
});
|