e2eAllCoverageRunner.test.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. import {
  5. createAllE2ECoverageRunPlan,
  6. hasRealUpstreamProviderConfig,
  7. } from "../scripts/run-all-e2e-coverage.mjs";
  8. describe("all E2E coverage runner", () => {
  9. it("runs formal, manual-review and the real provider smoke in one covered invocation", () => {
  10. const plan = createAllE2ECoverageRunPlan({
  11. args: ["--mochaOpts.timeout=120000"],
  12. env: { KEEP_ME: "1" },
  13. upstreamReady: true,
  14. sshReady: false,
  15. });
  16. expect(plan.command).toBe(process.platform === "win32" ? "pnpm.cmd" : "pnpm");
  17. expect(plan.env).toMatchObject({
  18. KEEP_ME: "1",
  19. ZCODE_E2E_COVERAGE: "1",
  20. ZCODE_E2E_MANUAL_REVIEW: "1",
  21. });
  22. expect(plan.args).toEqual([
  23. "test:e2e",
  24. "--",
  25. "--spec",
  26. "./test/e2e/**/*.test.ts",
  27. "--exclude",
  28. "./test/e2e/conversation-session/**/conversation-session-ssh-remote*.test.ts",
  29. "--exclude",
  30. "./test/e2e/conversation-session/**/manual-review/**/conversation-session-ssh-remote*.test.ts",
  31. "--mochaOpts.timeout=120000",
  32. ]);
  33. expect(plan.notes).toEqual([]);
  34. });
  35. it("excludes the real provider smoke when no non-placeholder key is available", () => {
  36. const plan = createAllE2ECoverageRunPlan({
  37. args: [],
  38. env: {},
  39. upstreamReady: false,
  40. sshReady: false,
  41. });
  42. expect(plan.args).toContain("./test/e2e/infrastructure/smoke/upstream-provider.test.ts");
  43. expect(plan.args).toContain("--exclude");
  44. expect(plan.notes).toEqual([
  45. "skipping real provider smoke: configure E2E_PROVIDER_BASE_URL and E2E_PROVIDER_API_KEY to include it",
  46. ]);
  47. });
  48. it("keeps SSH cases when their environment is available", () => {
  49. const plan = createAllE2ECoverageRunPlan({
  50. args: [],
  51. env: {},
  52. upstreamReady: true,
  53. sshReady: true,
  54. });
  55. expect(plan.args).not.toContain("--exclude");
  56. });
  57. it("exposes the same reusable command at the root and desktop package", () => {
  58. const desktopPackage = JSON.parse(
  59. readFileSync(resolve(process.cwd(), "packages/desktop/package.json"), "utf-8"),
  60. ) as { scripts: Record<string, string> };
  61. const rootPackage = JSON.parse(
  62. readFileSync(resolve(process.cwd(), "package.json"), "utf-8"),
  63. ) as { scripts: Record<string, string> };
  64. expect(desktopPackage.scripts["test:e2e:all:coverage"]).toBe(
  65. "node scripts/run-all-e2e-coverage.mjs",
  66. );
  67. expect(rootPackage.scripts["test:e2e:all:coverage"]).toBe(
  68. "pnpm --filter @zcode/desktop test:e2e:all:coverage",
  69. );
  70. });
  71. // 仓库不再提供共享 key:示例文件只列变量名,真实 key 只能来自 shell 或本机 .env.e2e.local。
  72. // 真实供应商由环境变量给出地址与 key,两者齐全才纳入真实 smoke;本机 env 文件不参与本用例。
  73. it("requires both E2E_PROVIDER_BASE_URL and a real E2E_PROVIDER_API_KEY", () => {
  74. const baseUrl = "https://provider.example.invalid/anthropic";
  75. const check = (env: Record<string, string>) => hasRealUpstreamProviderConfig(env, []);
  76. expect(check({ E2E_PROVIDER_API_KEY: "real-key", E2E_PROVIDER_BASE_URL: baseUrl })).toBe(true);
  77. expect(check({ E2E_PROVIDER_API_KEY: "real-key" })).toBe(false);
  78. expect(check({ E2E_PROVIDER_BASE_URL: baseUrl })).toBe(false);
  79. expect(check({ E2E_PROVIDER_API_KEY: "e2e-fixture-key", E2E_PROVIDER_BASE_URL: baseUrl })).toBe(
  80. false,
  81. );
  82. });
  83. it("ships an example env file without a default key", () => {
  84. const example = readFileSync(
  85. resolve(import.meta.dirname, "../../../.env.e2e.local.example"),
  86. "utf8",
  87. );
  88. for (const name of ["BASE_URL", "API_KEY", "MODEL", "SECONDARY_MODEL"]) {
  89. expect(example).toMatch(new RegExp(`^E2E_PROVIDER_${name}=$`, "m"));
  90. }
  91. });
  92. });