|
1 | 1 | // Check Plugin Sdk Wildcard Reexports tests cover check plugin sdk wildcard reexports script behavior. |
2 | | -import { describe, expect, it } from "vitest"; |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { copyFileSync, mkdirSync, symlinkSync, writeFileSync } from "node:fs"; |
| 4 | +import path from "node:path"; |
| 5 | +import { afterEach, describe, expect, it } from "vitest"; |
3 | 6 | import { findPluginSdkWildcardReexports } from "../../scripts/check-plugin-sdk-wildcard-reexports.mts"; |
| 7 | +import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js"; |
| 8 | + |
| 9 | +const tempDirs = useAutoCleanupTempDirTracker(afterEach); |
4 | 10 |
|
5 | 11 | describe("check-plugin-sdk-wildcard-reexports", () => { |
6 | 12 | it("flags wildcard re-exports from plugin-sdk subpaths", () => { |
@@ -34,4 +40,50 @@ describe("check-plugin-sdk-wildcard-reexports", () => { |
34 | 40 | ), |
35 | 41 | ).toStrictEqual([]); |
36 | 42 | }); |
| 43 | + |
| 44 | + it("follows extension-root API barrel symlinks", () => { |
| 45 | + const root = tempDirs.make("openclaw-plugin-sdk-wildcard-"); |
| 46 | + const scriptsDir = path.join(root, "scripts"); |
| 47 | + const scriptsLibDir = path.join(scriptsDir, "lib"); |
| 48 | + const extensionDir = path.join(root, "extensions", "fixture"); |
| 49 | + mkdirSync(scriptsLibDir, { recursive: true }); |
| 50 | + mkdirSync(extensionDir, { recursive: true }); |
| 51 | + writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n'); |
| 52 | + writeFileSync(path.join(root, "pnpm-workspace.yaml"), "packages: []\n"); |
| 53 | + copyFileSync( |
| 54 | + new URL("../../scripts/check-plugin-sdk-wildcard-reexports.mts", import.meta.url), |
| 55 | + path.join(scriptsDir, "check-plugin-sdk-wildcard-reexports.mts"), |
| 56 | + ); |
| 57 | + for (const fileName of ["extension-wildcard-reexport-scanner.mts", "repo-root.mjs"]) { |
| 58 | + copyFileSync( |
| 59 | + new URL(`../../scripts/lib/${fileName}`, import.meta.url), |
| 60 | + path.join(scriptsLibDir, fileName), |
| 61 | + ); |
| 62 | + } |
| 63 | + writeFileSync( |
| 64 | + path.join(extensionDir, "actual-api.ts"), |
| 65 | + 'export * from "openclaw/plugin-sdk/foo";\n', |
| 66 | + ); |
| 67 | + symlinkSync("actual-api.ts", path.join(extensionDir, "api.ts")); |
| 68 | + |
| 69 | + const result = spawnSync( |
| 70 | + process.execPath, |
| 71 | + [ |
| 72 | + "--import", |
| 73 | + import.meta.resolve("tsx"), |
| 74 | + path.join(scriptsDir, "check-plugin-sdk-wildcard-reexports.mts"), |
| 75 | + "--json", |
| 76 | + ], |
| 77 | + { cwd: root, encoding: "utf8" }, |
| 78 | + ); |
| 79 | + |
| 80 | + expect(result.status).toBe(1); |
| 81 | + expect(JSON.parse(result.stdout)).toEqual([ |
| 82 | + { |
| 83 | + file: "extensions/fixture/api.ts", |
| 84 | + line: 1, |
| 85 | + text: 'export * from "openclaw/plugin-sdk/foo";', |
| 86 | + }, |
| 87 | + ]); |
| 88 | + }); |
37 | 89 | }); |
0 commit comments