test: cover doctor launchctl env overrides (#1037)
* test: cover doctor launchctl env overrides * style(macos): fix swiftformat lint
This commit is contained in:
committed by
GitHub
parent
25ae5f897e
commit
33d17957e5
@@ -0,0 +1,61 @@
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { noteMacLaunchctlGatewayEnvOverrides } from "./doctor-platform-notes.js";
|
||||
|
||||
describe("noteMacLaunchctlGatewayEnvOverrides", () => {
|
||||
it("prints clear unsetenv instructions for token override", async () => {
|
||||
const noteFn = vi.fn();
|
||||
const getenv = vi.fn(async (name: string) =>
|
||||
name === "CLAWDBOT_GATEWAY_TOKEN" ? "launchctl-token" : undefined,
|
||||
);
|
||||
const cfg = {
|
||||
gateway: {
|
||||
auth: {
|
||||
token: "config-token",
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "darwin", getenv, noteFn });
|
||||
|
||||
expect(noteFn).toHaveBeenCalledTimes(1);
|
||||
expect(getenv).toHaveBeenCalledTimes(2);
|
||||
|
||||
const [message, title] = noteFn.mock.calls[0] ?? [];
|
||||
expect(title).toBe("Gateway (macOS)");
|
||||
expect(message).toContain("launchctl environment overrides detected");
|
||||
expect(message).toContain("CLAWDBOT_GATEWAY_TOKEN");
|
||||
expect(message).toContain("launchctl unsetenv CLAWDBOT_GATEWAY_TOKEN");
|
||||
expect(message).not.toContain("CLAWDBOT_GATEWAY_PASSWORD");
|
||||
});
|
||||
|
||||
it("does nothing when config has no gateway credentials", async () => {
|
||||
const noteFn = vi.fn();
|
||||
const getenv = vi.fn(async () => "launchctl-token");
|
||||
const cfg = {} as ClawdbotConfig;
|
||||
|
||||
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "darwin", getenv, noteFn });
|
||||
|
||||
expect(getenv).not.toHaveBeenCalled();
|
||||
expect(noteFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does nothing on non-darwin platforms", async () => {
|
||||
const noteFn = vi.fn();
|
||||
const getenv = vi.fn(async () => "launchctl-token");
|
||||
const cfg = {
|
||||
gateway: {
|
||||
auth: {
|
||||
token: "config-token",
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "linux", getenv, noteFn });
|
||||
|
||||
expect(getenv).not.toHaveBeenCalled();
|
||||
expect(noteFn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user