mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:07:40 +00:00
Co-authored-by: Josh Lehman <josh@martian.engineering>
This commit is contained in:
committed by
GitHub
parent
5d37b204c0
commit
990413534a
@@ -64,10 +64,20 @@ vi.mock("../../infra/session-cost-usage.js", async () => {
|
||||
cacheWriteCost: 0,
|
||||
missingCostEntries: 0,
|
||||
})),
|
||||
loadSessionUsageTimeSeries: vi.fn(async () => ({
|
||||
sessionId: "s-opus",
|
||||
points: [],
|
||||
})),
|
||||
loadSessionLogs: vi.fn(async () => []),
|
||||
};
|
||||
});
|
||||
|
||||
import { discoverAllSessions } from "../../infra/session-cost-usage.js";
|
||||
import {
|
||||
discoverAllSessions,
|
||||
loadSessionCostSummary,
|
||||
loadSessionLogs,
|
||||
loadSessionUsageTimeSeries,
|
||||
} from "../../infra/session-cost-usage.js";
|
||||
import { loadCombinedSessionStoreForGateway } from "../session-utils.js";
|
||||
import { usageHandlers } from "./usage.js";
|
||||
|
||||
@@ -148,6 +158,10 @@ describe("sessions.usage", () => {
|
||||
const result = respond.mock.calls[0]?.[1] as unknown as { sessions: Array<{ key: string }> };
|
||||
expect(result.sessions).toHaveLength(1);
|
||||
expect(result.sessions[0]?.key).toBe(storeKey);
|
||||
expect(vi.mocked(loadSessionCostSummary)).toHaveBeenCalled();
|
||||
expect(
|
||||
vi.mocked(loadSessionCostSummary).mock.calls.some((call) => call[0]?.agentId === "opus"),
|
||||
).toBe(true);
|
||||
} finally {
|
||||
if (previousStateDir === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
@@ -176,4 +190,32 @@ describe("sessions.usage", () => {
|
||||
const error = respond.mock.calls[0]?.[2] as { message?: string } | undefined;
|
||||
expect(error?.message).toContain("Invalid session reference");
|
||||
});
|
||||
|
||||
it("passes parsed agentId into sessions.usage.timeseries", async () => {
|
||||
const respond = vi.fn();
|
||||
|
||||
await usageHandlers["sessions.usage.timeseries"]({
|
||||
respond,
|
||||
params: {
|
||||
key: "agent:opus:s-opus",
|
||||
},
|
||||
} as unknown as Parameters<(typeof usageHandlers)["sessions.usage.timeseries"]>[0]);
|
||||
|
||||
expect(vi.mocked(loadSessionUsageTimeSeries)).toHaveBeenCalled();
|
||||
expect(vi.mocked(loadSessionUsageTimeSeries).mock.calls[0]?.[0]?.agentId).toBe("opus");
|
||||
});
|
||||
|
||||
it("passes parsed agentId into sessions.usage.logs", async () => {
|
||||
const respond = vi.fn();
|
||||
|
||||
await usageHandlers["sessions.usage.logs"]({
|
||||
respond,
|
||||
params: {
|
||||
key: "agent:opus:s-opus",
|
||||
},
|
||||
} as unknown as Parameters<(typeof usageHandlers)["sessions.usage.logs"]>[0]);
|
||||
|
||||
expect(vi.mocked(loadSessionLogs)).toHaveBeenCalled();
|
||||
expect(vi.mocked(loadSessionLogs).mock.calls[0]?.[0]?.agentId).toBe("opus");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user