mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 15:07:14 +00:00
test(auth-profiles): cover self-heal hook firing + survives hook errors
This commit is contained in:
@@ -17,7 +17,11 @@ import {
|
||||
clearRuntimeAuthProfileStoreSnapshots,
|
||||
ensureAuthProfileStore,
|
||||
} from "./auth-profiles/store.js";
|
||||
import { calculateAuthProfileCooldownMs, markAuthProfileFailure } from "./auth-profiles/usage.js";
|
||||
import {
|
||||
calculateAuthProfileCooldownMs,
|
||||
markAuthProfileFailure,
|
||||
setAuthProfileFailureHook,
|
||||
} from "./auth-profiles/usage.js";
|
||||
|
||||
type AuthProfileStore = ReturnType<typeof ensureAuthProfileStore>;
|
||||
|
||||
@@ -374,6 +378,46 @@ describe("markAuthProfileFailure", () => {
|
||||
expect(reloaded.usageStats?.["openrouter:default"]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("fires the auth profile failure hook so callers can self-heal", async () => {
|
||||
await withAuthProfileStore(async ({ agentDir, store }) => {
|
||||
const hook = vi.fn();
|
||||
setAuthProfileFailureHook(hook);
|
||||
try {
|
||||
await markAuthProfileFailure({
|
||||
store,
|
||||
profileId: "anthropic:default",
|
||||
reason: "auth",
|
||||
agentDir,
|
||||
});
|
||||
expect(hook).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
setAuthProfileFailureHook(undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("does not break failure recording when the hook throws", async () => {
|
||||
await withAuthProfileStore(async ({ agentDir, store }) => {
|
||||
const throwingHook = vi.fn(() => {
|
||||
throw new Error("boom");
|
||||
});
|
||||
setAuthProfileFailureHook(throwingHook);
|
||||
try {
|
||||
await markAuthProfileFailure({
|
||||
store,
|
||||
profileId: "anthropic:default",
|
||||
reason: "auth",
|
||||
agentDir,
|
||||
});
|
||||
expect(throwingHook).toHaveBeenCalledTimes(1);
|
||||
// Failure still got recorded despite the hook throwing.
|
||||
expect(store.usageStats?.["anthropic:default"]?.errorCount ?? 0).toBeGreaterThan(0);
|
||||
} finally {
|
||||
setAuthProfileFailureHook(undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("calculateAuthProfileCooldownMs", () => {
|
||||
|
||||
Reference in New Issue
Block a user