e2e-startup-credentials.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // 语音输入只对已登录用户显示,ticket 请求带 zcodejwttoken。
  26. fileName === "composer-voice-input.test.ts" ||
  27. isRequestSecuritySpec(fileName) ||
  28. fileName === "coding-plan-upgrade-webview-refresh-provider.test.ts" ||
  29. fileName === "start-plan-manual-claim-experience.test.ts" ||
  30. fileName === "provider-family-responsive.test.ts" ||
  31. fileName === "conversation-session-offpeak-subagent-model-inheritance.test.ts" ||
  32. // Team 回归只替代 HTTP,仍走真实凭据解析;缺少 JWT 会在创建前被拒绝。
  33. fileName === "conversation-session-off-peak-team-plan.test.ts" ||
  34. fileName === "conversation-session-off-peak-invalid-ticket.test.ts"
  35. );
  36. });
  37. // Bug 原因:默认假 OAuth 即使没有 JWT,仍会访问真实账号控制面并触发过期弹窗。
  38. // 默认空凭据;只有显式账号 mock 或 JWT 专项采用合成身份,不再逐条排除普通用例。
  39. if (!options.accountMock && !requiresZCodeJwt) return {};
  40. const restoredOAuthCredentials = { ...options.restoredOAuthCredentials };
  41. if (!requiresZCodeJwt) delete restoredOAuthCredentials.zcodejwttoken;
  42. return {
  43. auth_token: options.legacyAuthToken,
  44. ...restoredOAuthCredentials,
  45. };
  46. }