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