mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
fix(agents): keep upgrade-plan 402s in billing
This commit is contained in:
@@ -241,6 +241,21 @@ describe("failover-error", () => {
|
||||
).toBe("rate_limit");
|
||||
});
|
||||
|
||||
it("keeps plan-upgrade 402 wrappers aligned with status-split billing payloads", () => {
|
||||
const message = "Your usage limit has been reached. Please upgrade your plan.";
|
||||
expect(
|
||||
resolveFailoverReasonFromError({
|
||||
message: `HTTP 402 Payment Required: ${message}`,
|
||||
}),
|
||||
).toBe("billing");
|
||||
expect(
|
||||
resolveFailoverReasonFromError({
|
||||
status: 402,
|
||||
message,
|
||||
}),
|
||||
).toBe("billing");
|
||||
});
|
||||
|
||||
it("infers format errors from error messages", () => {
|
||||
expect(
|
||||
resolveFailoverReasonFromError({
|
||||
|
||||
@@ -579,6 +579,12 @@ describe("classifyFailoverReasonFromHttpStatus – 402 temporary limits", () =>
|
||||
);
|
||||
expect(classifyFailoverReasonFromHttpStatus(402, transientMessage)).toBe("rate_limit");
|
||||
});
|
||||
|
||||
it("keeps plan-upgrade 402 limit messages in billing", () => {
|
||||
const billingMessage = "Your usage limit has been reached. Please upgrade your plan.";
|
||||
expect(classifyFailoverReason(`HTTP 402 Payment Required: ${billingMessage}`)).toBe("billing");
|
||||
expect(classifyFailoverReasonFromHttpStatus(402, billingMessage)).toBe("billing");
|
||||
});
|
||||
});
|
||||
|
||||
describe("classifyFailoverReason", () => {
|
||||
|
||||
@@ -219,6 +219,12 @@ const BILLING_402_HINTS = [
|
||||
"add more credits",
|
||||
"top up",
|
||||
] as const;
|
||||
const BILLING_402_PLAN_HINTS = [
|
||||
"upgrade your plan",
|
||||
"upgrade plan",
|
||||
"current plan",
|
||||
"subscription",
|
||||
] as const;
|
||||
|
||||
const PERIODIC_402_HINTS = ["daily", "weekly", "monthly"] as const;
|
||||
const RETRYABLE_402_RETRY_HINTS = ["try again", "retry", "temporary", "cooldown"] as const;
|
||||
@@ -242,6 +248,7 @@ function includesAnyHint(text: string, hints: readonly string[]): boolean {
|
||||
function hasExplicit402BillingSignal(text: string): boolean {
|
||||
return (
|
||||
includesAnyHint(text, BILLING_402_HINTS) ||
|
||||
(includesAnyHint(text, BILLING_402_PLAN_HINTS) && text.includes("limit")) ||
|
||||
text.includes("billing hard limit") ||
|
||||
text.includes("hard limit reached") ||
|
||||
(text.includes("maximum allowed") && text.includes("limit"))
|
||||
|
||||
Reference in New Issue
Block a user