Open History to see the last commit
1import * as NodeAssert from "node:assert/strict";
2
3import { describe, it } from "vite-plus/test";
4
5import {
6 buildCodexAdditionalContext,
7 CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES,
8} from "./CodexDeveloperInstructions.ts";
9
10describe("buildCodexAdditionalContext", () => {
11 describe.each([
12 { model: "custom-model", modelName: "Custom 🦊 Model", reasoningEffort: "xhigh" },
13 ])("with runtime $model", (runtime) => {
14 it.each([undefined, { browser: true, device: true }])(
15 "keeps every entry within Codex's per-entry cap with tools %j",
16 (availability) => {
17 const context = buildCodexAdditionalContext(runtime, availability);
18
19 for (const [key, entry] of Object.entries(context)) {
20 // Codex counts ceil(UTF-8 bytes / 4) tokens, excluding keys and wrappers.
21 const bytes = Buffer.byteLength(entry.value, "utf8");
22 const limit = CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES;
23 NodeAssert.ok(
24 bytes <= limit,
25 `${key}: ${bytes} UTF-8 bytes exceeds Codex's ${limit}-byte per-entry cap by ${bytes - limit} bytes; split the instructions into separate entries to avoid silent truncation`,
26 );
27 }
28 },
29 );
30 });
31});
32
33describe("buildCodexDeveloperInstructions", () => {
34 it("flattens multiline metadata into single-line runtime info", () => {
35 const instructions = runtimeInstructions({
36 model: "gpt\n5.3\ncodex",
37 reasoningEffort: " high\neffort ",
38 });
39
40 NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/);
41 NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/);
42 });
43});
44
45function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
46 return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;
47}