e2e-formal-spec-selection.mjs 3.9 KB

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