fix(ui): fix web UI after tsdown migration and typing changes

This commit is contained in:
Gustavo Madeira Santana
2026-02-03 13:56:20 -05:00
parent 1c4db91593
commit 5935c4d23d
24 changed files with 499 additions and 43 deletions

View File

@@ -2,7 +2,12 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { resolveControlUiDistIndexPath, resolveControlUiRepoRoot } from "./control-ui-assets.js";
import {
resolveControlUiDistIndexPath,
resolveControlUiRepoRoot,
resolveControlUiRootOverrideSync,
resolveControlUiRootSync,
} from "./control-ui-assets.js";
describe("control UI assets helpers", () => {
it("resolves repo root from src argv1", async () => {
@@ -43,6 +48,53 @@ describe("control UI assets helpers", () => {
);
});
it("resolves control-ui root for dist bundle argv1", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
await fs.mkdir(path.join(tmp, "dist", "control-ui"), { recursive: true });
await fs.writeFile(path.join(tmp, "dist", "bundle.js"), "export {};\n");
await fs.writeFile(path.join(tmp, "dist", "control-ui", "index.html"), "<html></html>\n");
expect(resolveControlUiRootSync({ argv1: path.join(tmp, "dist", "bundle.js") })).toBe(
path.join(tmp, "dist", "control-ui"),
);
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("resolves control-ui root for dist/gateway bundle argv1", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
await fs.writeFile(path.join(tmp, "package.json"), JSON.stringify({ name: "openclaw" }));
await fs.mkdir(path.join(tmp, "dist", "gateway"), { recursive: true });
await fs.mkdir(path.join(tmp, "dist", "control-ui"), { recursive: true });
await fs.writeFile(path.join(tmp, "dist", "gateway", "control-ui.js"), "export {};\n");
await fs.writeFile(path.join(tmp, "dist", "control-ui", "index.html"), "<html></html>\n");
expect(
resolveControlUiRootSync({ argv1: path.join(tmp, "dist", "gateway", "control-ui.js") }),
).toBe(path.join(tmp, "dist", "control-ui"));
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("resolves control-ui root from override directory or index.html", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
const uiDir = path.join(tmp, "dist", "control-ui");
await fs.mkdir(uiDir, { recursive: true });
await fs.writeFile(path.join(uiDir, "index.html"), "<html></html>\n");
expect(resolveControlUiRootOverrideSync(uiDir)).toBe(uiDir);
expect(resolveControlUiRootOverrideSync(path.join(uiDir, "index.html"))).toBe(uiDir);
expect(resolveControlUiRootOverrideSync(path.join(uiDir, "missing.html"))).toBeNull();
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("resolves dist control-ui index path from package root argv1", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
@@ -59,6 +111,22 @@ describe("control UI assets helpers", () => {
}
});
it("resolves control-ui root for package entrypoint argv1", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {
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(resolveControlUiRootSync({ argv1: path.join(tmp, "openclaw.mjs") })).toBe(
path.join(tmp, "dist", "control-ui"),
);
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
});
it("resolves dist control-ui index path from .bin argv1", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
try {