fix full-suite isolation regressions
This commit is contained in:
@@ -304,6 +304,32 @@ describe("ralph-loop", () => {
|
||||
expect(state?.iteration).toBe(2)
|
||||
})
|
||||
|
||||
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)
|
||||
hook.startLoop("session-123", "Build a feature", { maxIterations: 10 })
|
||||
|
||||
// when - session goes idle
|
||||
const result = await Promise.race([
|
||||
hook.event({
|
||||
event: {
|
||||
type: "session.idle",
|
||||
properties: { sessionID: "session-123" },
|
||||
},
|
||||
}).then(() => "resolved" as const),
|
||||
new Promise<"timed-out">((resolvePromise) => setTimeout(() => resolvePromise("timed-out"), 50)),
|
||||
])
|
||||
|
||||
// then - continuation is not blocked by toast delivery
|
||||
expect(result).toBe("resolved")
|
||||
expect(promptCalls.length).toBe(1)
|
||||
expect(promptCalls[0].sessionID).toBe("session-123")
|
||||
})
|
||||
|
||||
test("should skip continuation when background task is running", async () => {
|
||||
// given - active loop state with a running background task
|
||||
const hook = createRalphLoopHook(createMockPluginInput(), {
|
||||
|
||||
@@ -70,27 +70,38 @@ function isAbortError(error: unknown): boolean {
|
||||
&& (error as { name?: unknown }).name === "MessageAbortedError"
|
||||
}
|
||||
|
||||
async function showMaxIterationsToast(
|
||||
function showToastBestEffort(
|
||||
ctx: PluginInput,
|
||||
state: RalphLoopState,
|
||||
): Promise<void> {
|
||||
await ctx.client.tui?.showToast?.({
|
||||
body: { title: "Ralph Loop Stopped", message: `Max iterations (${state.max_iterations}) reached without completion`, variant: "warning", duration: 5000 },
|
||||
}).catch(() => {})
|
||||
body: { title: string; message: string; variant: "warning" | "info"; duration: number },
|
||||
): void {
|
||||
try {
|
||||
void Promise.resolve(ctx.client.tui?.showToast?.({ body })).catch(() => {})
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
async function showIterationToast(
|
||||
function showMaxIterationsToast(
|
||||
ctx: PluginInput,
|
||||
state: RalphLoopState,
|
||||
): Promise<void> {
|
||||
await ctx.client.tui?.showToast?.({
|
||||
body: {
|
||||
title: "Ralph Loop",
|
||||
message: `Iteration ${state.iteration}/${typeof state.max_iterations === "number" ? state.max_iterations : "unbounded"}`,
|
||||
variant: "info",
|
||||
duration: 2000,
|
||||
},
|
||||
}).catch(() => {})
|
||||
): void {
|
||||
showToastBestEffort(ctx, {
|
||||
title: "Ralph Loop Stopped",
|
||||
message: `Max iterations (${state.max_iterations}) reached without completion`,
|
||||
variant: "warning",
|
||||
duration: 5000,
|
||||
})
|
||||
}
|
||||
|
||||
function showIterationToast(
|
||||
ctx: PluginInput,
|
||||
state: RalphLoopState,
|
||||
): void {
|
||||
showToastBestEffort(ctx, {
|
||||
title: "Ralph Loop",
|
||||
message: `Iteration ${state.iteration}/${typeof state.max_iterations === "number" ? state.max_iterations : "unbounded"}`,
|
||||
variant: "info",
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
|
||||
export function createRalphLoopEventHandler(
|
||||
@@ -253,7 +264,7 @@ export function createRalphLoopEventHandler(
|
||||
})
|
||||
options.loopState.clear()
|
||||
|
||||
await showMaxIterationsToast(ctx, state)
|
||||
showMaxIterationsToast(ctx, state)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -269,7 +280,7 @@ export function createRalphLoopEventHandler(
|
||||
max: newState.max_iterations,
|
||||
})
|
||||
|
||||
await showIterationToast(ctx, newState)
|
||||
showIterationToast(ctx, newState)
|
||||
|
||||
try {
|
||||
await continueIteration(ctx, newState, {
|
||||
@@ -361,7 +372,7 @@ export function createRalphLoopEventHandler(
|
||||
max: state.max_iterations,
|
||||
})
|
||||
options.loopState.clear()
|
||||
await showMaxIterationsToast(ctx, state)
|
||||
showMaxIterationsToast(ctx, state)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -371,7 +382,7 @@ export function createRalphLoopEventHandler(
|
||||
return
|
||||
}
|
||||
|
||||
await showIterationToast(ctx, newState)
|
||||
showIterationToast(ctx, newState)
|
||||
try {
|
||||
await continueIteration(ctx, newState, {
|
||||
previousSessionID: sessionID,
|
||||
|
||||
Reference in New Issue
Block a user