| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280 |
- import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
- import { tmpdir } from "node:os";
- import { join } from "node:path";
- import { afterEach, describe, expect, it } from "vitest";
- import {
- parseSubagentMarkdown,
- serializeSubagentMarkdown,
- } from "../src/subagents/subagentMarkdown.js";
- import {
- resolveSubagentStateFile,
- resolveUserSubagentRoot,
- } from "../src/subagents/subagentStorage.js";
- import { createSubagentsService } from "../src/subagents/subagentsService.js";
- const tempRoots: string[] = [];
- async function makeTempHome(prefix = "zcode-subagents-home-"): Promise<string> {
- const home = await mkdtemp(join(tmpdir(), prefix));
- tempRoots.push(home);
- return home;
- }
- /** 在临时 HOME 下构造一个内置官方插件缓存目录(无 installed_plugins.json 记录),返回版本根目录。 */
- async function writeOfficialPluginFixture(
- home: string,
- pluginName: string,
- version: string,
- agentName: string,
- frontmatter: { model?: string } = {},
- ): Promise<string> {
- const root = join(
- home,
- ".zcode",
- "cli",
- "plugins",
- "cache",
- "zcode-plugins-official",
- pluginName,
- version,
- );
- await mkdir(join(home, ".zcode", "cli", "plugins"), { recursive: true });
- await mkdir(join(root, ".zcode-plugin"), { recursive: true });
- await mkdir(join(root, "agents"), { recursive: true });
- await writeFile(
- join(root, ".zcode-plugin", "plugin.json"),
- JSON.stringify({ name: pluginName, version }),
- "utf8",
- );
- await writeFile(
- join(root, "agents", `${agentName}.md`),
- [
- "---",
- `name: ${agentName}`,
- `description: ${pluginName} ${agentName} @ ${version}`,
- ...(frontmatter.model ? [`model: ${frontmatter.model}`] : []),
- "---",
- `${agentName} prompt ${version}`,
- ].join("\n"),
- "utf8",
- );
- return root;
- }
- afterEach(async () => {
- while (tempRoots.length > 0) {
- const root = tempRoots.pop();
- if (root) {
- await rm(root, { recursive: true, force: true });
- }
- }
- });
- describe("subagent markdown helpers", () => {
- it("lists only direct custom profiles while preserving recursive plugin discovery", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- for (const [scope, root] of [
- ["user", join(home, ".zcode", "agents")],
- ["project", join(workspacePath, ".zcode", "agents")],
- ] as const) {
- await mkdir(join(root, "nested"), { recursive: true });
- for (const nested of [false, true]) {
- const name = `${scope}-${nested ? "nested" : "direct"}`;
- await writeFile(
- join(root, ...(nested ? ["nested"] : []), `${name}.MARKDOWN`),
- serializeSubagentMarkdown({ name, description: name, systemPrompt: name }),
- );
- }
- }
- const pluginRoot = await writeOfficialPluginFixture(home, "documents", "0.1.4", "direct");
- await mkdir(join(pluginRoot, "agents", "nested"));
- await writeFile(
- join(pluginRoot, "agents", "nested", "deep.md"),
- serializeSubagentMarkdown({ name: "deep", description: "Deep", systemPrompt: "Deep" }),
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- for (const mode of ["settingsUserOnly", "allRuntimeScopes"] as const) {
- const result = await service.list({ workspacePath, mode });
- expect(
- result.agents.filter((agent) => agent.source === "user").map((agent) => agent.name),
- ).toEqual(mode === "settingsUserOnly" ? ["user-direct"] : ["user-direct", "project-direct"]);
- expect(result.pluginAgents.map((agent) => agent.name).sort()).toEqual([
- "documents:deep",
- "documents:direct",
- ]);
- expect(result.pluginAgents.find((agent) => agent.name === "documents:deep")?.path).toBe(
- join(pluginRoot, "agents", "nested", "deep.md"),
- );
- expect(result.diagnostics).toEqual([]);
- }
- });
- it("lists built-in official plugin agents from the official cache without an install record", async () => {
- // Bug 根因:discoverPluginAgents 只读 installed_plugins.json,内置官方插件由 CLI seed 到
- // cache/zcode-plugins-official 且没有安装记录,documents:visual-judge 在 Settings 永远不可见。
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const oldRoot = await writeOfficialPluginFixture(home, "documents", "0.1.9", "visual-judge");
- const newRoot = await writeOfficialPluginFixture(home, "documents", "0.1.10", "visual-judge");
- const invalidRoot = await writeOfficialPluginFixture(home, "documents", "99.0", "visual-judge");
- await writeFile(
- join(invalidRoot, ".zcode-plugin", "plugin.json"),
- JSON.stringify({ name: "wrong" }),
- );
- await writeOfficialPluginFixture(home, "documents", "99.0.backup-1", "visual-judge");
- await mkdir(join(newRoot, "..", "0.1.4.backup-1"), { recursive: true });
- await mkdir(join(newRoot, "..", ".seed-lock"), { recursive: true });
- // ios-simulator 不在默认启用集合里,且 config 没有显式启用,必须被忽略。
- await writeOfficialPluginFixture(home, "ios-simulator", "0.2.0", "simulator-runner");
- // browser-use 默认启用,但被用户「卸载」进入 suppressedBuiltins,同样不能贡献 agent。
- await writeOfficialPluginFixture(home, "browser-use", "0.5.0", "browser-auditor");
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: {
- suppressedBuiltins: ["browser-use@zcode-plugins-official"],
- },
- }),
- "utf8",
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.pluginAgents.map((agent) => agent.name)).toEqual(["documents:visual-judge"]);
- expect(result.pluginAgents[0]).toMatchObject({
- id: "plugin:documents@zcode-plugins-official:visual-judge",
- pluginId: "documents@zcode-plugins-official",
- pluginName: "documents",
- // 多版本缓存共存时取数字感知最新的版本目录,而不是字典序首项。
- path: join(newRoot, "agents", "visual-judge.md"),
- scope: "user",
- source: "plugin",
- });
- expect(result.pluginAgents[0]?.path).not.toBe(join(oldRoot, "agents", "visual-judge.md"));
- expect(
- result.agents.filter((agent) => agent.source === "plugin").map((agent) => agent.name),
- ).toEqual(["documents:visual-judge", "visual-judge"]);
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: {
- enabledPlugins: { "documents@zcode-plugins-official": false },
- suppressedBuiltins: ["browser-use@zcode-plugins-official"],
- },
- }),
- );
- expect((await service.list({ workspacePath, provider: "glm" })).pluginAgents).toEqual([]);
- });
- it("settingsUserOnly 仍返回本地插件资源,不引入运行时别名或项目文件", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- await writeOfficialPluginFixture(home, "documents", "0.1.4", "visual-judge");
- const projectPath = join(workspacePath, ".zcode", "agents", "project.md");
- await mkdir(join(workspacePath, ".zcode", "agents"), { recursive: true });
- const projectContent =
- "---\nname: project\nmodel: builtin:zai-coding-plan/GLM-5.3\n---\nProject.";
- await writeFile(projectPath, projectContent);
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath, mode: "settingsUserOnly" });
- expect(result.pluginAgents.map((agent) => agent.name)).toEqual(["documents:visual-judge"]);
- expect(result.pluginAgents[0]?.readOnly).toBe(true);
- expect(
- result.agents.some((agent) => agent.source === "plugin" || agent.scope === "workspace"),
- ).toBe(false);
- expect(await readFile(projectPath, "utf8")).toBe(projectContent);
- });
- it("prefers the install record over the official cache for the same plugin id", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- await writeOfficialPluginFixture(home, "documents", "0.1.4", "visual-judge");
- const installedRoot = join(home, "installed", "documents");
- await mkdir(join(installedRoot, ".zcode-plugin"), { recursive: true });
- await mkdir(join(installedRoot, "agents"), { recursive: true });
- await writeFile(
- join(installedRoot, ".zcode-plugin", "plugin.json"),
- JSON.stringify({ name: "documents" }),
- "utf8",
- );
- await writeFile(
- join(installedRoot, "agents", "visual-judge.md"),
- "---\nname: visual-judge\ndescription: installed visual-judge\n---\ninstalled prompt",
- "utf8",
- );
- await writeFile(
- join(home, ".zcode", "cli", "plugins", "installed_plugins.json"),
- JSON.stringify({
- version: 1,
- plugins: [
- {
- id: "documents@zcode-plugins-official",
- name: "documents",
- marketplace: "zcode-plugins-official",
- version: "9.9.9",
- installPath: installedRoot,
- scope: "user",
- },
- ],
- }),
- "utf8",
- );
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: { enabledPlugins: { "documents@zcode-plugins-official": true } },
- }),
- "utf8",
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.pluginAgents.map((agent) => agent.path)).toEqual([
- join(installedRoot, "agents", "visual-judge.md"),
- ]);
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: {
- enabledPlugins: { "documents@zcode-plugins-official": true },
- suppressedBuiltins: ["documents@zcode-plugins-official"],
- },
- }),
- );
- expect((await service.list({ workspacePath, provider: "glm" })).pluginAgents).toEqual([]);
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: { enabledPlugins: { "documents@zcode-plugins-official": false } },
- }),
- );
- expect((await service.list({ workspacePath, provider: "glm" })).pluginAgents).toEqual([]);
- });
- it("插件覆盖按稳定身份原子保存,别名一致,清除后回到未修改的插件默认", async () => {
- const home = await makeTempHome();
- const pluginRoot = join(home, "installed", "fixture");
- const pluginStorage = join(home, ".zcode", "cli", "plugins");
- const pluginId = "fixture@personal";
- const agentId = "plugin:fixture@personal:visual-judge";
- const path = join(pluginRoot, "agents", "visual-judge.md");
- await mkdir(join(pluginRoot, "agents"), { recursive: true });
- await mkdir(join(pluginRoot, ".zcode-plugin"), { recursive: true });
- await mkdir(pluginStorage, { recursive: true });
- await writeFile(
- join(pluginRoot, ".zcode-plugin", "plugin.json"),
- JSON.stringify({ name: "fixture" }),
- );
- const markdown =
- "---\nname: visual-judge\ndescription: visual-judge\nmodel: custom:p:old\nthoughtLevel: low\n---\nKeep prompt";
- await writeFile(path, markdown);
- await writeFile(
- join(pluginStorage, "installed_plugins.json"),
- JSON.stringify({
- version: 1,
- plugins: [{ id: pluginId, name: "fixture", installPath: pluginRoot, scope: "user" }],
- }),
- );
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: { enabledPlugins: { [pluginId]: true } },
- }),
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const selection = { providerId: "p", modelId: "new", options: { reasoningLevel: "high" } };
- await Promise.all([
- service.setPluginAgentModelOverride({ agentId, modelSelection: selection }),
- service.setBuiltInModelOverride({ agentName: "Explore", modelSelection: selection }),
- service.setEnabled({ agentId: "user:user:disabled", enabled: false }),
- ]);
- const statePath = await resolveSubagentStateFile({ homeDir: home });
- const state = JSON.parse(await readFile(statePath, "utf8"));
- expect(state).toMatchObject({
- pluginAgentModelSelectionOverrides: { [agentId]: selection },
- builtInModelSelectionOverrides: { Explore: selection },
- disabledAgentIds: ["user:user:disabled"],
- });
- expect(state.pluginAgentModelOverrides).toBeUndefined();
- const result = await service.list({ workspacePath: join(home, "workspace"), provider: "glm" });
- expect(result.pluginAgents[0]).toMatchObject({
- modelSelection: selection,
- modelSelectionOverride: selection,
- defaultModelSelection: {
- providerId: "p",
- modelId: "old",
- options: { reasoningLevel: "low" },
- },
- });
- expect(result.agents.filter((a) => a.source === "plugin").map((a) => a.modelSelection)).toEqual(
- [selection, selection],
- );
- await service.setPluginAgentModelOverride({
- agentId,
- modelSelection: { providerId: "p", modelId: "no-effort" },
- });
- const modelOnly = await service.list({
- workspacePath: join(home, "workspace"),
- provider: "glm",
- });
- expect(modelOnly.pluginAgents[0]?.modelSelection).toEqual({
- providerId: "p",
- modelId: "no-effort",
- });
- await service.setPluginAgentModelOverride({ agentId });
- const cleared = await service.list({ workspacePath: join(home, "workspace"), provider: "glm" });
- expect(cleared.pluginAgents[0]?.modelSelectionOverride).toBeUndefined();
- expect(cleared.pluginAgents[0]?.modelSelection).toEqual({
- providerId: "p",
- modelId: "old",
- options: { reasoningLevel: "low" },
- });
- expect(
- JSON.parse(await readFile(statePath, "utf8")).pluginAgentModelSelectionOverrides,
- ).toEqual({});
- expect(await readFile(path, "utf8")).toBe(markdown);
- });
- it("serializes user subagent markdown with runtime profile fields", () => {
- const markdown = serializeSubagentMarkdown({
- name: "code-reviewer",
- description: "提交前审查代码",
- systemPrompt: "你是严格的代码审查员。",
- color: "cyan",
- modelSelection: {
- providerId: "provider-a",
- modelId: "lite",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read", "Grep", "Bash(git diff *)"],
- disallowedTools: ["Write"],
- skills: ["code-review"],
- permissionMode: "acceptEdits",
- maxTurns: 7,
- background: true,
- injectAgentsMd: false,
- });
- expect(markdown).toContain('name: "code-reviewer"');
- expect(markdown).toContain('description: "提交前审查代码"');
- expect(markdown).toContain("tools:");
- expect(markdown).toContain("- Read");
- expect(markdown).toContain("- Bash(git diff *)");
- expect(markdown).toContain("permissionMode: acceptEdits");
- expect(markdown).toContain("model: provider-a/lite");
- expect(markdown).toContain("thoughtLevel: high");
- expect(markdown).not.toContain("modelSelection:");
- expect(markdown).toContain("maxTurns: 7");
- expect(markdown).toContain("background: true");
- expect(markdown).toContain("injectAgentsMd: false");
- expect(markdown).toContain("你是严格的代码审查员。");
- });
- it("parses user subagent markdown into the settings summary shape", () => {
- const parsed = parseSubagentMarkdown({
- content: `---
- name: code-reviewer
- description: 提交前审查代码
- model: custom:custom-openai:lite
- thoughtLevel: high
- tools:
- - Read
- - Bash(git diff *)
- disallowedTools:
- - Write
- skills:
- - code-review
- permissionMode: acceptEdits
- maxTurns: 7
- background: true
- injectAgentsMd: true
- color: cyan
- ---
- 你是严格的代码审查员。`,
- path: "/tmp/code-reviewer.md",
- scope: "user",
- });
- expect(parsed.diagnostic).toBeUndefined();
- expect(parsed.agent).toMatchObject({
- id: "user:user:code-reviewer",
- name: "code-reviewer",
- description: "提交前审查代码",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "lite",
- options: { reasoningLevel: "high" },
- },
- tools: ["Read", "Bash(git diff *)"],
- disallowedTools: ["Write"],
- skills: ["code-review"],
- permissionMode: "acceptEdits",
- maxTurns: 7,
- background: true,
- injectAgentsMd: true,
- color: "cyan",
- enabled: true,
- readOnly: false,
- systemPrompt: "你是严格的代码审查员。",
- });
- });
- it("preserves concrete model select values from subagent markdown", () => {
- const markdown = serializeSubagentMarkdown({
- name: "custom-model-reviewer",
- description: "Use selected model",
- systemPrompt: "Review carefully.",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- const parsed = parseSubagentMarkdown({
- content: markdown,
- path: "/tmp/custom-model-reviewer.md",
- scope: "user",
- });
- expect(markdown).toContain("model: custom-openai/gpt-5.4");
- expect(parsed.agent?.modelSelection).toEqual({
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- });
- });
- it.each([true, false])(
- "round-trips injectAgentsMd=%s through subagent markdown",
- (injectAgentsMd) => {
- const markdown = serializeSubagentMarkdown({
- name: "instruction-aware-reviewer",
- description: "Controls AGENTS.md injection",
- systemPrompt: "Review carefully.",
- injectAgentsMd,
- });
- const parsed = parseSubagentMarkdown({
- content: markdown,
- path: "/tmp/instruction-aware-reviewer.md",
- scope: "user",
- });
- expect(parsed.agent?.injectAgentsMd).toBe(injectAgentsMd);
- },
- );
- it("keeps missing injectAgentsMd unset for legacy markdown", () => {
- const parsed = parseSubagentMarkdown({
- content: `---
- name: legacy-reviewer
- description: Legacy profile
- ---
- Review carefully.`,
- path: "/tmp/legacy-reviewer.md",
- scope: "user",
- });
- expect(parsed.agent?.injectAgentsMd).toBeUndefined();
- });
- it("parses runtime-compatible loose frontmatter that is not strict YAML", () => {
- const parsed = parseSubagentMarkdown({
- content: `---
- name: reviewer
- description: foo: bar
- tools:
- - Read
- - Bash(git commit -m foo: bar)
- ---
- prompt`,
- path: "/tmp/reviewer.md",
- scope: "user",
- });
- expect(parsed.diagnostic).toBeUndefined();
- expect(parsed.agent).toMatchObject({
- name: "reviewer",
- description: "foo: bar",
- tools: ["Read", "Bash(git commit -m foo: bar)"],
- });
- });
- it("round-trips structured mcpServers entries through markdown serialization", () => {
- const mcpServers = [
- {
- name: "github",
- command: "gh",
- args: ["repo", "view"],
- env: {
- GITHUB_TOKEN: "${GITHUB_TOKEN}",
- },
- },
- {
- name: "linear",
- type: "sse",
- url: "https://mcp.linear.app/sse",
- },
- ];
- const markdown = serializeSubagentMarkdown({
- name: "mcp-reviewer",
- description: "checks changes with MCP context",
- systemPrompt: "Use MCP context when available.",
- mcpServers,
- });
- const parsed = parseSubagentMarkdown({
- content: markdown,
- path: "/tmp/mcp-reviewer.md",
- scope: "user",
- });
- expect(parsed.diagnostic).toBeUndefined();
- expect(parsed.agent?.mcpServers).toEqual(mcpServers);
- });
- });
- describe("subagent storage roots", () => {
- it("uses runtime storage.dir agents root for user subagents", async () => {
- const home = await makeTempHome();
- const storageRoot = join(home, "custom-storage");
- await mkdir(join(home, ".zcode", "cli"), { recursive: true });
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({ storage: { dir: storageRoot } }),
- "utf8",
- );
- await expect(resolveUserSubagentRoot({ homeDir: home })).resolves.toBe(
- join(storageRoot, "agents"),
- );
- await expect(resolveSubagentStateFile({ homeDir: home })).resolves.toBe(
- join(storageRoot, "v2", "agents-state.json"),
- );
- });
- });
- describe("createSubagentsService", () => {
- it("用户 Markdown 先原地迁移后正式读取,项目文件和中间格式不自动迁", async () => {
- const home = await makeTempHome();
- const userRoot = await resolveUserSubagentRoot({ homeDir: home });
- const workspacePath = join(home, "workspace");
- const projectRoot = join(workspacePath, ".zcode", "agents");
- await mkdir(userRoot, { recursive: true });
- await mkdir(projectRoot, { recursive: true });
- const content =
- "---\nname: helper\ndescription: review\nmodel: builtin:zai-coding-plan/m\nthoughtLevel: high\n# comment\nextra: user-data\n---\n正文 builtin:zai-coding-plan/m\n";
- const userFile = join(userRoot, "helper.md");
- const projectFile = join(projectRoot, "project.md");
- await writeFile(userFile, content);
- await writeFile(projectFile, content.replace("name: helper", "name: project-helper"));
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath });
- expect(result.agents.find((agent) => agent.name === "helper")?.modelSelection?.providerId).toBe(
- "account:zai-individual-coding-plan",
- );
- expect(
- result.agents.find((agent) => agent.name === "project-helper")?.modelSelection?.providerId,
- ).toBe("builtin:zai-coding-plan");
- expect(await readFile(userFile, "utf8")).toBe(
- content.replace(
- "model: builtin:zai-coding-plan",
- "model: account:zai-individual-coding-plan",
- ),
- );
- expect(await readFile(projectFile, "utf8")).toBe(
- content.replace("name: helper", "name: project-helper"),
- );
- expect(
- (
- await createSubagentsService({ homeDir: home, isDesktopRuntime: true }).list({
- workspacePath,
- })
- ).agents.find((agent) => agent.name === "helper")?.modelSelection,
- ).toEqual(result.agents.find((agent) => agent.name === "helper")?.modelSelection);
- });
- it("损坏的 Subagent state 不阻塞整个会话启动,也不覆盖原文件", async () => {
- const home = await makeTempHome();
- const path = await resolveSubagentStateFile({ homeDir: home });
- await mkdir(join(home, ".zcode", "v2"), { recursive: true });
- const original = '{"builtInModelOverrides":';
- await writeFile(path, original);
- await expect(
- createSubagentsService({ homeDir: home }).prepareRuntimeState(),
- ).resolves.toBeUndefined();
- expect(await readFile(path, "utf8")).toBe(original);
- });
- it("启动准备将旧内置选择落盘,让独立 Agent loader 不必等待用户编辑", async () => {
- const home = await makeTempHome();
- const statePath = await resolveSubagentStateFile({ homeDir: home });
- await mkdir(join(home, ".zcode", "v2"), { recursive: true });
- const legacy = {
- builtInModelOverrides: { Explore: "custom:builtin%3Azai-coding-plan:GLM-5.3-Flash" },
- builtInThoughtLevelOverrides: { Explore: "high" },
- disabledAgentIds: ["disabled-profile"],
- };
- await writeFile(statePath, JSON.stringify(legacy));
- const service = createSubagentsService({
- homeDir: home,
- });
- await service.prepareRuntimeState();
- const saved = JSON.parse(await readFile(statePath, "utf8"));
- expect(saved).toMatchObject(legacy);
- expect(saved.builtInModelSelectionOverrides.Explore).toEqual({
- providerId: "account:zai-individual-coding-plan",
- modelId: "GLM-5.3-Flash",
- options: { reasoningLevel: "high" },
- });
- await service.setBuiltInModelOverride({ agentName: "Explore", modelSelection: undefined });
- await service.prepareRuntimeState();
- expect(JSON.parse(await readFile(statePath, "utf8")).builtInModelSelectionOverrides).toEqual(
- {},
- );
- });
- it("并发启动导入与新版手动清空,写队列保留用户结果", async () => {
- const home = await makeTempHome();
- const statePath = await resolveSubagentStateFile({ homeDir: home });
- await mkdir(join(home, ".zcode", "v2"), { recursive: true });
- await writeFile(
- statePath,
- JSON.stringify({ builtInModelOverrides: { Explore: "custom:builtin%3Azai-coding-plan:m" } }),
- );
- const service = createSubagentsService({ homeDir: home });
- await Promise.all([
- service.prepareRuntimeState(),
- service.setBuiltInModelOverride({ agentName: "Explore", modelSelection: undefined }),
- ]);
- await service.prepareRuntimeState();
- expect(JSON.parse(await readFile(statePath, "utf8")).builtInModelSelectionOverrides).toEqual(
- {},
- );
- });
- it("旧内置模型覆盖导入并随正常保存固定;旧字段仅保留供回滚", async () => {
- const home = await makeTempHome();
- const statePath = await resolveSubagentStateFile({ homeDir: home });
- await mkdir(join(home, ".zcode", "v2"), { recursive: true });
- const legacy = {
- builtInModelOverrides: { Explore: "custom:builtin%3Azai-coding-plan:GLM-5.3-Flash" },
- builtInThoughtLevelOverrides: { Explore: "high" },
- disabledAgentIds: [],
- };
- await writeFile(statePath, JSON.stringify(legacy));
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const params = { workspacePath: join(home, "workspace"), mode: "settingsUserOnly" as const };
- const listed = await service.list(params);
- const explore = listed.agents.find((agent) => agent.name === "Explore")!;
- expect(explore.modelSelection).toEqual({
- providerId: "account:zai-individual-coding-plan",
- modelId: "GLM-5.3-Flash",
- options: { reasoningLevel: "high" },
- });
- await service.setEnabled({ agentId: explore.id, enabled: false });
- const saved = JSON.parse(await readFile(statePath, "utf8"));
- expect(saved).toMatchObject({
- builtInModelOverrides: legacy.builtInModelOverrides,
- builtInThoughtLevelOverrides: legacy.builtInThoughtLevelOverrides,
- });
- expect(saved.builtInModelSelectionOverrides.Explore).toEqual(explore.modelSelection);
- await service.setBuiltInModelOverride({ agentName: "Explore", modelSelection: undefined });
- expect(
- (await service.list(params)).agents.find((agent) => agent.name === "Explore")?.modelSelection,
- ).toBeUndefined();
- });
- it("persists model overrides for built-in subagents without making them editable", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- await service.setBuiltInModelOverride({
- agentName: "general-purpose",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- await service.setBuiltInModelOverride({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- });
- const result = await service.list({
- workspacePath,
- provider: "glm",
- mode: "settingsUserOnly",
- });
- const state = JSON.parse(
- await readFile(await resolveSubagentStateFile({ homeDir: home }), "utf8"),
- ) as {
- builtInModelSelectionOverrides: Record<string, unknown>;
- disabledAgentIds: string[];
- };
- expect(result.agents.find((agent) => agent.name === "general-purpose")).toMatchObject({
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- readOnly: true,
- });
- expect(result.agents.find((agent) => agent.name === "Explore")).toMatchObject({
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- modelSelectionOverride: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- readOnly: true,
- });
- expect(state.builtInModelSelectionOverrides).toEqual({
- Explore: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- "general-purpose": {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- });
- });
- it("clears a built-in subagent model override and restores inheritance", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- await service.setBuiltInModelOverride({
- agentName: "Explore",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "max" },
- },
- });
- await service.setBuiltInModelOverride({
- agentName: "Explore",
- modelSelection: undefined,
- });
- const result = await service.list({
- workspacePath,
- provider: "glm",
- mode: "settingsUserOnly",
- });
- expect(result.agents.find((agent) => agent.name === "Explore")).toMatchObject({
- modelSelection: undefined,
- modelSelectionOverride: undefined,
- readOnly: true,
- });
- const state = JSON.parse(
- await readFile(await resolveSubagentStateFile({ homeDir: home }), "utf8"),
- ) as {
- builtInModelSelectionOverrides: Record<string, unknown>;
- };
- expect(state.builtInModelSelectionOverrides).toEqual({});
- });
- it("settings user-only list hides workspace agents but keeps built-ins and user agents", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- await mkdir(join(home, ".zcode", "agents"), { recursive: true });
- await mkdir(join(workspacePath, ".zcode", "agents"), { recursive: true });
- await writeFile(
- join(home, ".zcode", "agents", "code-reviewer.md"),
- serializeSubagentMarkdown({
- name: "code-reviewer",
- description: "提交前审查代码",
- systemPrompt: "你是严格的代码审查员。",
- }),
- "utf8",
- );
- await writeFile(
- join(workspacePath, ".zcode", "agents", "workspace-reviewer.md"),
- serializeSubagentMarkdown({
- name: "workspace-reviewer",
- description: "工作区审查",
- systemPrompt: "workspace prompt",
- }),
- "utf8",
- );
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const result = await service.list({
- workspacePath,
- provider: "glm",
- mode: "settingsUserOnly",
- });
- expect(result.agents.map((agent) => agent.name)).toEqual([
- "general-purpose",
- "Explore",
- "code-reviewer",
- ]);
- expect(result.agents.every((agent) => agent.scope !== "workspace")).toBe(true);
- // Bugfix 回归:workspace profile 曾被 parser 标为 readOnly,于是在设置页既不可编辑
- // 也不可删除,还被归入“内置”分组。只有内置 agent 才是真正只读的。
- const allScopes = await service.list({
- workspacePath,
- provider: "glm",
- });
- expect(allScopes.agents.find((agent) => agent.name === "workspace-reviewer")).toMatchObject({
- scope: "workspace",
- source: "user",
- readOnly: false,
- });
- expect(result.agents.find((agent) => agent.name === "general-purpose")?.readOnly).toBe(true);
- expect(result.agents.find((agent) => agent.name === "general-purpose")?.color).toBe("blue");
- expect(result.agents.find((agent) => agent.name === "Explore")?.color).toBe("cyan");
- expect(result.agents.find((agent) => agent.name === "code-reviewer")?.readOnly).toBe(false);
- });
- it("lists enabled plugin agents from installed plugin cache", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const pluginRoot = join(
- home,
- ".zcode",
- "cli",
- "plugins",
- "cache",
- "claude-plugins-official",
- "feature-dev",
- "0.0.0",
- );
- await mkdir(join(home, ".zcode", "cli", "plugins"), { recursive: true });
- await mkdir(join(pluginRoot, ".claude-plugin"), { recursive: true });
- await mkdir(join(pluginRoot, "agents"), { recursive: true });
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: {
- enabledPlugins: {
- "feature-dev@claude-plugins-official": true,
- },
- },
- }),
- "utf8",
- );
- await writeFile(
- join(home, ".zcode", "cli", "plugins", "installed_plugins.json"),
- JSON.stringify({
- version: 1,
- plugins: [
- {
- id: "feature-dev@claude-plugins-official",
- name: "feature-dev",
- marketplace: "claude-plugins-official",
- version: "0.0.0",
- installPath: pluginRoot,
- installedAt: "2026-06-27T00:00:00.000Z",
- scope: "user",
- },
- ],
- }),
- "utf8",
- );
- await writeFile(
- join(pluginRoot, ".claude-plugin", "plugin.json"),
- JSON.stringify({ name: "feature-dev", description: "Feature workflow" }),
- "utf8",
- );
- await writeFile(
- join(pluginRoot, "agents", "code-architect.md"),
- `---
- name: code-architect
- description: 设计功能架构
- tools:
- - Read
- ---
- 架构 prompt`,
- "utf8",
- );
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(
- result.agents.filter((agent) => agent.source === "plugin").map((agent) => agent.name),
- ).toEqual(["code-architect", "feature-dev:code-architect"]);
- expect(result.pluginAgents.map((agent) => agent.name)).toEqual(["feature-dev:code-architect"]);
- expect(new Set(result.pluginAgents.map((agent) => agent.path))).toEqual(
- new Set([join(pluginRoot, "agents", "code-architect.md")]),
- );
- expect(result.pluginAgents.every((agent) => agent.source === "plugin")).toBe(true);
- expect(result.pluginAgents.every((agent) => agent.readOnly)).toBe(true);
- });
- it("lists built-in official plugin agents from the official cache without an install record", async () => {
- // Bug 根因:discoverPluginAgents 只读 installed_plugins.json,内置官方插件由 CLI seed 到
- // cache/zcode-plugins-official 且没有安装记录,documents:visual-judge 在 Settings 永远不可见。
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const oldRoot = await writeOfficialPluginFixture(home, "documents", "0.1.2", "visual-judge");
- const newRoot = await writeOfficialPluginFixture(home, "documents", "0.1.4", "visual-judge");
- await mkdir(join(newRoot, "..", "0.1.4.backup-1"), { recursive: true });
- await mkdir(join(newRoot, "..", ".seed-lock"), { recursive: true });
- // ios-simulator 不在默认启用集合里,且 config 没有显式启用,必须被忽略。
- await writeOfficialPluginFixture(home, "ios-simulator", "0.2.0", "simulator-runner");
- // browser-use 默认启用,但被用户「卸载」进入 suppressedBuiltins,同样不能贡献 agent。
- await writeOfficialPluginFixture(home, "browser-use", "0.5.0", "browser-auditor");
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: {
- suppressedBuiltins: ["browser-use@zcode-plugins-official"],
- },
- }),
- "utf8",
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.pluginAgents.map((agent) => agent.name)).toEqual(["documents:visual-judge"]);
- expect(result.pluginAgents[0]).toMatchObject({
- id: "plugin:documents@zcode-plugins-official:visual-judge",
- pluginId: "documents@zcode-plugins-official",
- pluginName: "documents",
- // 多版本缓存共存时取数字感知最新的版本目录,而不是字典序首项。
- path: join(newRoot, "agents", "visual-judge.md"),
- scope: "user",
- source: "plugin",
- });
- expect(result.pluginAgents[0]?.path).not.toBe(join(oldRoot, "agents", "visual-judge.md"));
- expect(
- result.agents.filter((agent) => agent.source === "plugin").map((agent) => agent.name),
- ).toEqual(["documents:visual-judge", "visual-judge"]);
- });
- it("prefers the install record over the official cache for the same plugin id", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- await writeOfficialPluginFixture(home, "documents", "0.1.4", "visual-judge");
- const installedRoot = join(home, "installed", "documents");
- await mkdir(join(installedRoot, ".zcode-plugin"), { recursive: true });
- await mkdir(join(installedRoot, "agents"), { recursive: true });
- await writeFile(
- join(installedRoot, ".zcode-plugin", "plugin.json"),
- JSON.stringify({ name: "documents" }),
- "utf8",
- );
- await writeFile(
- join(installedRoot, "agents", "visual-judge.md"),
- "---\nname: visual-judge\ndescription: installed visual-judge\n---\ninstalled prompt",
- "utf8",
- );
- await writeFile(
- join(home, ".zcode", "cli", "plugins", "installed_plugins.json"),
- JSON.stringify({
- version: 1,
- plugins: [
- {
- id: "documents@zcode-plugins-official",
- name: "documents",
- marketplace: "zcode-plugins-official",
- version: "9.9.9",
- installPath: installedRoot,
- scope: "user",
- },
- ],
- }),
- "utf8",
- );
- await writeFile(
- join(home, ".zcode", "cli", "config.json"),
- JSON.stringify({
- plugins: { enabledPlugins: { "documents@zcode-plugins-official": true } },
- }),
- "utf8",
- );
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const result = await service.list({ workspacePath, provider: "glm" });
- expect(result.pluginAgents.map((agent) => agent.path)).toEqual([
- join(installedRoot, "agents", "visual-judge.md"),
- ]);
- });
- it("persists plugin agent model overrides by agent id and echoes them in list", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const pluginRoot = await writeOfficialPluginFixture(home, "documents", "0.1.4", "visual-judge", {
- model: "custom:custom-openai:gpt-5.4",
- });
- const agentId = "plugin:documents@zcode-plugins-official:visual-judge";
- const service = createSubagentsService({ homeDir: home, isDesktopRuntime: true });
- const before = await service.list({ workspacePath, provider: "glm" });
- expect(before.pluginAgents[0]).toMatchObject({
- defaultModelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- path: join(pluginRoot, "agents", "visual-judge.md"),
- });
- expect(before.pluginAgents[0]?.modelSelectionOverride).toBeUndefined();
- const selection = {
- providerId: "custom-openai",
- modelId: "glm-5.2",
- options: { reasoningLevel: "high" },
- };
- await service.setPluginAgentModelOverride({
- agentId,
- modelSelection: selection,
- });
- const stateFile = await resolveSubagentStateFile({ homeDir: home });
- expect(JSON.parse(await readFile(stateFile, "utf8"))).toMatchObject({
- pluginAgentModelSelectionOverrides: { [agentId]: selection },
- });
- const overridden = await service.list({ workspacePath, provider: "glm" });
- expect(overridden.pluginAgents[0]).toMatchObject({
- defaultModelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- modelSelection: selection,
- modelSelectionOverride: selection,
- });
- // 运行时投影(规范名 + 裸名别名)与设置页资源投影必须回显同一覆盖,否则 @ 提及与设置页不一致。
- expect(
- overridden.agents.filter((agent) => agent.source === "plugin").map((agent) => agent.modelSelection),
- ).toEqual([selection, selection]);
- // 清除完整选择时一并清掉档位,回落到 md 声明;不恢复旧双 map 保存入口。
- await service.setPluginAgentModelOverride({ agentId });
- const cleared = await service.list({ workspacePath, provider: "glm" });
- expect(cleared.pluginAgents[0]).toMatchObject({
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- });
- expect(cleared.pluginAgents[0]?.modelSelectionOverride).toBeUndefined();
- expect(JSON.parse(await readFile(stateFile, "utf8"))).toMatchObject({
- pluginAgentModelSelectionOverrides: {},
- });
- });
- it("creates user agents in the runtime-consumed user agents root", async () => {
- const home = await makeTempHome();
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const result = await service.createAgent({
- provider: "glm",
- config: {
- name: "code-reviewer",
- description: "提交前审查代码",
- systemPrompt: "你是严格的代码审查员。",
- tools: ["Read", "Grep"],
- },
- });
- expect(result.agent.path).toBe(join(home, ".zcode", "agents", "code-reviewer.md"));
- await expect(readFile(result.agent.path, "utf8")).resolves.toContain("你是严格的代码审查员。");
- });
- it("creates and updates workspace agents in the selected workspace root", async () => {
- const home = await makeTempHome();
- const workspacePath = join(home, "workspace");
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const created = await service.createAgent({
- provider: "glm",
- scope: "workspace",
- workspacePath,
- workspaceIdentity: "ssh://dev/workspace",
- config: {
- name: "workspace-reviewer",
- description: "reviews this workspace",
- systemPrompt: "Review workspace changes.",
- },
- });
- expect(created.agent).toMatchObject({
- scope: "workspace",
- projectPath: workspacePath,
- path: join(workspacePath, ".zcode", "agents", "workspace-reviewer.md"),
- });
- const updated = await service.updateAgent({
- agentId: created.agent.id,
- oldFilePath: created.agent.path,
- provider: "glm",
- scope: "workspace",
- workspacePath,
- workspaceIdentity: "ssh://dev/workspace",
- config: {
- name: "workspace-reviewer-v2",
- description: "reviews this workspace",
- systemPrompt: "Review workspace changes carefully.",
- },
- });
- expect(updated.agent.scope).toBe("workspace");
- expect(updated.agent.path).toBe(
- join(workspacePath, ".zcode", "agents", "workspace-reviewer-v2.md"),
- );
- await expect(readFile(updated.agent.path, "utf8")).resolves.toContain(
- "Review workspace changes carefully.",
- );
- });
- it("removes a custom thoughtLevel when the updated config omits it", async () => {
- const home = await makeTempHome();
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const created = await service.createAgent({
- provider: "glm",
- config: {
- name: "effort-reviewer",
- description: "Review with explicit effort",
- systemPrompt: "Review carefully.",
- modelSelection: {
- providerId: "custom-openai",
- modelId: "gpt-5.4",
- options: { reasoningLevel: "high" },
- },
- },
- });
- await service.updateAgent({
- agentId: created.agent.id,
- oldFilePath: created.agent.path,
- provider: "glm",
- config: {
- name: "effort-reviewer",
- description: "Review with model default effort",
- systemPrompt: "Review carefully.",
- modelSelection: { providerId: "custom-openai", modelId: "gpt-5.4" },
- },
- });
- const markdown = await readFile(created.agent.path, "utf8");
- expect(markdown).toContain("model: custom-openai/gpt-5.4");
- expect(markdown).not.toContain("thoughtLevel:");
- });
- it("creates agents with wildcard and colon tool patterns as valid markdown", async () => {
- const home = await makeTempHome();
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const result = await service.createAgent({
- provider: "glm",
- config: {
- name: "wildcard-runner",
- description: "runs broad tools",
- systemPrompt: "Use the selected tools.",
- tools: ["*", "Bash(git commit -m foo: bar)"],
- },
- });
- expect(result.agent.tools).toEqual(["*", "Bash(git commit -m foo: bar)"]);
- const raw = await readFile(result.agent.path, "utf8");
- expect(raw).toContain(' - "*"');
- expect(raw).toContain(' - "Bash(git commit -m foo: bar)"');
- expect(
- parseSubagentMarkdown({
- content: raw,
- path: result.agent.path,
- scope: "user",
- }).diagnostic,
- ).toBeUndefined();
- });
- it("preserves disabled state when a user agent is renamed", async () => {
- const home = await makeTempHome();
- const service = createSubagentsService({
- homeDir: home,
- isDesktopRuntime: true,
- });
- const created = await service.createAgent({
- provider: "glm",
- config: {
- name: "code-reviewer",
- description: "reviews code",
- systemPrompt: "Review the code.",
- },
- });
- await service.setEnabled({
- agentId: created.agent.id,
- enabled: false,
- });
- await service.setBuiltInModelOverride({
- agentName: "Explore",
- modelSelection: { providerId: "custom-openai", modelId: "glm-5.2" },
- });
- const renamed = await service.updateAgent({
- agentId: created.agent.id,
- oldFilePath: created.agent.path,
- provider: "glm",
- config: {
- name: "code-reviewer-v2",
- description: "reviews code",
- systemPrompt: "Review the code.",
- },
- });
- const listed = await service.list({
- workspacePath: join(home, "workspace"),
- provider: "glm",
- mode: "settingsUserOnly",
- });
- const state = JSON.parse(
- await readFile(await resolveSubagentStateFile({ homeDir: home }), "utf8"),
- ) as {
- builtInModelSelectionOverrides: Record<string, unknown>;
- disabledAgentIds: string[];
- };
- expect(listed.agents.find((agent) => agent.name === "code-reviewer-v2")?.enabled).toBe(false);
- expect(state.builtInModelSelectionOverrides).toEqual({
- Explore: { providerId: "custom-openai", modelId: "glm-5.2" },
- });
- expect(state.disabledAgentIds).toContain(renamed.agent.id);
- expect(state.disabledAgentIds).not.toContain(created.agent.id);
- });
- });
|