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

CodexDeveloperInstructions.test.ts

77 lines2.7 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 CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES,
12} from "./CodexDeveloperInstructions.ts";
13​
14describe("buildCodexAdditionalContext", () => {
15 describe.each([
16 { model: "gpt-5.3-codex", reasoningEffort: "high" },
17 { model: "custom-model", modelName: "Custom 🦊 Model", reasoningEffort: "xhigh" },
18 ])("with runtime $model", (runtime) => {
19 it.each([
20 undefined,
21 false,
22 true,
23 { browser: false, device: false },
24 { browser: true, device: false },
25 { browser: false, device: true },
26 { browser: true, device: true },
27 ])("keeps every entry within Codex's per-entry cap with tools %j", (availability) => {
28 const context = buildCodexAdditionalContext(runtime, availability);
29​
30 for (const [key, entry] of Object.entries(context)) {
31 // Codex counts ceil(UTF-8 bytes / 4) tokens, excluding keys and wrappers.
32 const bytes = Buffer.byteLength(entry.value, "utf8");
33 const limit = CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES;
34 NodeAssert.ok(
35 bytes <= limit,
36 `${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`,
37 );
38 }
39 });
40 });
41​
42 it("delivers all orchestration sections in authored order when keys are sorted", () => {
43 const context = buildCodexAdditionalContext({
44 model: "gpt-5.3-codex",
45 reasoningEffort: "high",
46 });
47 const sections = Object.keys(context)
48 .filter((key) => key.startsWith("t3_code_orchestration_"))
49 .sort()
50 .map((key) => context[key]!);
51​
52 NodeAssert.deepEqual(
53 sections,
54 T3_CODE_ORCHESTRATION_SECTIONS.map((value) => ({ kind: "application", value })),
55 );
56 NodeAssert.equal(
57 sections.map((entry) => entry.value).join("\n\n"),
58 T3_CODE_ORCHESTRATION_INSTRUCTIONS.trim(),
59 );
60 });
61});
62​
63describe("buildCodexDeveloperInstructions", () => {
64 it("flattens multiline metadata into single-line runtime info", () => {
65 const instructions = runtimeInstructions({
66 model: "gpt\n5.3\ncodex",
67 reasoningEffort: " high\neffort ",
68 });
69​
70 NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/);
71 NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/);
72 });
73});
74​
75function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) {
76 return buildCodexAdditionalContext(runtime).t3_code_runtime!.value;