mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
refactor: tighten extension test support boundaries
This commit is contained in:
@@ -81,6 +81,14 @@ function findBundledPluginPublicSurfaceImports(source: string): string[] {
|
||||
].map((match) => match[0]);
|
||||
}
|
||||
|
||||
function findRelativeSrcImports(source: string): string[] {
|
||||
return [
|
||||
...source.matchAll(/from\s+["']((?:\.\.?\/)+src\/[^"']+)["']/g),
|
||||
...source.matchAll(/import\(\s*["']((?:\.\.?\/)+src\/[^"']+)["']\s*\)/g),
|
||||
...source.matchAll(/vi\.(?:mock|doMock)\s*\(\s*["']((?:\.\.?\/)+src\/[^"']+)["']/g),
|
||||
].map((match) => match[1]);
|
||||
}
|
||||
|
||||
function getImportBasename(importPath: string): string {
|
||||
return importPath.split("/").at(-1) ?? importPath;
|
||||
}
|
||||
@@ -229,6 +237,21 @@ describe("non-extension test boundaries", () => {
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps extension root test-support helpers from reaching into private src trees", () => {
|
||||
const files = walkCode(path.join(repoRoot, "extensions")).filter((file) =>
|
||||
/^extensions\/[^/]+\/test-support(?:\.ts|\/)/u.test(file),
|
||||
);
|
||||
|
||||
const offenders = files
|
||||
.map((file) => {
|
||||
const imports = findRelativeSrcImports(fs.readFileSync(path.join(repoRoot, file), "utf8"));
|
||||
return imports.length === 0 ? null : { file, imports };
|
||||
})
|
||||
.filter((entry): entry is { file: string; imports: string[] } => entry !== null);
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps bundled extension sources off deprecated channel config schema aliases", () => {
|
||||
const files = walkCode(path.join(repoRoot, "extensions"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user