1import { describe, expect, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3
4import * as V1 from "./_generated/schema-v1.gen.ts";
5import * as V2 from "./schema.ts";
6
7describe("pinned ACP wire schemas", () => {
8 it("validates known content variants without accepting malformed ones as future content", () => {
9 const accepts = Schema.is(V2.ContentBlock);
10 expect(accepts({ type: "text", text: "hello" })).toBe(true);
11 expect(accepts({ type: "text" })).toBe(false);
12 expect(accepts({ type: "image", data: "aGVsbG8=" })).toBe(false);
13 expect(accepts({ type: "future_content", payload: { value: 1 } })).toBe(true);
14 });
15
16 it("requires both the elicitation scope and the selected mode's fields", () => {
17 const accepts = Schema.is(V2.CreateElicitationRequest);
18 const form = {
19 sessionId: "session-1",
20 mode: "form",
21 message: "Choose a branch",
22 requestedSchema: { type: "object", properties: {} },
23 };
24 expect(accepts(form)).toBe(true);
25 expect(accepts({ ...form, requestedSchema: undefined })).toBe(false);
26 expect(accepts({ ...form, sessionId: undefined })).toBe(false);
27 expect(accepts({ sessionId: "session-1", mode: "url", message: "Sign in" })).toBe(false);
28 });
29
30 it("keeps v1 command inputs compatible with native agents", () => {
31 const command = { name: "plan", description: "Make a plan", input: { hint: "Task" } };
32 expect(Schema.is(V1.AvailableCommand)(command)).toBe(true);
33 expect(
34 Schema.is(V2.AvailableCommand)({ ...command, input: { type: "text", hint: "Task" } }),
35 ).toBe(true);
36 });
37});