Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import { isTransportConnectionErrorMessage, sanitizeThreadErrorMessage } from "./transportError.ts";
4
5describe("isTransportConnectionErrorMessage", () => {
6 it("returns true for SocketCloseError", () => {
7 expect(isTransportConnectionErrorMessage("SocketCloseError: connection reset")).toBe(true);
8 });
9
10 it("returns true for SocketOpenError", () => {
11 expect(isTransportConnectionErrorMessage("SocketOpenError: ECONNREFUSED")).toBe(true);
12 });
13
14 it("returns true for the T3 server WebSocket message", () => {
15 expect(isTransportConnectionErrorMessage("Unable to connect to the T3 server WebSocket.")).toBe(
16 true,
17 );
18 });
19
20 it("returns true for ping timeout", () => {
21 expect(isTransportConnectionErrorMessage("ping timeout")).toBe(true);
22 });
23
24 it("returns false for business logic errors", () => {
25 expect(isTransportConnectionErrorMessage("Thread not found")).toBe(false);
26 expect(isTransportConnectionErrorMessage("Invalid model selection")).toBe(false);
27 });
28
29 it("returns false for null, undefined, and empty strings", () => {
30 expect(isTransportConnectionErrorMessage(null)).toBe(false);
31 expect(isTransportConnectionErrorMessage(undefined)).toBe(false);
32 expect(isTransportConnectionErrorMessage("")).toBe(false);
33 expect(isTransportConnectionErrorMessage(" ")).toBe(false);
34 });
35});
36
37describe("sanitizeThreadErrorMessage", () => {
38 it("strips transport errors", () => {
39 expect(sanitizeThreadErrorMessage("SocketCloseError: oops")).toBeNull();
40 });
41
42 it("preserves non-transport errors", () => {
43 expect(sanitizeThreadErrorMessage("Thread not found")).toBe("Thread not found");
44 expect(sanitizeThreadErrorMessage("Select a base branch before sending.")).toBe(
45 "Select a base branch before sending.",
46 );
47 });
48
49 it("returns null for null/undefined", () => {
50 expect(sanitizeThreadErrorMessage(null)).toBeNull();
51 expect(sanitizeThreadErrorMessage(undefined)).toBeNull();
52 });
53});