Compare commits
3 Commits
main
...
test/docto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41896a3d14 | ||
|
|
2fc2c8608e | ||
|
|
67bcfa6177 |
@ -47,4 +47,3 @@ enum ConnectionModeResolver {
|
|||||||
return EffectiveConnectionMode(mode: seen ? .local : .unconfigured, source: .onboarding)
|
return EffectiveConnectionMode(mode: seen ? .local : .unconfigured, source: .onboarding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ test("background exec still times out after tool signal abort", async () => {
|
|||||||
abortController.abort();
|
abortController.abort();
|
||||||
|
|
||||||
let finished = getFinishedSession(sessionId);
|
let finished = getFinishedSession(sessionId);
|
||||||
const deadline = Date.now() + 2000;
|
const deadline = Date.now() + (process.platform === "win32" ? 10_000 : 2_000);
|
||||||
while (!finished && Date.now() < deadline) {
|
while (!finished && Date.now() < deadline) {
|
||||||
await sleep(20);
|
await sleep(20);
|
||||||
finished = getFinishedSession(sessionId);
|
finished = getFinishedSession(sessionId);
|
||||||
@ -72,6 +72,7 @@ test("background exec still times out after tool signal abort", async () => {
|
|||||||
const running = getSession(sessionId);
|
const running = getSession(sessionId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
expect(finished).toBeTruthy();
|
||||||
expect(finished?.status).toBe("failed");
|
expect(finished?.status).toBe("failed");
|
||||||
} finally {
|
} finally {
|
||||||
const pid = running?.pid;
|
const pid = running?.pid;
|
||||||
@ -121,7 +122,7 @@ test("yielded background exec still times out", async () => {
|
|||||||
const sessionId = (result.details as { sessionId: string }).sessionId;
|
const sessionId = (result.details as { sessionId: string }).sessionId;
|
||||||
|
|
||||||
let finished = getFinishedSession(sessionId);
|
let finished = getFinishedSession(sessionId);
|
||||||
const deadline = Date.now() + 2000;
|
const deadline = Date.now() + (process.platform === "win32" ? 10_000 : 2_000);
|
||||||
while (!finished && Date.now() < deadline) {
|
while (!finished && Date.now() < deadline) {
|
||||||
await sleep(20);
|
await sleep(20);
|
||||||
finished = getFinishedSession(sessionId);
|
finished = getFinishedSession(sessionId);
|
||||||
@ -130,6 +131,7 @@ test("yielded background exec still times out", async () => {
|
|||||||
const running = getSession(sessionId);
|
const running = getSession(sessionId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
expect(finished).toBeTruthy();
|
||||||
expect(finished?.status).toBe("failed");
|
expect(finished?.status).toBe("failed");
|
||||||
} finally {
|
} finally {
|
||||||
const pid = running?.pid;
|
const pid = running?.pid;
|
||||||
|
|||||||
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -49,12 +49,21 @@ function hasConfigGatewayCreds(cfg: ClawdbotConfig): boolean {
|
|||||||
return Boolean(localToken || localPassword || remoteToken || remotePassword);
|
return Boolean(localToken || localPassword || remoteToken || remotePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function noteMacLaunchctlGatewayEnvOverrides(cfg: ClawdbotConfig) {
|
export async function noteMacLaunchctlGatewayEnvOverrides(
|
||||||
if (process.platform !== "darwin") return;
|
cfg: ClawdbotConfig,
|
||||||
|
deps?: {
|
||||||
|
platform?: NodeJS.Platform;
|
||||||
|
getenv?: (name: string) => Promise<string | undefined>;
|
||||||
|
noteFn?: typeof note;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const platform = deps?.platform ?? process.platform;
|
||||||
|
if (platform !== "darwin") return;
|
||||||
if (!hasConfigGatewayCreds(cfg)) return;
|
if (!hasConfigGatewayCreds(cfg)) return;
|
||||||
|
|
||||||
const envToken = await launchctlGetenv("CLAWDBOT_GATEWAY_TOKEN");
|
const getenv = deps?.getenv ?? launchctlGetenv;
|
||||||
const envPassword = await launchctlGetenv("CLAWDBOT_GATEWAY_PASSWORD");
|
const envToken = await getenv("CLAWDBOT_GATEWAY_TOKEN");
|
||||||
|
const envPassword = await getenv("CLAWDBOT_GATEWAY_PASSWORD");
|
||||||
if (!envToken && !envPassword) return;
|
if (!envToken && !envPassword) return;
|
||||||
|
|
||||||
const lines = [
|
const lines = [
|
||||||
@ -68,5 +77,5 @@ export async function noteMacLaunchctlGatewayEnvOverrides(cfg: ClawdbotConfig) {
|
|||||||
envPassword ? " launchctl unsetenv CLAWDBOT_GATEWAY_PASSWORD" : undefined,
|
envPassword ? " launchctl unsetenv CLAWDBOT_GATEWAY_PASSWORD" : undefined,
|
||||||
].filter((line): line is string => Boolean(line));
|
].filter((line): line is string => Boolean(line));
|
||||||
|
|
||||||
note(lines.join("\n"), "Gateway (macOS)");
|
(deps?.noteFn ?? note)(lines.join("\n"), "Gateway (macOS)");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user