| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { |
| 4 | type ModelSelection, |
| 5 | type OrchestrationV2ProviderCapabilities, |
| 6 | ProviderInstanceId, |
| 7 | } from "@t3tools/contracts"; |
| 8 | |
| 9 | import { AcpProviderCapabilitiesV2 } from "@t3tools/provider-acp/server/adapter"; |
| 10 | import { acpSelectionTransition } from "@t3tools/provider-core/server/selectionTransition"; |
| 11 | |
| 12 | const selection = (model: string, effort = "medium"): ModelSelection => ({ |
| 13 | instanceId: ProviderInstanceId.make("acp_test"), |
| 14 | model, |
| 15 | options: [{ id: "effort", value: effort }], |
| 16 | }); |
| 17 | |
| 18 | describe("acpSelectionTransition", () => { |
| 19 | it("rejects model changes when the negotiated session cannot apply them", () => { |
| 20 | expect( |
| 21 | acpSelectionTransition({ |
| 22 | current: selection("old"), |
| 23 | target: selection("new"), |
| 24 | sessionCapabilities: AcpProviderCapabilitiesV2, |
| 25 | }).type, |
| 26 | ).toBe("reject"); |
| 27 | }); |
| 28 | |
| 29 | it("allows model changes when the negotiated session can apply them", () => { |
| 30 | const sessionCapabilities: OrchestrationV2ProviderCapabilities = { |
| 31 | ...AcpProviderCapabilitiesV2, |
| 32 | sessions: { |
| 33 | ...AcpProviderCapabilitiesV2.sessions, |
| 34 | supportsModelSwitchInSession: true, |
| 35 | }, |
| 36 | }; |
| 37 | expect( |
| 38 | acpSelectionTransition({ |
| 39 | current: selection("old"), |
| 40 | target: selection("new"), |
| 41 | sessionCapabilities, |
| 42 | }), |
| 43 | ).toEqual({ type: "apply_on_next_turn" }); |
| 44 | }); |
| 45 | |
| 46 | it("allows option-only changes to be applied through ACP config options", () => { |
| 47 | expect( |
| 48 | acpSelectionTransition({ |
| 49 | current: selection("same", "medium"), |
| 50 | target: selection("same", "high"), |
| 51 | sessionCapabilities: AcpProviderCapabilitiesV2, |
| 52 | }), |
| 53 | ).toEqual({ type: "apply_on_next_turn" }); |
| 54 | }); |
| 55 | }); |