Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { NETWORK_BLOCKING_HINT } from "./network.ts";
4import { isTransportConnectionErrorMessage, sanitizeThreadErrorMessage } from "./transport.ts";
5
6describe("isTransportConnectionErrorMessage", () => {
7 it("returns true for SocketCloseError", () => {
8 expect(isTransportConnectionErrorMessage("SocketCloseError: connection reset")).toBe(true);
9 });
10
11 it("returns true for SocketOpenError", () => {
12 expect(isTransportConnectionErrorMessage("SocketOpenError: ECONNREFUSED")).toBe(true);
13 });
14
15 it("returns true for React Native disconnected socket errors", () => {
16 expect(
17 isTransportConnectionErrorMessage(
18 "The operation couldn't be completed. Socket is not connected",
19 ),
20 ).toBe(true);
21 });
22
23 it("recognizes connection errors emitted by the Effect RPC session", () => {
24 expect(isTransportConnectionErrorMessage("Test environment disconnected.")).toBe(true);
25 expect(isTransportConnectionErrorMessage("Test environment stopped responding.")).toBe(true);
26 expect(
27 isTransportConnectionErrorMessage(
28 "Test environment stopped responding for 15s. It may be overloaded, asleep, or off the network.",
29 ),
30 ).toBe(true);
31 expect(
32 isTransportConnectionErrorMessage(
33 "Test environment could not establish a WebSocket connection.",
34 ),
35 ).toBe(true);
36 expect(isTransportConnectionErrorMessage("Test environment is not connected.")).toBe(true);
37 expect(isTransportConnectionErrorMessage("ClientProtocolError: socket closed")).toBe(true);
38 });
39
40 it("recognizes relay connection errors that carry the network hint", () => {
41 for (const sentence of [
42 "Relay environment disconnected.",
43 "Relay environment stopped responding.",
44 "Relay environment could not establish a WebSocket connection.",
45 ]) {
46 expect(isTransportConnectionErrorMessage(`${sentence} ${NETWORK_BLOCKING_HINT}`)).toBe(true);
47 }
48 expect(
49 isTransportConnectionErrorMessage(
50 "Your ChatGPT connection expired or was disconnected. Sign in again.",
51 ),
52 ).toBe(false);
53 });
54
55 it("returns true for the T3 server WebSocket message", () => {
56 expect(isTransportConnectionErrorMessage("Unable to connect to the T3 server WebSocket.")).toBe(
57 true,
58 );
59 });
60
61 it("returns true for ping timeout", () => {
62 expect(isTransportConnectionErrorMessage("ping timeout")).toBe(true);
63 });
64
65 it("returns false for business logic errors", () => {
66 expect(isTransportConnectionErrorMessage("Thread not found")).toBe(false);
67 expect(isTransportConnectionErrorMessage("Invalid model selection")).toBe(false);
68 });
69
70 it("returns false for null, undefined, and empty strings", () => {
71 expect(isTransportConnectionErrorMessage(null)).toBe(false);
72 expect(isTransportConnectionErrorMessage(undefined)).toBe(false);
73 expect(isTransportConnectionErrorMessage("")).toBe(false);
74 expect(isTransportConnectionErrorMessage(" ")).toBe(false);
75 });
76});
77
78describe("sanitizeThreadErrorMessage", () => {
79 it("strips transport errors", () => {
80 expect(sanitizeThreadErrorMessage("SocketCloseError: oops")).toBeNull();
81 });
82
83 it("preserves non-transport errors", () => {
84 expect(sanitizeThreadErrorMessage("Thread not found")).toBe("Thread not found");
85 expect(sanitizeThreadErrorMessage("Select a base branch before sending.")).toBe(
86 "Select a base branch before sending.",
87 );
88 });
89
90 it("returns null for null/undefined", () => {
91 expect(sanitizeThreadErrorMessage(null)).toBeNull();
92 expect(sanitizeThreadErrorMessage(undefined)).toBeNull();
93 });
94});