Files
codex/codex-cli/tests/context-percent.test.ts
Eason Goodale cdc0897a25 initial cost tracking
Signed-off-by: Eason Goodale <easong@openai.com>
2025-04-18 03:10:54 -07:00

29 lines
901 B
TypeScript

import { describe, expect, it } from "vitest";
import type { ResponseItem } from "openai/resources/responses/responses.mjs";
import { calculateContextPercentRemaining } from "../src/components/chat/terminal-chat-utils.js";
function makeUserMessage(id: string, text: string): ResponseItem {
return {
id,
type: "message",
role: "user",
content: [{ type: "input_text", text }],
} as ResponseItem;
}
describe("calculateContextPercentRemaining", () => {
it("includes extra context characters in calculation", () => {
const msgText = "a".repeat(40); // 40 chars → 10 tokens
const items = [makeUserMessage("1", msgText)];
const model = "gpt-4-16k";
const base = calculateContextPercentRemaining(items, model);
const withExtra = calculateContextPercentRemaining(items, model, 8); // +8 chars → +2 tokens
expect(withExtra).toBeLessThan(base);
});
});