Repository navigation
Expand file tree
/
Copy pathCodexDeveloperInstructions.test.ts
More file actions
97 lines (85 loc) · 3.99 KB
/
Copy pathCodexDeveloperInstructions.test.ts
File metadata and controls
97 lines (85 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as NodeAssert from "node:assert/strict";
import { T3_CODE_DEVICE_TOOL_INSTRUCTIONS } from "@t3tools/provider-core/server/orchestrationInstructions";
import { describe, it } from "vite-plus/test";
import {
buildCodexAdditionalContext,
CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES,
} from "./CodexDeveloperInstructions.ts";
describe("buildCodexAdditionalContext", () => {
describe.each([
{ model: "custom-model", modelName: "Custom 🦊 Model", reasoningEffort: "xhigh" },
])("with runtime $model", (runtime) => {
it.each([undefined, { browser: true, device: true }])(
"keeps every entry within Codex's per-entry cap with tools %j",
(availability) => {
const context = buildCodexAdditionalContext(runtime, availability);
for (const [key, entry] of Object.entries(context)) {
// Codex counts ceil(UTF-8 bytes / 4) tokens, excluding keys and wrappers.
const bytes = Buffer.byteLength(entry.value, "utf8");
const limit = CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES;
NodeAssert.ok(
bytes <= limit,
`${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`,
);
}
},
);
});
});
describe("Codex runtime context", () => {
it("describes Markdown media support in the runtime context in both modes", () => {
{
const instructions = runtimeInstructions({
model: "gpt-5.3-codex",
reasoningEffort: "high",
});
NodeAssert.match(
instructions,
/<runtime_info>.*embed images, video, and audio.*Markdown image syntax with absolute file paths.*Link every other file you cite or produce by its absolute path.*files viewer.*<\/runtime_info>/,
);
}
});
it("flattens multiline metadata into single-line runtime info", () => {
const instructions = runtimeInstructions({
model: "gpt\n5.3\ncodex",
reasoningEffort: " high\neffort ",
});
NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/);
NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/);
});
});
describe("Codex orchestration context", () => {
it("routes subagents native first, delegate_task for the rest", () => {
const orchestration = Object.entries(buildCodexAdditionalContext({ model: "gpt-6.1-sol" }))
.filter(([key]) => key.startsWith("t3_code_orchestration_"))
.map(([, entry]) => entry.value)
.join("\n");
NodeAssert.ok(orchestration.includes("use your native tool when the child uses your provider"));
NodeAssert.ok(orchestration.includes("`run_in_background:false`"));
NodeAssert.ok(orchestration.includes("A native type on another provider's model"));
NodeAssert.ok(
orchestration.includes("Background agent: `delegate_task`, never a background `Agent`."),
);
NodeAssert.ok(
orchestration.includes("Every new delegate review or re-check is a new `delegate_task`"),
);
NodeAssert.ok(orchestration.includes("never a `t3_thread_send`"));
NodeAssert.ok(!orchestration.includes("inheritedOptions"));
NodeAssert.ok(!orchestration.includes("Prefer native"));
// The ACP terminal fallback is ACP-only; Codex agents never need it.
NodeAssert.ok(!orchestration.includes("acp-mcp-call"));
});
});
describe("Codex device context", () => {
it("adds the shared device block only when the session holds device access", () => {
const tools = (device: boolean) =>
buildCodexAdditionalContext({ model: "gpt-6.1-sol" }, { browser: true, device }).t3_code_tools
?.value ?? "";
NodeAssert.ok(tools(true).includes(T3_CODE_DEVICE_TOOL_INSTRUCTIONS));
NodeAssert.ok(!tools(true).includes("ToolSearch"));
NodeAssert.ok(!tools(false).includes("## T3 Code devices"));
});
});
function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;
}