provider-dynamic-model-edit.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { BUILTIN_MODEL_PROVIDER_IDS, TID_MODEL_PROVIDER_ADD_MODEL_BUTTON } from "@zcode/shared";
  2. import { ModelConfig } from "@zcode/provider";
  3. import { NodePersonalProviderConfigRepository } from "@zcode/provider-node";
  4. import { clickTestIdByDom, getE2EAppDataPaths } from "./desktop-app.js";
  5. /** Todo 88:只从账单 mock 提供成员,不能 seed Personal modelIds 让错误的静态校验侥幸通过。 */
  6. export async function assertDynamicStartPlanModelEditing() {
  7. const providerId = BUILTIN_MODEL_PROVIDER_IDS.bigmodelStartPlan;
  8. const modelId = "glm-5.3-flash";
  9. const modelRow = (id: string) => $(`[data-model-provider-model-id="${id}"]`);
  10. const editor = '[data-model-reasoning-level-editor="true"]';
  11. const context = '[data-model-settings-group="tokens"] input';
  12. const repository = new NodePersonalProviderConfigRepository({
  13. filePath: getE2EAppDataPaths().configFile,
  14. pollingIntervalMs: false,
  15. });
  16. async function open() {
  17. const edit = modelRow(modelId).$("button:has(svg.lucide-pencil)");
  18. await edit.waitForClickable({ timeout: 15000 });
  19. await edit.click();
  20. await $(editor).waitForExist({ timeout: 15000 });
  21. }
  22. async function close(action: "Save" | "Cancel") {
  23. const localLabel = action === "Save" ? "保存" : "取消";
  24. const button = await $('[data-model-settings-footer="true"]').$(
  25. `.//button[normalize-space(.)="${action}" or normalize-space(.)="${localLabel}"]`,
  26. );
  27. await button.click();
  28. await $(editor).waitForExist({ reverse: true, timeout: 15000 });
  29. }
  30. async function add(id: string) {
  31. await clickTestIdByDom(TID_MODEL_PROVIDER_ADD_MODEL_BUTTON);
  32. await $('[data-model-identity-row="true"] input').setValue(id);
  33. const save = $('[data-model-settings-footer="true"]').$(
  34. './/button[normalize-space(.)="Save" or normalize-space(.)="保存"]',
  35. );
  36. await save.waitForClickable({ timeout: 15000 });
  37. await save.click();
  38. await browser.waitUntil(
  39. async () =>
  40. (await repository.read()).providers.get(providerId)?.personalModelIds?.includes(id) ===
  41. true,
  42. { timeout: 15000, timeoutMsg: "首次添加 Account 模型未保存" },
  43. );
  44. }
  45. async function remove(id: string) {
  46. await modelRow(id).$("button:has(svg.lucide-trash-2)").click();
  47. await browser.waitUntil(
  48. async () =>
  49. !(await repository.read()).providers.get(providerId)?.personalModelIds?.includes(id),
  50. { timeout: 15000 },
  51. );
  52. }
  53. try {
  54. // 首次添加必须从无根覆盖开始,不能再靠先排序绕过创建缺陷。
  55. expect((await repository.read()).providers.has(providerId)).toBe(false);
  56. await add("glm-todo89-first");
  57. expect((await repository.read()).providers.get(providerId)?.builtinModelIds).toBeUndefined();
  58. await remove("glm-todo89-first");
  59. await open();
  60. await $(context).setValue("234567");
  61. // 外部配置刷新走真实文件监听;只改另一个模型,不能把被测输入值直接写进仓库。
  62. await repository.update((current) => ({
  63. ...current,
  64. models: current.models.setExact(
  65. providerId,
  66. "glm-5-turbo",
  67. new ModelConfig({ enabled: false }),
  68. ),
  69. }));
  70. await browser.waitUntil(
  71. async () =>
  72. (await modelRow("glm-5-turbo").$('[role="switch"]').getAttribute("aria-checked")) ===
  73. "false",
  74. { timeout: 15000 },
  75. );
  76. expect(await $(context).getValue()).toBe("234567");
  77. await $('[data-model-settings-footer="true"]')
  78. .$('.//button[normalize-space(.)="Save" or normalize-space(.)="保存"]')
  79. .click();
  80. await browser.waitUntil(
  81. async () =>
  82. (await browser.execute(() => document.body.innerText)).includes("revision conflict"),
  83. { timeout: 15000 },
  84. );
  85. expect(await $(context).getValue()).toBe("234567");
  86. await close("Cancel");
  87. await open();
  88. expect(
  89. await $('[data-model-identity-row="true"] input').getAttribute("readonly"),
  90. ).not.toBeNull();
  91. await $(context).setValue("240000");
  92. await close("Save");
  93. await open();
  94. expect(await $(context).getValue()).toBe("240000");
  95. await close("Cancel");
  96. const source = modelRow("glm-5-turbo");
  97. const target = modelRow(modelId);
  98. await target.scrollIntoView({ block: "center" });
  99. const a = await source.getLocation();
  100. const b = await target.getLocation();
  101. const aSize = await source.getSize();
  102. const bSize = await target.getSize();
  103. const x = Math.round(a.x + aSize.width / 2);
  104. const y = Math.round(a.y + aSize.height / 2);
  105. await browser.performActions([
  106. {
  107. id: "dynamic-model-order",
  108. type: "pointer",
  109. parameters: { pointerType: "mouse" },
  110. actions: [
  111. { type: "pointerMove", duration: 0, x, y },
  112. { type: "pointerDown", button: 0 },
  113. { type: "pointerMove", duration: 120, x, y: y + 10 },
  114. {
  115. type: "pointerMove",
  116. duration: 260,
  117. x: Math.round(b.x + bSize.width / 2),
  118. y: Math.round(b.y + bSize.height - 4),
  119. },
  120. { type: "pointerUp", button: 0 },
  121. ],
  122. },
  123. ]);
  124. await browser.releaseActions();
  125. await browser.waitUntil(
  126. async () => {
  127. const personal = await repository.read();
  128. return (
  129. personal.providers.get(providerId)?.modelOrder?.join("/") === `${modelId}/glm-5-turbo`
  130. );
  131. },
  132. { timeout: 15000, timeoutMsg: "动态模型拖拽后顺序没有保存" },
  133. );
  134. const personal = await repository.read();
  135. expect(personal.providers.get(providerId)?.personalModelIds ?? []).toEqual([]);
  136. expect(personal.models.getExact(providerId, modelId)?.properties?.contextWindow).toBe(240000);
  137. await add("glm-todo89-last");
  138. expect((await repository.read()).providers.get(providerId)?.modelOrder).toEqual([
  139. modelId,
  140. "glm-5-turbo",
  141. "glm-todo89-last",
  142. ]);
  143. await remove("glm-todo89-last");
  144. } finally {
  145. repository.dispose();
  146. }
  147. }