e2eWorkerIsolation.test.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. ["./test/e2e/conversation-session/conversation-session-background-subagent-rate-limit.test.ts"],
  45. undefined,
  46. );
  47. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  48. applyE2EWorkerModelRetryEnv(env, ["./test/e2e/conversation-session/smoke.test.ts"], undefined);
  49. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBeUndefined();
  50. applyE2EWorkerModelRetryEnv(
  51. env,
  52. ["./test/e2e/conversation-session/conversation-session-background-subagent-rate-limit.test.ts"],
  53. "4",
  54. );
  55. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  56. applyE2EWorkerModelRetryEnv(
  57. env,
  58. [
  59. "./test/e2e/conversation-session/conversation-session-model-switch-restore-repro.test.ts",
  60. ],
  61. "4",
  62. );
  63. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("0");
  64. applyE2EWorkerModelRetryEnv(env, ["./test/e2e/conversation-session/smoke.test.ts"], "4");
  65. expect(env.ZCODE_MODEL_RETRY_MAX_RETRIES).toBe("4");
  66. });
  67. it("routes BG25 and I55 through replay proxy while keeping BG26 direct", () => {
  68. const env: Record<string, string | undefined> = {
  69. ZCODE_HTTP_PROXY: "http://configured-proxy:8080",
  70. ZCODE_NO_PROXY: "localhost",
  71. };
  72. applyE2EWorkerReplayProxyEnv(
  73. env,
  74. ["./test/e2e/conversation-session/conversation-session-background-subagent-rate-limit.test.ts"],
  75. "http://127.0.0.1:43123",
  76. {
  77. httpProxy: "http://configured-proxy:8080",
  78. noProxy: "localhost",
  79. },
  80. );
  81. expect(env.ZCODE_HTTP_PROXY).toBe("http://configured-proxy:8080");
  82. expect(env.ZCODE_NO_PROXY).toBe("localhost");
  83. applyE2EWorkerReplayProxyEnv(
  84. env,
  85. [
  86. "./test/e2e/conversation-session/conversation-session-subagent-respond-to-coordinator.test.ts",
  87. ],
  88. "http://127.0.0.1:43126",
  89. {
  90. httpProxy: "http://configured-proxy:8080",
  91. noProxy: "localhost",
  92. },
  93. );
  94. expect(env.ZCODE_HTTP_PROXY).toBe("http://127.0.0.1:43126");
  95. expect(env.ZCODE_NO_PROXY).toBe("");
  96. applyE2EWorkerReplayProxyEnv(
  97. env,
  98. ["./test/e2e/conversation-session/conversation-session-thought-level-session-isolation.test.ts"],
  99. "http://127.0.0.1:43125",
  100. {
  101. httpProxy: "http://configured-proxy:8080",
  102. noProxy: "localhost",
  103. },
  104. );
  105. expect(env.ZCODE_HTTP_PROXY).toBe("http://127.0.0.1:43125");
  106. expect(env.ZCODE_NO_PROXY).toBe("");
  107. applyE2EWorkerReplayProxyEnv(
  108. env,
  109. ["./test/e2e/conversation-session/smoke.test.ts"],
  110. "http://127.0.0.1:43124",
  111. {
  112. httpProxy: "http://configured-proxy:8080",
  113. noProxy: "localhost",
  114. },
  115. );
  116. expect(env.ZCODE_HTTP_PROXY).toBe("http://configured-proxy:8080");
  117. expect(env.ZCODE_NO_PROXY).toBe("localhost");
  118. applyE2EWorkerReplayProxyEnv(
  119. env,
  120. ["./test/e2e/conversation-session/smoke.test.ts"],
  121. "http://127.0.0.1:43124",
  122. { httpProxy: undefined, noProxy: undefined },
  123. );
  124. expect(env.ZCODE_HTTP_PROXY).toBeUndefined();
  125. expect(env.ZCODE_NO_PROXY).toBeUndefined();
  126. });
  127. it("shortens stream idle recovery only for BG25 and I55 replay workers", () => {
  128. expect(
  129. resolveE2EWorkerModelStreamIdleTimeoutMs([
  130. "./test/e2e/conversation-session/conversation-session-subagent-respond-to-coordinator.test.ts",
  131. ]),
  132. ).toBe(10_000);
  133. expect(
  134. resolveE2EWorkerModelStreamIdleTimeoutMs([
  135. "./test/e2e/conversation-session/conversation-session-thought-level-session-isolation.test.ts",
  136. ]),
  137. ).toBe(10_000);
  138. expect(
  139. resolveE2EWorkerModelStreamIdleTimeoutMs([
  140. "./test/e2e/conversation-session/conversation-session-background-subagent-rate-limit.test.ts",
  141. ]),
  142. ).toBeUndefined();
  143. expect(
  144. resolveE2EWorkerModelStreamIdleTimeoutMs([
  145. "./test/e2e/conversation-session/smoke.test.ts",
  146. ]),
  147. ).toBeUndefined();
  148. });
  149. it("assigns each worker a separate Chromium profile and replaces stale profile args", () => {
  150. const rootDir = "/tmp/zcode-e2e/chromium-profiles";
  151. const firstProfile = resolveE2EWorkerChromiumProfileDir(rootDir, "0-1");
  152. const secondProfile = resolveE2EWorkerChromiumProfileDir(rootDir, "0/2");
  153. expect(firstProfile).not.toBe(secondProfile);
  154. expect(secondProfile).toBe(resolve(rootDir, "0-2"));
  155. expect(
  156. replaceChromeUserDataDirArg(
  157. ["--no-sandbox", "--user-data-dir=/tmp/stale-profile"],
  158. firstProfile,
  159. ),
  160. ).toEqual(["--no-sandbox", `--user-data-dir=${firstProfile}`]);
  161. });
  162. });