refactor: tighten extension test support boundaries

This commit is contained in:
Peter Steinberger
2026-04-28 03:52:16 +01:00
parent e5452a9c57
commit 129b996a4e
16 changed files with 223 additions and 70 deletions

View File

@@ -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"));