fix(ralph-loop): settle idle before continuation
This commit is contained in:
@@ -304,13 +304,35 @@ describe("ralph-loop", () => {
|
||||
expect(state?.iteration).toBe(2)
|
||||
})
|
||||
|
||||
test("should settle idle before injecting continuation", async () => {
|
||||
// given - active loop state with a configured idle settle delay
|
||||
const hook = createRalphLoopHook(createMockPluginInput(), { idleSettleMs: 25 })
|
||||
hook.startLoop("session-123", "Build a feature", { maxIterations: 10 })
|
||||
|
||||
// when - session goes idle
|
||||
const eventPromise = hook.event({
|
||||
event: {
|
||||
type: "session.idle",
|
||||
properties: { sessionID: "session-123" },
|
||||
},
|
||||
})
|
||||
await Promise.resolve()
|
||||
|
||||
// then - continuation should not be injected in the same event-loop turn
|
||||
expect(promptCalls.length).toBe(0)
|
||||
|
||||
await eventPromise
|
||||
expect(promptCalls.length).toBe(1)
|
||||
expect(promptCalls[0].sessionID).toBe("session-123")
|
||||
})
|
||||
|
||||
test("#given hanging toast #when session idles #then continuation still injects", async () => {
|
||||
// given - TUI toast never settles
|
||||
const ctx = createMockPluginInput()
|
||||
ctx.client.tui = {
|
||||
showToast: () => new Promise(() => {}),
|
||||
} as never
|
||||
const hook = createRalphLoopHook(ctx)
|
||||
const hook = createRalphLoopHook(ctx, { idleSettleMs: 0 })
|
||||
hook.startLoop("session-123", "Build a feature", { maxIterations: 10 })
|
||||
|
||||
// when - session goes idle
|
||||
@@ -359,7 +381,7 @@ describe("ralph-loop", () => {
|
||||
|
||||
test("should stop loop when max iterations reached", async () => {
|
||||
// given - loop at max iteration
|
||||
const hook = createRalphLoopHook(createMockPluginInput())
|
||||
const hook = createRalphLoopHook(createMockPluginInput(), { idleSettleMs: 0 })
|
||||
hook.startLoop("session-123", "Build something", { maxIterations: 2 })
|
||||
|
||||
const state = hook.getState()!
|
||||
|
||||
Reference in New Issue
Block a user