e2eAllCoverageRunner.test.ts 3.9 KB

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