mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 19:40:40 +00:00
* 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>
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { clearActiveProgressLine } from "./terminal/progress-line.js";
|
|
import { restoreTerminalState } from "./terminal/restore.js";
|
|
|
|
export type RuntimeEnv = {
|
|
log: typeof console.log;
|
|
error: typeof console.error;
|
|
exit: (code: number) => never;
|
|
};
|
|
|
|
function shouldEmitRuntimeLog(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
if (env.VITEST !== "true") {
|
|
return true;
|
|
}
|
|
if (env.OPENCLAW_TEST_RUNTIME_LOG === "1") {
|
|
return true;
|
|
}
|
|
const maybeMockedLog = console.log as unknown as { mock?: unknown };
|
|
return typeof maybeMockedLog.mock === "object";
|
|
}
|
|
|
|
export const defaultRuntime: RuntimeEnv = {
|
|
log: (...args: Parameters<typeof console.log>) => {
|
|
if (!shouldEmitRuntimeLog()) {
|
|
return;
|
|
}
|
|
clearActiveProgressLine();
|
|
console.log(...args);
|
|
},
|
|
error: (...args: Parameters<typeof console.error>) => {
|
|
clearActiveProgressLine();
|
|
console.error(...args);
|
|
},
|
|
exit: (code) => {
|
|
restoreTerminalState("runtime exit", { resumeStdin: false });
|
|
process.exit(code);
|
|
throw new Error("unreachable"); // satisfies tests when mocked
|
|
},
|
|
};
|
|
|
|
export function createNonExitingRuntime(): RuntimeEnv {
|
|
return {
|
|
log: (...args: Parameters<typeof console.log>) => {
|
|
if (!shouldEmitRuntimeLog()) {
|
|
return;
|
|
}
|
|
clearActiveProgressLine();
|
|
console.log(...args);
|
|
},
|
|
error: (...args: Parameters<typeof console.error>) => {
|
|
clearActiveProgressLine();
|
|
console.error(...args);
|
|
},
|
|
exit: (code: number): never => {
|
|
throw new Error(`exit ${code}`);
|
|
},
|
|
};
|
|
}
|