e2e-before-session.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. export interface E2EBeforeSessionSetupOptions {
  2. cid: string;
  3. specs: string[];
  4. configureAgentServerEnv: () => void;
  5. configureCodingPlanTeamMockForSpecs: (specs: string[]) => Promise<void>;
  6. recordBeforeSession: (cid: string, specs: string[]) => void;
  7. resetHome: (specs: string[]) => Promise<void>;
  8. startCodingPlanTeamMockIfNeeded: (specs: string[]) => Promise<void>;
  9. startCodingPlanDataPlaneProxyIfNeeded: (specs: string[]) => Promise<void>;
  10. startCodingPlanUpgradeMockIfNeeded: (specs: string[]) => Promise<void>;
  11. startUpstreamHttpIfNeeded: (specs: string[]) => Promise<void>;
  12. startPluginCdnZipFixtureIfNeeded: (specs: string[]) => Promise<void>;
  13. startOffPeakMockIfNeeded: (specs: string[]) => Promise<void>;
  14. }
  15. export async function runE2EBeforeSessionSetup(options: E2EBeforeSessionSetupOptions) {
  16. options.recordBeforeSession(options.cid, options.specs);
  17. // 修复原因:并行 worker 的日志目录在 recordBeforeSession 内按 cid 设置;随后再配置
  18. // agent server,子进程才能继承 worker 专属的 ZCODE_LOG_DIR,而不会写到共享日志文件。
  19. options.configureAgentServerEnv();
  20. await options.startCodingPlanTeamMockIfNeeded(options.specs);
  21. // Bug 根因:Coding Plan mock 由 launcher 进程在整个 WDIO run 内共享;只在创建
  22. // server 时读取 configured specs,会让 AUTH-04 的 OAuth/catalog 模式污染后续 spec。
  23. // 每个 worker session 启动 Electron 前按自己的 spec 重置模式,保持 case 隔离。
  24. await options.configureCodingPlanTeamMockForSpecs(options.specs);
  25. await options.startUpstreamHttpIfNeeded(options.specs);
  26. // 混合批次的 ToolSearch 不能关闭其他 worker 的账号数据面回放;代理在当前
  27. // worker 的上游网络配置完成后启动,避免被通用 replay 初始化恢复成直连。
  28. await options.startCodingPlanDataPlaneProxyIfNeeded(options.specs);
  29. await options.startCodingPlanUpgradeMockIfNeeded(options.specs);
  30. await options.startPluginCdnZipFixtureIfNeeded(options.specs);
  31. await options.startOffPeakMockIfNeeded(options.specs);
  32. // 修复原因:HOME 删除、重建和 fixture seed 是 Electron session 启动的前置事务;
  33. // 这里必须等待 reset 完成,否则 Windows 文件锁重试期间会用旧 HOME 启动新 Electron。
  34. await options.resetHome(options.specs);
  35. }