Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexDeveloperInstructions.test.ts

68 lines2.8 KB

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("Codex runtime context", () => {
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​
45describe("Codex orchestration context", () => {
46 it("routes subagents native first, delegate_task for the rest", () => {
47 const orchestration = Object.entries(buildCodexAdditionalContext({ model: "gpt-6.1-sol" }))
48 .filter(([key]) => key.startsWith("t3_code_orchestration_"))
49 .map(([, entry]) => entry.value)
50 .join("\n");
51​
52 NodeAssert.ok(orchestration.includes("use your native tool when the child uses your provider"));
53 NodeAssert.ok(orchestration.includes("`run_in_background:false`"));
54 NodeAssert.ok(orchestration.includes("A native type running another provider's model"));
55 NodeAssert.ok(
56 orchestration.includes("Every new delegate review or re-check is a new `delegate_task`"),
57 );
58 NodeAssert.ok(orchestration.includes("never a `t3_thread_send`"));
59 NodeAssert.ok(!orchestration.includes("inheritedOptions"));
60 NodeAssert.ok(!orchestration.includes("Prefer native"));
61 // The ACP terminal fallback is ACP-only; Codex agents never need it.
62 NodeAssert.ok(!orchestration.includes("acp-mcp-call"));
63 });
64});
65​
66function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
67 return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;