mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 12:00:43 +00:00
test: share discord auto presence assertions
This commit is contained in:
@@ -29,45 +29,33 @@ function createStore(params?: {
|
||||
};
|
||||
}
|
||||
|
||||
function expectExhaustedDecision(params: { failureCounts: Record<string, number> }) {
|
||||
const now = Date.now();
|
||||
const decision = resolveDiscordAutoPresenceDecision({
|
||||
discordConfig: {
|
||||
autoPresence: {
|
||||
enabled: true,
|
||||
exhaustedText: "token exhausted",
|
||||
},
|
||||
},
|
||||
authStore: createStore({ cooldownUntil: now + 60_000, failureCounts: params.failureCounts }),
|
||||
gatewayConnected: true,
|
||||
now,
|
||||
});
|
||||
|
||||
expect(decision).toBeTruthy();
|
||||
expect(decision?.state).toBe("exhausted");
|
||||
expect(decision?.presence.status).toBe("dnd");
|
||||
expect(decision?.presence.activities[0]?.state).toBe("token exhausted");
|
||||
}
|
||||
|
||||
describe("discord auto presence", () => {
|
||||
it("maps exhausted runtime signal to dnd", () => {
|
||||
const now = Date.now();
|
||||
const decision = resolveDiscordAutoPresenceDecision({
|
||||
discordConfig: {
|
||||
autoPresence: {
|
||||
enabled: true,
|
||||
exhaustedText: "token exhausted",
|
||||
},
|
||||
},
|
||||
authStore: createStore({ cooldownUntil: now + 60_000, failureCounts: { rate_limit: 2 } }),
|
||||
gatewayConnected: true,
|
||||
now,
|
||||
});
|
||||
|
||||
expect(decision).toBeTruthy();
|
||||
expect(decision?.state).toBe("exhausted");
|
||||
expect(decision?.presence.status).toBe("dnd");
|
||||
expect(decision?.presence.activities[0]?.state).toBe("token exhausted");
|
||||
expectExhaustedDecision({ failureCounts: { rate_limit: 2 } });
|
||||
});
|
||||
|
||||
it("treats overloaded cooldown as exhausted", () => {
|
||||
const now = Date.now();
|
||||
const decision = resolveDiscordAutoPresenceDecision({
|
||||
discordConfig: {
|
||||
autoPresence: {
|
||||
enabled: true,
|
||||
exhaustedText: "token exhausted",
|
||||
},
|
||||
},
|
||||
authStore: createStore({ cooldownUntil: now + 60_000, failureCounts: { overloaded: 2 } }),
|
||||
gatewayConnected: true,
|
||||
now,
|
||||
});
|
||||
|
||||
expect(decision).toBeTruthy();
|
||||
expect(decision?.state).toBe("exhausted");
|
||||
expect(decision?.presence.status).toBe("dnd");
|
||||
expect(decision?.presence.activities[0]?.state).toBe("token exhausted");
|
||||
expectExhaustedDecision({ failureCounts: { overloaded: 2 } });
|
||||
});
|
||||
|
||||
it("recovers from exhausted to online once a profile becomes usable", () => {
|
||||
|
||||
Reference in New Issue
Block a user