upstream-provider.test.ts 2.0 KB

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