The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as NodeAssert from "node:assert/strict"; |
| 2 | |
| 3 | import { T3_CODE_DEVICE_TOOL_INSTRUCTIONS } from "@t3tools/provider-core/server/orchestrationInstructions"; |
| 4 | import { describe, it } from "vite-plus/test"; |
| 5 | |
| 6 | import { |
| 7 | buildCodexAdditionalContext, |
| 8 | CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES, |
| 9 | } from "./CodexDeveloperInstructions.ts"; |
| 10 | |
| 11 | describe("buildCodexAdditionalContext", () => { |
| 12 | describe.each([ |
| 13 | { model: "custom-model", modelName: "Custom 🦊 Model", reasoningEffort: "xhigh" }, |
| 14 | ])("with runtime $model", (runtime) => { |
| 15 | it.each([undefined, { browser: true, device: true }])( |
| 16 | "keeps every entry within Codex's per-entry cap with tools %j", |
| 17 | (availability) => { |
| 18 | const context = buildCodexAdditionalContext(runtime, availability); |
| 19 | |
| 20 | for (const [key, entry] of Object.entries(context)) { |
| 21 | // Codex counts ceil(UTF-8 bytes / 4) tokens, excluding keys and wrappers. |
| 22 | const bytes = Buffer.byteLength(entry.value, "utf8"); |
| 23 | const limit = CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES; |
| 24 | NodeAssert.ok( |
| 25 | bytes <= limit, |
| 26 | `${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`, |
| 27 | ); |
| 28 | } |
| 29 | }, |
| 30 | ); |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | describe("Codex runtime context", () => { |
| 35 | it("flattens multiline metadata into single-line runtime info", () => { |
| 36 | const instructions = runtimeInstructions({ |
| 37 | model: "gpt\n5.3\ncodex", |
| 38 | reasoningEffort: " high\neffort ", |
| 39 | }); |
| 40 | |
| 41 | NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/); |
| 42 | NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | describe("Codex orchestration context", () => { |
| 47 | it("routes subagents native first, delegate_task for the rest", () => { |
| 48 | const orchestration = Object.entries(buildCodexAdditionalContext({ model: "gpt-6.1-sol" })) |
| 49 | .filter(([key]) => key.startsWith("t3_code_orchestration_")) |
| 50 | .map(([, entry]) => entry.value) |
| 51 | .join("\n"); |
| 52 | |
| 53 | NodeAssert.ok(orchestration.includes("use your native tool when the child uses your provider")); |
| 54 | NodeAssert.ok(orchestration.includes("`run_in_background:false`")); |
| 55 | NodeAssert.ok(orchestration.includes("A native type on another provider's model")); |
| 56 | NodeAssert.ok( |
| 57 | orchestration.includes("Background agent: `delegate_task`, never a background `Agent`."), |
| 58 | ); |
| 59 | NodeAssert.ok( |
| 60 | orchestration.includes("Every new delegate review or re-check is a new `delegate_task`"), |
| 61 | ); |
| 62 | NodeAssert.ok(orchestration.includes("never a `t3_thread_send`")); |
| 63 | NodeAssert.ok(!orchestration.includes("inheritedOptions")); |
| 64 | NodeAssert.ok(!orchestration.includes("Prefer native")); |
| 65 | // The ACP terminal fallback is ACP-only; Codex agents never need it. |
| 66 | NodeAssert.ok(!orchestration.includes("acp-mcp-call")); |
| 67 | }); |
| 68 | }); |
| 69 | |
| 70 | describe("Codex device context", () => { |
| 71 | it("adds the shared device block only when the session holds device access", () => { |
| 72 | const tools = (device: boolean) => |
| 73 | buildCodexAdditionalContext({ model: "gpt-6.1-sol" }, { browser: true, device }).t3_code_tools |
| 74 | ?.value ?? ""; |
| 75 | |
| 76 | NodeAssert.ok(tools(true).includes(T3_CODE_DEVICE_TOOL_INSTRUCTIONS)); |
| 77 | NodeAssert.ok(!tools(true).includes("ToolSearch")); |
| 78 | NodeAssert.ok(!tools(false).includes("## T3 Code devices")); |
| 79 | }); |
| 80 | }); |
| 81 | |
| 82 | function runtimeInstructions(runtime: Parameters<typeof buildCodexAdditionalContext>[0]) { |
| 83 | return buildCodexAdditionalContext(runtime).t3_code_runtime!.value; |
| 84 | } |