provider-model-metadata-dialog.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Key } from "webdriverio";
  2. /** 专用参数回归显式配置 Personal 档位与 Map,不依赖内置模型目录继续收录旧型号。 */
  3. export async function configureProviderModelReasoning(
  4. levels: readonly [string, string],
  5. map: string,
  6. ) {
  7. const dialog = $('[role="dialog"]');
  8. const chips = '[data-model-reasoning-chip="true"]';
  9. if (!(await dialog.$(chips).isDisplayed())) {
  10. await dialog.$("[data-model-advanced-trigger]").click();
  11. }
  12. await browser.waitUntil(
  13. async () =>
  14. !(await dialog.$('[role="status"]').isExisting()) && (await dialog.$$(chips).length) === 2,
  15. { timeout: 15000, timeoutMsg: "模型能力解析没有完成并提供通用两档" },
  16. );
  17. for (const [index, level] of levels.entries()) {
  18. await dialog.$$(chips)[index]!.$("button").click();
  19. const input = dialog.$('[data-model-reasoning-level-input="true"]');
  20. await input.waitForDisplayed();
  21. // WebDriver clear 会触发失焦提交并卸载行内编辑框;用真实全选输入保留同一个编辑过程。
  22. await browser.keys([process.platform === "darwin" ? Key.Command : Key.Control, "a"]);
  23. await input.addValue(level);
  24. await browser.keys("Enter");
  25. await browser.waitUntil(
  26. async () => (await dialog.$$(chips)[index]!.$("button").getText()) === level,
  27. { timeout: 5000, timeoutMsg: `个人推理档位没有写入 ${level}` },
  28. );
  29. }
  30. const editor = dialog.$('[data-model-reasoning-level-map-editor="true"] textarea');
  31. if (!(await editor.isDisplayed())) await dialog.$("[data-model-advanced-trigger]").click();
  32. await editor.setValue(map);
  33. expect(await editor.getValue()).toBe(map);
  34. }
  35. export async function saveProviderModelMetadataDialog(label: string) {
  36. // 修复原因:模型 ID 改变后会 debounce 查询 catalog 的最大输出 Token,查询期间
  37. // 保存按钮按产品合同禁用。旧 case 只判断按钮存在就 click,disabled click 实际
  38. // 无效,随后把 provider 前置失败误报成具体模型或 Fork 等业务失败。
  39. await browser.waitUntil(
  40. async () =>
  41. browser.execute(() => {
  42. const dialog = document.querySelector<HTMLElement>('[role="dialog"]');
  43. const saveButton = Array.from(
  44. dialog?.querySelectorAll<HTMLButtonElement>("button") ?? [],
  45. ).find((button) => {
  46. const text = button.innerText.replace(/\s+/g, " ").trim();
  47. return text === "保存" || text.startsWith("Save");
  48. });
  49. if (!saveButton || saveButton.disabled || dialog?.querySelector('[role="status"]')) {
  50. return false;
  51. }
  52. saveButton.click();
  53. return true;
  54. }),
  55. {
  56. timeout: 15000,
  57. timeoutMsg: `新增 ${label} 模型 metadata 保存按钮没有结束 catalog 查询并进入可点击状态`,
  58. },
  59. );
  60. await browser.waitUntil(
  61. () => browser.execute(() => !document.querySelector<HTMLElement>('[role="dialog"]')),
  62. {
  63. timeout: 10000,
  64. timeoutMsg: `新增 ${label} 模型 metadata 弹窗保存后没有关闭`,
  65. },
  66. );
  67. }