| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077 |
- // @vitest-environment jsdom
- import { createElement, type ChangeEvent } from "react";
- import { renderToStaticMarkup } from "react-dom/server";
- import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
- import {
- TID_SUBAGENT_BUILT_IN_MODEL_TRIGGER,
- TID_SUBAGENT_ROW,
- testId,
- } from "@zcode/shared/test-ids";
- import type { IServiceAccessor } from "@zcode/services";
- import { useRemoteWorkspaceSessionStore } from "@/store/remoteWorkspaceSessionStore.js";
- import { encodeCustomModelValue } from "../src/lib/zcodeCustomModelValue.js";
- const capturedButtons: Array<Record<string, unknown>> = [];
- const capturedModelConfigSelects: Array<Record<string, unknown>> = [];
- const capturedThoughtLevelControls: Array<Record<string, unknown>> = [];
- let useStateCallCount = 0;
- let stateOverrides = new Map<number, unknown>();
- let onManageModels = vi.fn();
- let useRealReactHooks = false;
- const mockTabs = vi.hoisted(() => ({ tabs: [] as unknown[] }));
- const mockScopeRouting = vi.hoisted(() => ({
- enabled: false,
- context: null as IServiceAccessor | null,
- modelServices: [] as unknown[],
- }));
- const mockInitializePlugins = vi.hoisted(() => vi.fn(async () => {}));
- const mockSubagentsService = vi.hoisted(() => ({
- list: vi.fn(async () => ({
- agents: [],
- userAgents: [],
- pluginAgents: [],
- capability: { userScopeAvailable: false, userScopeReason: "desktop_only" },
- })),
- getPrimaryUserAgentsDirectory: vi.fn(async () => ({ path: "/tmp/agents" })),
- createAgent: vi.fn(),
- updateAgent: vi.fn(),
- deleteAgent: vi.fn(),
- setEnabled: vi.fn(),
- setBuiltInModelOverride: vi.fn(),
- setPluginAgentModelOverride: vi.fn(),
- }));
- const mockRefreshLoadedSubagentsStoreForWorkspace = vi.hoisted(() => vi.fn(async () => {}));
- const mockUseModelProviders = vi.hoisted(() =>
- vi.fn(() => ({
- displayOrder: { providerIds: [] },
- loading: false,
- modelProviders: [],
- })),
- );
- const mockToolbarConfigState = vi.hoisted(() => ({
- configOptions: [
- {
- id: "model",
- name: "Model",
- category: "model",
- type: "select" as const,
- currentValue: "custom-openai/gpt-5.4",
- options: [
- {
- value: "custom-openai/gpt-5.4",
- name: "gpt-5.4",
- modelProviderId: "custom-openai",
- modelProviderName: "Custom OpenAI",
- modelThoughtLevels: ["low", "high"],
- modelDefaultThoughtLevel: "high",
- },
- {
- value: "custom-openai/glm-5.2",
- name: "glm-5.2",
- modelProviderId: "custom-openai",
- modelProviderName: "Custom OpenAI",
- modelThoughtLevels: ["high", "max"],
- modelDefaultThoughtLevel: "max",
- },
- {
- value: "custom-openai/plain-chat",
- name: "plain-chat",
- modelProviderId: "custom-openai",
- modelProviderName: "Custom OpenAI",
- modelThoughtLevels: [],
- },
- ],
- },
- ],
- status: "ready" as "idle" | "loading" | "ready" | "error",
- }));
- const mockModelSelectionView = vi.hoisted(() => ({
- revision: 1,
- providers: [
- {
- providerId: "custom-openai",
- config: {
- label: "Custom OpenAI",
- access: { type: "api-key" as const, apiKey: "token" },
- api: {
- type: "openai-chat-completions" as const,
- baseUrl: "https://example.test/v1",
- },
- models: ["gpt-5.4", "glm-5.2", "plain-chat"],
- },
- models: [
- {
- modelId: "gpt-5.4",
- config: {
- optionSpecs: {
- reasoningLevel: {
- values: ["low", "high"],
- map: "{}",
- },
- maxOutputTokens: { max: 32_000, map: "{}" },
- },
- },
- },
- {
- modelId: "glm-5.2",
- config: {
- optionSpecs: {
- reasoningLevel: {
- values: ["high", "max"],
- map: "{}",
- },
- maxOutputTokens: { max: 32_000, map: "{}" },
- },
- },
- },
- {
- modelId: "plain-chat",
- config: {
- optionSpecs: {
- reasoningLevel: { values: ["disabled"], map: "{}" },
- maxOutputTokens: { max: 32_000, map: "{}" },
- },
- },
- },
- ],
- },
- ],
- }));
- vi.mock("react", async () => {
- const actual = await vi.importActual<typeof import("react")>("react");
- return {
- ...actual,
- useEffect: (effect: () => void | (() => void), dependencies?: readonly unknown[]) =>
- useRealReactHooks ? actual.useEffect(effect, dependencies) : undefined,
- useState: (initialValue: unknown) => {
- if (useRealReactHooks) {
- return actual.useState(initialValue);
- }
- useStateCallCount += 1;
- if (stateOverrides.has(useStateCallCount)) {
- return [stateOverrides.get(useStateCallCount), vi.fn()] as const;
- }
- if (useStateCallCount === 1) {
- return [[], vi.fn()] as const;
- }
- if (useStateCallCount === 2) {
- return [{ userScopeAvailable: false, userScopeReason: "desktop_only" }, vi.fn()] as const;
- }
- if (useStateCallCount === 3) {
- return [false, vi.fn()] as const;
- }
- if (useStateCallCount === 4) {
- return [false, vi.fn()] as const;
- }
- return [typeof initialValue === "function" ? initialValue() : initialValue, vi.fn()] as const;
- },
- };
- });
- vi.mock("lucide-react", () => ({
- Cloud: () => null,
- Monitor: () => null,
- ArrowLeft: (props: Record<string, unknown>) => createElement("svg", props),
- Bot: (props: Record<string, unknown>) => createElement("svg", props),
- Check: (props: Record<string, unknown>) => createElement("svg", props),
- ChevronDown: (props: Record<string, unknown>) => createElement("svg", props),
- CircleHelp: (props: Record<string, unknown>) =>
- createElement("svg", { ...props, "data-icon": "reasoning-unavailable" }),
- FolderOpen: (props: Record<string, unknown>) => createElement("svg", props),
- InfoIcon: (props: Record<string, unknown>) => createElement("svg", props, "info"),
- Download: (props: Record<string, unknown>) => createElement("svg", props),
- Import: (props: Record<string, unknown>) => createElement("svg", props),
- SquareArrowRightEnter: (props: Record<string, unknown>) => createElement("svg", props),
- Loader2: (props: Record<string, unknown>) => createElement("svg", props),
- MoreHorizontal: (props: Record<string, unknown>) => createElement("svg", props),
- Pencil: (props: Record<string, unknown>) => createElement("svg", props),
- Plus: (props: Record<string, unknown>) => createElement("svg", props),
- RefreshCw: (props: Record<string, unknown>) => createElement("svg", props),
- RefreshCcw: (props: Record<string, unknown>) => createElement("svg", props),
- Search: (props: Record<string, unknown>) => createElement("svg", props),
- Trash2: (props: Record<string, unknown>) => createElement("svg", props),
- X: (props: Record<string, unknown>) => createElement("svg", props),
- }));
- vi.mock("@/components/ui/button.js", () => ({
- Button: ({ children, ...props }: { children: unknown; [key: string]: unknown }) => {
- capturedButtons.push({ children, ...props });
- return createElement("button", props, children);
- },
- }));
- vi.mock("@/ModelConfigSelect.js", () => ({
- ModelConfigSelect: ({ triggerLabel, normalizedValue, ...props }: Record<string, unknown>) => {
- capturedModelConfigSelects.push({
- triggerLabel,
- normalizedValue,
- ...props,
- });
- return createElement(
- "button",
- {
- type: "button",
- "data-model-current-value": normalizedValue,
- },
- triggerLabel,
- );
- },
- }));
- vi.mock("@/ControlHintTooltip.js", () => ({
- ControlHintTooltip: ({ children }: { children: unknown }) => children,
- }));
- vi.mock("@/store/TabStoreProvider.js", () => ({
- useTabStore: (selector: (state: { tabs: unknown[] }) => unknown) => selector(mockTabs),
- }));
- vi.mock("@/store/pluginManagementStore.js", () => ({
- usePluginManagementStore: (selector: (state: Record<string, unknown>) => unknown) =>
- selector({ plugins: [], availablePlugins: [], initialize: mockInitializePlugins }),
- }));
- vi.mock("@/settings/PluginScopeMenu.js", () => ({
- PluginScopeMenu: ({
- workspaceTabs,
- onScopeKeyChange,
- }: {
- workspaceTabs: Array<{ workspacePath: string; workspaceIdentity?: string }>;
- onScopeKeyChange: (key: string) => void;
- }) =>
- mockScopeRouting.enabled
- ? createElement(
- "div",
- null,
- ["user", ...workspaceTabs.map((tab) => tab.workspaceIdentity || tab.workspacePath)].map(
- (key) =>
- createElement(
- "button",
- {
- key,
- type: "button",
- "data-testid": `scope-${key}`,
- onClick: () => onScopeKeyChange(key),
- },
- key,
- ),
- ),
- )
- : createElement("button", null, "scope"),
- getPluginWorkspaceKey: (tab: { workspacePath: string; workspaceIdentity?: string }) =>
- mockScopeRouting.enabled ? tab.workspaceIdentity || tab.workspacePath : "workspace",
- isPluginScopeWorkspaceConnected: () => true,
- }));
- vi.mock("@/chat-input-toolbar/ThoughtLevelCycleControl.js", () => ({
- ThoughtLevelCycleControl: (props: Record<string, unknown>) => {
- capturedThoughtLevelControls.push(props);
- return createElement("button", {
- type: "button",
- "data-testid": "subagent-thought-level",
- });
- },
- }));
- vi.mock("@/components/ui/input.js", () => ({
- Input: (props: Record<string, unknown>) => createElement("input", props),
- }));
- vi.mock("@/components/ui/select.js", () => ({
- Select: ({ children }: { children: unknown }) => createElement("div", null, children),
- SelectContent: ({ children }: { children: unknown }) => createElement("div", null, children),
- SelectItem: ({ children }: { children: unknown }) => createElement("div", null, children),
- SelectTrigger: ({ children }: { children: unknown }) => createElement("button", null, children),
- SelectValue: () => createElement("span"),
- }));
- vi.mock("@/components/ui/tabs.js", () => ({
- Tabs: ({ children }: { children: unknown }) => createElement("div", null, children),
- TabsList: ({ children }: { children: unknown }) => createElement("div", null, children),
- TabsTrigger: ({ children, value }: { children: unknown; value: string }) =>
- createElement("button", { type: "button", "data-value": value }, children),
- }));
- vi.mock("@/components/ui/switch.js", () => ({
- Switch: ({ onCheckedChange, ...props }: Record<string, unknown>) =>
- createElement("input", {
- type: "checkbox",
- role: "switch",
- ...props,
- onChange: (event: ChangeEvent<HTMLInputElement>) => {
- if (typeof onCheckedChange === "function") {
- (onCheckedChange as (checked: boolean) => void)(event.target.checked);
- }
- },
- }),
- }));
- vi.mock("@/components/ui/textarea.js", () => ({
- Textarea: (props: Record<string, unknown>) => createElement("textarea", props),
- }));
- vi.mock("@/components/ui/toast.js", () => ({
- toast: vi.fn(),
- }));
- vi.mock("@/hooks/useConfirmDialog.js", () => ({
- useConfirmDialog: () => vi.fn(async () => true),
- }));
- vi.mock("@/hooks/usePlatform.js", () => ({
- useOptionalPlatform: () => null,
- usePlatform: () => ({
- openInFileManager: vi.fn(async () => ({ success: true })),
- }),
- }));
- vi.mock("@/hooks/useServices.js", () => ({
- useOptionalServices: () => null,
- useServices: () =>
- mockScopeRouting.context ?? {
- subagentsService: mockSubagentsService,
- },
- }));
- vi.mock("@/store/subagentsStore.js", () => ({
- refreshLoadedSubagentsStoreForWorkspace: mockRefreshLoadedSubagentsStoreForWorkspace,
- }));
- vi.mock("@/hooks/useModelProviders.js", () => ({
- useModelProviders: mockUseModelProviders,
- }));
- vi.mock("@/hooks/useModelSelectionView.js", () => {
- return {
- useModelSelectionView: () => ({
- state: { status: "ready", view: mockModelSelectionView },
- reload: vi.fn(),
- }),
- useModelSelectionServiceView: (service: unknown) => {
- mockScopeRouting.modelServices.push(service);
- return { state: { status: "ready", view: mockModelSelectionView }, reload: vi.fn() };
- },
- };
- });
- vi.mock("@/hooks/useZCodeConfig.js", () => ({
- useToolbarConfigOptions: () => ({
- configOptions: mockToolbarConfigState.configOptions,
- loading: mockToolbarConfigState.status === "loading",
- error: mockToolbarConfigState.status === "error",
- status: mockToolbarConfigState.status,
- }),
- }));
- vi.mock("@/settings/model-provider-section/useEnterpriseCodingPlanProducts.js", () => ({
- useEnterpriseCodingPlanProducts: () => ({
- snapshot: null,
- loading: false,
- error: null,
- refresh: vi.fn(async () => {}),
- }),
- }));
- vi.mock("@/i18n/IntlProvider.js", () => ({
- useZCodeIntl: () => ({
- intl: {
- formatMessage: ({ id }: { id: string }, values?: Record<string, string | number>) => {
- const messages: Record<string, string> = {
- "settings.subagents.description": "Manage subagents.",
- "settings.subagents.workspaceScopeUnsupported":
- "Workspace-level creation or editing is unsupported",
- "settings.subagents.addNew": "New subagent",
- "settings.create.action": "New",
- "settings.resourceActions.import": "Import",
- "settings.resourceActions.export": "Export",
- "settings.resourceActions.more": "More actions",
- "common.loading": "Loading...",
- "common.refresh": "Refresh",
- "settings.subagents.openUserAgentsFolder": "Open user subagents folder",
- "settings.subagents.noDescription": "No description",
- "settings.skills.refresh": "Refresh",
- "settings.skills.refreshing": "Refreshing...",
- "settings.subagents.searchPlaceholder": "Search subagents",
- "settings.subagents.userScopeDesktopOnly": "Subagents are desktop only.",
- "settings.subagents.empty": "No subagents found",
- "settings.subagents.group.user": "Installed",
- "settings.subagents.group.plugin": "Plugin subagents",
- "settings.subagents.group.plugin.hint": "Plugin agents are read-only.",
- "settings.subagents.group.builtIn": "Built-in subagents",
- "settings.subagents.group.builtIn.hint": "Built-in agents are read-only.",
- "settings.modelProvider.connectionMode.apiKeyBadge": "API",
- "settings.modelProvider.connectionMode.codingPlanBadge": "Individual",
- "settings.modelProvider.connectionMode.startPlan": "Start Plan",
- "settings.modelProvider.connectionMode.startPlanBadge": "Start",
- "settings.modelProvider.connectionMode.teamPlan": "Team Plan",
- "settings.modelProvider.connectionMode.teamPlanBadge": "Team",
- "settings.subagents.scope.builtIn": "Built-in",
- "settings.subagents.scope.plugin": "Plugin",
- "settings.scope.user": "User",
- "settings.subagents.model.select": "Select model",
- "settings.subagents.model.inherit": "Inherit default",
- "settings.subagents.model.defaultMain": "Inherit default",
- "settings.subagents.model.main": "Main model",
- "settings.subagents.reasoningUnavailable": "Reasoning effort unavailable",
- "settings.subagents.toolsCount": `${values?.count ?? 0} tools`,
- "settings.subagents.tools.all": "All tools",
- "settings.subagents.tools.inherit": "Inherit tools",
- "settings.subagents.toggleAria": `Toggle ${values?.name ?? ""}`,
- "settings.subagents.form.injectAgentsMd.label": "Inject AGENTS.md",
- "settings.modelProvider.apiKey": "API key",
- "settings.modelProvider.connectionMode.codingPlan": "Individual Plan",
- "chat.toolbar.model.manageModels": "Manage models",
- "settings.subagents.form.validation.thoughtLevelUnavailable": "Select a supported effort",
- };
- return messages[id] ?? id;
- },
- },
- }),
- }));
- vi.mock("@/settings/SettingsResourceGroupHeader.js", () => ({
- SettingsResourceGroupHeader: ({ title }: { title: string }) => createElement("h3", null, title),
- }));
- async function renderSubagentsSection() {
- useStateCallCount = 0;
- const { SubagentsSection } = await import("../src/settings/SubagentsSection.js");
- return renderToStaticMarkup(
- createElement(SubagentsSection, {
- onManageModels,
- workspacePath: "/repo",
- }),
- );
- }
- async function renderInteractiveSubagentsSection() {
- useRealReactHooks = true;
- const { SubagentsSection } = await import("../src/settings/SubagentsSection.js");
- return render(
- createElement(SubagentsSection, {
- onManageModels,
- workspacePath: "/repo",
- }),
- );
- }
- function findButton(label: string) {
- return capturedButtons.find((button) => button["aria-label"] === label);
- }
- describe("SubagentsSection", () => {
- afterEach(() => {
- cleanup();
- });
- beforeEach(() => {
- capturedButtons.length = 0;
- capturedModelConfigSelects.length = 0;
- capturedThoughtLevelControls.length = 0;
- useStateCallCount = 0;
- stateOverrides = new Map<number, unknown>();
- onManageModels = vi.fn();
- useRealReactHooks = false;
- mockScopeRouting.enabled = false;
- mockScopeRouting.context = null;
- mockScopeRouting.modelServices = [];
- useRemoteWorkspaceSessionStore.setState({
- baseServices: null,
- sessionsById: {},
- sessionIdByWorkspacePath: {},
- sessionIdByWorkspaceIdentity: {},
- });
- mockTabs.tabs = [];
- mockInitializePlugins.mockReset().mockResolvedValue(undefined);
- mockToolbarConfigState.status = "ready";
- vi.clearAllMocks();
- mockSubagentsService.list.mockResolvedValue({
- agents: [],
- userAgents: [],
- pluginAgents: [],
- capability: {
- userScopeAvailable: false,
- userScopeReason: "desktop_only",
- },
- });
- mockRefreshLoadedSubagentsStoreForWorkspace.mockResolvedValue(undefined);
- });
- function setupScopeRouting(includeLocalWorkspace = true, connected = true) {
- useRealReactHooks = true;
- mockScopeRouting.enabled = true;
- const makeServices = () => ({
- subagentsService: {
- ...mockSubagentsService,
- list: vi.fn(async () => ({
- agents: [],
- userAgents: [],
- pluginAgents: [],
- capability: { userScopeAvailable: true },
- })),
- createAgent: vi.fn(async () => ({})),
- },
- pluginManagementService: {},
- modelSelectionService: {},
- });
- const local = makeServices();
- const remoteA = makeServices();
- const remoteB = makeServices();
- const path = "/workspace/same-path";
- const identityA = `remote:server:source-a:${path}`;
- const identityB = `remote:server:source-b:${path}`;
- mockTabs.tabs = [
- ...(includeLocalWorkspace ? [{ id: "local", kind: "workspace", workspacePath: path }] : []),
- {
- id: "remote-a",
- kind: "workspace",
- workspacePath: path,
- workspaceIdentity: identityA,
- remoteSessionId: connected ? "session-a" : undefined,
- },
- {
- id: "remote-b",
- kind: "workspace",
- workspacePath: path,
- workspaceIdentity: identityB,
- remoteSessionId: connected ? "session-b" : undefined,
- },
- ];
- mockScopeRouting.context = remoteA as unknown as IServiceAccessor;
- useRemoteWorkspaceSessionStore.setState({
- baseServices: local as unknown as IServiceAccessor,
- sessionsById: connected
- ? {
- "session-a": {
- sessionId: "session-a",
- services: remoteA as unknown as IServiceAccessor,
- target: { kind: "ssh", host: "a", port: 22, username: "dev" },
- },
- "session-b": {
- sessionId: "session-b",
- services: remoteB as unknown as IServiceAccessor,
- target: { kind: "ssh", host: "b", port: 22, username: "dev" },
- },
- }
- : {},
- sessionIdByWorkspaceIdentity: connected
- ? { [identityA]: "session-a", [identityB]: "session-b" }
- : {},
- });
- return { local, remoteA, remoteB, path, identityA, identityB };
- }
- async function submitScopeAgent(container: HTMLElement) {
- await waitFor(() =>
- expect(screen.getAllByRole("button", { name: "New" })[0]).not.toHaveProperty(
- "disabled",
- true,
- ),
- );
- fireEvent.click(screen.getAllByRole("button", { name: "New" })[0]!);
- fireEvent.change(screen.getByPlaceholderText("settings.subagents.form.name.placeholder"), {
- target: { value: "scope-agent" },
- });
- fireEvent.change(
- screen.getByPlaceholderText("settings.subagents.form.description.placeholder"),
- { target: { value: "Scope description" } },
- );
- fireEvent.change(
- screen.getByPlaceholderText("settings.subagents.form.systemPrompt.placeholder"),
- { target: { value: "Scope prompt" } },
- );
- fireEvent.submit(container.querySelector("form")!);
- await waitFor(() => expect(container.querySelector("form")).toBeNull());
- }
- it("远端激活时 User 的列表、模型、插件初始化和保存都属于本机", async () => {
- const { local, remoteA, path, identityA } = setupScopeRouting();
- const { SubagentsSection } = await import("@/settings/SubagentsSection.js");
- const view = render(
- createElement(SubagentsSection, { workspacePath: path, workspaceIdentity: identityA }),
- );
- await waitFor(() => expect(local.subagentsService.list).toHaveBeenCalled());
- expect(view.container.querySelector("[data-settings-machine]")).toBeNull();
- expect(remoteA.subagentsService.list).not.toHaveBeenCalled();
- expect(mockScopeRouting.modelServices.at(-1)).toBe(local.modelSelectionService);
- expect(mockInitializePlugins).toHaveBeenCalledWith(
- expect.objectContaining({
- workspacePath: path,
- workspaceIdentity: undefined,
- configScope: "user",
- pluginService: local.pluginManagementService,
- }),
- );
- await submitScopeAgent(view.container);
- expect(local.subagentsService.createAgent).toHaveBeenCalledWith(
- expect.objectContaining({ scope: "user", workspaceIdentity: undefined }),
- );
- expect(remoteA.subagentsService.createAgent).not.toHaveBeenCalled();
- expect(mockRefreshLoadedSubagentsStoreForWorkspace).toHaveBeenCalledWith(
- expect.objectContaining({ scope: "user", subagentsService: local.subagentsService }),
- );
- });
- it("没有本机 workspace 且远端离线时 User 仍可保存,不借远端目录初始化插件", async () => {
- const { local, path, identityA } = setupScopeRouting(false, false);
- const { SubagentsSection } = await import("@/settings/SubagentsSection.js");
- const view = render(
- createElement(SubagentsSection, { workspacePath: path, workspaceIdentity: identityA }),
- );
- await waitFor(() =>
- expect(local.subagentsService.list).toHaveBeenCalledWith(
- expect.objectContaining({
- workspacePath: "",
- workspaceIdentity: undefined,
- mode: "settingsUserOnly",
- }),
- ),
- );
- expect(mockInitializePlugins).not.toHaveBeenCalled();
- await submitScopeAgent(view.container);
- expect(local.subagentsService.createAgent).toHaveBeenCalledOnce();
- });
- it("显式 Source User 无 workspace attachment 时仍使用注入的 Source 服务", async () => {
- const { local, remoteA } = setupScopeRouting(false, false);
- mockTabs.tabs = [];
- const { SubagentsSection } = await import("@/settings/SubagentsSection.js");
- const view = render(
- createElement(SubagentsSection, {
- settingsSourceServerId: "source-a",
- workspacePath: "/home/dev",
- }),
- );
- await waitFor(() => expect(remoteA.subagentsService.list).toHaveBeenCalled());
- expect(local.subagentsService.list).not.toHaveBeenCalled();
- expect(mockScopeRouting.modelServices.at(-1)).toBe(remoteA.modelSelectionService);
- await submitScopeAgent(view.container);
- expect(remoteA.subagentsService.createAgent).toHaveBeenCalledWith(
- expect.objectContaining({ scope: "user" }),
- );
- expect(local.subagentsService.createAgent).not.toHaveBeenCalled();
- });
- it("选中同路径的 Source B workspace 后通过 B 保存,再切 User 回到本机", async () => {
- const { local, remoteA, remoteB, path, identityA, identityB } = setupScopeRouting();
- const { SubagentsSection } = await import("@/settings/SubagentsSection.js");
- const view = render(
- createElement(SubagentsSection, { workspacePath: path, workspaceIdentity: identityA }),
- );
- fireEvent.click(screen.getByTestId(`scope-${identityB}`));
- await waitFor(() => expect(remoteB.subagentsService.list).toHaveBeenCalled());
- await submitScopeAgent(view.container);
- expect(remoteB.subagentsService.createAgent).toHaveBeenCalledWith(
- expect.objectContaining({
- scope: "workspace",
- workspacePath: path,
- workspaceIdentity: identityB,
- }),
- );
- expect(remoteA.subagentsService.createAgent).not.toHaveBeenCalled();
- fireEvent.click(screen.getByTestId("scope-user"));
- await waitFor(() => expect(local.subagentsService.list).toHaveBeenCalled());
- expect(mockScopeRouting.modelServices.at(-1)).toBe(local.modelSelectionService);
- });
- it.each([false, true])(
- "插件初始化晚于首读时刷新用户页资源;卸载=%s 不消费迟到结果",
- async (unmounted) => {
- mockTabs.tabs = [{ kind: "workspace", id: "local", workspacePath: "/repo" }];
- let resolveInventory!: () => void;
- mockInitializePlugins.mockImplementationOnce(
- () =>
- new Promise<void>((resolve) => {
- resolveInventory = resolve;
- }),
- );
- await renderInteractiveSubagentsSection();
- await waitFor(() => expect(mockSubagentsService.list).toHaveBeenCalledTimes(1));
- expect(mockInitializePlugins).toHaveBeenCalledWith(
- expect.objectContaining({ workspacePath: "/repo", configScope: "user" }),
- );
- if (unmounted) cleanup();
- await act(async () => {
- resolveInventory();
- await Promise.resolve();
- });
- expect(mockSubagentsService.list).toHaveBeenCalledTimes(unmounted ? 1 : 2);
- expect(mockSubagentsService.list).toHaveBeenLastCalledWith(
- expect.objectContaining({ workspacePath: "/repo", mode: "settingsUserOnly" }),
- );
- },
- );
- it("keeps same-name plugin subagents in separate marketplace groups", async () => {
- const { groupPluginAgentsById } = await import("../src/settings/SubagentsSection.js");
- const groups = groupPluginAgentsById([
- {
- id: "official-agent",
- name: "official-agent",
- description: "",
- systemPrompt: "",
- path: "/official",
- scope: "workspace",
- source: "plugin",
- enabled: true,
- pluginId: "computer-use@zcode-plugins-official",
- pluginName: "computer-use",
- },
- {
- id: "custom-agent",
- name: "custom-agent",
- description: "",
- systemPrompt: "",
- path: "/custom",
- scope: "workspace",
- source: "plugin",
- enabled: true,
- pluginId: "zcode-cua@custom-marketplace",
- pluginName: "zcode-cua",
- },
- ]);
- expect(groups.map(([key, items]) => [key, items[0]?.id])).toEqual([
- ["computer-use@zcode-plugins-official", "official-agent"],
- ["zcode-cua@custom-marketplace", "custom-agent"],
- ]);
- });
- it("hides user-level write actions when user subagents are unavailable", async () => {
- const html = await renderSubagentsSection();
- expect(findButton("New")).toBeUndefined();
- expect(findButton("Open user subagents folder")).toBeUndefined();
- expect(html).not.toContain("Workspace-level creation or editing is unsupported");
- expect(html).toContain("Subagents are desktop only.");
- });
- it("renders plugin subagents in their own read-only group", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "plugin:feature-dev@claude-plugins-official:code-architect",
- name: "feature-dev:code-architect",
- description: "Designs feature architectures",
- systemPrompt: "Architect.",
- path: "/cache/feature-dev/agents/code-architect.md",
- scope: "user",
- source: "plugin",
- enabled: true,
- readOnly: true,
- },
- ],
- ],
- ]);
- const html = await renderSubagentsSection();
- expect(html).toContain("Feature Dev");
- expect(html).toContain("feature-dev:code-architect");
- });
- it("projects one settings row per plugin agent file while keeping runtime aliases separate", async () => {
- const { projectSettingsSubagents } = await import("../src/settings/SubagentsSection.js");
- const canonical = {
- id: "plugin:feature-dev@claude-plugins-official:code-architect",
- name: "feature-dev:code-architect",
- description: "Designs feature architectures",
- systemPrompt: "Architect.",
- path: "/cache/feature-dev/agents/code-architect.md",
- scope: "user" as const,
- source: "plugin" as const,
- enabled: true,
- readOnly: true,
- };
- const alias = {
- ...canonical,
- id: "plugin:feature-dev@claude-plugins-official:code-architect:alias",
- name: "code-architect",
- };
- const builtIn = {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "Search.",
- path: "built-in:Explore",
- scope: "built-in" as const,
- source: "built-in" as const,
- enabled: true,
- readOnly: true,
- };
- expect(
- projectSettingsSubagents({
- agents: [builtIn, alias, canonical],
- userAgents: [],
- pluginAgents: [canonical],
- capability: { userScopeAvailable: true },
- }).map((agent) => agent.name),
- ).toEqual(["Explore", "feature-dev:code-architect"]);
- });
- it("renders wildcard tools as all tools instead of a single tool", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "Search.",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- tools: ["*"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- const html = await renderSubagentsSection();
- expect(html).toContain("Explore");
- expect(html).toContain("All tools");
- expect(html).not.toContain("1 tools");
- });
- it("renders model controls for built-in subagents while keeping user model badges", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "Search.",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- tools: ["Read"],
- },
- {
- id: "user:code-reviewer",
- name: "code-reviewer",
- description: "Review code",
- systemPrompt: "Review.",
- color: "blue",
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- tools: ["Read", "Grep"],
- path: "/tmp/agents/code-reviewer.md",
- scope: "user",
- source: "user",
- enabled: true,
- readOnly: false,
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- const html = await renderSubagentsSection();
- expect(html).toContain("Explore");
- expect(html).toContain("code-reviewer");
- expect(html).toContain("Inherit default");
- expect(html).toContain("gpt-5.4");
- expect(capturedModelConfigSelects).toEqual([
- expect.objectContaining({
- normalizedValue: "inherit",
- showManageModelsAction: false,
- triggerLabel: "Inherit default",
- contentSide: "top",
- contentAlign: "end",
- }),
- ]);
- });
- it("offers disabled without implicitly selecting it when reasoning is missing", async () => {
- const plainModel = "custom:custom-openai:plain-chat";
- const customAgent = {
- id: "user:plain-reviewer",
- name: "plain-reviewer",
- description: "Review without reasoning",
- systemPrompt: "Review.",
- path: "/tmp/agents/plain-reviewer.md",
- scope: "user",
- source: "user",
- enabled: true,
- readOnly: false,
- modelSelection: { providerId: "custom-openai", modelId: "plain-chat" },
- tools: ["Read"],
- };
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "Search.",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "custom-openai", modelId: "plain-chat" },
- modelSelectionOverride: { providerId: "custom-openai", modelId: "plain-chat" },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- expect(capturedModelConfigSelects).toEqual([
- expect.objectContaining({ normalizedValue: plainModel }),
- ]);
- expect(capturedThoughtLevelControls).toEqual([
- expect.objectContaining({
- option: expect.objectContaining({
- currentValue: "",
- options: [{ value: "disabled", name: "disabled" }],
- }),
- }),
- ]);
- capturedModelConfigSelects.length = 0;
- capturedThoughtLevelControls.length = 0;
- stateOverrides = new Map<number, unknown>([
- [1, []],
- [2, { userScopeAvailable: true }],
- [7, true],
- [8, customAgent],
- ]);
- await renderSubagentsSection();
- expect(capturedModelConfigSelects).toEqual([
- expect.objectContaining({ normalizedValue: plainModel }),
- ]);
- expect(capturedThoughtLevelControls).toEqual([
- expect.objectContaining({
- option: expect.objectContaining({ currentValue: "" }),
- }),
- ]);
- });
- it("shows built-in overrides and persists model changes through the subagents service", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:general-purpose",
- name: "general-purpose",
- description: "General-purpose agent",
- systemPrompt: "",
- path: "built-in:general-purpose",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- tools: ["*"],
- },
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- const html = await renderSubagentsSection();
- const generalPurposePicker = capturedModelConfigSelects.find(
- (picker) => picker.triggerLabel === "Inherit default",
- );
- const explorePicker = capturedModelConfigSelects.find(
- (picker) => picker.normalizedValue === "custom:custom-openai:glm-5.2",
- );
- expect(html).toContain("Inherit default");
- expect(explorePicker).toMatchObject({
- normalizedValue: "custom:custom-openai:glm-5.2",
- triggerLabel: "glm-5.2",
- showManageModelsAction: false,
- });
- expect(explorePicker?.tooltipTitle).toBeUndefined();
- expect(explorePicker?.footerActions).toContainEqual(
- expect.objectContaining({
- key: "subagent-model:built-in-default",
- label: "Inherit default",
- selected: false,
- }),
- );
- expect(generalPurposePicker?.onValueChange).toBeTypeOf("function");
- await (generalPurposePicker!.onValueChange as (value: string) => Promise<void>)(
- "custom:custom-openai:gpt-5.4",
- );
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "general-purpose",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- await waitFor(() =>
- expect(mockSubagentsService.list).toHaveBeenCalledWith({
- workspacePath: "",
- workspaceIdentity: undefined,
- provider: "glm",
- mode: "settingsUserOnly",
- }),
- );
- });
- it("persists changed and explicitly selected built-in reasoning efforts", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- modelSelectionOverride: { providerId: "custom-openai", modelId: "gpt-5.4" },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- const effortControl = capturedThoughtLevelControls[0];
- if (!effortControl) {
- throw new Error("Expected the built-in reasoning effort control to render");
- }
- expect(effortControl.option).toMatchObject({
- // 原选择未保存档位时保持空;下面显式选择 high/low 才写入。
- currentValue: "",
- options: [{ value: "low" }, { value: "high" }],
- });
- expect(effortControl.onCurrentValueCommit).toBeTypeOf("function");
- (effortControl.onCurrentValueCommit as (value: string) => void)("high");
- await waitFor(() => {
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- });
- mockSubagentsService.setBuiltInModelOverride.mockClear();
- (effortControl.onValueChange as (value: string) => void)("low");
- await waitFor(() => {
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "low" },
- },
- });
- });
- });
- it("renders the shared model override control for plugin subagents and persists by agent id", async () => {
- // 插件文件只读;保存用户覆盖时沿用完整 Selection 和主动选模最高档,而非上游的旧双字段。
- const selection = {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- };
- const pluginAgent = {
- id: "plugin:document-skills@zcode-plugins-official:judge",
- name: "document-skills:judge",
- description: "Visual acceptance reviewer",
- systemPrompt: "Judge.",
- path: "/cache/document-skills/0.1.4/agents/judge.md",
- scope: "user",
- source: "plugin",
- pluginId: "document-skills@zcode-plugins-official",
- pluginName: "document-skills",
- enabled: true,
- readOnly: true,
- tools: ["Read", "Bash"],
- defaultModelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- modelSelection: selection,
- modelSelectionOverride: selection,
- };
- stateOverrides = new Map<number, unknown>([
- [1, [pluginAgent]],
- [2, { userScopeAvailable: true }],
- ]);
- const container = document.createElement("div");
- container.innerHTML = await renderSubagentsSection();
- const row = container.querySelector(
- `[data-testid="${testId(TID_SUBAGENT_ROW, pluginAgent.name)}"]`,
- );
- expect(row?.getAttribute("role")).toBeNull();
- expect(
- container.querySelector(
- `[data-testid="${testId(TID_SUBAGENT_BUILT_IN_MODEL_TRIGGER, pluginAgent.name)}"]`,
- ),
- ).not.toBeNull();
- const picker = capturedModelConfigSelects.find(
- (candidate) => candidate.normalizedValue === "custom:custom-openai:glm-5.2",
- );
- expect(picker).toMatchObject({ triggerLabel: "glm-5.2", showManageModelsAction: false });
- (picker!.onValueChange as (value: string) => void)("custom:custom-openai:gpt-5.4");
- await waitFor(() =>
- expect(mockSubagentsService.setPluginAgentModelOverride).toHaveBeenCalledWith({
- agentId: pluginAgent.id,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- }),
- );
- expect(mockSubagentsService.setBuiltInModelOverride).not.toHaveBeenCalled();
- expect(mockSubagentsService.list).toHaveBeenCalled();
- });
- it("uses the new model's highest effort when the built-in model changes", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "low" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "low" },
- },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- const picker = capturedModelConfigSelects.find(
- (candidate) => candidate.normalizedValue === "custom:custom-openai:glm-5.2",
- );
- const onValueChange = picker?.onValueChange as (value: string) => void;
- onValueChange("custom:custom-openai:glm-5.2");
- expect(mockSubagentsService.setBuiltInModelOverride).not.toHaveBeenCalled();
- onValueChange("custom:custom-openai:gpt-5.4");
- await waitFor(() => {
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- });
- });
- it("restores the previous built-in model config when persistence fails", async () => {
- const agent = {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in" as const,
- source: "built-in" as const,
- enabled: true,
- readOnly: true,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read"],
- };
- mockSubagentsService.list.mockResolvedValue({
- agents: [agent],
- userAgents: [agent],
- pluginAgents: [],
- capability: { userScopeAvailable: true },
- });
- let rejectWrite: ((reason?: unknown) => void) | undefined;
- mockSubagentsService.setBuiltInModelOverride.mockImplementationOnce(
- () =>
- new Promise<void>((_resolve, reject) => {
- rejectWrite = reject;
- }),
- );
- await renderInteractiveSubagentsSection();
- await waitFor(() => {
- expect(
- capturedModelConfigSelects.some(
- (candidate) => candidate.normalizedValue === "custom:custom-openai:glm-5.2",
- ),
- ).toBe(true);
- });
- const initialPicker = capturedModelConfigSelects.findLast(
- (candidate) => candidate.normalizedValue === "custom:custom-openai:glm-5.2",
- );
- const onModelValueChange = initialPicker?.onValueChange;
- expect(onModelValueChange).toBeTypeOf("function");
- const beforeOptimisticRender = capturedModelConfigSelects.length;
- act(() => {
- (onModelValueChange as (value: string) => void)("custom:custom-openai:gpt-5.4");
- });
- await waitFor(() => {
- expect(
- capturedModelConfigSelects
- .slice(beforeOptimisticRender)
- .some((candidate) => candidate.normalizedValue === "custom:custom-openai:gpt-5.4"),
- ).toBe(true);
- });
- expect(rejectWrite).toBeTypeOf("function");
- const beforeRollbackRender = capturedModelConfigSelects.length;
- const beforeThoughtRollbackRender = capturedThoughtLevelControls.length;
- await act(async () => {
- rejectWrite!(new Error("write failed"));
- await Promise.resolve();
- });
- await waitFor(() => {
- expect(
- capturedModelConfigSelects
- .slice(beforeRollbackRender)
- .some((candidate) => candidate.normalizedValue === "custom:custom-openai:glm-5.2"),
- ).toBe(true);
- expect(
- capturedThoughtLevelControls
- .slice(beforeThoughtRollbackRender)
- .some((candidate) => candidate.option?.currentValue === "high"),
- ).toBe(true);
- });
- });
- it("keeps the committed built-in config when the follow-up refresh fails", async () => {
- const agent = {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in" as const,
- source: "built-in" as const,
- enabled: true,
- readOnly: true,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read"],
- };
- mockSubagentsService.list.mockResolvedValue({
- agents: [agent],
- userAgents: [agent],
- pluginAgents: [],
- capability: { userScopeAvailable: true },
- });
- mockRefreshLoadedSubagentsStoreForWorkspace.mockRejectedValueOnce(new Error("refresh failed"));
- let resolveWrite: (() => void) | undefined;
- mockSubagentsService.setBuiltInModelOverride.mockImplementationOnce(
- () =>
- new Promise<void>((resolve) => {
- resolveWrite = resolve;
- }),
- );
- await renderInteractiveSubagentsSection();
- await waitFor(() => {
- expect(capturedThoughtLevelControls.at(-1)?.option).toMatchObject({
- currentValue: "high",
- });
- });
- const onThoughtLevelChange = capturedThoughtLevelControls.at(-1)?.onValueChange;
- expect(onThoughtLevelChange).toBeTypeOf("function");
- act(() => {
- (onThoughtLevelChange as (value: string) => void)("max");
- });
- await waitFor(() => {
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- });
- expect(capturedThoughtLevelControls.at(-1)).toMatchObject({
- disabled: true,
- option: expect.objectContaining({ currentValue: "max" }),
- });
- });
- expect(resolveWrite).toBeTypeOf("function");
- // 显式控制持久化提交点,避免慢速 CI 中乐观渲染与后续刷新微任务乱序。
- await act(async () => {
- resolveWrite!();
- await Promise.resolve();
- });
- await waitFor(() => {
- expect(mockRefreshLoadedSubagentsStoreForWorkspace).toHaveBeenCalledTimes(1);
- expect(capturedThoughtLevelControls.at(-1)).toMatchObject({
- disabled: false,
- option: expect.objectContaining({ currentValue: "max" }),
- });
- });
- });
- it("clears built-in model overrides through the default model item", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "custom-openai", modelId: "glm-5.2" },
- modelSelectionOverride: { providerId: "custom-openai", modelId: "glm-5.2" },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- const explorePicker = capturedModelConfigSelects.find(
- (picker) => picker.normalizedValue === "custom:custom-openai:glm-5.2",
- );
- const defaultAction = (
- explorePicker?.footerActions as
- | Array<{ key: string; onSelect?: () => Promise<void> | void }>
- | undefined
- )?.find((action) => action.key === "subagent-model:built-in-default");
- expect(defaultAction?.onSelect).toBeTypeOf("function");
- await defaultAction!.onSelect!();
- expect(mockSubagentsService.setBuiltInModelOverride).toHaveBeenCalledWith({
- agentName: "Explore",
- modelSelection: undefined,
- });
- });
- it("keeps the saved label when a built-in model override is no longer available", async () => {
- const staleModel = "custom:retired-provider:GLM-5-Turbo";
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:general-purpose",
- name: "general-purpose",
- description: "General-purpose agent",
- systemPrompt: "",
- path: "built-in:general-purpose",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "retired-provider", modelId: "GLM-5-Turbo" },
- modelSelectionOverride: {
- providerId: "retired-provider",
- modelId: "GLM-5-Turbo",
- },
- tools: ["*"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- expect(capturedModelConfigSelects).toContainEqual(
- expect.objectContaining({
- normalizedValue: staleModel,
- triggerLabel: "Select model",
- showManageModelsAction: false,
- }),
- );
- expect(capturedModelConfigSelects).not.toContainEqual(
- expect.objectContaining({
- triggerLabel: "GLM-5-Turbo",
- }),
- );
- const stalePicker = capturedModelConfigSelects.find(
- (picker) => picker.normalizedValue === staleModel,
- );
- const selectableValues = ((stalePicker?.modelGroups ?? []) as ModelSelectGroup[]).flatMap(
- (group) => group.items.map((item) => item.value),
- );
- expect(selectableValues).not.toContain(staleModel);
- });
- it("renders tools permissions using the workspace-access row pattern", async () => {
- stateOverrides = new Map<number, unknown>([
- [2, { userScopeAvailable: true }],
- [7, true],
- ]);
- const html = await renderSubagentsSection();
- expect(html).toContain("settings.subagents.form.tools.card.title");
- expect(html).toContain("settings.subagents.form.tools.mode.all");
- expect(html).toContain("settings.subagents.form.tools.mode.custom");
- expect(html).toContain("settings.scope.label");
- expect(html).toContain("scope");
- expect(html).not.toContain('role="checkbox"');
- expect(html).not.toContain("Bash(git diff *)");
- });
- it("uses the real chat toolbar model picker values with an inherit option in the form", async () => {
- stateOverrides = new Map<number, unknown>([
- [2, { userScopeAvailable: true }],
- [7, true],
- ]);
- const html = await renderSubagentsSection();
- const modelPicker = capturedModelConfigSelects.at(-1);
- const modelGroups = modelPicker?.modelGroups as
- | Array<{
- key: string;
- label?: string;
- items: Array<{ value: string; name: string }>;
- }>
- | undefined;
- const modelValues = modelGroups?.flatMap((group) => group.items.map((item) => item.value));
- expect(html).toContain("Inherit default");
- expect(modelPicker).toMatchObject({
- normalizedValue: "inherit",
- triggerLabel: "Inherit default",
- showManageModelsAction: true,
- manageModelsLabel: "Manage models",
- contentSide: "bottom",
- });
- expect(modelValues).toEqual([
- "custom:custom-openai:gpt-5.4",
- "custom:custom-openai:glm-5.2",
- "custom:custom-openai:plain-chat",
- ]);
- expect(modelPicker?.footerActions).toContainEqual(
- expect.objectContaining({
- key: "subagent-model:inherit",
- label: "Inherit default",
- selected: true,
- }),
- );
- expect(modelValues).not.toContain("main");
- expect(modelValues).not.toContain("lite");
- expect(modelValues).not.toContain("inherit");
- expect(modelPicker?.onManageModels).toBe(onManageModels);
- expect(mockUseModelProviders).not.toHaveBeenCalled();
- });
- it("derives refreshed edit form state from the saved custom model value", async () => {
- const { createSubagentFormInitialState } = await import("../src/settings/SubagentsSection.js");
- const customModel = "custom:728858ba-605a-4be5-80f8-15cf4de51eae:mimo-v2.5-pro";
- const formState = createSubagentFormInitialState({
- name: "qa-reviewer",
- description: "Review product flows",
- systemPrompt: "Review carefully",
- color: "blue",
- modelSelection: {
- providerId: "728858ba-605a-4be5-80f8-15cf4de51eae",
- modelId: "mimo-v2.5-pro",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read", "Grep"],
- });
- expect(formState.model).toBe(customModel);
- expect(formState.thoughtLevel).toBe("high");
- expect(formState.injectAgentsMd).toBe(true);
- expect(formState.inheritAllTools).toBe(false);
- expect(formState.selectedTools).toEqual(["Read", "Grep"]);
- });
- it("preserves unknown intent and leaves an unsupported resolved effort unselected", async () => {
- const {
- createSubagentFormInitialState,
- isSubagentThoughtLevelAvailable,
- resolveSubagentThoughtOptionState,
- } = await import("../src/settings/SubagentsSection.js");
- const model = "custom:custom-openai:gpt-5.4";
- const initial = createSubagentFormInitialState({
- name: "qa-reviewer",
- description: "Review product flows",
- systemPrompt: "Review carefully",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "medium" },
- },
- });
- expect(initial.thoughtLevel).toBe("medium");
- const unknownState = resolveSubagentThoughtOptionState({
- model,
- modelAvailable: true,
- modelSelectionView: null,
- modelSelectionLoading: true,
- thoughtLevel: initial.thoughtLevel,
- });
- expect(unknownState).toEqual({ kind: "unknown", status: "loading" });
- expect(isSubagentThoughtLevelAvailable(unknownState, initial.thoughtLevel)).toBe(true);
- const supportedState = resolveSubagentThoughtOptionState({
- model,
- modelAvailable: true,
- modelSelectionView: mockModelSelectionView,
- modelSelectionLoading: false,
- thoughtLevel: initial.thoughtLevel,
- });
- expect(supportedState.option?.currentValue).toBe("");
- expect(initial.thoughtLevel).toBe("medium");
- expect(isSubagentThoughtLevelAvailable(supportedState, initial.thoughtLevel)).toBe(false);
- expect(isSubagentThoughtLevelAvailable(supportedState, "high")).toBe(true);
- });
- it("uses only the Local Host selection view to resolve reasoning", async () => {
- const { resolveSubagentThoughtOptionState } =
- await import("../src/settings/SubagentsSection.js");
- const model = "custom:custom-openai:glm-5.2";
- const state = resolveSubagentThoughtOptionState({
- model,
- modelAvailable: true,
- modelSelectionView: mockModelSelectionView,
- modelSelectionLoading: false,
- thoughtLevel: undefined,
- });
- expect(state).toMatchObject({
- kind: "supported",
- option: {
- currentValue: "",
- options: [{ value: "high" }, { value: "max" }],
- },
- });
- });
- it("renders built-in reasoning from the Local Host selection view", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- modelSelectionOverride: { providerId: "custom-openai", modelId: "gpt-5.4" },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- await renderSubagentsSection();
- expect(capturedThoughtLevelControls).toHaveLength(1);
- expect(capturedThoughtLevelControls[0]?.option).toMatchObject({ currentValue: "" });
- });
- it("uses only the Local Host view to resolve reasoning capability", async () => {
- const { isSubagentThoughtLevelAvailable, resolveSubagentThoughtOptionState } =
- await import("../src/settings/SubagentsSection.js");
- const base = {
- model: "custom:custom-openai:gpt-5.4",
- modelAvailable: true,
- modelSelectionLoading: false,
- thoughtLevel: undefined,
- };
- const loading = resolveSubagentThoughtOptionState({
- ...base,
- modelSelectionView: null,
- modelSelectionLoading: true,
- });
- expect(loading).toEqual({ kind: "unknown", status: "loading" });
- // Registry 尚未发布时保持未知,不能把已保存的档位误判为非法并清空。
- expect(isSubagentThoughtLevelAvailable(loading, "max")).toBe(true);
- const error = resolveSubagentThoughtOptionState({
- ...base,
- modelSelectionView: null,
- });
- expect(error).toEqual({ kind: "unsupported" });
- const targetModelMissing = resolveSubagentThoughtOptionState({
- ...base,
- model: "custom:custom-openai:other-model",
- thoughtLevel: "max",
- modelSelectionView: mockModelSelectionView,
- });
- expect(targetModelMissing).toEqual({ kind: "unsupported" });
- expect(isSubagentThoughtLevelAvailable(targetModelMissing, "max")).toBe(false);
- const targetModelReconciling = resolveSubagentThoughtOptionState({
- ...base,
- thoughtLevel: "max",
- modelSelectionView: null,
- modelSelectionLoading: true,
- });
- expect(targetModelReconciling).toEqual({ kind: "unknown", status: "loading" });
- const authoritative = resolveSubagentThoughtOptionState({
- ...base,
- modelSelectionView: mockModelSelectionView,
- });
- expect(authoritative).toMatchObject({
- kind: "supported",
- option: {
- currentValue: "",
- options: [{ value: "low" }, { value: "high" }],
- },
- });
- });
- it("renders the Registry disabled option without unavailable placeholders", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "built-in:explore",
- name: "Explore",
- description: "Search broadly",
- systemPrompt: "",
- path: "built-in:Explore",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- modelSelection: { providerId: "custom-openai", modelId: "plain-chat" },
- modelSelectionOverride: { providerId: "custom-openai", modelId: "plain-chat" },
- tools: ["Read"],
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- const html = await renderSubagentsSection();
- expect(capturedThoughtLevelControls).toEqual([
- expect.objectContaining({
- option: expect.objectContaining({ currentValue: "" }),
- }),
- ]);
- expect(html).not.toContain('data-subagent-thought-level-unavailable="true"');
- expect(html).not.toContain('data-subagent-thought-level-loading="true"');
- });
- it("uses the Registry selection view while it refreshes when there is no workspace", async () => {
- const { resolveSubagentThoughtOptionState } =
- await import("../src/settings/SubagentsSection.js");
- const base = {
- model: "custom:custom-openai:gpt-5.4",
- modelAvailable: true,
- modelSelectionView: {
- revision: 1,
- providers: [
- {
- providerId: "custom-openai",
- config: {},
- models: [
- {
- modelId: "gpt-5.4",
- config: {
- optionSpecs: {
- reasoningLevel: {
- values: ["low", "high"],
- map: "{}",
- },
- maxOutputTokens: { max: 32_000, map: "{}" },
- },
- },
- },
- ],
- },
- ],
- },
- thoughtLevel: undefined,
- };
- expect(
- resolveSubagentThoughtOptionState({
- ...base,
- modelSelectionLoading: true,
- }),
- ).toMatchObject({
- kind: "supported",
- option: {
- currentValue: "",
- options: [{ value: "low" }, { value: "high" }],
- },
- });
- expect(
- resolveSubagentThoughtOptionState({
- ...base,
- modelSelectionLoading: false,
- }),
- ).toMatchObject({
- kind: "supported",
- option: {
- currentValue: "",
- options: [{ value: "low" }, { value: "high" }],
- },
- });
- });
- it("does not infer reasoning from the model name before the Registry view is available", async () => {
- const { resolveSubagentThoughtOptionState } =
- await import("../src/settings/SubagentsSection.js");
- expect(
- resolveSubagentThoughtOptionState({
- model: encodeCustomModelValue("provider-demo", "GLM-5.2"),
- modelAvailable: true,
- modelSelectionView: null,
- modelSelectionLoading: true,
- thoughtLevel: undefined,
- }),
- ).toEqual({ kind: "unknown", status: "loading" });
- });
- it("uses the Registry disabled option instead of App metadata", async () => {
- const { isSubagentThoughtLevelAvailable, resolveSubagentThoughtOptionState } =
- await import("../src/settings/SubagentsSection.js");
- const base = {
- model: "custom:custom-openai:plain-chat",
- modelAvailable: true,
- modelSelectionView: mockModelSelectionView,
- modelSelectionLoading: false,
- thoughtLevel: "high",
- };
- const disabled = resolveSubagentThoughtOptionState(base);
- expect(disabled).toMatchObject({
- kind: "supported",
- option: {
- currentValue: "",
- options: [{ value: "disabled" }],
- },
- });
- expect(isSubagentThoughtLevelAvailable(disabled, "high")).toBe(false);
- });
- it("defers persisted model availability validation only during initial provider loading", async () => {
- const { isSubagentModelAvailable } = await import("../src/settings/SubagentsSection.js");
- const model = "custom:custom-anthropic:claude-opus-4-8";
- expect(isSubagentModelAvailable([], model, true)).toBe(true);
- expect(isSubagentModelAvailable([], model, false)).toBe(false);
- });
- it("defaults new and legacy custom agents to AGENTS.md injection and preserves false", async () => {
- const { createSubagentFormInitialState } = await import("../src/settings/SubagentsSection.js");
- expect(createSubagentFormInitialState().injectAgentsMd).toBe(true);
- expect(
- createSubagentFormInitialState({
- name: "legacy-reviewer",
- description: "Legacy profile",
- systemPrompt: "Review carefully",
- }).injectAgentsMd,
- ).toBe(true);
- expect(
- createSubagentFormInitialState({
- name: "isolated-reviewer",
- description: "Do not inherit instructions",
- systemPrompt: "Review carefully",
- injectAgentsMd: false,
- }).injectAgentsMd,
- ).toBe(false);
- });
- it("saves AGENTS.md injection and an explicitly selected reasoning level", async () => {
- mockSubagentsService.list.mockResolvedValue({
- agents: [],
- userAgents: [],
- pluginAgents: [],
- capability: { userScopeAvailable: true },
- });
- const view = await renderInteractiveSubagentsSection();
- const [addButton] = await screen.findAllByRole("button", { name: "New" });
- fireEvent.click(addButton);
- const onModelChange = capturedModelConfigSelects.at(-1)?.onValueChange;
- expect(onModelChange).toBeTypeOf("function");
- act(() => {
- (onModelChange as (value: string) => void)("custom:custom-openai:gpt-5.4");
- });
- await waitFor(() => {
- expect(capturedThoughtLevelControls.at(-1)).toMatchObject({
- // 主动选模使用最高档;后续显式选低档仍须按用户选择保存。
- option: expect.objectContaining({ currentValue: "high" }),
- onCurrentValueCommit: expect.any(Function),
- });
- });
- const onCurrentValueCommit = capturedThoughtLevelControls.at(-1)?.onCurrentValueCommit;
- expect(onCurrentValueCommit).toBeTypeOf("function");
- act(() => {
- (onCurrentValueCommit as (value: string) => void)("low");
- });
- const systemPromptInput = screen.getByPlaceholderText(
- "settings.subagents.form.systemPrompt.placeholder",
- );
- const injectSwitch = screen.getByRole("switch", {
- name: "Inject AGENTS.md",
- });
- expect(systemPromptInput.compareDocumentPosition(injectSwitch)).toBe(
- Node.DOCUMENT_POSITION_FOLLOWING,
- );
- expect((injectSwitch as HTMLInputElement).checked).toBe(true);
- fireEvent.click(injectSwitch);
- expect((injectSwitch as HTMLInputElement).checked).toBe(false);
- fireEvent.change(screen.getByPlaceholderText("settings.subagents.form.name.placeholder"), {
- target: { value: "isolated-reviewer" },
- });
- fireEvent.change(
- screen.getByPlaceholderText("settings.subagents.form.description.placeholder"),
- { target: { value: "Review without parent instructions" } },
- );
- fireEvent.change(
- screen.getByPlaceholderText("settings.subagents.form.systemPrompt.placeholder"),
- { target: { value: "Review carefully." } },
- );
- fireEvent.submit(view.container.querySelector("form")!);
- await waitFor(() => {
- expect(mockSubagentsService.createAgent).toHaveBeenCalledWith(
- expect.objectContaining({
- config: expect.objectContaining({
- injectAgentsMd: false,
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "low" },
- },
- }),
- }),
- );
- });
- });
- it("preserves the unavailable selection but prompts to select a model in the edit form", async () => {
- const customModel = "custom:728858ba-605a-4be5-80f8-15cf4de51eae:mimo-v2.5-pro";
- const agent = {
- id: "user:qa-reviewer",
- name: "qa-reviewer",
- description: "Review product flows",
- systemPrompt: "Review carefully",
- color: "blue",
- modelSelection: {
- providerId: "728858ba-605a-4be5-80f8-15cf4de51eae",
- modelId: "mimo-v2.5-pro",
- },
- tools: ["Read", "Grep"],
- path: "/tmp/agents/qa-reviewer.md",
- scope: "user",
- source: "user",
- enabled: true,
- readOnly: false,
- };
- stateOverrides = new Map<number, unknown>([
- [1, [agent]],
- [2, { userScopeAvailable: true }],
- [8, agent],
- ]);
- mockToolbarConfigState.status = "error";
- const html = await renderSubagentsSection();
- expect(capturedModelConfigSelects.at(-1)).toMatchObject({
- normalizedValue: customModel,
- triggerLabel: "Select model",
- });
- expect(capturedThoughtLevelControls).toHaveLength(0);
- expect(html).not.toContain('data-subagent-thought-level-unavailable="true"');
- });
- it("treats unavailable persisted models as invalid form selections", async () => {
- const { isSubagentModelAvailable } = await import("../src/settings/SubagentsSection.js");
- const modelGroups = [
- {
- key: "custom-openai",
- label: "Custom OpenAI",
- items: [
- {
- key: "custom-openai:gpt-5.4",
- value: "custom:custom-openai:gpt-5.4",
- name: "gpt-5.4",
- },
- ],
- },
- ];
- expect(isSubagentModelAvailable(modelGroups, "custom:missing:mimo-v2.5-pro")).toBe(false);
- expect(isSubagentModelAvailable([], "custom:missing:mimo-v2.5-pro", true)).toBe(true);
- expect(isSubagentModelAvailable(modelGroups, "custom:custom-openai:gpt-5.4")).toBe(true);
- expect(isSubagentModelAvailable(modelGroups, "inherit")).toBe(true);
- expect(isSubagentModelAvailable(modelGroups, undefined)).toBe(true);
- });
- it("groups editable user agents and read-only built-ins like command settings lists", async () => {
- stateOverrides = new Map<number, unknown>([
- [
- 1,
- [
- {
- id: "user:code-reviewer",
- name: "code-reviewer",
- description: "Review code",
- systemPrompt: "Review code carefully",
- color: "blue",
- tools: ["Read", "Grep"],
- path: "/tmp/agents/code-reviewer.md",
- scope: "user",
- source: "user",
- enabled: true,
- readOnly: false,
- },
- {
- id: "built-in:general-purpose",
- name: "general-purpose",
- description: "General-purpose agent",
- systemPrompt: "General agent",
- path: "builtin://general-purpose",
- scope: "built-in",
- source: "built-in",
- enabled: true,
- readOnly: true,
- },
- ],
- ],
- [2, { userScopeAvailable: true }],
- ]);
- const html = await renderSubagentsSection();
- expect(html).toContain("Installed");
- expect(html).toContain("Built-in subagents");
- expect(html).toContain("code-reviewer");
- expect(html).not.toContain("/tmp/agents/code-reviewer.md");
- expect(html).not.toContain("built-in:general-purpose");
- expect(html).toContain("general-purpose");
- expect(html).not.toContain("Workspace-level creation or editing is unsupported");
- expect(findButton("New")).toBeDefined();
- expect(findButton("Open user subagents folder")).toBeUndefined();
- });
- });
- // 本套验证 Subagent 表单行为;目录读取/连接竞态由 Catalog 合同与真实 hook 用例覆盖。
- vi.mock("@/workspace-config-catalog/index.js", async (importOriginal) => {
- const actual = await importOriginal<typeof import("@/workspace-config-catalog/index.js")>();
- const workspace = await import("@/hooks/useWorkspaceServices.js");
- return {
- ...actual,
- useConfigWorkspaceTargets: () => mockTabs.tabs,
- useConfigWorkspaceServicesResolution: workspace.useWorkspaceServicesResolution,
- };
- });
|