Files
openclaw-zero-token/commands/doctor-platform-notes.launchctl-env-overrides.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

85 lines
2.7 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
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 === "OPENCLAW_GATEWAY_TOKEN" ? "launchctl-token" : undefined,
);
const cfg = {
gateway: {
auth: {
token: "config-token",
},
},
} as OpenClawConfig;
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("OPENCLAW_GATEWAY_TOKEN");
expect(message).toContain("launchctl unsetenv OPENCLAW_GATEWAY_TOKEN");
expect(message).not.toContain("OPENCLAW_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 OpenClawConfig;
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "darwin", getenv, noteFn });
expect(getenv).not.toHaveBeenCalled();
expect(noteFn).not.toHaveBeenCalled();
});
it("treats SecretRef-backed credentials as configured", async () => {
const noteFn = vi.fn();
const getenv = vi.fn(async (name: string) =>
name === "OPENCLAW_GATEWAY_PASSWORD" ? "launchctl-password" : undefined,
);
const cfg = {
gateway: {
auth: {
password: { source: "env", provider: "default", id: "OPENCLAW_GATEWAY_PASSWORD" },
},
},
secrets: {
providers: {
default: { source: "env" },
},
},
} as OpenClawConfig;
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "darwin", getenv, noteFn });
expect(noteFn).toHaveBeenCalledTimes(1);
const [message] = noteFn.mock.calls[0] ?? [];
expect(message).toContain("OPENCLAW_GATEWAY_PASSWORD");
});
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 OpenClawConfig;
await noteMacLaunchctlGatewayEnvOverrides(cfg, { platform: "linux", getenv, noteFn });
expect(getenv).not.toHaveBeenCalled();
expect(noteFn).not.toHaveBeenCalled();
});
});