fix: resolve acpx plugin root from shared chunks

This commit is contained in:
Ayaan Zaidi
2026-04-05 11:36:04 +05:30
parent e25693315e
commit f039bbf2aa
2 changed files with 26 additions and 1 deletions

View File

@@ -64,6 +64,22 @@ describe("acpx plugin config parsing", () => {
}
});
it("resolves workspace plugin root from dist shared chunks", () => {
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), "acpx-root-shared-dist-"));
const workspacePluginRoot = bundledPluginRootAt(repoRoot, "acpx");
try {
fs.mkdirSync(path.join(repoRoot, "dist"), { recursive: true });
fs.mkdirSync(workspacePluginRoot, { recursive: true });
fs.writeFileSync(path.join(workspacePluginRoot, "package.json"), "{}\n", "utf8");
fs.writeFileSync(path.join(workspacePluginRoot, "openclaw.plugin.json"), "{}\n", "utf8");
const moduleUrl = pathToFileURL(path.join(repoRoot, "dist", "register.runtime.js")).href;
expect(resolveAcpxPluginRoot(moduleUrl)).toBe(workspacePluginRoot);
} finally {
fs.rmSync(repoRoot, { recursive: true, force: true });
}
});
it("resolves bundled acpx with pinned version by default", () => {
const resolved = resolveAcpxPluginConfig({
rawConfig: {

View File

@@ -62,11 +62,20 @@ function resolveWorkspaceAcpxPluginRoot(currentRoot: string): string | null {
return isAcpxPluginRoot(workspaceRoot) ? workspaceRoot : null;
}
function resolveRepoAcpxPluginRoot(currentRoot: string): string | null {
const workspaceRoot = path.join(currentRoot, "extensions", "acpx");
return isAcpxPluginRoot(workspaceRoot) ? workspaceRoot : null;
}
export function resolveAcpxPluginRoot(moduleUrl: string = import.meta.url): string {
const resolvedRoot = resolveNearestAcpxPluginRoot(moduleUrl);
// In a live repo checkout, dist/ can be rebuilt out from under the running gateway.
// Prefer the stable source plugin root when a built extension is running beside it.
return resolveWorkspaceAcpxPluginRoot(resolvedRoot) ?? resolvedRoot;
return (
resolveWorkspaceAcpxPluginRoot(resolvedRoot) ??
resolveRepoAcpxPluginRoot(resolvedRoot) ??
resolvedRoot
);
}
export const ACPX_PLUGIN_ROOT = resolveAcpxPluginRoot();