mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-09 06:02:55 +00:00
fix(cli): clamp progress delay timers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js";
|
||||
import { createCliProgress, shouldUseInteractiveProgressSpinner } from "./progress.js";
|
||||
|
||||
function withStdinIsRaw<T>(isRaw: boolean, run: () => T): T {
|
||||
@@ -130,4 +131,25 @@ describe("cli progress", () => {
|
||||
|
||||
expect(firstWrites).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("clamps oversized delayed progress timers", () => {
|
||||
const stream = {
|
||||
isTTY: true,
|
||||
write: vi.fn(),
|
||||
} as unknown as NodeJS.WriteStream;
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
try {
|
||||
const progress = createCliProgress({
|
||||
label: "Delayed",
|
||||
stream,
|
||||
fallback: "line",
|
||||
delayMs: Number.MAX_SAFE_INTEGER,
|
||||
});
|
||||
progress.done();
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
unregisterActiveProgressLine,
|
||||
} from "../../packages/terminal-core/src/progress-line.js";
|
||||
import { theme } from "../../packages/terminal-core/src/theme.js";
|
||||
import { resolveTimerTimeoutMs } from "../shared/number-coercion.js";
|
||||
|
||||
const DEFAULT_DELAY_MS = 0;
|
||||
let activeProgress = 0;
|
||||
@@ -67,7 +68,7 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
return noopReporter;
|
||||
}
|
||||
|
||||
const delayMs = typeof options.delayMs === "number" ? options.delayMs : DEFAULT_DELAY_MS;
|
||||
const delayMs = resolveTimerTimeoutMs(options.delayMs, DEFAULT_DELAY_MS, 0);
|
||||
const canOsc = isTty && supportsOscProgress(process.env, isTty);
|
||||
const stdinIsRaw = process.stdin.isRaw;
|
||||
const allowSpinner = shouldUseInteractiveProgressSpinner({
|
||||
|
||||
Reference in New Issue
Block a user