fix: tighten machine name coverage

This commit is contained in:
Peter Steinberger 2026-03-13 23:43:06 +00:00
parent 47a15d7a9a
commit f8b13e5b70
2 changed files with 6 additions and 10 deletions

View File

@ -34,12 +34,12 @@ afterEach(() => {
});
describe("getMachineDisplayName", () => {
it("uses the hostname fallback in test mode and trims .local", async () => {
const hostnameSpy = vi.spyOn(os, "hostname").mockReturnValue(" clawbox.local ");
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 machineName = await importMachineName("test-fallback");
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox.local");
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox.local");
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox");
await expect(machineName.getMachineDisplayName()).resolves.toBe("clawbox");
expect(hostnameSpy).toHaveBeenCalledTimes(1);
expect(execFileMock).not.toHaveBeenCalled();
});

View File

@ -20,12 +20,8 @@ async function tryScutil(key: "ComputerName" | "LocalHostName") {
}
function fallbackHostName() {
return (
os
.hostname()
.replace(/\.local$/i, "")
.trim() || "openclaw"
);
const trimmed = os.hostname().trim();
return trimmed.replace(/\.local$/i, "") || "openclaw";
}
export async function getMachineDisplayName(): Promise<string> {