e2e-before-session.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132
  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. startCodingPlanUpgradeMockIfNeeded: (specs: string[]) => Promise<void>;
  10. startUpstreamHttpIfNeeded: (specs: string[]) => Promise<void>;
  11. startPluginCdnZipFixtureIfNeeded: (specs: string[]) => Promise<void>;
  12. startOffPeakMockIfNeeded: (specs: string[]) => Promise<void>;
  13. }
  14. export async function runE2EBeforeSessionSetup(options: E2EBeforeSessionSetupOptions) {
  15. options.recordBeforeSession(options.cid, options.specs);
  16. // 修复原因:并行 worker 的日志目录在 recordBeforeSession 内按 cid 设置;随后再配置
  17. // agent server,子进程才能继承 worker 专属的 ZCODE_LOG_DIR,而不会写到共享日志文件。
  18. options.configureAgentServerEnv();
  19. await options.startCodingPlanTeamMockIfNeeded(options.specs);
  20. // Bug 根因:Coding Plan mock 由 launcher 进程在整个 WDIO run 内共享;只在创建
  21. // server 时读取 configured specs,会让 AUTH-04 的 OAuth/catalog 模式污染后续 spec。
  22. // 每个 worker session 启动 Electron 前按自己的 spec 重置模式,保持 case 隔离。
  23. await options.configureCodingPlanTeamMockForSpecs(options.specs);
  24. await options.startUpstreamHttpIfNeeded(options.specs);
  25. await options.startCodingPlanUpgradeMockIfNeeded(options.specs);
  26. await options.startPluginCdnZipFixtureIfNeeded(options.specs);
  27. await options.startOffPeakMockIfNeeded(options.specs);
  28. // 修复原因:HOME 删除、重建和 fixture seed 是 Electron session 启动的前置事务;
  29. // 这里必须等待 reset 完成,否则 Windows 文件锁重试期间会用旧 HOME 启动新 Electron。
  30. await options.resetHome(options.specs);
  31. }