mirror of
https://github.com/openai/codex.git
synced 2026-04-28 02:11:08 +03:00
29 lines
901 B
TypeScript
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);
|
|
});
|
|
});
|