fix(prompt-gate): bind session messages receiver

This commit is contained in:
YeonGyu-Kim
2026-05-18 13:56:11 +09:00
parent d44cd1c1a0
commit 66cb72b831
2 changed files with 47 additions and 2 deletions
@@ -242,6 +242,50 @@ describe("dispatchInternalPrompt shared gate behavior", () => {
})
})
test("#given SDK messages depends on its session receiver #when latest assistant waits on tools #then method binding is preserved and no prompt is sent", async () => {
// given
let promptCalls = 0
const session = {
_client: {
messages: [
{
info: { id: "msg_user", role: "user" },
parts: [{ type: "text", text: "run work" }],
},
{
info: { id: "msg_assistant", role: "assistant", finish: "tool-calls" },
parts: [{ type: "tool_use", id: "toolu_pending", state: { status: "running" } }],
},
],
},
async messages(
this: { _client: { messages: unknown[] } },
_input: { path: { id: string }; query: { directory: string } },
) {
return { data: this._client.messages }
},
async promptAsync() {
promptCalls += 1
},
}
const client = { session }
// when
const result = await dispatchInternalPrompt({
mode: "async",
client,
sessionID: "ses_bound_messages",
input: { path: { id: "ses_bound_messages" }, body: { parts: [] } },
source: "test:bound-messages",
settleMs: 0,
postDispatchHoldMs: 0,
})
// then
expect(result.status).toBe("active")
expect(promptCalls).toBe(0)
})
test("#given session.status reports busy #when an internal promptAsync is requested #then no prompt is sent", async () => {
// given
let promptCalls = 0
+3 -2
View File
@@ -238,10 +238,11 @@ async function sessionLatestAssistantIsWaitingOnTools<TInput>(args: {
source: string
timeoutMs: number
}): Promise<boolean> {
const messages = args.client.session?.messages
if (typeof messages !== "function") {
const session = args.client.session
if (typeof session?.messages !== "function") {
return false
}
const messages = session.messages.bind(session)
try {
const response = await withDispatchTimeout(