mirror of https://github.com/openclaw/openclaw.git
fix: tighten machine name coverage
This commit is contained in:
parent
47a15d7a9a
commit
f8b13e5b70
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue