mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 06:14:23 +00:00
fix: stabilize macos daemon onboarding
This commit is contained in:
@@ -13,8 +13,9 @@ const gatewayClientCalls: Array<{
|
||||
onClose?: (code: number, reason: string) => void;
|
||||
}> = [];
|
||||
const ensureWorkspaceAndSessionsMock = vi.fn(async (..._args: unknown[]) => {});
|
||||
const installGatewayDaemonNonInteractiveMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||
let waitForGatewayReachableMock:
|
||||
| ((params: { url: string; token?: string; password?: string }) => Promise<{
|
||||
| ((params: { url: string; token?: string; password?: string; deadlineMs?: number }) => Promise<{
|
||||
ok: boolean;
|
||||
detail?: string;
|
||||
}>)
|
||||
@@ -59,6 +60,10 @@ vi.mock("./onboard-helpers.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./onboard-non-interactive/local/daemon-install.js", () => ({
|
||||
installGatewayDaemonNonInteractive: installGatewayDaemonNonInteractiveMock,
|
||||
}));
|
||||
|
||||
const { runNonInteractiveOnboarding } = await import("./onboard-non-interactive.js");
|
||||
const { resolveConfigPath: resolveStateConfigPath } = await import("../config/paths.js");
|
||||
const { resolveConfigPath } = await import("../config/config.js");
|
||||
@@ -128,6 +133,7 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
|
||||
afterEach(() => {
|
||||
waitForGatewayReachableMock = undefined;
|
||||
installGatewayDaemonNonInteractiveMock.mockClear();
|
||||
});
|
||||
|
||||
it("writes gateway token auth into config", async () => {
|
||||
@@ -343,6 +349,33 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("uses a longer health deadline when daemon install was requested", async () => {
|
||||
await withStateDir("state-local-daemon-health-", async (stateDir) => {
|
||||
let capturedDeadlineMs: number | undefined;
|
||||
waitForGatewayReachableMock = vi.fn(async (params: { deadlineMs?: number }) => {
|
||||
capturedDeadlineMs = params.deadlineMs;
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
await runNonInteractiveOnboarding(
|
||||
{
|
||||
nonInteractive: true,
|
||||
mode: "local",
|
||||
workspace: path.join(stateDir, "openclaw"),
|
||||
authChoice: "skip",
|
||||
skipSkills: true,
|
||||
skipHealth: false,
|
||||
installDaemon: true,
|
||||
gatewayBind: "loopback",
|
||||
},
|
||||
runtime,
|
||||
);
|
||||
|
||||
expect(installGatewayDaemonNonInteractiveMock).toHaveBeenCalledTimes(1);
|
||||
expect(capturedDeadlineMs).toBe(45_000);
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("auto-generates token auth when binding LAN and persists the token", async () => {
|
||||
if (process.platform === "win32") {
|
||||
// Windows runner occasionally drops the temp config write in this flow; skip to keep CI green.
|
||||
|
||||
@@ -19,6 +19,9 @@ import { logNonInteractiveOnboardingJson } from "./local/output.js";
|
||||
import { applyNonInteractiveSkillsConfig } from "./local/skills-config.js";
|
||||
import { resolveNonInteractiveWorkspaceDir } from "./local/workspace.js";
|
||||
|
||||
const INSTALL_DAEMON_HEALTH_DEADLINE_MS = 45_000;
|
||||
const ATTACH_EXISTING_GATEWAY_HEALTH_DEADLINE_MS = 15_000;
|
||||
|
||||
export async function runNonInteractiveOnboardingLocal(params: {
|
||||
opts: OnboardOptions;
|
||||
runtime: RuntimeEnv;
|
||||
@@ -107,7 +110,9 @@ export async function runNonInteractiveOnboardingLocal(params: {
|
||||
const probe = await waitForGatewayReachable({
|
||||
url: links.wsUrl,
|
||||
token: gatewayResult.gatewayToken,
|
||||
deadlineMs: 15_000,
|
||||
deadlineMs: opts.installDaemon
|
||||
? INSTALL_DAEMON_HEALTH_DEADLINE_MS
|
||||
: ATTACH_EXISTING_GATEWAY_HEALTH_DEADLINE_MS,
|
||||
});
|
||||
if (!probe.ok) {
|
||||
const message = [
|
||||
|
||||
@@ -250,7 +250,7 @@ describe("launchd install", () => {
|
||||
};
|
||||
}
|
||||
|
||||
it("enables service before bootstrap (clears persisted disabled state)", async () => {
|
||||
it("enables service before bootstrap without self-restarting the fresh agent", async () => {
|
||||
const env = createDefaultLaunchdEnv();
|
||||
await installLaunchAgent({
|
||||
env,
|
||||
@@ -269,9 +269,13 @@ describe("launchd install", () => {
|
||||
const bootstrapIndex = state.launchctlCalls.findIndex(
|
||||
(c) => c[0] === "bootstrap" && c[1] === domain && c[2] === plistPath,
|
||||
);
|
||||
const installKickstartIndex = state.launchctlCalls.findIndex(
|
||||
(c) => c[0] === "kickstart" && c[2] === serviceId,
|
||||
);
|
||||
expect(enableIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(bootstrapIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(enableIndex).toBeLessThan(bootstrapIndex);
|
||||
expect(installKickstartIndex).toBe(-1);
|
||||
});
|
||||
|
||||
it("writes TMPDIR to LaunchAgent environment when provided", async () => {
|
||||
|
||||
@@ -431,7 +431,9 @@ export async function installLaunchAgent({
|
||||
}
|
||||
throw new Error(`launchctl bootstrap failed: ${detail}`);
|
||||
}
|
||||
await execLaunchctl(["kickstart", "-k", `${domain}/${label}`]);
|
||||
// `bootstrap` already loads RunAtLoad agents. Avoid `kickstart -k` here:
|
||||
// on slow macOS guests it SIGTERMs the freshly booted gateway and pushes the
|
||||
// real listener startup past onboarding's health deadline.
|
||||
|
||||
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
||||
writeFormattedLines(
|
||||
|
||||
Reference in New Issue
Block a user