mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:01:24 +00:00
fix: Docker installation keeps hanging on MacOS (#12972)
* Onboarding: avoid stdin resume after wizard finish * Changelog: remove Docker hang entry from PR * Terminal: make stdin resume behavior explicit at call sites * CI: rerun format check * Onboarding: restore terminal before cancel exit * test(onboard): align restoreTerminalState expectation * chore(format): align onboarding restore test with updated oxfmt config * chore(format): enforce updated oxfmt on restore test * chore(format): apply updated oxfmt spacing to restore test * fix: avoid stdin resume after onboarding (#12972) (thanks @vincentkoc) --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -46,7 +46,9 @@ describe("runInteractiveOnboarding", () => {
|
||||
await runInteractiveOnboarding({} as never, runtime);
|
||||
|
||||
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish");
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish", {
|
||||
resumeStdin: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("rethrows non-cancel errors", async () => {
|
||||
@@ -56,6 +58,8 @@ describe("runInteractiveOnboarding", () => {
|
||||
await expect(runInteractiveOnboarding({} as never, runtime)).rejects.toThrow("boom");
|
||||
|
||||
expect(runtime.exit).not.toHaveBeenCalled();
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish");
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish", {
|
||||
resumeStdin: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
72
src/commands/onboard-interactive.test.ts
Normal file
72
src/commands/onboard-interactive.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { WizardCancelledError } from "../wizard/prompts.js";
|
||||
import { runInteractiveOnboarding } from "./onboard-interactive.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
createClackPrompter: vi.fn(() => ({ id: "prompter" })),
|
||||
runOnboardingWizard: vi.fn(async () => {}),
|
||||
restoreTerminalState: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../wizard/clack-prompter.js", () => ({
|
||||
createClackPrompter: mocks.createClackPrompter,
|
||||
}));
|
||||
|
||||
vi.mock("../wizard/onboarding.js", () => ({
|
||||
runOnboardingWizard: mocks.runOnboardingWizard,
|
||||
}));
|
||||
|
||||
vi.mock("../terminal/restore.js", () => ({
|
||||
restoreTerminalState: mocks.restoreTerminalState,
|
||||
}));
|
||||
|
||||
function makeRuntime(): RuntimeEnv {
|
||||
return {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn() as unknown as RuntimeEnv["exit"],
|
||||
};
|
||||
}
|
||||
|
||||
describe("runInteractiveOnboarding", () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("restores terminal state without resuming stdin on success", async () => {
|
||||
const runtime = makeRuntime();
|
||||
|
||||
await runInteractiveOnboarding({} as never, runtime);
|
||||
|
||||
expect(mocks.runOnboardingWizard).toHaveBeenCalledOnce();
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish", {
|
||||
resumeStdin: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("restores terminal state without resuming stdin on cancel", async () => {
|
||||
const exitError = new Error("exit");
|
||||
const runtime: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(() => {
|
||||
throw exitError;
|
||||
}) as unknown as RuntimeEnv["exit"],
|
||||
};
|
||||
mocks.runOnboardingWizard.mockRejectedValueOnce(new WizardCancelledError("cancelled"));
|
||||
|
||||
await expect(runInteractiveOnboarding({} as never, runtime)).rejects.toBe(exitError);
|
||||
|
||||
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish", {
|
||||
resumeStdin: false,
|
||||
});
|
||||
const restoreOrder =
|
||||
mocks.restoreTerminalState.mock.invocationCallOrder[0] ?? Number.MAX_SAFE_INTEGER;
|
||||
const exitOrder =
|
||||
(runtime.exit as unknown as ReturnType<typeof vi.fn>).mock.invocationCallOrder[0] ??
|
||||
Number.MAX_SAFE_INTEGER;
|
||||
expect(restoreOrder).toBeLessThan(exitOrder);
|
||||
});
|
||||
});
|
||||
@@ -11,15 +11,21 @@ export async function runInteractiveOnboarding(
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
) {
|
||||
const prompter = createClackPrompter();
|
||||
let exitCode: number | null = null;
|
||||
try {
|
||||
await runOnboardingWizard(opts, runtime, prompter);
|
||||
} catch (err) {
|
||||
if (err instanceof WizardCancelledError) {
|
||||
runtime.exit(1);
|
||||
// Best practice: cancellation is not a successful completion.
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} finally {
|
||||
restoreTerminalState("onboarding finish");
|
||||
// Keep stdin paused so non-daemon runs can exit cleanly (e.g. Docker setup).
|
||||
restoreTerminalState("onboarding finish", { resumeStdin: false });
|
||||
if (exitCode !== null) {
|
||||
runtime.exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user