mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 04:22:43 +00:00
perf(test): consolidate pi-embedded helpers e2e suites
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
BILLING_ERROR_USER_MESSAGE,
|
||||
formatBillingErrorMessage,
|
||||
formatAssistantErrorText,
|
||||
formatRawAssistantErrorForUi,
|
||||
} from "./pi-embedded-helpers.js";
|
||||
|
||||
describe("formatAssistantErrorText", () => {
|
||||
@@ -114,3 +115,38 @@ describe("formatAssistantErrorText", () => {
|
||||
expect(formatAssistantErrorText(msg)).toBe("LLM request timed out.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatRawAssistantErrorForUi", () => {
|
||||
it("renders HTTP code + type + message from Anthropic payloads", () => {
|
||||
const text = formatRawAssistantErrorForUi(
|
||||
'429 {"type":"error","error":{"type":"rate_limit_error","message":"Rate limited."},"request_id":"req_123"}',
|
||||
);
|
||||
|
||||
expect(text).toContain("HTTP 429");
|
||||
expect(text).toContain("rate_limit_error");
|
||||
expect(text).toContain("Rate limited.");
|
||||
expect(text).toContain("req_123");
|
||||
});
|
||||
|
||||
it("renders a generic unknown error message when raw is empty", () => {
|
||||
expect(formatRawAssistantErrorForUi("")).toContain("unknown error");
|
||||
});
|
||||
|
||||
it("formats plain HTTP status lines", () => {
|
||||
expect(formatRawAssistantErrorForUi("500 Internal Server Error")).toBe(
|
||||
"HTTP 500: Internal Server Error",
|
||||
);
|
||||
});
|
||||
|
||||
it("sanitizes HTML error pages into a clean unavailable message", () => {
|
||||
const htmlError = `521 <!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head><title>Web server is down | example.com | Cloudflare</title></head>
|
||||
<body>Ray ID: abc123</body>
|
||||
</html>`;
|
||||
|
||||
expect(formatRawAssistantErrorForUi(htmlError)).toBe(
|
||||
"The AI service is temporarily unavailable (HTTP 521). Please try again in a moment.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user