mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:58:38 +00:00
fix: tighten machine name coverage
This commit is contained in:
@@ -34,12 +34,12 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getMachineDisplayName", () => {
|
describe("getMachineDisplayName", () => {
|
||||||
it("uses the hostname fallback in test mode and trims .local", async () => {
|
it("uses the hostname fallback in test mode and strips a trimmed .local suffix", async () => {
|
||||||
const hostnameSpy = vi.spyOn(os, "hostname").mockReturnValue(" clawbox.local ");
|
const hostnameSpy = vi.spyOn(os, "hostname").mockReturnValue(" clawbox.LOCAL ");
|
||||||
const machineName = await importMachineName("test-fallback");
|
const machineName = await importMachineName("test-fallback");
|
||||||
|
|
||||||
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox.local");
|
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox");
|
||||||
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox.local");
|
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox");
|
||||||
expect(hostnameSpy).toHaveBeenCalledTimes(1);
|
expect(hostnameSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(execFileMock).not.toHaveBeenCalled();
|
expect(execFileMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,12 +20,8 @@ async function tryScutil(key: "ComputerName" | "LocalHostName") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fallbackHostName() {
|
function fallbackHostName() {
|
||||||
return (
|
const trimmed = os.hostname().trim();
|
||||||
os
|
return trimmed.replace(/\.local$/i, "") || "openclaw";
|
||||||
.hostname()
|
|
||||||
.replace(/\.local$/i, "")
|
|
||||||
.trim() || "openclaw"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMachineDisplayName(): Promise<string> {
|
export async function getMachineDisplayName(): Promise<string> {
|
||||||
|
|||||||
Reference in New Issue
Block a user