upstream-provider.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. UPSTREAM_MODEL,
  3. UPSTREAM_THOUGHT_LEVEL,
  4. } from "./helpers/upstream-provider.js";
  5. import {
  6. assertUpstreamRequestCapture,
  7. assertUpstreamThoughtLevelCapture,
  8. readUpstreamUsageFromCapture,
  9. waitForContextUsageFromCapture,
  10. waitForUpstreamNetworkCapture,
  11. } from "./helpers/upstream-capture.js";
  12. import { clearAppData } from "./helpers/desktop-app.js";
  13. import {
  14. prepareV4ConversationE2E,
  15. sendV4Prompt,
  16. waitForV4AssistantMessageContaining,
  17. } from "./helpers/v4-conversation.js";
  18. const UPSTREAM_REPLY_TOKEN =
  19. process.env.E2E_PROVIDER_EXPECT_REPLY_TEXT?.trim() || "upstream-e2e-ok";
  20. const UPSTREAM_REQUEST_PROMPT =
  21. process.env.E2E_PROVIDER_PROMPT?.trim() ||
  22. `Reply with exactly "${UPSTREAM_REPLY_TOKEN}" and no other text.`;
  23. describe("桌面端 上游 Provider E2E", () => {
  24. after(async () => {
  25. await browser.electron.restoreAllMocks();
  26. await clearAppData();
  27. });
  28. it("应能在设置页配置 上游 并用新增模型发消息", async function () {
  29. this.timeout(120000);
  30. // 修复原因:beforeSession 重置 HOME 后会按当前 case 预置登录态;无条件点击欢迎页
  31. // 会让真实 smoke 在全量运行时误报缺少登录按钮。统一准备流程只在欢迎页真实存在时登录。
  32. await prepareV4ConversationE2E();
  33. // 修复原因:legacy chat-input 已被 V4 composer 替代;真实 provider smoke 必须走
  34. // 当前产品发送入口,否则会在请求发出前误报旧 DOM 不存在。
  35. await sendV4Prompt(UPSTREAM_REQUEST_PROMPT);
  36. const captureRecord = await waitForUpstreamNetworkCapture(UPSTREAM_REQUEST_PROMPT);
  37. assertUpstreamRequestCapture(captureRecord, {
  38. expectedText: UPSTREAM_REQUEST_PROMPT,
  39. model: UPSTREAM_MODEL,
  40. });
  41. if (UPSTREAM_THOUGHT_LEVEL) {
  42. assertUpstreamThoughtLevelCapture(captureRecord, UPSTREAM_THOUGHT_LEVEL);
  43. }
  44. await waitForV4AssistantMessageContaining(UPSTREAM_REPLY_TOKEN, 90000);
  45. await waitForContextUsageFromCapture(readUpstreamUsageFromCapture(captureRecord));
  46. });
  47. });