mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 14:41:34 +00:00
test: smoke packed bundled channel entries
This commit is contained in:
@@ -14,6 +14,7 @@ afterEach(() => {
|
||||
}
|
||||
vi.resetModules();
|
||||
vi.doUnmock("jiti");
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("loadBundledEntryExportSync", () => {
|
||||
@@ -84,4 +85,39 @@ describe("loadBundledEntryExportSync", () => {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("can disable source-tree fallback for dist bundled entry checks", () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-channel-entry-contract-"));
|
||||
tempDirs.push(tempRoot);
|
||||
|
||||
fs.writeFileSync(path.join(tempRoot, "package.json"), '{"name":"openclaw"}\n', "utf8");
|
||||
const pluginRoot = path.join(tempRoot, "dist", "extensions", "telegram");
|
||||
const sourceRoot = path.join(tempRoot, "extensions", "telegram", "src");
|
||||
fs.mkdirSync(pluginRoot, { recursive: true });
|
||||
fs.mkdirSync(sourceRoot, { recursive: true });
|
||||
|
||||
const importerPath = path.join(pluginRoot, "index.js");
|
||||
fs.writeFileSync(importerPath, "export default {};\n", "utf8");
|
||||
fs.writeFileSync(
|
||||
path.join(sourceRoot, "secret-contract.ts"),
|
||||
"export const sentinel = 42;\n",
|
||||
"utf8",
|
||||
);
|
||||
|
||||
expect(
|
||||
loadBundledEntryExportSync<number>(pathToFileURL(importerPath).href, {
|
||||
specifier: "./src/secret-contract.js",
|
||||
exportName: "sentinel",
|
||||
}),
|
||||
).toBe(42);
|
||||
|
||||
vi.stubEnv("OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK", "1");
|
||||
|
||||
expect(() =>
|
||||
loadBundledEntryExportSync<number>(pathToFileURL(importerPath).href, {
|
||||
specifier: "./src/secret-contract.js",
|
||||
exportName: "sentinel",
|
||||
}),
|
||||
).toThrow(`resolved "${path.join(pluginRoot, "src", "secret-contract.js")}"`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,6 +67,11 @@ export type BundledChannelSetupEntryContract<TPlugin = ChannelPlugin> = {
|
||||
const nodeRequire = createRequire(import.meta.url);
|
||||
const jitiLoaders = new Map<string, ReturnType<typeof createJiti>>();
|
||||
const loadedModuleExports = new Map<string, unknown>();
|
||||
const disableBundledEntrySourceFallbackEnv = "OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK";
|
||||
|
||||
function isTruthyEnvFlag(value: string | undefined): boolean {
|
||||
return value !== undefined && !/^(?:0|false)$/iu.test(value.trim());
|
||||
}
|
||||
|
||||
function resolveSpecifierCandidates(modulePath: string): string[] {
|
||||
const ext = normalizeLowercaseStringOrEmpty(path.extname(modulePath));
|
||||
@@ -140,6 +145,9 @@ function resolveBundledEntryModuleCandidates(
|
||||
if (!importerPath.startsWith(distExtensionsRoot)) {
|
||||
return candidates;
|
||||
}
|
||||
if (isTruthyEnvFlag(process.env[disableBundledEntrySourceFallbackEnv])) {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
const pluginDirName = path.basename(importerDir);
|
||||
const sourcePluginRoot = path.join(packageRoot, "extensions", pluginDirName);
|
||||
|
||||
Reference in New Issue
Block a user