feat(shared): define harness protocols

This commit is contained in:
Wenxin Duan
2026-09-07 15:23:12 +08:00
parent 98baf9aee7
commit e87c68f3ad
9 changed files with 380 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import * as shared from "../src/index.js";
function messageSchema(): { safeParse(value: unknown): { success: boolean } } {
const candidate = Reflect.get(shared, "MessageInputSchema");
expect(candidate, "MessageInputSchema must be exported").toBeDefined();
return candidate;
}
describe("MessageInputSchema", () => {
it("accepts text-only, image-only, and combined messages", () => {
expect(messageSchema().safeParse({ text: "hello", attachmentIds: [] }).success).toBe(true);
expect(messageSchema().safeParse({ text: "", attachmentIds: ["att_123"] }).success).toBe(true);
expect(messageSchema().safeParse({ text: "look", attachmentIds: ["att_123"] }).success).toBe(true);
});
it("rejects a message without text or attachments", () => {
expect(messageSchema().safeParse({ text: " ", attachmentIds: [] }).success).toBe(false);
});
it("rejects duplicate or malformed attachment ids", () => {
expect(messageSchema().safeParse({ text: "x", attachmentIds: ["att_1", "att_1"] }).success).toBe(false);
expect(messageSchema().safeParse({ text: "x", attachmentIds: ["../secret"] }).success).toBe(false);
});
});