Skip to content

Commit 54734a3

Browse files
ampagentsteipete
authored andcommitted
fix(scripts): preserve symlinked API barrels
1 parent 522f06f commit 54734a3

4 files changed

Lines changed: 74 additions & 2 deletions

File tree

‎scripts/lib/extension-wildcard-reexport-scanner.mts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ export type ExtensionWildcardReexportPolicy = {
2121
remediationMessage: string;
2222
};
2323

24+
async function isFileFollowingLinks(filePath: string): Promise<boolean> {
25+
try {
26+
return (await fs.stat(filePath)).isFile();
27+
} catch (error) {
28+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
29+
return false;
30+
}
31+
throw error;
32+
}
33+
}
34+
2435
async function listGuardedFiles(policy: ExtensionWildcardReexportPolicy) {
2536
const files: string[] = [];
2637
const recursive = policy.fileScope === "all-extension-api-files";
@@ -39,7 +50,12 @@ async function listGuardedFiles(policy: ExtensionWildcardReexportPolicy) {
3950
await visit(filePath, depth + 1);
4051
continue;
4152
}
42-
if ((recursive || depth === 1) && entry.isFile() && guardedFileNames.has(entry.name)) {
53+
if (!guardedFileNames.has(entry.name) || (!recursive && depth !== 1)) {
54+
continue;
55+
}
56+
// The root-only SDK guard historically follows API barrel symlinks; the
57+
// recursive local-barrel guard intentionally retains Dirent semantics.
58+
if (recursive ? entry.isFile() : await isFileFollowingLinks(filePath)) {
4359
files.push(filePath);
4460
}
4561
}

‎test/scripts/check-plugin-sdk-wildcard-reexports.test.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// 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";
36
import { findPluginSdkWildcardReexports } from "../../scripts/check-plugin-sdk-wildcard-reexports.mts";
7+
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
8+
9+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
410

511
describe("check-plugin-sdk-wildcard-reexports", () => {
612
it("flags wildcard re-exports from plugin-sdk subpaths", () => {
@@ -34,4 +40,50 @@ describe("check-plugin-sdk-wildcard-reexports", () => {
3440
),
3541
).toStrictEqual([]);
3642
});
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+
});
3789
});

‎test/scripts/test-projects.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ describe("scripts/test-projects changed-target routing", () => {
969969

970970
it.each([
971971
"test/scripts/check-extension-package-tsc-boundary.test.ts",
972+
"test/scripts/check-plugin-sdk-wildcard-reexports.test.ts",
972973
"test/scripts/control-ui-i18n.test.ts",
973974
])("routes process-group test %s to the isolated tooling shard", (testFile) => {
974975
expectSingleVitestRunPlan(buildVitestRunPlans([testFile]), {
@@ -1370,6 +1371,7 @@ describe("scripts/test-projects changed-target routing", () => {
13701371
forwardedArgs: [],
13711372
includePatterns: [
13721373
"test/scripts/check-extension-package-tsc-boundary.test.ts",
1374+
"test/scripts/check-plugin-sdk-wildcard-reexports.test.ts",
13731375
"test/scripts/control-ui-i18n.test.ts",
13741376
"test/scripts/openclaw-e2e-instance.test.ts",
13751377
],
@@ -1556,6 +1558,7 @@ describe("scripts/test-projects changed-target routing", () => {
15561558
forwardedArgs: [],
15571559
includePatterns: [
15581560
"test/scripts/check-extension-package-tsc-boundary.test.ts",
1561+
"test/scripts/check-plugin-sdk-wildcard-reexports.test.ts",
15591562
"test/scripts/control-ui-i18n.test.ts",
15601563
"test/scripts/openclaw-e2e-instance.test.ts",
15611564
],

‎test/vitest/vitest.tooling-isolated-paths.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const toolingIsolatedTestFiles = [
44
"test/plugins/bundled-provider-auth-literal-parity.2.test.ts",
55
"test/plugins/bundled-provider-auth-literal-parity.3.test.ts",
66
"test/scripts/check-extension-package-tsc-boundary.test.ts",
7+
"test/scripts/check-plugin-sdk-wildcard-reexports.test.ts",
78
"test/scripts/control-ui-i18n.test.ts",
89
"test/scripts/openclaw-e2e-instance.test.ts",
910
];

0 commit comments

Comments
 (0)