mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:54:58 +00:00
fix: resolve symlinked argv1 for Control UI asset detection (#14919)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 07b85041dc
Co-authored-by: gumadeiras <116837+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
bdd0c12329
commit
8d5094e1f4
@@ -2,6 +2,24 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
/** Try to create a symlink; returns false if the OS denies it (Windows CI without Developer Mode). */
|
||||
async function trySymlink(target: string, linkPath: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.symlink(target, linkPath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function canonicalPath(p: string): Promise<string> {
|
||||
try {
|
||||
return await fs.realpath(p);
|
||||
} catch {
|
||||
return path.resolve(p);
|
||||
}
|
||||
}
|
||||
import {
|
||||
resolveControlUiDistIndexHealth,
|
||||
resolveControlUiDistIndexPath,
|
||||
@@ -10,6 +28,7 @@ import {
|
||||
resolveControlUiRootOverrideSync,
|
||||
resolveControlUiRootSync,
|
||||
} from "./control-ui-assets.js";
|
||||
import { resolveOpenClawPackageRoot } from "./openclaw-root.js";
|
||||
|
||||
describe("control UI assets helpers", () => {
|
||||
it("resolves repo root from src argv1", async () => {
|
||||
@@ -221,4 +240,89 @@ describe("control UI assets helpers", () => {
|
||||
await fs.rm(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves control-ui root when argv1 is a symlink (nvm scenario)", async () => {
|
||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
|
||||
try {
|
||||
const realPkg = path.join(tmp, "real-pkg");
|
||||
const bin = path.join(tmp, "bin");
|
||||
await fs.mkdir(realPkg, { recursive: true });
|
||||
await fs.mkdir(bin, { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||
await fs.writeFile(path.join(realPkg, "openclaw.mjs"), "export {};\n");
|
||||
await fs.mkdir(path.join(realPkg, "dist", "control-ui"), { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "dist", "control-ui", "index.html"), "<html></html>\n");
|
||||
const ok = await trySymlink(
|
||||
path.join("..", "real-pkg", "openclaw.mjs"),
|
||||
path.join(bin, "openclaw"),
|
||||
);
|
||||
if (!ok) {
|
||||
return; // symlinks not supported (Windows CI)
|
||||
}
|
||||
|
||||
const resolvedRoot = resolveControlUiRootSync({ argv1: path.join(bin, "openclaw") });
|
||||
expect(resolvedRoot).not.toBeNull();
|
||||
expect(await canonicalPath(resolvedRoot ?? "")).toBe(
|
||||
await canonicalPath(path.join(realPkg, "dist", "control-ui")),
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves package root via symlinked argv1", async () => {
|
||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
|
||||
try {
|
||||
const realPkg = path.join(tmp, "real-pkg");
|
||||
const bin = path.join(tmp, "bin");
|
||||
await fs.mkdir(realPkg, { recursive: true });
|
||||
await fs.mkdir(bin, { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||
await fs.writeFile(path.join(realPkg, "openclaw.mjs"), "export {};\n");
|
||||
await fs.mkdir(path.join(realPkg, "dist", "control-ui"), { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "dist", "control-ui", "index.html"), "<html></html>\n");
|
||||
const ok = await trySymlink(
|
||||
path.join("..", "real-pkg", "openclaw.mjs"),
|
||||
path.join(bin, "openclaw"),
|
||||
);
|
||||
if (!ok) {
|
||||
return; // symlinks not supported (Windows CI)
|
||||
}
|
||||
|
||||
const packageRoot = await resolveOpenClawPackageRoot({ argv1: path.join(bin, "openclaw") });
|
||||
expect(packageRoot).not.toBeNull();
|
||||
expect(await canonicalPath(packageRoot ?? "")).toBe(await canonicalPath(realPkg));
|
||||
} finally {
|
||||
await fs.rm(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves dist index path via symlinked argv1 (async)", async () => {
|
||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
|
||||
try {
|
||||
const realPkg = path.join(tmp, "real-pkg");
|
||||
const bin = path.join(tmp, "bin");
|
||||
await fs.mkdir(realPkg, { recursive: true });
|
||||
await fs.mkdir(bin, { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||
await fs.writeFile(path.join(realPkg, "openclaw.mjs"), "export {};\n");
|
||||
await fs.mkdir(path.join(realPkg, "dist", "control-ui"), { recursive: true });
|
||||
await fs.writeFile(path.join(realPkg, "dist", "control-ui", "index.html"), "<html></html>\n");
|
||||
const ok = await trySymlink(
|
||||
path.join("..", "real-pkg", "openclaw.mjs"),
|
||||
path.join(bin, "openclaw"),
|
||||
);
|
||||
if (!ok) {
|
||||
return; // symlinks not supported (Windows CI)
|
||||
}
|
||||
|
||||
const indexPath = await resolveControlUiDistIndexPath(path.join(bin, "openclaw"));
|
||||
expect(indexPath).not.toBeNull();
|
||||
expect(await canonicalPath(indexPath ?? "")).toBe(
|
||||
await canonicalPath(path.join(realPkg, "dist", "control-ui", "index.html")),
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user