fix(matrix): align extension-api source aliases

This commit is contained in:
Vincent Koc
2026-04-14 18:03:16 +01:00
parent 3362cccc20
commit 0a9616caa8
2 changed files with 34 additions and 2 deletions

View File

@@ -122,8 +122,10 @@ function buildPluginSdkAliasMap(moduleUrl) {
}
const extensionApi =
resolveExistingFile(path.join(packageRoot, "src", "extensionAPI"), [".ts", ".js"]) ??
resolveExistingFile(path.join(packageRoot, "dist", "extensionAPI"), [".js"]);
resolveExistingFile(
path.join(packageRoot, "src", "extensionAPI"),
PLUGIN_SDK_SOURCE_EXTENSIONS,
) ?? resolveExistingFile(path.join(packageRoot, "dist", "extensionAPI"), [".js"]);
if (extensionApi) {
aliasMap["openclaw/extension-api"] = extensionApi;
}

View File

@@ -246,6 +246,36 @@ it("builds scoped and unscoped plugin-sdk aliases for the wrapper jiti loader",
});
}, 240_000);
it("resolves extension-api aliases through the same source extension family", async () => {
const fixtureRoot = makeFixtureRoot(".tmp-matrix-runtime-extension-api-");
const wrapperSource = fs.readFileSync(
path.join(REPO_ROOT, "extensions", "matrix", "src", "plugin-entry.runtime.js"),
"utf8",
);
delete matrixWrapperGlobal.__openclawMatrixWrapperJitiOptions;
writeOpenClawAliasFixture(fixtureRoot);
writeFixtureFile(fixtureRoot, "src/extensionAPI.mts", "export {};\n");
writeCapturingJitiFixture(fixtureRoot);
writeFixtureFile(fixtureRoot, "extensions/matrix/src/plugin-entry.runtime.js", wrapperSource);
writeFixtureFile(
fixtureRoot,
"extensions/matrix/plugin-entry.handlers.runtime.js",
PACKAGED_RUNTIME_STUB,
);
const wrapperUrl = pathToFileURL(
path.join(fixtureRoot, "extensions", "matrix", "src", "plugin-entry.runtime.js"),
);
await import(`${wrapperUrl.href}?t=${Date.now()}`);
expect(matrixWrapperGlobal.__openclawMatrixWrapperJitiOptions).toMatchObject({
alias: {
"openclaw/extension-api": path.join(fixtureRoot, "src", "extensionAPI.mts"),
},
});
}, 240_000);
it("keeps wrapper plugin-sdk aliases deterministic and ignores unsafe subpaths", async () => {
const fixtureRoot = makeFixtureRoot(".tmp-matrix-runtime-alias-order-");
const wrapperSource = fs.readFileSync(