File size: 1,778 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import { describe, expect, it } from "vitest";
import type { SessionEntry } from "./types.js";
import { mergeSessionEntry } from "./types.js";
describe("SessionEntry cache fields", () => {
it("supports cacheRead and cacheWrite fields", () => {
const entry: SessionEntry = {
sessionId: "test-session",
updatedAt: Date.now(),
cacheRead: 1500,
cacheWrite: 300,
};
expect(entry.cacheRead).toBe(1500);
expect(entry.cacheWrite).toBe(300);
});
it("merges cache fields properly", () => {
const existing: SessionEntry = {
sessionId: "test-session",
updatedAt: Date.now(),
cacheRead: 1000,
cacheWrite: 200,
totalTokens: 5000,
};
const patch: Partial<SessionEntry> = {
cacheRead: 1500,
cacheWrite: 300,
};
const merged = mergeSessionEntry(existing, patch);
expect(merged.cacheRead).toBe(1500);
expect(merged.cacheWrite).toBe(300);
expect(merged.totalTokens).toBe(5000); // Preserved from existing
});
it("handles undefined cache fields", () => {
const entry: SessionEntry = {
sessionId: "test-session",
updatedAt: Date.now(),
totalTokens: 5000,
};
expect(entry.cacheRead).toBeUndefined();
expect(entry.cacheWrite).toBeUndefined();
});
it("allows cache fields to be cleared with undefined", () => {
const existing: SessionEntry = {
sessionId: "test-session",
updatedAt: Date.now(),
cacheRead: 1000,
cacheWrite: 200,
};
const patch: Partial<SessionEntry> = {
cacheRead: undefined,
cacheWrite: undefined,
};
const merged = mergeSessionEntry(existing, patch);
expect(merged.cacheRead).toBeUndefined();
expect(merged.cacheWrite).toBeUndefined();
});
});
|