conversation-session-compact-stream-fallback.test.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SF 是 catalog F08 的 transport 接线门禁:compact 必须先发 stream 请求,首腿失败后才回退到 non-stream。
  2. import { TID_V4_COMPOSER_INPUT } from "@zcode/shared/test-ids";
  3. import { clearAppData, setInputValueByTestIdDom } from "#e2e/helpers/desktop-app";
  4. import { waitForUpstreamNetworkCapture } from "#e2e/helpers/upstream-capture";
  5. import { countUpstreamRequestsContainingAll } from "#e2e/helpers/conversation-session-network";
  6. import {
  7. clickV4Send,
  8. prepareV4ConversationE2E,
  9. sendV4Prompt,
  10. waitForV4CompactMarker,
  11. waitForV4Pane,
  12. waitForV4TimelineContaining,
  13. } from "#e2e/helpers/v4-conversation";
  14. const SEED_MARKER = "E2E_COMPACT_STREAM_FALLBACK_SEED";
  15. const SEED_REPLY = "COMPACT_STREAM_FALLBACK_SEED_OK";
  16. const COMPACT_PROMPT_MARKER = "CRITICAL: Respond with TEXT ONLY";
  17. describe("SF compact stream-first fallback", () => {
  18. after(async () => {
  19. await browser.electron.restoreAllMocks();
  20. await clearAppData();
  21. });
  22. it("stream 首腿失败后只回退一次 non-stream,并完成 manual compact", async function () {
  23. this.timeout(150000);
  24. await prepareV4ConversationE2E();
  25. await sendV4Prompt(`${SEED_MARKER} 请回复种子`);
  26. await waitForV4TimelineContaining(SEED_REPLY, 45000);
  27. await waitForV4Pane(
  28. (snapshot) =>
  29. !snapshot.canStop && snapshot.sessionId !== "draft" && snapshot.sessionId !== null,
  30. "compact fallback seed 没有回到空闲态",
  31. 45000,
  32. );
  33. await setInputValueByTestIdDom(TID_V4_COMPOSER_INPUT, "/compact", {
  34. timeout: 15000,
  35. timeoutMsg: "compact fallback composer 没有出现",
  36. });
  37. await clickV4Send();
  38. await waitForV4CompactMarker({ origin: "manual", status: "success" }, 90000);
  39. const compactRequestMarkers = [SEED_MARKER, SEED_REPLY, COMPACT_PROMPT_MARKER];
  40. await browser.waitUntil(
  41. async () => (await countUpstreamRequestsContainingAll(compactRequestMarkers)) === 2,
  42. {
  43. timeout: 30000,
  44. timeoutMsg: "compact 没有形成 stream failure → non-stream success 两段请求",
  45. },
  46. );
  47. const fallbackCapture = await waitForUpstreamNetworkCapture(SEED_MARKER);
  48. expect(fallbackCapture.replay?.fixtureId).toBe("compact-stream-fallback-non-stream-success");
  49. expect(fallbackCapture.statusCode).toBe(200);
  50. expect((fallbackCapture.requestJson as { stream?: unknown }).stream).not.toBe(true);
  51. });
  52. });