Use tagged errors in tests

This commit is contained in:
elpresidank 2026-06-04 08:10:09 -05:00
parent c4500f216e
commit c48927b7c5
8 changed files with 104 additions and 23 deletions

View file

@ -324,7 +324,10 @@ describe("Message Types", () => {
describe("LibraryResponse", () => {
it("should have correct structure", () => {
const response: LibraryResponse = {
error: new Error(),
error: {
message: "Library unavailable",
type: "library-error",
},
"document-metadatas": [
{
id: "doc-1",
@ -334,7 +337,10 @@ describe("Message Types", () => {
],
};
expect(response.error).toBeInstanceOf(Error);
expect(response.error).toMatchObject({
message: "Library unavailable",
type: "library-error",
});
expect(response["document-metadatas"]).toHaveLength(1);
expect(response["document-metadatas"]![0].id).toBe("doc-1");
});

View file

@ -2,13 +2,14 @@ import type { Term, Triple } from "./Triple.js";
export type Request = object;
export type Response = object;
export type Error = object | string;
export interface ResponseError {
type?: string;
message: string;
}
export type WireError = object | string;
export interface RequestMessage {
id: string;
service: string;
@ -315,7 +316,7 @@ export interface LibraryRequest {
}
export interface LibraryResponse {
error?: Error;
error?: WireError;
"document-metadata"?: DocumentMetadata;
documentMetadata?: DocumentMetadata;
content?: string;
@ -340,7 +341,7 @@ export interface KnowledgeRequest {
}
export interface KnowledgeResponse {
error?: Error;
error?: WireError;
ids?: string[];
eos?: boolean;
triples?: Triple[];
@ -371,7 +372,7 @@ export interface FlowResponse {
| {
message?: string;
}
| Error;
| WireError;
}
export interface PromptRequest {