mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 06:50:22 +00:00
fix: guard bundled channel runtime against TDZ imports
This commit is contained in:
@@ -18,4 +18,24 @@ describe("bundled channel config runtime", () => {
|
||||
expect(runtimeModule.getBundledChannelConfigSchemaMap().get("msteams")).toBeDefined();
|
||||
expect(runtimeModule.getBundledChannelRuntimeMap().get("msteams")).toBeDefined();
|
||||
});
|
||||
|
||||
it("falls back to static channel schemas when bundled plugin access hits a TDZ-style ReferenceError", async () => {
|
||||
vi.resetModules();
|
||||
vi.doMock("../channels/plugins/bundled.js", () => {
|
||||
const mockModule = {} as { bundledChannelPlugins?: unknown };
|
||||
Object.defineProperty(mockModule, "bundledChannelPlugins", {
|
||||
enumerable: true,
|
||||
get() {
|
||||
throw new ReferenceError("Cannot access 'bundledChannelPlugins' before initialization.");
|
||||
},
|
||||
});
|
||||
return mockModule;
|
||||
});
|
||||
|
||||
const runtime = await import("./bundled-channel-config-runtime.js");
|
||||
const configSchemaMap = runtime.getBundledChannelConfigSchemaMap();
|
||||
|
||||
expect(configSchemaMap.has("msteams")).toBe(true);
|
||||
expect(configSchemaMap.has("whatsapp")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,9 +71,18 @@ function buildBundledChannelMaps(
|
||||
}
|
||||
|
||||
function readBundledChannelPlugins(): readonly BundledChannelPluginShape[] | undefined {
|
||||
return Array.isArray(bundledChannelModule.bundledChannelPlugins)
|
||||
? (bundledChannelModule.bundledChannelPlugins as readonly BundledChannelPluginShape[])
|
||||
: undefined;
|
||||
try {
|
||||
return Array.isArray(bundledChannelModule.bundledChannelPlugins)
|
||||
? (bundledChannelModule.bundledChannelPlugins as readonly BundledChannelPluginShape[])
|
||||
: undefined;
|
||||
} catch (error) {
|
||||
// Circular bundled channel imports can transiently hit TDZ during test/bootstrap
|
||||
// initialization. Fall back to metadata/static schemas until the registry is ready.
|
||||
if (error instanceof ReferenceError) {
|
||||
return undefined;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function getBundledChannelMaps(): BundledChannelMaps {
|
||||
|
||||
Reference in New Issue
Block a user