e2eWorkerIsolation.test.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { resolve } from "node:path";
  2. import { describe, expect, it } from "vitest";
  3. import {
  4. applyE2EWorkerModelRetryEnv,
  5. applyE2EWorkerReplayProxyEnv,
  6. replaceChromeUserDataDirArg,
  7. resolveE2EWorkerModelStreamIdleTimeoutMs,
  8. resolveE2EWebDriverRequestLimits,
  9. resolveE2EWorkerChromiumProfileDir,
  10. workerSpecsContain,
  11. } from "./e2e/helpers/e2e-worker-isolation.js";
  12. describe("desktop e2e worker isolation", () => {
  13. it("bounds a broken WebDriver request before the renderer preflight can stall", () => {
  14. expect(resolveE2EWebDriverRequestLimits({})).toEqual({
  15. retryCount: 0,
  16. timeoutMs: 30_000,
  17. });
  18. expect(resolveE2EWebDriverRequestLimits({ retryCount: "2", timeoutMs: "45000" })).toEqual({
  19. retryCount: 2,
  20. timeoutMs: 45_000,
  21. });
  22. expect(resolveE2EWebDriverRequestLimits({ retryCount: "99", timeoutMs: "999999" })).toEqual({
  23. retryCount: 3,
  24. timeoutMs: 300_000,
  25. });
  26. expect(resolveE2EWebDriverRequestLimits({ retryCount: "-1", timeoutMs: "invalid" })).toEqual({
  27. retryCount: 0,
  28. timeoutMs: 30_000,
  29. });
  30. });
  31. it("matches fixture markers against the current worker specs only", () => {
  32. const requestedBatch = ["smoke.test.ts", "oauth-credential-recovery.test.ts"];
  33. const currentWorkerSpecs = [requestedBatch[0] as string];
  34. // Bugfix: launcher 的完整请求列表不能决定当前 worker 的 credential/provider fixture。
  35. expect(workerSpecsContain(currentWorkerSpecs, "oauth-credential-recovery.test.ts")).toBe(false);
  36. expect(
  37. workerSpecsContain([requestedBatch[1] as string], "oauth-credential-recovery.test.ts"),
  38. ).toBe(true);
  39. });
  40. it("disables model retries only for terminal projection workers and restores the value", () => {
  41. const env: Record<string, string | undefined> = {};
  42. applyE2EWorkerModelRetryEnv(
  43. env,
  44. [
  45. "./test/e2e/conversation-session/background/conversation-session-background-subagent-rate-limit.test.ts",
  46. ],
  47. undefined,
  48. );
  49. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  50. applyE2EWorkerModelRetryEnv(env, ["./test/e2e/conversation-session/smoke.test.ts"], undefined);
  51. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBeUndefined();
  52. applyE2EWorkerModelRetryEnv(
  53. env,
  54. [
  55. "./test/e2e/conversation-session/background/conversation-session-background-subagent-rate-limit.test.ts",
  56. ],
  57. "4",
  58. );
  59. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  60. applyE2EWorkerModelRetryEnv(
  61. env,
  62. [
  63. "./test/e2e/conversation-session/models/conversation-session-model-switch-restore-repro.test.ts",
  64. ],
  65. "4",
  66. );
  67. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  68. applyE2EWorkerModelRetryEnv(env, ["./test/e2e/conversation-session/smoke.test.ts"], "4");
  69. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("4");
  70. });
  71. it("routes BG25 and I55 through replay proxy while keeping BG26 direct", () => {
  72. const env: Record<string, string | undefined> = {
  73. ZCODE_HTTP_PROXY: "http://configured-proxy:8080",
  74. ZCODE_NO_PROXY: "localhost",
  75. };
  76. applyE2EWorkerReplayProxyEnv(
  77. env,
  78. [
  79. "./test/e2e/conversation-session/background/conversation-session-background-subagent-rate-limit.test.ts",
  80. ],
  81. "http://127.0.0.1:43123",
  82. {
  83. httpProxy: "http://configured-proxy:8080",
  84. noProxy: "localhost",
  85. },
  86. );
  87. expect(env.ZCODE_HTTP_PROXY).toBe("http://configured-proxy:8080");
  88. expect(env.ZCODE_NO_PROXY).toBe("localhost");
  89. applyE2EWorkerReplayProxyEnv(
  90. env,
  91. [
  92. "./test/e2e/conversation-session/subagents/conversation-session-subagent-respond-to-coordinator.test.ts",
  93. ],
  94. "http://127.0.0.1:43126",
  95. {
  96. httpProxy: "http://configured-proxy:8080",
  97. noProxy: "localhost",
  98. },
  99. );
  100. expect(env.ZCODE_HTTP_PROXY).toBe("http://127.0.0.1:43126");
  101. expect(env.ZCODE_NO_PROXY).toBe("");
  102. applyE2EWorkerReplayProxyEnv(
  103. env,
  104. [
  105. "./test/e2e/conversation-session/models/conversation-session-thought-level-session-isolation.test.ts",
  106. ],
  107. "http://127.0.0.1:43125",
  108. {
  109. httpProxy: "http://configured-proxy:8080",
  110. noProxy: "localhost",
  111. },
  112. );
  113. expect(env.ZCODE_HTTP_PROXY).toBe("http://127.0.0.1:43125");
  114. expect(env.ZCODE_NO_PROXY).toBe("");
  115. applyE2EWorkerReplayProxyEnv(
  116. env,
  117. ["./test/e2e/conversation-session/smoke.test.ts"],
  118. "http://127.0.0.1:43124",
  119. {
  120. httpProxy: "http://configured-proxy:8080",
  121. noProxy: "localhost",
  122. },
  123. );
  124. expect(env.ZCODE_HTTP_PROXY).toBe("http://configured-proxy:8080");
  125. expect(env.ZCODE_NO_PROXY).toBe("localhost");
  126. applyE2EWorkerReplayProxyEnv(
  127. env,
  128. ["./test/e2e/conversation-session/smoke.test.ts"],
  129. "http://127.0.0.1:43124",
  130. { httpProxy: undefined, noProxy: undefined },
  131. );
  132. expect(env.ZCODE_HTTP_PROXY).toBeUndefined();
  133. expect(env.ZCODE_NO_PROXY).toBeUndefined();
  134. });
  135. it("shortens stream idle recovery only for BG25 and I55 replay workers", () => {
  136. expect(
  137. resolveE2EWorkerModelStreamIdleTimeoutMs([
  138. "./test/e2e/conversation-session/subagents/conversation-session-subagent-respond-to-coordinator.test.ts",
  139. ]),
  140. ).toBe(10_000);
  141. expect(
  142. resolveE2EWorkerModelStreamIdleTimeoutMs([
  143. "./test/e2e/conversation-session/models/conversation-session-thought-level-session-isolation.test.ts",
  144. ]),
  145. ).toBe(10_000);
  146. expect(
  147. resolveE2EWorkerModelStreamIdleTimeoutMs([
  148. "./test/e2e/conversation-session/background/conversation-session-background-subagent-rate-limit.test.ts",
  149. ]),
  150. ).toBeUndefined();
  151. expect(
  152. resolveE2EWorkerModelStreamIdleTimeoutMs(["./test/e2e/conversation-session/smoke.test.ts"]),
  153. ).toBeUndefined();
  154. });
  155. it("assigns each worker a separate Chromium profile and replaces stale profile args", () => {
  156. const rootDir = "/tmp/zcode-e2e/chromium-profiles";
  157. const firstProfile = resolveE2EWorkerChromiumProfileDir(rootDir, "0-1");
  158. const secondProfile = resolveE2EWorkerChromiumProfileDir(rootDir, "0/2");
  159. expect(firstProfile).not.toBe(secondProfile);
  160. expect(secondProfile).toBe(resolve(rootDir, "0-2"));
  161. expect(
  162. replaceChromeUserDataDirArg(
  163. ["--no-sandbox", "--user-data-dir=/tmp/stale-profile"],
  164. firstProfile,
  165. ),
  166. ).toEqual(["--no-sandbox", `--user-data-dir=${firstProfile}`]);
  167. });
  168. });