|
|
@@ -1,6 +1,7 @@
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
+import type { SessionNotFoundError } from "@opencode-ai/sdk/v2/client"
|
|
|
import type { ConfigInvalidError, ProviderModelNotFoundError } from "./server-errors"
|
|
|
-import { formatServerError, parseReadableConfigInvalidError } from "./server-errors"
|
|
|
+import { formatServerError, isSessionNotFoundError, parseReadableConfigInvalidError } from "./server-errors"
|
|
|
|
|
|
function fill(text: string, vars?: Record<string, string | number>) {
|
|
|
if (!vars) return text
|
|
|
@@ -142,3 +143,33 @@ describe("formatServerError", () => {
|
|
|
expect(formatServerError(wrapped, language.t)).toBe("Arquivo de config em config invalido: Missing host")
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+describe("isSessionNotFoundError", () => {
|
|
|
+ test("matches an SDK-wrapped error for the requested session", () => {
|
|
|
+ const body = {
|
|
|
+ _tag: "SessionNotFoundError",
|
|
|
+ sessionID: "ses_missing",
|
|
|
+ message: "Session not found",
|
|
|
+ } satisfies SessionNotFoundError
|
|
|
+
|
|
|
+ expect(isSessionNotFoundError(new Error(body.message, { cause: { body, status: 404 } }), body.sessionID)).toBe(true)
|
|
|
+ })
|
|
|
+
|
|
|
+ test("rejects errors for other sessions and other 404 responses", () => {
|
|
|
+ const body = {
|
|
|
+ _tag: "SessionNotFoundError",
|
|
|
+ sessionID: "ses_parent",
|
|
|
+ message: "Session not found",
|
|
|
+ } satisfies SessionNotFoundError
|
|
|
+
|
|
|
+ expect(isSessionNotFoundError(new Error(body.message, { cause: { body, status: 404 } }), "ses_tab")).toBe(false)
|
|
|
+ expect(
|
|
|
+ isSessionNotFoundError(
|
|
|
+ new Error("Provider not found", {
|
|
|
+ cause: { body: { _tag: "ProviderNotFoundError", providerID: "missing" }, status: 404 },
|
|
|
+ }),
|
|
|
+ "ses_tab",
|
|
|
+ ),
|
|
|
+ ).toBe(false)
|
|
|
+ })
|
|
|
+})
|