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
+23
View File
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import * as shared from "../src/index.js";
describe("createApiError", () => {
it("returns the uniform safe error envelope", () => {
const factory = Reflect.get(shared, "createApiError") as ((code: string, message: string, requestId: string, details?: Record<string, unknown>) => unknown) | undefined;
expect(factory, "createApiError must be exported").toBeDefined();
expect(factory?.("SESSION_NOT_FOUND", "Session not found", "req_1", { sessionId: "ses_1" })).toEqual({
error: {
code: "SESSION_NOT_FOUND",
message: "Session not found",
requestId: "req_1",
details: { sessionId: "ses_1" },
},
});
});
it("rejects malformed envelopes", () => {
const candidate = Reflect.get(shared, "ApiErrorSchema") as { safeParse(value: unknown): { success: boolean } } | undefined;
expect(candidate, "ApiErrorSchema must be exported").toBeDefined();
expect(candidate?.safeParse({ error: { code: "", message: "bad" } }).success).toBe(false);
});
});