From fbac18a1fc87fa58ebb534dd14ab96c49a21b88b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 04:53:48 +0100 Subject: [PATCH] test(tooling): share bundled channel entry scan --- .../bundled-plugin-build-entries.test.ts | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/test/scripts/bundled-plugin-build-entries.test.ts b/test/scripts/bundled-plugin-build-entries.test.ts index 7d5a7774994..03b015b7862 100644 --- a/test/scripts/bundled-plugin-build-entries.test.ts +++ b/test/scripts/bundled-plugin-build-entries.test.ts @@ -8,6 +8,27 @@ import { describe("bundled plugin build entries", () => { const bundledChannelEntrySources = ["index.ts", "channel-entry.ts", "setup-entry.ts"]; + const forEachBundledChannelEntry = ( + visit: (params: { entryPath: string; entry: string; pluginId: string }) => void, + ) => { + for (const dirent of fs.readdirSync("extensions", { withFileTypes: true })) { + if (!dirent.isDirectory()) { + continue; + } + + for (const sourceEntry of bundledChannelEntrySources) { + const entryPath = path.join("extensions", dirent.name, sourceEntry); + if (!fs.existsSync(entryPath)) { + continue; + } + visit({ + entryPath, + entry: fs.readFileSync(entryPath, "utf8"), + pluginId: dirent.name, + }); + } + } + }; it("includes manifest-less runtime core support packages in dist build entries", () => { const entries = listBundledPluginBuildEntries(); @@ -68,27 +89,16 @@ describe("bundled plugin build entries", () => { const offenders: string[] = []; const secretBackedPluginIds = new Set(); - for (const dirent of fs.readdirSync("extensions", { withFileTypes: true })) { - if (!dirent.isDirectory()) { - continue; + forEachBundledChannelEntry(({ entryPath, entry, pluginId }) => { + if (!entry.includes('exportName: "channelSecrets"')) { + return; } - - for (const sourceEntry of bundledChannelEntrySources) { - const entryPath = path.join("extensions", dirent.name, sourceEntry); - if (!fs.existsSync(entryPath)) { - continue; - } - const entry = fs.readFileSync(entryPath, "utf8"); - if (!entry.includes('exportName: "channelSecrets"')) { - continue; - } - secretBackedPluginIds.add(dirent.name); - if (entry.includes("./src/secret-contract.js")) { - offenders.push(entryPath); - } - expect(entry).toContain('specifier: "./secret-contract-api.js"'); + secretBackedPluginIds.add(pluginId); + if (entry.includes("./src/secret-contract.js")) { + offenders.push(entryPath); } - } + expect(entry).toContain('specifier: "./secret-contract-api.js"'); + }); expect(offenders).toEqual([]); @@ -102,28 +112,17 @@ describe("bundled plugin build entries", () => { it("keeps bundled channel entry metadata on packed top-level sidecars", () => { const offenders: string[] = []; - for (const dirent of fs.readdirSync("extensions", { withFileTypes: true })) { - if (!dirent.isDirectory()) { - continue; + forEachBundledChannelEntry(({ entryPath, entry }) => { + if ( + !entry.includes("defineBundledChannelEntry") && + !entry.includes("defineBundledChannelSetupEntry") + ) { + return; } - - for (const sourceEntry of bundledChannelEntrySources) { - const entryPath = path.join("extensions", dirent.name, sourceEntry); - if (!fs.existsSync(entryPath)) { - continue; - } - const entry = fs.readFileSync(entryPath, "utf8"); - if ( - !entry.includes("defineBundledChannelEntry") && - !entry.includes("defineBundledChannelSetupEntry") - ) { - continue; - } - if (/specifier:\s*["']\.\/src\//u.test(entry)) { - offenders.push(entryPath); - } + if (/specifier:\s*["']\.\/src\//u.test(entry)) { + offenders.push(entryPath); } - } + }); expect(offenders).toEqual([]); });