mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 23:50:45 +00:00
* fix(#3584): automated AI fix * fix: address Codex review on PR #3585 * fix: address Codex review on PR #3585 --------- Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
129 lines
4.5 KiB
TypeScript
129 lines
4.5 KiB
TypeScript
import test 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';
|
|
|
|
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/);
|
|
// The host no longer renders built-in presets while loading (#3584).
|
|
assert.doesNotMatch(html, /gpt-5\.1/);
|
|
});
|