Skip to content

Commit d62e443

Browse files
committed
fix(plugins): honor parent bundled source overlays
1 parent 817f0cd commit d62e443

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎src/channels/plugins/package-state-probes.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,52 @@ describe("channel package-state probes", () => {
214214
).toBe(true);
215215
});
216216

217+
it("preserves parent-mounted source overlay precedence over packaged package-state probes", () => {
218+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-package-state-parent-overlay-"));
219+
tempDirs.push(root);
220+
const extensionsRoot = path.join(root, "extensions");
221+
const sourceRoot = path.join(extensionsRoot, "matrix");
222+
const builtRoot = path.join(root, "dist", "extensions", "matrix");
223+
fs.mkdirSync(sourceRoot, { recursive: true });
224+
fs.mkdirSync(builtRoot, { recursive: true });
225+
fs.writeFileSync(
226+
path.join(sourceRoot, "auth-presence.js"),
227+
"module.exports.hasAnyMatrixAuth = () => true;\n",
228+
"utf8",
229+
);
230+
fs.writeFileSync(
231+
path.join(builtRoot, "auth-presence.js"),
232+
"module.exports.hasAnyMatrixAuth = () => false;\n",
233+
"utf8",
234+
);
235+
isBundledSourceOverlayPathMock.mockImplementation(
236+
({ sourcePath }: { sourcePath: string }) => path.resolve(sourcePath) === extensionsRoot,
237+
);
238+
239+
listChannelCatalogEntriesMock.mockReturnValue([
240+
{
241+
pluginId: "matrix",
242+
origin: "bundled",
243+
rootDir: sourceRoot,
244+
channel: {
245+
id: "matrix",
246+
persistedAuthState: {
247+
specifier: "./auth-presence",
248+
exportName: "hasAnyMatrixAuth",
249+
},
250+
},
251+
} satisfies PluginChannelCatalogEntry,
252+
]);
253+
254+
expect(
255+
hasBundledChannelPackageState({
256+
metadataKey: "persistedAuthState",
257+
channelId: "matrix",
258+
cfg: {},
259+
}),
260+
).toBe(true);
261+
});
262+
217263
it("tries dist-runtime package-state probes before falling back to source", () => {
218264
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-package-state-runtime-"));
219265
tempDirs.push(root);

‎src/channels/plugins/package-state-probes.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,20 @@ function resolveSourceBundledPluginRoot(rootDir: string): {
9393
};
9494
}
9595

96+
function isBundledSourceOverlayPluginRoot(rootDir: string): boolean {
97+
const pluginRoot = path.resolve(rootDir);
98+
return (
99+
isBundledSourceOverlayPath({ sourcePath: pluginRoot }) ||
100+
(path.basename(path.dirname(pluginRoot)) === "extensions" &&
101+
isBundledSourceOverlayPath({ sourcePath: path.dirname(pluginRoot) }))
102+
);
103+
}
104+
96105
function listBuiltBundledPackageStateModules(params: {
97106
rootDir: string;
98107
specifier: string;
99108
}): ChannelPackageStateModuleLocation[] {
100-
if (isBundledSourceOverlayPath({ sourcePath: params.rootDir })) {
109+
if (isBundledSourceOverlayPluginRoot(params.rootDir)) {
101110
return [];
102111
}
103112
const sourceRoot = resolveSourceBundledPluginRoot(params.rootDir);

0 commit comments

Comments
 (0)