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

CodexDeveloperInstructions.test.ts

68 lines2.5 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("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​
45describe("Codex orchestration context", () => {
46 it("routes same-child follow-ups to t3_thread_send and independent reviews to delegate_task", () => {
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(
53 orchestration.includes(
54 "For independent T3 delegated review rounds, call `delegate_task` again.",
55 ),
56 );
57 NodeAssert.ok(
58 orchestration.includes(
59 "For a follow-up that needs the same child's conversation, use `t3_thread_send` on its `childThreadId`.",
60 ),
61 );
62 NodeAssert.ok(!orchestration.includes("Do not use `t3_thread_send`"));
63 });
64});
65​
66function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
67 return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;