refactor(prompt-async-gate): remove deprecated dispatch wrappers
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -3,8 +3,6 @@ import { afterEach, describe, expect, test } from "bun:test"
|
||||
import {
|
||||
_setPromptGateMessagesFetchTimeoutMsForTesting,
|
||||
dispatchInternalPrompt,
|
||||
promptAfterSessionIdle,
|
||||
promptAsyncAfterSessionIdle,
|
||||
releaseAllPromptAsyncReservationsForTesting,
|
||||
releasePromptAsyncReservation,
|
||||
} from "./prompt-async-gate"
|
||||
@@ -125,7 +123,7 @@ describe("dispatchInternalPrompt", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("promptAsyncAfterSessionIdle", () => {
|
||||
describe("dispatchInternalPrompt shared gate behavior", () => {
|
||||
afterEach(() => {
|
||||
// then
|
||||
releaseAllPromptAsyncReservationsForTesting()
|
||||
@@ -149,7 +147,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = promptAsyncAfterSessionIdle({
|
||||
const first = dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_race",
|
||||
input: { path: { id: "ses_race" }, body: { parts: [] } },
|
||||
@@ -158,7 +157,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
postDispatchHoldMs: 0,
|
||||
})
|
||||
await Promise.resolve()
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_race",
|
||||
input: { path: { id: "ses_race" }, body: { parts: [] } },
|
||||
@@ -187,7 +187,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = promptAsyncAfterSessionIdle({
|
||||
const first = dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_hold_after_dispatch",
|
||||
input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } },
|
||||
@@ -195,7 +196,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
settleMs: 0,
|
||||
})
|
||||
const firstResult = await first
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_hold_after_dispatch",
|
||||
input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } },
|
||||
@@ -223,7 +225,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
const client = { session }
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_bound_prompt_async",
|
||||
input: { path: { id: "ses_bound_prompt_async" }, body: { parts: [] } },
|
||||
@@ -252,7 +255,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_busy",
|
||||
input: { path: { id: "ses_busy" }, body: { parts: [] } },
|
||||
@@ -291,7 +295,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_waiting_tools",
|
||||
input: { path: { id: "ses_waiting_tools" }, body: { parts: [] } },
|
||||
@@ -324,7 +329,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_recovery_tools",
|
||||
input: { path: { id: "ses_recovery_tools" }, body: { parts: [] } },
|
||||
@@ -354,7 +360,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_messages_hang",
|
||||
input: { path: { id: "ses_messages_hang" }, body: { parts: [] } },
|
||||
@@ -385,7 +392,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
|
||||
try {
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_expired_hold",
|
||||
input: { path: { id: "ses_expired_hold" }, body: { parts: [] } },
|
||||
@@ -394,7 +402,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
postDispatchHoldMs: 1,
|
||||
})
|
||||
currentNow += 2
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_expired_hold",
|
||||
input: { path: { id: "ses_expired_hold" }, body: { parts: [] } },
|
||||
@@ -424,7 +433,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_release_scope",
|
||||
input: {
|
||||
@@ -437,7 +447,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
settleMs: 0,
|
||||
})
|
||||
releasePromptAsyncReservation("ses_release_scope", "ralph-loop:activity")
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_release_scope",
|
||||
input: {
|
||||
@@ -467,7 +478,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_release_family_scope",
|
||||
input: {
|
||||
@@ -482,7 +494,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
"model-fallback-abort:session.error",
|
||||
{ reservedByPrefix: "model-fallback:" },
|
||||
)
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_release_family_scope",
|
||||
input: {
|
||||
@@ -514,7 +527,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_dispatch_timeout",
|
||||
input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } },
|
||||
@@ -523,7 +537,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
dispatchTimeoutMs: 1,
|
||||
postDispatchHoldMs: 0,
|
||||
})
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_dispatch_timeout",
|
||||
input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } },
|
||||
@@ -552,14 +567,16 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_post_dispatch_reject",
|
||||
input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } },
|
||||
source: "test:reject:first",
|
||||
settleMs: 0,
|
||||
})
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_post_dispatch_reject",
|
||||
input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } },
|
||||
@@ -585,7 +602,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = await promptAsyncAfterSessionIdle({
|
||||
const first = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_prefix_sibling",
|
||||
input: {
|
||||
@@ -600,7 +618,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
"model-fallback-abort:session.error",
|
||||
{ reservedByPrefix: "model-fallback:" },
|
||||
)
|
||||
const second = await promptAsyncAfterSessionIdle({
|
||||
const second = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_prefix_sibling",
|
||||
input: {
|
||||
@@ -637,23 +656,19 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = promptAfterSessionIdle({
|
||||
client,
|
||||
sessionID: "ses_prompt_race",
|
||||
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
|
||||
source: "test:prompt:first",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0,
|
||||
})
|
||||
const first = dispatchInternalPrompt({ mode: "sync", client,
|
||||
sessionID: "ses_prompt_race",
|
||||
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
|
||||
source: "test:prompt:first",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0, })
|
||||
await Promise.resolve()
|
||||
const second = await promptAfterSessionIdle({
|
||||
client,
|
||||
sessionID: "ses_prompt_race",
|
||||
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
|
||||
source: "test:prompt:second",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0,
|
||||
})
|
||||
const second = await dispatchInternalPrompt({ mode: "sync", client,
|
||||
sessionID: "ses_prompt_race",
|
||||
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
|
||||
source: "test:prompt:second",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0, })
|
||||
releasePrompt?.()
|
||||
const firstResult = await first
|
||||
|
||||
@@ -675,21 +690,17 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const first = promptAfterSessionIdle({
|
||||
client,
|
||||
sessionID: "ses_prompt_hold_after_dispatch",
|
||||
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
|
||||
source: "test:prompt-hold:first",
|
||||
settleMs: 0,
|
||||
})
|
||||
const first = dispatchInternalPrompt({ mode: "sync", client,
|
||||
sessionID: "ses_prompt_hold_after_dispatch",
|
||||
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
|
||||
source: "test:prompt-hold:first",
|
||||
settleMs: 0, })
|
||||
const firstResult = await first
|
||||
const second = await promptAfterSessionIdle({
|
||||
client,
|
||||
sessionID: "ses_prompt_hold_after_dispatch",
|
||||
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
|
||||
source: "test:prompt-hold:second",
|
||||
settleMs: 0,
|
||||
})
|
||||
const second = await dispatchInternalPrompt({ mode: "sync", client,
|
||||
sessionID: "ses_prompt_hold_after_dispatch",
|
||||
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
|
||||
source: "test:prompt-hold:second",
|
||||
settleMs: 0, })
|
||||
|
||||
// then
|
||||
expect(firstResult.status).toBe("dispatched")
|
||||
@@ -710,7 +721,8 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
}
|
||||
|
||||
// when
|
||||
const result = await promptAsyncAfterSessionIdle({
|
||||
const result = await dispatchInternalPrompt({
|
||||
mode: "async",
|
||||
client,
|
||||
sessionID: "ses_status_hang",
|
||||
input: { path: { id: "ses_status_hang" }, body: { parts: [] } },
|
||||
@@ -739,14 +751,12 @@ describe("promptAsyncAfterSessionIdle", () => {
|
||||
const client = { session }
|
||||
|
||||
// when
|
||||
const result = await promptAfterSessionIdle({
|
||||
client,
|
||||
sessionID: "ses_bound_prompt",
|
||||
input: { path: { id: "ses_bound_prompt" }, body: { parts: [] } },
|
||||
source: "test:bound-prompt",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0,
|
||||
})
|
||||
const result = await dispatchInternalPrompt({ mode: "sync", client,
|
||||
sessionID: "ses_bound_prompt",
|
||||
input: { path: { id: "ses_bound_prompt" }, body: { parts: [] } },
|
||||
source: "test:bound-prompt",
|
||||
settleMs: 0,
|
||||
postDispatchHoldMs: 0, })
|
||||
|
||||
// then
|
||||
expect(result).toEqual({
|
||||
|
||||
@@ -431,40 +431,6 @@ export async function dispatchInternalPrompt<TInput = PromptAsyncInput>(
|
||||
})
|
||||
}
|
||||
|
||||
export async function promptAsyncAfterSessionIdle<TInput = PromptAsyncInput>(args: {
|
||||
client: PromptAsyncClient<TInput>
|
||||
sessionID: string
|
||||
input: TInput
|
||||
source: string
|
||||
settleMs?: number
|
||||
postDispatchHoldMs?: number
|
||||
dispatchTimeoutMs?: number
|
||||
checkStatus?: boolean
|
||||
checkToolState?: boolean
|
||||
}): Promise<PromptAsyncGateResult> {
|
||||
return dispatchInternalPrompt({
|
||||
...args,
|
||||
mode: "async",
|
||||
})
|
||||
}
|
||||
|
||||
export async function promptAfterSessionIdle<TInput = PromptAsyncInput>(args: {
|
||||
client: PromptClient<TInput>
|
||||
sessionID: string
|
||||
input: TInput
|
||||
source: string
|
||||
settleMs?: number
|
||||
postDispatchHoldMs?: number
|
||||
dispatchTimeoutMs?: number
|
||||
checkStatus?: boolean
|
||||
checkToolState?: boolean
|
||||
}): Promise<PromptAsyncGateResult> {
|
||||
return dispatchInternalPrompt({
|
||||
...args,
|
||||
mode: "sync",
|
||||
})
|
||||
}
|
||||
|
||||
export function releaseAllPromptAsyncReservationsForTesting(): void {
|
||||
promptAsyncReservations.clear()
|
||||
promptGateMessagesFetchTimeoutMsForTesting = undefined
|
||||
|
||||
Reference in New Issue
Block a user