feat: initial commit

This commit is contained in:
Jeffrey Wu
2026-09-07 09:57:33 +08:00
commit f39f6ac881
66 changed files with 9859 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import { apiErrorSchema, harnessEventSchema, modelConnectionInputSchema, persistedModelConnectionSchema, sendMessageSchema } from "../src/index.js";
describe("shared boundary schemas", () => {
it("accepts a typed HarnessEvent variant", () => {
expect(harnessEventSchema.parse({ eventId: "evt_1", sessionId: "ses_1", runId: "run_1", timestamp: new Date().toISOString(), sequence: 1, type: "assistant.delta", payload: { messageId: "msg_1", delta: "Hi" } }).type).toBe("assistant.delta");
});
it("rejects the wrong discriminated payload", () => {
expect(() => harnessEventSchema.parse({ eventId: "e", sessionId: "s", timestamp: new Date().toISOString(), sequence: 1, type: "run.completed", payload: { unexpected: true } })).toThrow();
});
it("strictly validates model configuration", () => {
expect(() => modelConnectionInputSchema.parse({ providerId: "openai", api: "made-up", modelId: "x", supportsImages: false })).toThrow();
expect(() => modelConnectionInputSchema.parse({ providerId: "openai", api: "openai-responses", modelId: "x", supportsImages: false, headers: {} })).toThrow();
});
it("accepts valid model configuration", () => {
expect(modelConnectionInputSchema.parse({ providerId: "openai", api: "openai-responses", modelId: "gpt", supportsImages: true }).modelId).toBe("gpt");
});
it("persists only non-sensitive model configuration", () => {
const value = { providerId: "openai", api: "openai-responses", modelId: "gpt", supportsImages: true };
expect(persistedModelConnectionSchema.parse(value)).toEqual(value);
expect(() => persistedModelConnectionSchema.parse({ ...value, apiKey: "secret" })).toThrow();
});
it("requires text or attachments", () => {
expect(() => sendMessageSchema.parse({ text: "", attachmentIds: [] })).toThrow();
expect(sendMessageSchema.parse({ text: "", attachmentIds: ["att_ok"] }).attachmentIds).toEqual(["att_ok"]);
});
it("rejects malformed attachment ids", () => {
expect(() => sendMessageSchema.parse({ text: "x", attachmentIds: ["../escape"] })).toThrow();
});
it("validates the unified error envelope", () => {
expect(apiErrorSchema.parse({ error: { code: "SESSION_NOT_FOUND", message: "Session not found", requestId: "req_1", details: {} } }).error.code).toBe("SESSION_NOT_FOUND");
});
});