pluginE2EAdmissionScripts.test.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { spawnSync } from "node:child_process";
  2. import { mkdirSync, rmSync, writeFileSync } from "node:fs";
  3. import { resolve } from "node:path";
  4. import { afterAll, beforeAll, describe, expect, it } from "vitest";
  5. const repoRoot = process.cwd();
  6. const desktopDir = resolve(repoRoot, "packages/desktop");
  7. const pendingSpec =
  8. "./packages/desktop/test/e2e/plugins/manual-review/pending/plugin-management-personal-lifecycle.test.ts";
  9. const manualOnlySpec =
  10. "./packages/desktop/test/e2e/plugins/manual-review/pending/plugin-cdn-zip-official-cdn-smoke.test.ts";
  11. const fixtureCheckCase = "plugin-fixture-check-probe";
  12. const formalProbeSpec = resolve(desktopDir, "test/e2e/plugins", `${fixtureCheckCase}.test.ts`);
  13. const formalProbeFixture = resolve(
  14. desktopDir,
  15. "test/e2e/fixtures/upstream/plugin-management",
  16. `${fixtureCheckCase}.json`,
  17. );
  18. const formalProbeManifest = resolve(
  19. desktopDir,
  20. "test/e2e/fixtures/cases/plugins",
  21. `${fixtureCheckCase}.json`,
  22. );
  23. beforeAll(() => {
  24. writeProbeFile(formalProbeSpec, 'describe("E2E_PLUGIN_FIXTURE_CHECK_PROBE", () => {});\n');
  25. writeProbeFile(
  26. formalProbeFixture,
  27. `${JSON.stringify(
  28. {
  29. version: 1,
  30. // 修复原因:pending 与 formal 共用 canonical fixture identity,probe 也必须模拟完整合同。
  31. caseName: fixtureCheckCase,
  32. spec: `./test/e2e/plugins/${fixtureCheckCase}.test.ts`,
  33. fixtures: [
  34. {
  35. id: fixtureCheckCase,
  36. match: {
  37. method: "POST",
  38. pathIncludes: "/messages",
  39. bodyIncludes: ["E2E_PLUGIN_FIXTURE_CHECK_PROBE"],
  40. },
  41. response: { statusCode: 200, text: "ok" },
  42. },
  43. ],
  44. },
  45. null,
  46. 2,
  47. )}\n`,
  48. );
  49. writeProbeFile(
  50. formalProbeManifest,
  51. `${JSON.stringify(
  52. {
  53. version: 1,
  54. caseName: fixtureCheckCase,
  55. spec: `./test/e2e/plugins/${fixtureCheckCase}.test.ts`,
  56. providerFixtures: [
  57. "./test/e2e/fixtures/upstream/common.json",
  58. `./test/e2e/fixtures/upstream/plugin-management/${fixtureCheckCase}.json`,
  59. ],
  60. requests: [
  61. {
  62. id: fixtureCheckCase,
  63. kind: "main",
  64. source: "synthetic",
  65. syntheticReason:
  66. "Exercise plugin fixture-check routing without a promoted product case.",
  67. },
  68. ],
  69. },
  70. null,
  71. 2,
  72. )}\n`,
  73. );
  74. });
  75. afterAll(() => {
  76. rmSync(formalProbeSpec, { force: true });
  77. rmSync(formalProbeFixture, { force: true });
  78. rmSync(formalProbeManifest, { force: true });
  79. });
  80. describe("plugin lifecycle E2E admission scripts", () => {
  81. it("dry-runs promotion but requires explicit human review before applying", () => {
  82. const dryRun = runScript("promote-plugin-e2e.mjs", ["--spec", pendingSpec]);
  83. expect(dryRun.status).toBe(0);
  84. expect(dryRun.stdout).toContain("Dry run plugin E2E promotion");
  85. expect(dryRun.stdout).toContain(
  86. "Do not apply until screenshots and behavior have passed human review",
  87. );
  88. const unreviewedApply = runScript("promote-plugin-e2e.mjs", ["--spec", pendingSpec, "--apply"]);
  89. expect(unreviewedApply.status).toBe(1);
  90. expect(unreviewedApply.stdout).toContain("Use --reviewed when applying plugin promotion");
  91. });
  92. it("rejects Docker admission for a pending manual-review spec", () => {
  93. const result = runScript("admit-plugin-e2e-docker.mjs", ["--spec", pendingSpec]);
  94. expect(result.status).toBe(1);
  95. expect(result.stdout).toContain("Spec must be a promoted formal plugin case");
  96. });
  97. it("routes promoted plugin specs to plugin case manifests and fixtures", () => {
  98. const result = runScript("check-e2e-fixtures.mjs", ["--spec", formalProbeSpec]);
  99. expect(result.status).toBe(0);
  100. expect(result.stdout).toContain(`Case: ${fixtureCheckCase}`);
  101. expect(result.stdout).toContain("Fixture check passed");
  102. });
  103. it("never promotes the real official CDN manual smoke", () => {
  104. const result = runScript("promote-plugin-e2e.mjs", ["--spec", manualOnlySpec, "--reviewed"]);
  105. expect(result.status).toBe(1);
  106. expect(result.stdout).toContain("manual-only and cannot be promoted");
  107. });
  108. });
  109. function runScript(scriptName: string, args: string[]) {
  110. return spawnSync(
  111. process.execPath,
  112. [resolve(repoRoot, "packages/desktop/scripts", scriptName), ...args],
  113. { cwd: repoRoot, encoding: "utf-8" },
  114. );
  115. }
  116. function writeProbeFile(path: string, content: string): void {
  117. mkdirSync(resolve(path, ".."), { recursive: true });
  118. writeFileSync(path, content, "utf-8");
  119. }