fix: add fallback for Control UI asset resolution in global installs

This commit is contained in:
Gustavo Madeira Santana
2026-02-05 22:03:43 -05:00
parent 7b2a221212
commit 72245855e5
3 changed files with 74 additions and 3 deletions

View File

@@ -145,4 +145,49 @@ describe("control UI assets helpers", () => {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("resolves via fallback when package root resolution fails but package name matches", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
// Package named "openclaw" but resolveOpenClawPackageRoot failed for other reasons
await fs.writeFile(path.join(tmp, "package.json"), JSON.stringify({ name: "openclaw" }));
await fs.writeFile(path.join(tmp, "openclaw.mjs"), "export {};\n");
await fs.mkdir(path.join(tmp, "dist", "control-ui"), { recursive: true });
await fs.writeFile(path.join(tmp, "dist", "control-ui", "index.html"), "<html></html>\n");
expect(await resolveControlUiDistIndexPath(path.join(tmp, "openclaw.mjs"))).toBe(
path.join(tmp, "dist", "control-ui", "index.html"),
);
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("returns null when package name does not match openclaw", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
// Package with different name should not be resolved
await fs.writeFile(path.join(tmp, "package.json"), JSON.stringify({ name: "malicious-pkg" }));
await fs.writeFile(path.join(tmp, "index.mjs"), "export {};\n");
await fs.mkdir(path.join(tmp, "dist", "control-ui"), { recursive: true });
await fs.writeFile(path.join(tmp, "dist", "control-ui", "index.html"), "<html></html>\n");
expect(await resolveControlUiDistIndexPath(path.join(tmp, "index.mjs"))).toBeNull();
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("returns null when no control-ui assets exist", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
// Just a package.json, no dist/control-ui
await fs.writeFile(path.join(tmp, "package.json"), JSON.stringify({ name: "some-pkg" }));
await fs.writeFile(path.join(tmp, "index.mjs"), "export {};\n");
expect(await resolveControlUiDistIndexPath(path.join(tmp, "index.mjs"))).toBeNull();
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
});