subagentStateMigration.test.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, expect, it } from "vitest";
  2. import { importSubagentStateSelections } from "../src/subagent-state-migration.js";
  3. describe("Subagent 内置 state 单向导入", () => {
  4. const pluginId = "plugin:document-skills@zcode-plugins-official:judge";
  5. const pluginLegacy = {
  6. pluginAgentModelOverrides: { [pluginId]: "custom:builtin%3Azai-coding-plan:GLM" },
  7. pluginAgentThoughtLevelOverrides: { [pluginId]: "high" },
  8. };
  9. it("staging 插件双map仅在存储边界离线导入,保留来源记录且再次导入幂等", () => {
  10. const next = importSubagentStateSelections(pluginLegacy);
  11. expect(next.pluginAgentModelSelectionOverrides).toEqual({
  12. [pluginId]: {
  13. providerId: "account:zai-individual-coding-plan",
  14. modelId: "GLM",
  15. options: { reasoningLevel: "high" },
  16. },
  17. });
  18. expect(next).toMatchObject(pluginLegacy);
  19. expect(importSubagentStateSelections(next)).toEqual(next);
  20. });
  21. it.each([{}, null, { [pluginId]: "custom:p/m" }, { [pluginId]: { modelId: "bad" } }])(
  22. "插件正式map %j 存在时不回读旧map",
  23. (current) => {
  24. expect(
  25. importSubagentStateSelections({
  26. ...pluginLegacy,
  27. pluginAgentModelSelectionOverrides: current,
  28. }).pluginAgentModelSelectionOverrides,
  29. ).toEqual({});
  30. },
  31. );
  32. it("插件正式model-only覆盖不回填旧档位/不继续迁移旧Provider中间身份", () => {
  33. const selection = { providerId: "builtin:zai-coding-plan", modelId: "GLM" };
  34. expect(
  35. importSubagentStateSelections({
  36. ...pluginLegacy,
  37. pluginAgentModelSelectionOverrides: { [pluginId]: selection },
  38. }).pluginAgentModelSelectionOverrides,
  39. ).toEqual({ [pluginId]: selection });
  40. });
  41. const legacy = {
  42. builtInModelOverrides: { Explore: "custom:builtin%3Azai-coding-plan:m" },
  43. builtInThoughtLevelOverrides: { Explore: "high" },
  44. disabledAgentIds: ["a"],
  45. extra: "keep",
  46. };
  47. it("旧双 map 在明确导入边界转换,保留回滚数据", () => {
  48. const next = importSubagentStateSelections(legacy);
  49. expect(next).toMatchObject(legacy);
  50. expect(next.builtInModelSelectionOverrides).toEqual({
  51. Explore: {
  52. providerId: "account:zai-individual-coding-plan",
  53. modelId: "m",
  54. options: { reasoningLevel: "high" },
  55. },
  56. });
  57. expect(importSubagentStateSelections(next)).toEqual(next);
  58. });
  59. it.each([
  60. {},
  61. null,
  62. { Explore: null },
  63. { Explore: "custom:p/m" },
  64. { Explore: { modelId: "bad" } },
  65. ])("已有正式字段 %j 不回读旧双 map", (current) => {
  66. expect(
  67. importSubagentStateSelections({ ...legacy, builtInModelSelectionOverrides: current })
  68. .builtInModelSelectionOverrides,
  69. ).toEqual({});
  70. });
  71. it.each([undefined, "low"])("正式选择的档位 %s 不从旧 high 补值", (reasoningLevel) => {
  72. const selection = {
  73. providerId: "p",
  74. modelId: "m",
  75. ...(reasoningLevel ? { options: { reasoningLevel } } : {}),
  76. };
  77. expect(
  78. importSubagentStateSelections({
  79. ...legacy,
  80. builtInModelSelectionOverrides: { Explore: selection },
  81. }).builtInModelSelectionOverrides.Explore,
  82. ).toEqual(selection);
  83. });
  84. it("正式 map 不兼容未发布的旧身份中间产物", () => {
  85. const selection = { providerId: "builtin:zai-coding-plan", modelId: "m" };
  86. expect(
  87. importSubagentStateSelections({
  88. ...legacy,
  89. builtInModelSelectionOverrides: { Explore: selection },
  90. }).builtInModelSelectionOverrides.Explore,
  91. ).toEqual(selection);
  92. });
  93. });