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

CodexDeveloperInstructions.test.ts

166 lines5.9 KB

1import * as NodeAssert from "node:assert/strict";
2​
3import {
4 T3_CODE_ORCHESTRATION_INSTRUCTIONS,
5 T3_CODE_ORCHESTRATION_SECTIONS,
6} from "@t3tools/provider-core/server/orchestrationInstructions";
7import { describe, it } from "vite-plus/test";
8​
9import {
10 buildCodexAdditionalContext,
11 buildCodexDeveloperInstructions,
12 CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES,
13} from "./CodexDeveloperInstructions.ts";
14​
15describe("buildCodexAdditionalContext", () => {
16 describe.each([
17 { model: "gpt-5.3-codex", reasoningEffort: "high" },
18 { model: "custom-model", modelName: "Custom 🦊 Model", reasoningEffort: "xhigh" },
19 ])("with runtime $model", (runtime) => {
20 it.each([
21 undefined,
22 false,
23 true,
24 { browser: false, device: false },
25 { browser: true, device: false },
26 { browser: false, device: true },
27 { browser: true, device: true },
28 ])("keeps every entry within Codex's per-entry cap with tools %j", (availability) => {
29 const context = buildCodexAdditionalContext(runtime, availability);
30​
31 for (const [key, entry] of Object.entries(context)) {
32 // Codex counts ceil(UTF-8 bytes / 4) tokens, excluding keys and wrappers.
33 const bytes = Buffer.byteLength(entry.value, "utf8");
34 const limit = CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES;
35 NodeAssert.ok(
36 bytes <= limit,
37 `${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`,
38 );
39 }
40 });
41 });
42​
43 it("delivers all orchestration sections in authored order when keys are sorted", () => {
44 const context = buildCodexAdditionalContext({
45 model: "gpt-5.3-codex",
46 reasoningEffort: "high",
47 });
48 const sections = Object.keys(context)
49 .filter((key) => key.startsWith("t3_code_orchestration_"))
50 .sort()
51 .map((key) => context[key]!);
52​
53 NodeAssert.deepEqual(
54 sections,
55 T3_CODE_ORCHESTRATION_SECTIONS.map((value) => ({ kind: "application", value })),
56 );
57 NodeAssert.equal(
58 sections.map((entry) => entry.value).join("\n\n"),
59 T3_CODE_ORCHESTRATION_INSTRUCTIONS.trim(),
60 );
61 });
62});
63​
64describe("buildCodexDeveloperInstructions", () => {
65 it("appends runtime info after the mode instructions", () => {
66 const instructions = runtimeInstructions({
67 model: "gpt-5.3-codex",
68 reasoningEffort: "high",
69 });
70​
71 NodeAssert.match(
72 buildCodexDeveloperInstructions("default"),
73 /^<collaboration_mode># Collaboration Mode: Default/,
74 );
75 NodeAssert.match(instructions, /T3 Code/);
76 NodeAssert.match(instructions, /Codex harness/);
77 NodeAssert.match(instructions, /as gpt-5\.3-codex with high reasoning effort/);
78 });
79​
80 it("describes Markdown media support in the runtime context in both modes", () => {
81 {
82 const instructions = runtimeInstructions({
83 model: "gpt-5.3-codex",
84 reasoningEffort: "high",
85 });
86 NodeAssert.match(
87 instructions,
88 /<runtime_info>.*embed images and videos.*Markdown.*<\/runtime_info>/,
89 );
90 }
91 });
92​
93 it("includes runtime info alongside plan mode instructions", () => {
94 const instructions = runtimeInstructions({
95 model: "gpt-5.3-codex",
96 reasoningEffort: "medium",
97 });
98​
99 NodeAssert.match(buildCodexDeveloperInstructions("plan"), /^<collaboration_mode># Plan Mode/);
100 NodeAssert.match(instructions, /as gpt-5\.3-codex with medium reasoning effort/);
101 });
102​
103 it("varies with the model and effort of each turn", () => {
104 const first = runtimeInstructions({
105 model: "gpt-5.3-codex",
106 reasoningEffort: "medium",
107 });
108 const second = runtimeInstructions({
109 model: "gpt-5.4",
110 reasoningEffort: "high",
111 });
112​
113 NodeAssert.notEqual(first, second);
114 });
115​
116 it("flattens multiline metadata into single-line runtime info", () => {
117 const instructions = runtimeInstructions({
118 model: "gpt\n5.3\ncodex",
119 reasoningEffort: " high\neffort ",
120 });
121​
122 NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/);
123 NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/);
124 });
125});
126​
127describe("T3 browser developer instructions", () => {
128 const runtime = { model: "gpt-5.3-codex", reasoningEffort: "high" };
129​
130 it("prefers the product-native preview tools in both collaboration modes", () => {
131 {
132 const instructions = toolInstructions(runtime, true);
133 NodeAssert.match(instructions, /t3-code/);
134 NodeAssert.match(instructions, /preview_status/);
135 NodeAssert.match(instructions, /preview_open/);
136 NodeAssert.match(instructions, /Do not switch to global browser skills/);
137 }
138 });
139​
140 it("omits the browser block entirely when the preview tools are not attached", () => {
141 for (const mode of ["default", "plan"] as const) {
142 const instructions = toolInstructions(runtime, false);
143 NodeAssert.doesNotMatch(instructions, /preview_status/);
144 NodeAssert.doesNotMatch(instructions, /preview_open/);
145 NodeAssert.doesNotMatch(instructions, /T3 Code collaborative browser/);
146 NodeAssert.doesNotMatch(instructions, /Do not switch to global browser skills/);
147 NodeAssert.match(buildCodexDeveloperInstructions(mode), /<collaboration_mode>/);
148 NodeAssert.match(buildCodexDeveloperInstructions(mode), /<\/collaboration_mode>/);
149 }
150 });
151​
152 it("tracks the turn's MCP configuration rather than defaulting to on", () => {
153 NodeAssert.match(toolInstructions(runtime, true), /preview_open/);
154 NodeAssert.doesNotMatch(toolInstructions(runtime, false), /preview_open/);
155 });
156});
157​
158function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
159 return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;
161function toolInstructions(
162 runtime: Parameters<typeof buildCodexAdditionalContext>[0],
163 available: boolean,
164) {
165 return buildCodexAdditionalContext(runtime, available).t3_code_tools?.value ?? "";