provider-dynamic-model-edit.ts 5.9 KB

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