|
1 | 1 | // Imported by dispatch-from-config.test.ts to keep its mocked suite in one Vitest module graph. |
2 | 2 | import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { registerAgentHarness } from "../../agents/harness/registry.js"; |
| 4 | +import { |
| 5 | + buildAgentHarnessQuestionPromptPayload, |
| 6 | + deliverAgentHarnessUserInputPrompt, |
| 7 | +} from "../../agents/harness/user-input-bridge.js"; |
4 | 8 | import type { OpenClawConfig } from "../../config/config.js"; |
5 | 9 | import { settleReplyDispatcher } from "../dispatch-dispatcher.js"; |
6 | 10 | import { getReplyPayloadMetadata, setReplyPayloadMetadata } from "../reply-payload.js"; |
@@ -163,6 +167,54 @@ describe("sendPolicy deny — suppress delivery, not processing (#53328)", () => |
163 | 167 | expect(onBlockReplyQueued).not.toHaveBeenCalled(); |
164 | 168 | }); |
165 | 169 |
|
| 170 | + it.each([ |
| 171 | + { |
| 172 | + name: "gateway-backed choice", |
| 173 | + deliver: async (onBlockReply: NonNullable<GetReplyOptions["onBlockReply"]>) => { |
| 174 | + await onBlockReply( |
| 175 | + buildAgentHarnessQuestionPromptPayload({ |
| 176 | + questionId: "question-owned-by-harness", |
| 177 | + questions: [ |
| 178 | + { |
| 179 | + id: "color", |
| 180 | + header: "Color", |
| 181 | + question: "Choose a color", |
| 182 | + options: [{ label: "Red" }, { label: "Blue" }], |
| 183 | + }, |
| 184 | + ], |
| 185 | + }), |
| 186 | + ); |
| 187 | + }, |
| 188 | + }, |
| 189 | + { |
| 190 | + name: "plain secret", |
| 191 | + deliver: async (onBlockReply: NonNullable<GetReplyOptions["onBlockReply"]>) => { |
| 192 | + await deliverAgentHarnessUserInputPrompt({ onBlockReply }, [ |
| 193 | + { id: "token", header: "Token", question: "Enter your token", isSecret: true }, |
| 194 | + ]); |
| 195 | + }, |
| 196 | + }, |
| 197 | + ])("delivers $name harness questions in direct message-tool-only turns", async ({ deliver }) => { |
| 198 | + setNoAbort(); |
| 199 | + sessionStoreMocks.currentEntry = { sessionId: "s1", updatedAt: 0, sendPolicy: "allow" }; |
| 200 | + const dispatcher = createDispatcher(); |
| 201 | + const replyResolver = vi.fn(async (_ctx: MsgContext, opts?: GetReplyOptions) => { |
| 202 | + await deliver(requireBlockReplyHandler(opts?.onBlockReply)); |
| 203 | + return []; |
| 204 | + }); |
| 205 | + |
| 206 | + const result = await dispatchReplyFromConfig({ |
| 207 | + ctx: buildTestCtx({ ChatType: "direct", SessionKey: "test:harness-question" }), |
| 208 | + cfg: emptyConfig, |
| 209 | + dispatcher, |
| 210 | + replyResolver, |
| 211 | + replyOptions: { sourceReplyDeliveryMode: "message_tool_only" }, |
| 212 | + }); |
| 213 | + |
| 214 | + expect(result.queuedFinal).toBe(false); |
| 215 | + expect(dispatcher.sendBlockReply).toHaveBeenCalledTimes(1); |
| 216 | + }); |
| 217 | + |
166 | 218 | it("keeps hook-cancelled marked blocks out of delivery and queued callbacks", async () => { |
167 | 219 | setNoAbort(); |
168 | 220 | sessionStoreMocks.currentEntry = { |
|
0 commit comments