e2e-formal-spec-selection.mjs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // 直接读取内部队列会让开源 WDIO 配置加载失败;清单由原队列生成,目标判定保持一致。
  2. import remoteTargetSpecs from "./e2e-remote-target-specs.json" with { type: "json" };
  3. export const SSH_FORMAL_SPEC_GLOB =
  4. "./test/e2e/conversation-session/**/conversation-session-ssh-remote*.test.ts";
  5. // Bug 根因:逐领域枚举漏掉新增候选目录,导致单进程全量与分片正式集合不一致。
  6. export const MANUAL_REVIEW_SPEC_GLOB = "./test/e2e/**/manual-review/**/*.test.ts";
  7. const REQUIRED_SSH_E2E_ENV = [
  8. "ZCODE_E2E_SSH_HOST",
  9. "ZCODE_E2E_SSH_USERNAME",
  10. "ZCODE_E2E_SSH_PASSWORD",
  11. ];
  12. export function hasRequiredSshE2EEnvironment(env) {
  13. return REQUIRED_SSH_E2E_ENV.every((name) => env[name]?.trim());
  14. }
  15. // 修复原因:远程队列 case 由 harness 按 case 准备干净目标(ZCODE_E2E_SSH_CONTAINER 是其标记)。
  16. // Windows CI 只有共享 SSH 凭据时仍纳入它们,多个分片在同一主机上互相升级/抢占,
  17. // 表现为"更新中"、source-server-upgrade-required 与缺少容器。没有 harness 时整体排除。
  18. function hasSshHarnessE2EEnvironment(env) {
  19. return hasRequiredSshE2EEnvironment(env) && Boolean(env.ZCODE_E2E_SSH_CONTAINER?.trim());
  20. }
  21. function isRemoteQueueFormalSpec(spec) {
  22. const normalized = spec.replaceAll("\\", "/");
  23. return remoteTargetSpecs.some((candidate) => normalized.endsWith(`/test/e2e/${candidate}`));
  24. }
  25. export function isSshFormalSpec(spec) {
  26. const normalized = spec.replaceAll("\\", "/");
  27. return (
  28. /\/conversation-session\/(?:[^/]+\/)*conversation-session-ssh-remote/u.test(normalized) ||
  29. isRemoteQueueFormalSpec(normalized)
  30. );
  31. }
  32. /** 默认正式集合的环境准入:队列 case 要 harness,尚未入队的 ssh-remote 只要凭据。 */
  33. export function isFormalSpecAdmittedByEnvironment(spec, env) {
  34. // 场景 glob 会递归命中候选;分片展开为显式文件前必须排除,不能把目录迁移当作转正。
  35. if (spec.replaceAll("\\", "/").includes("/manual-review/")) return false;
  36. if (isRemoteQueueFormalSpec(spec)) return hasSshHarnessE2EEnvironment(env);
  37. if (isSshFormalSpec(spec)) return hasRequiredSshE2EEnvironment(env);
  38. return true;
  39. }
  40. export function resolveEnvironmentGatedFormalSpecExcludes({ env, targeted }) {
  41. // 修复原因:SSH P0 依赖真实服务器,默认全量在无凭据时纳入只会把环境缺失
  42. // 误记为三个产品失败;显式定向运行仍保留 helper 的缺变量 fail-closed 提示。
  43. if (targeted) return [];
  44. return [
  45. ...(hasRequiredSshE2EEnvironment(env) ? [] : [SSH_FORMAL_SPEC_GLOB]),
  46. ...(hasSshHarnessE2EEnvironment(env)
  47. ? []
  48. : remoteTargetSpecs.map((spec) => `./test/e2e/${spec}`)),
  49. ];
  50. }
  51. /** 目录 glob 是批量回归;只有逐个指定文件才覆盖环境门禁并按缺配置报错。 */
  52. export function isExplicitE2ESpecSelection(specs) {
  53. return specs.length > 0 && specs.every((spec) => !/[*?[{]/u.test(spec));
  54. }