subagentMarkdownSelection.test.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. parseSubagentMarkdownSelection,
  4. formatSubagentMarkdownModel,
  5. migrateSubagentMarkdownProvider,
  6. } from "../src/subagent-markdown-selection.js";
  7. describe("Subagent 正式 Markdown 字段和单向文本迁移", () => {
  8. it("只读取 model/thoughtLevel,不读取未发布中间字段或结构化 model", () => {
  9. expect(
  10. parseSubagentMarkdownSelection({ modelSelection: { providerId: "p", modelId: "m" } }),
  11. ).toBeUndefined();
  12. expect(
  13. parseSubagentMarkdownSelection({ model: { providerId: "p", modelId: "m" } }),
  14. ).toBeUndefined();
  15. expect(
  16. parseSubagentMarkdownSelection({
  17. model: "p/m",
  18. thoughtLevel: "high",
  19. modelSelection: { providerId: "wrong", modelId: "wrong" },
  20. }),
  21. ).toEqual({ providerId: "p", modelId: "m", options: { reasoningLevel: "high" } });
  22. });
  23. it.each(["plain", "vendor/model", "model$variant", "模型:% /x"])(
  24. "模型 ID 无损往返 %s",
  25. (modelId) => {
  26. const selection = {
  27. providerId: "account:bigmodel-individual-coding-plan",
  28. modelId,
  29. options: { reasoningLevel: "high" },
  30. };
  31. expect(
  32. parseSubagentMarkdownSelection({
  33. model: formatSubagentMarkdownModel(selection),
  34. thoughtLevel: "high",
  35. }),
  36. ).toEqual(selection);
  37. },
  38. );
  39. it("普通读取不替换范围外的旧账号身份", () => {
  40. expect(
  41. parseSubagentMarkdownSelection({ model: "builtin:bigmodel-coding-plan/GLM" })?.providerId,
  42. ).toBe("builtin:bigmodel-coding-plan");
  43. });
  44. it.each(["custom:my-provider", "vendor/provider"])("Provider ID 无损往返 %s", (providerId) => {
  45. const selection = { providerId, modelId: "model" };
  46. expect(
  47. parseSubagentMarkdownSelection({ model: formatSubagentMarkdownModel(selection) }),
  48. ).toEqual(selection);
  49. });
  50. it.each([
  51. ["builtin:zai-start-plan/glm-5.3-flash", "account:zai-start-plan/GLM-5.3-Flash"],
  52. [
  53. "custom:builtin%3Abigmodel-coding-plan:glm-5.3",
  54. "custom:account%3Abigmodel-individual-coding-plan:GLM-5.3",
  55. ],
  56. [
  57. "builtin:bigmodel-coding-plan/glm-5.3$high",
  58. "account:bigmodel-individual-coding-plan/GLM-5.3$high",
  59. ],
  60. [
  61. "builtin:bigmodel-coding-plan/GLM/vendor",
  62. "account:bigmodel-individual-coding-plan/GLM/vendor",
  63. ],
  64. [
  65. "custom:builtin%3Azai-coding-plan:model%24variant",
  66. "custom:account%3Azai-individual-coding-plan:model%24variant",
  67. ],
  68. [
  69. "custom:builtin:bigmodel-coding-plan:GLM%2Fx",
  70. "custom:account%3Abigmodel-individual-coding-plan:GLM%2Fx",
  71. ],
  72. ])("迁移仅改变身份,不改正文、档位和注释:%s", (before, after) => {
  73. const content = `\uFEFF---\r\nname: helper\r\n# 备注\r\nmodel: '${before}' # 保留\r\nthoughtLevel: high\r\nextra: 123\r\n---\r\n正文 ${before}\r\n`;
  74. const expected = content.replace(`model: '${before}'`, `model: '${after}'`);
  75. expect(migrateSubagentMarkdownProvider(content)).toBe(expected);
  76. expect(migrateSubagentMarkdownProvider(expected)).toBe(expected);
  77. });
  78. it("无 frontmatter、仅中间字段、继承、未知旧身份不改写", () => {
  79. for (const content of [
  80. "model: builtin:bigmodel-coding-plan/GLM",
  81. '---\nmodelSelection: {"providerId":"builtin:bigmodel-coding-plan","modelId":"GLM"}\n---\nbody',
  82. "---\nmodel: inherit\n---\nbody",
  83. "---\nmodel: builtin:unknown/GLM\n---\nbody",
  84. ])
  85. expect(migrateSubagentMarkdownProvider(content)).toBe(content);
  86. });
  87. });