mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 04:50:35 +00:00
fix(auth): distinguish revoked API keys from transient auth errors (#25754)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 8f9c07a200
Co-authored-by: rrenamed <87486610+rrenamed@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
f312222159
commit
c0026274d9
@@ -141,6 +141,24 @@ describe("resolveProfilesUnavailableReason", () => {
|
||||
).toBe("billing");
|
||||
});
|
||||
|
||||
it("returns auth_permanent for active permanent auth disables", () => {
|
||||
const now = Date.now();
|
||||
const store = makeStore({
|
||||
"anthropic:default": {
|
||||
disabledUntil: now + 60_000,
|
||||
disabledReason: "auth_permanent",
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProfilesUnavailableReason({
|
||||
store,
|
||||
profileIds: ["anthropic:default"],
|
||||
now,
|
||||
}),
|
||||
).toBe("auth_permanent");
|
||||
});
|
||||
|
||||
it("uses recorded non-rate-limit failure counts for active cooldown windows", () => {
|
||||
const now = Date.now();
|
||||
const store = makeStore({
|
||||
@@ -490,7 +508,7 @@ describe("markAuthProfileFailure — active windows do not extend on retry", ()
|
||||
async function markFailureAt(params: {
|
||||
store: ReturnType<typeof makeStore>;
|
||||
now: number;
|
||||
reason: "rate_limit" | "billing";
|
||||
reason: "rate_limit" | "billing" | "auth_permanent";
|
||||
}): Promise<void> {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(params.now);
|
||||
@@ -528,6 +546,18 @@ describe("markAuthProfileFailure — active windows do not extend on retry", ()
|
||||
}),
|
||||
readUntil: (stats: WindowStats | undefined) => stats?.disabledUntil,
|
||||
},
|
||||
{
|
||||
label: "disabledUntil(auth_permanent)",
|
||||
reason: "auth_permanent" as const,
|
||||
buildUsageStats: (now: number): WindowStats => ({
|
||||
disabledUntil: now + 20 * 60 * 60 * 1000,
|
||||
disabledReason: "auth_permanent",
|
||||
errorCount: 5,
|
||||
failureCounts: { auth_permanent: 5 },
|
||||
lastFailureAt: now - 60_000,
|
||||
}),
|
||||
readUntil: (stats: WindowStats | undefined) => stats?.disabledUntil,
|
||||
},
|
||||
];
|
||||
|
||||
for (const testCase of activeWindowCases) {
|
||||
@@ -573,6 +603,19 @@ describe("markAuthProfileFailure — active windows do not extend on retry", ()
|
||||
expectedUntil: (now: number) => now + 20 * 60 * 60 * 1000,
|
||||
readUntil: (stats: WindowStats | undefined) => stats?.disabledUntil,
|
||||
},
|
||||
{
|
||||
label: "disabledUntil(auth_permanent)",
|
||||
reason: "auth_permanent" as const,
|
||||
buildUsageStats: (now: number): WindowStats => ({
|
||||
disabledUntil: now - 60_000,
|
||||
disabledReason: "auth_permanent",
|
||||
errorCount: 5,
|
||||
failureCounts: { auth_permanent: 2 },
|
||||
lastFailureAt: now - 60_000,
|
||||
}),
|
||||
expectedUntil: (now: number) => now + 20 * 60 * 60 * 1000,
|
||||
readUntil: (stats: WindowStats | undefined) => stats?.disabledUntil,
|
||||
},
|
||||
];
|
||||
|
||||
for (const testCase of expiredWindowCases) {
|
||||
|
||||
Reference in New Issue
Block a user