From 1e91eb6a2e7ebe97655b4dfd85bf6544da9f9bec Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:05:40 +0100 Subject: [PATCH 1/7] test(scenarios): ACP question requires the requested number of choices Co-authored-by: Claude Opus 5.5 --- ...cp-question-requires-enough-choices.e2e.ts | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 scripts/scenarios/acp-question-requires-enough-choices.e2e.ts diff --git a/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts b/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts new file mode 100644 index 0000000000000..ec60e002c4adf --- /dev/null +++ b/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts @@ -0,0 +1,98 @@ +// @effect-diagnostics nodeBuiltinImport:off -- Seed a local recording for the dev Replay agent. +import * as NodeFSP from "node:fs/promises"; +import * as NodePath from "node:path"; + +import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; +import { expect } from "e2e"; +import * as Effect from "effect/Effect"; + +import { T3_HOME } from "../e2e.config.ts"; +import { rpcClient, runPromise, test, WEB } from "./t3.ts"; + +const recording = [ + { type: "expect_outbound", frame: { kind: "request", method: "session/prompt" } }, + { + type: "emit_inbound", + frame: { + kind: "request", + method: "elicitation/create", + params: { + sessionId: "demo-session", + mode: "form", + message: "Choose where to run the tests.", + requestedSchema: { + type: "object", + properties: { + targets: { + type: "array", + title: "Test targets", + description: "Choose at least two targets.", + items: { type: "string", enum: ["Web", "Desktop", "Mobile"] }, + minItems: 2, + }, + }, + required: ["targets"], + }, + }, + }, + }, + { + type: "emit_inbound", + frame: { kind: "response", method: "session/prompt", result: { stopReason: "end_turn" } }, + }, +] + .map((entry) => JSON.stringify(entry)) + .join("\n"); + +test( + "An ACP question requires the requested number of choices", + WEB, + async ({ t3, app, screen }) => { + const replayAgent = await NodeFSP.readFile( + new URL("../../apps/server/scripts/dev-replay-agent.ts", import.meta.url), + "utf8", + ); + const project = await t3.project("Test targets demo", { + "replay/dev-replay-agent.ts": replayAgent, + "replay/dev-replay/showcase_transcript.ndjson": recording, + }); + await runPromise( + Effect.gen(function* () { + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); + yield* client["server.updateSettings"]({ + patch: {}, + providerInstanceMutation: { + operation: "upsert", + instanceId: ProviderInstanceId.make("devReplay"), + instance: { + driver: ProviderDriverKind.make("acpRegistry"), + displayName: "Replay (dev)", + enabled: true, + config: { + source: "local", + commandPath: process.execPath, + commandArgs: [NodePath.join(project, "replay/dev-replay-agent.ts")], + }, + }, + }, + }); + }).pipe(Effect.scoped), + ); + const thread = await t3.thread({ + project, + title: "Choose test targets", + messages: ["Ask me where to run the tests."], + model: "default", + }); + await t3.open(thread); + + const web = screen.getByRole("button", { name: /^Web\b/ }); + const submit = screen.getByRole("button", { name: "Submit", exact: true }); + await web.tap(); + await expect(web).toHaveAttribute("aria-pressed", "true"); + await app.screenshot("one-of-two-required-targets"); + await expect(submit).toBeDisabled(); + await screen.getByRole("button", { name: /^Mobile\b/ }).tap(); + await expect(submit).toBeEnabled(); + }, +); From ee7f507916b7545435ba0ba2a3b457fc4fb74add Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:06:13 +0100 Subject: [PATCH 2/7] fix(acp): ACP forms need the requested number of choices before submitting Multi-select questions now carry the schema's minItems as minSelections, and the shared answer resolver keeps Submit disabled until enough options are checked, so a too-short selection is no longer sent as a cancellation. Co-authored-by: Claude Opus 5.5 --- packages/client-runtime/src/state/pendingUserInput.ts | 6 ++++-- packages/contracts/src/orchestrationV2.ts | 2 ++ packages/provider-acp/src/server/elicitationForm.ts | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.ts b/packages/client-runtime/src/state/pendingUserInput.ts index 821ca1eddad7a..dc3f36faff152 100644 --- a/packages/client-runtime/src/state/pendingUserInput.ts +++ b/packages/client-runtime/src/state/pendingUserInput.ts @@ -3,6 +3,7 @@ export interface PendingUserInputQuestion { readonly id: string; readonly options: ReadonlyArray<{ readonly label: string; readonly value?: string | undefined }>; readonly multiSelect?: boolean | undefined; + readonly minSelections?: number | undefined; readonly allowCustomAnswer?: boolean | undefined; readonly initialAnswer?: string | undefined; readonly required?: boolean | undefined; @@ -82,9 +83,10 @@ export function resolvePendingUserInputAnswer( (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null); if (question.multiSelect) { // Checking nothing answers "none of these" unless the provider requires a choice. - return selectedOptionValues.length > 0 + if (selectedOptionValues.length === 0) return fallback ?? (question.required ? null : []); + return selectedOptionValues.length >= (question.minSelections ?? 1) ? selectedOptionValues - : (fallback ?? (question.required ? null : [])); + : null; } return selectedOptionValues[0] ?? fallback; } diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 68f90a24532f6..b0d14a158948c 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -1660,6 +1660,8 @@ export const OrchestrationV2UserInputQuestion = Schema.Struct({ }), ), multiSelect: Schema.optional(Schema.Boolean), + /** The fewest options a non-empty multi-select answer may check. */ + minSelections: Schema.optional(PositiveInt), allowCustomAnswer: Schema.optional(Schema.Boolean), initialAnswer: Schema.optional(Schema.String), required: Schema.optional(Schema.Boolean), diff --git a/packages/provider-acp/src/server/elicitationForm.ts b/packages/provider-acp/src/server/elicitationForm.ts index 2b11f37f8ec12..dd8c6340cd06e 100644 --- a/packages/provider-acp/src/server/elicitationForm.ts +++ b/packages/provider-acp/src/server/elicitationForm.ts @@ -279,6 +279,9 @@ export function parseElicitationForm( ? {} : { allowCustomAnswer: false }), ...(kind === "multiChoice" ? { multiSelect: true } : {}), + ...(field?.kind === "multiChoice" && field.minItems > 1 + ? { minSelections: field.minItems } + : {}), // An empty selection answers "none" unless the schema demands a choice. ...(field?.kind === "multiChoice" && field.minItems > 0 && required.has(id) ? { required: true } From 35ff6c90f9f1007587f66758d3a455b1bd63681a Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:07:02 +0100 Subject: [PATCH 3/7] test: cover minimum multi-select counts in ACP forms and answers Co-authored-by: Claude Opus 5.5 --- .../src/state/pendingUserInput.test.ts | 26 +++++++++++++++++++ .../src/server/elicitationForm.test.ts | 21 ++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.test.ts b/packages/client-runtime/src/state/pendingUserInput.test.ts index 05c38d7756cf1..ec2ba6c607a5c 100644 --- a/packages/client-runtime/src/state/pendingUserInput.test.ts +++ b/packages/client-runtime/src/state/pendingUserInput.test.ts @@ -224,6 +224,32 @@ describe("buildPendingUserInputAnswers", () => { ).toBeNull(); }); + it("waits for the provider's minimum number of checked options", () => { + const targets = { + id: "targets", + header: "Targets", + question: "Where should the tests run?", + options: [{ label: "Web" }, { label: "Desktop" }, { label: "Mobile" }], + multiSelect: true, + minSelections: 2, + } as const; + const answers = (selectedOptionValues: ReadonlyArray) => + buildPendingUserInputAnswers([targets], { targets: { selectedOptionValues } }); + + expect(answers([])).toEqual({ targets: [] }); + expect(answers(["Web"])).toBeNull(); + expect(answers(["Web", "Web"])).toBeNull(); + expect(answers(["Web", "Mobile"])).toEqual({ targets: ["Web", "Mobile"] }); + expect(answers(["Web", "Desktop", "Mobile"])).toEqual({ + targets: ["Web", "Desktop", "Mobile"], + }); + expect( + buildPendingUserInputAnswers([{ ...targets, required: true }], { + targets: { selectedOptionValues: [] }, + }), + ).toBeNull(); + }); + it("omits an unselected optional single choice and keeps explicit false and empty choices", () => { const extras = { id: "extras", diff --git a/packages/provider-acp/src/server/elicitationForm.test.ts b/packages/provider-acp/src/server/elicitationForm.test.ts index 3bb0ab52bc8b3..062ec5078c9e0 100644 --- a/packages/provider-acp/src/server/elicitationForm.test.ts +++ b/packages/provider-acp/src/server/elicitationForm.test.ts @@ -169,24 +169,27 @@ describe("parseElicitationForm", () => { targets: { type: "array", minItems: 1, items }, extras: { type: "array", items }, platforms: { type: "array", minItems: 1, items }, + pair: { type: "array", minItems: 2, items }, }, - required: ["targets"], + required: ["targets", "pair"], }, "Choose", ); assert(form !== undefined); assert.deepStrictEqual( - form.questions.map((question) => [question.id, question.required]), + form.questions.map((question) => [question.id, question.required, question.minSelections]), [ - ["targets", true], - ["extras", undefined], - ["platforms", undefined], + ["targets", true, undefined], + ["extras", undefined, undefined], + ["platforms", undefined, undefined], + ["pair", true, 2], ], ); - assert.deepStrictEqual(form.content({ targets: ["web"], extras: [], platforms: [] }), { - targets: ["web"], - extras: [], - }); + assert.isUndefined(form.content({ targets: ["web"], pair: ["web"] })); + assert.deepStrictEqual( + form.content({ targets: ["web"], extras: [], platforms: [], pair: ["web", "mobile"] }), + { targets: ["web"], extras: [], pair: ["web", "mobile"] }, + ); }); it("marks optional number and integer fields as not required and omits blank answers", () => { From 7b75cb32b16f6c5a3da60566200e2f6364f9d121 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:18:43 +0100 Subject: [PATCH 4/7] fix(client-runtime): text and attachments do not replace a required minimum of choices Co-authored-by: Claude Opus 5.5 --- packages/client-runtime/src/state/pendingUserInput.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.ts b/packages/client-runtime/src/state/pendingUserInput.ts index dc3f36faff152..b1d0de07f208c 100644 --- a/packages/client-runtime/src/state/pendingUserInput.ts +++ b/packages/client-runtime/src/state/pendingUserInput.ts @@ -64,13 +64,18 @@ export function resolvePendingUserInputAnswer( draft: PendingUserInputDraftAnswer | undefined, ): PendingUserInputAnswer | null { if (draft?.attachmentsBlocked) return null; + // Text or attachments cannot stand in for a required minimum of checked options. + const selectionsRequired = + question.multiSelect === true && + question.required === true && + question.minSelections !== undefined; const customAnswer = question.allowCustomAnswer === false ? null : question.initialAnswer !== undefined ? (draft?.customAnswer ?? null) : normalizeDraftAnswer(draft?.customAnswer); - if (customAnswer !== null && customAnswer.length > 0) { + if (customAnswer !== null && customAnswer.length > 0 && !selectionsRequired) { return customAnswer; } if (question.required === false && question.options.length === 0) { @@ -83,7 +88,9 @@ export function resolvePendingUserInputAnswer( (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null); if (question.multiSelect) { // Checking nothing answers "none of these" unless the provider requires a choice. - if (selectedOptionValues.length === 0) return fallback ?? (question.required ? null : []); + if (selectedOptionValues.length === 0) { + return selectionsRequired ? null : (fallback ?? (question.required ? null : [])); + } return selectedOptionValues.length >= (question.minSelections ?? 1) ? selectedOptionValues : null; From 97d7c227bf05b6131c9c70865e996d62743f2133 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:18:43 +0100 Subject: [PATCH 5/7] test(client-runtime): cover text and attachment answers on a required minimum Co-authored-by: Claude Opus 5.5 --- .../src/state/pendingUserInput.test.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.test.ts b/packages/client-runtime/src/state/pendingUserInput.test.ts index ec2ba6c607a5c..3fa77cf798fcc 100644 --- a/packages/client-runtime/src/state/pendingUserInput.test.ts +++ b/packages/client-runtime/src/state/pendingUserInput.test.ts @@ -243,11 +243,24 @@ describe("buildPendingUserInputAnswers", () => { expect(answers(["Web", "Desktop", "Mobile"])).toEqual({ targets: ["Web", "Desktop", "Mobile"], }); + expect(buildPendingUserInputAnswers([targets], { targets: { customAnswer: "CI" } })).toEqual({ + targets: "CI", + }); + + const required = { ...targets, required: true }; + for (const draft of [ + { selectedOptionValues: [] }, + { customAnswer: "CI" }, + { attachmentCount: 1 }, + { selectedOptionValues: ["Web"], attachmentCount: 1 }, + ]) { + expect(buildPendingUserInputAnswers([required], { targets: draft })).toBeNull(); + } expect( - buildPendingUserInputAnswers([{ ...targets, required: true }], { - targets: { selectedOptionValues: [] }, + buildPendingUserInputAnswers([required], { + targets: { selectedOptionValues: ["Web", "Desktop"], attachmentCount: 1 }, }), - ).toBeNull(); + ).toEqual({ targets: ["Web", "Desktop"] }); }); it("omits an unselected optional single choice and keeps explicit false and empty choices", () => { From bbad730cbc081550cda951792f08b2dde3c7f409 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 3 Dec 2026 21:02:29 +0000 Subject: [PATCH 6/7] test(client-runtime): drop minimum-choice assertions other cases already cover Co-Authored-By: Claude Opus 5.5 --- .../client-runtime/src/state/pendingUserInput.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.test.ts b/packages/client-runtime/src/state/pendingUserInput.test.ts index 3fa77cf798fcc..03aac437c0b62 100644 --- a/packages/client-runtime/src/state/pendingUserInput.test.ts +++ b/packages/client-runtime/src/state/pendingUserInput.test.ts @@ -238,18 +238,10 @@ describe("buildPendingUserInputAnswers", () => { expect(answers([])).toEqual({ targets: [] }); expect(answers(["Web"])).toBeNull(); - expect(answers(["Web", "Web"])).toBeNull(); expect(answers(["Web", "Mobile"])).toEqual({ targets: ["Web", "Mobile"] }); - expect(answers(["Web", "Desktop", "Mobile"])).toEqual({ - targets: ["Web", "Desktop", "Mobile"], - }); - expect(buildPendingUserInputAnswers([targets], { targets: { customAnswer: "CI" } })).toEqual({ - targets: "CI", - }); const required = { ...targets, required: true }; for (const draft of [ - { selectedOptionValues: [] }, { customAnswer: "CI" }, { attachmentCount: 1 }, { selectedOptionValues: ["Web"], attachmentCount: 1 }, From 247daaf7baff3a8b6cdb054da947209a10f19184 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 3 Dec 2026 21:09:08 +0000 Subject: [PATCH 7/7] test(scenarios): run the minimum-choice scenario on its own provider instance The scenario no longer repoints the shared Replay (dev) provider. Co-Authored-By: Claude Opus 5.5 --- ...cp-question-requires-enough-choices.e2e.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts b/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts index ec60e002c4adf..52c3b58bd0c0c 100644 --- a/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts +++ b/scripts/scenarios/acp-question-requires-enough-choices.e2e.ts @@ -7,7 +7,7 @@ import { expect } from "e2e"; import * as Effect from "effect/Effect"; import { T3_HOME } from "../e2e.config.ts"; -import { rpcClient, runPromise, test, WEB } from "./t3.ts"; +import { makeState, rpcClient, runPromise, test, WEB } from "./t3.ts"; const recording = [ { type: "expect_outbound", frame: { kind: "request", method: "session/prompt" } }, @@ -56,6 +56,7 @@ test( "replay/dev-replay-agent.ts": replayAgent, "replay/dev-replay/showcase_transcript.ndjson": recording, }); + const instanceId = ProviderInstanceId.make("scenario-choice-agent"); await runPromise( Effect.gen(function* () { const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); @@ -63,10 +64,10 @@ test( patch: {}, providerInstanceMutation: { operation: "upsert", - instanceId: ProviderInstanceId.make("devReplay"), + instanceId, instance: { driver: ProviderDriverKind.make("acpRegistry"), - displayName: "Replay (dev)", + displayName: "Choice fixture", enabled: true, config: { source: "local", @@ -78,13 +79,28 @@ test( }); }).pipe(Effect.scoped), ); - const thread = await t3.thread({ - project, - title: "Choose test targets", - messages: ["Ask me where to run the tests."], - model: "default", - }); - await t3.open(thread); + const { cli } = makeState(T3_HOME); + const started = await runPromise( + cli( + [ + "thread", + "start", + project, + "Ask me where to run the tests.", + "--title", + "Choose test targets", + "--provider", + instanceId, + "--model", + "default", + "--wait", + "--json", + ], + [2], + ), + ); + const { threadId } = JSON.parse(started.stdout) as { threadId: string }; + await t3.open({ threadId }); const web = screen.getByRole("button", { name: /^Web\b/ }); const submit = screen.getByRole("button", { name: "Submit", exact: true });