Download src/infra/approval-errors.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/infra/approval-errors.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/infra/approval-errors.test.ts
-
curl -L -o approval-errors.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/infra/approval-errors.test.ts
1.91 kB
| // Covers approval-not-found error detection. | |
| import { describe, expect, it } from "vitest"; | |
| import { isApprovalNotFoundError, isApprovalStaleError } from "./approval-errors.js"; | |
| describe("isApprovalNotFoundError", () => { | |
| it("matches direct approval-not-found gateway codes", () => { | |
| const err = Object.assign(new Error("approval not found"), { | |
| gatewayCode: "APPROVAL_NOT_FOUND", | |
| }); | |
| expect(isApprovalNotFoundError(err)).toBe(true); | |
| }); | |
| it("matches structured invalid-request approval-not-found details", () => { | |
| const err = Object.assign(new Error("approval not found"), { | |
| gatewayCode: "INVALID_REQUEST", | |
| details: { reason: "APPROVAL_NOT_FOUND" }, | |
| }); | |
| expect(isApprovalNotFoundError(err)).toBe(true); | |
| }); | |
| it("matches legacy message-only not-found errors", () => { | |
| expect(isApprovalNotFoundError(new Error("unknown or expired approval id"))).toBe(true); | |
| expect(isApprovalNotFoundError(new Error("approval expired or not found"))).toBe(true); | |
| }); | |
| it("ignores unrelated errors", () => { | |
| expect(isApprovalNotFoundError(new Error("network timeout"))).toBe(false); | |
| expect(isApprovalNotFoundError("unknown or expired approval id")).toBe(false); | |
| }); | |
| }); | |
| describe("isApprovalStaleError", () => { | |
| it("matches structured already-resolved gateway errors", () => { | |
| const err = Object.assign(new Error("request rejected"), { | |
| gatewayCode: "INVALID_REQUEST", | |
| details: { reason: "APPROVAL_ALREADY_RESOLVED" }, | |
| }); | |
| expect(isApprovalStaleError(err)).toBe(true); | |
| }); | |
| it("includes approval-not-found errors", () => { | |
| const err = Object.assign(new Error("approval not found"), { | |
| gatewayCode: "APPROVAL_NOT_FOUND", | |
| }); | |
| expect(isApprovalStaleError(err)).toBe(true); | |
| }); | |
| it("ignores transient errors", () => { | |
| expect(isApprovalStaleError(new Error("gateway unavailable"))).toBe(false); | |
| }); | |
| }); | |