e2e-startup-credentials.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { isRequestSecuritySpec } from "./request-security-edition/index.js";
  2. export interface E2EStartupCredentialSeedOptions {
  3. specs?: string[];
  4. remoteProfile?: boolean;
  5. accountMock?: boolean;
  6. legacyAuthToken: string;
  7. restoredOAuthCredentials: Record<string, string>;
  8. }
  9. export function createE2EStartupCredentialSeed(
  10. options: E2EStartupCredentialSeedOptions,
  11. ): Record<string, string> {
  12. // 根因:远程回放 runner 默认假 OAuth 触发真实控制面的登录过期弹窗,SSH 前置入口被遮挡。
  13. // 回放从匿名 Personal Provider 开始;live case 仍在自己的步骤中导入真实凭据。
  14. if (options.remoteProfile) return {};
  15. const requiresZCodeJwt = options.specs?.some((spec) => {
  16. const fileName = spec.replaceAll("\\", "/").split("/").at(-1);
  17. return (
  18. // 营销投放 spec 按主题拆成 marketing-touch-delivery*.test.ts,领取用例都需要本地 JWT。
  19. fileName?.startsWith("marketing-touch-delivery") ||
  20. fileName === "conversation-session-share-popover.test.ts" ||
  21. fileName === "marketing-touch-entitlement.test.ts" ||
  22. // Rewards 专项走本地控制面,需要同时验证 OAuth 与 JWT 注入。
  23. fileName === "marketing-touch-rewards.test.ts" ||
  24. fileName === "jwt-401-auto-logout.test.ts" ||
  25. isRequestSecuritySpec(fileName) ||
  26. fileName === "coding-plan-upgrade-webview-refresh-provider.test.ts" ||
  27. fileName === "start-plan-manual-claim-experience.test.ts" ||
  28. fileName === "provider-family-responsive.test.ts" ||
  29. fileName === "conversation-session-offpeak-subagent-model-inheritance.test.ts" ||
  30. fileName === "conversation-session-off-peak-invalid-ticket.test.ts"
  31. );
  32. });
  33. // Bug 原因:默认假 OAuth 即使没有 JWT,仍会访问真实账号控制面并触发过期弹窗。
  34. // 默认空凭据;只有显式账号 mock 或 JWT 专项采用合成身份,不再逐条排除普通用例。
  35. if (!options.accountMock && !requiresZCodeJwt) return {};
  36. const restoredOAuthCredentials = { ...options.restoredOAuthCredentials };
  37. if (!requiresZCodeJwt) delete restoredOAuthCredentials.zcodejwttoken;
  38. return {
  39. auth_token: options.legacyAuthToken,
  40. ...restoredOAuthCredentials,
  41. };
  42. }