60086d8a49
* fix(coding-agent): restore ask timeout auto-select behavior Fixes #266 * fix(coding-agent): derive ask timeout from ui timeout events * fix(coding-agent): enforce ask timeout during custom input * fix(ask): preserve sub-second timeout precision in interactive flow * fix(ask): reset hook input timeout on user activity * fix(ask): keep expiration timeout when refreshing tick interval * fix(ask): auto-select deterministic default on timeout Fixes #266 --------- Co-authored-by: Vũ Anh Nguyễn <vu.anh.nguyen@mgm-tp.com> Co-authored-by: can1357 <me@can.ac>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
|
|
import { CountdownTimer } from "@oh-my-pi/pi-coding-agent/modes/components/countdown-timer";
|
|
|
|
describe("CountdownTimer", () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("expires using precise sub-second timeout instead of second rounding", () => {
|
|
const onTick = vi.fn();
|
|
const onExpire = vi.fn();
|
|
new CountdownTimer(250, undefined, onTick, onExpire);
|
|
|
|
expect(onTick).toHaveBeenCalledWith(1);
|
|
vi.advanceTimersByTime(249);
|
|
expect(onExpire).not.toHaveBeenCalled();
|
|
|
|
vi.advanceTimersByTime(1);
|
|
expect(onExpire).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("reset restarts precise timeout window", () => {
|
|
const onExpire = vi.fn();
|
|
const timer = new CountdownTimer(300, undefined, () => {}, onExpire);
|
|
|
|
vi.advanceTimersByTime(200);
|
|
timer.reset();
|
|
vi.advanceTimersByTime(299);
|
|
expect(onExpire).not.toHaveBeenCalled();
|
|
|
|
vi.advanceTimersByTime(1);
|
|
expect(onExpire).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|