feat(shared): define harness protocols
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user