1import { assert, describe, it } from "@effect/vitest";
2
3import {
4 T3_CODE_ORCHESTRATION_INSTRUCTIONS,
5 t3AcpPromptWithInstructions,
6 t3OrchestrationPromptForFirstRun,
7 t3OrchestrationSystemPrompt,
8} from "./orchestrationInstructions.ts";
9
10describe("T3 orchestration provider instructions", () => {
11 it("distinguishes delegated subagents from ordinary top-level threads", () => {
12 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "Use `delegate_task`");
13 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "ordinary top-level T3 conversations");
14 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "Never use them merely");
15 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "cross-provider");
16 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "call `delegate_task` again");
17 assert.include(
18 T3_CODE_ORCHESTRATION_INSTRUCTIONS,
19 "Do not use `t3_thread_send` on `childThreadId`",
20 );
21 });
22
23 it("documents structured schedules instead of JSON strings", () => {
24 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "structured object, never as JSON text");
25 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, '"everyMs":3600000');
26 assert.include(T3_CODE_ORCHESTRATION_INSTRUCTIONS, "bindToCurrentThread=false");
27 });
28
29 it("injects prompt fallback only for an MCP-enabled first run", () => {
30 const prompt = "Inspect the repository.";
31 const injected = t3OrchestrationPromptForFirstRun({
32 prompt,
33 runOrdinal: 1,
34 hasT3Mcp: true,
35 });
36
37 assert.include(injected, "<t3_code_orchestration_instructions>");
38 assert.include(injected, `<user_request>\n${prompt}\n</user_request>`);
39 assert.equal(
40 t3OrchestrationPromptForFirstRun({ prompt, runOrdinal: 2, hasT3Mcp: true }),
41 prompt,
42 );
43 assert.equal(
44 t3OrchestrationPromptForFirstRun({ prompt, runOrdinal: 1, hasT3Mcp: false }),
45 prompt,
46 );
47 });
48
49 it("only exposes the system prompt when the T3 MCP server is attached", () => {
50 assert.equal(t3OrchestrationSystemPrompt(false), undefined);
51 assert.equal(t3OrchestrationSystemPrompt(true), T3_CODE_ORCHESTRATION_INSTRUCTIONS);
52 });
53
54 it("gives ACP sessions provider-neutral mode, browser, and orchestration guidance", () => {
55 const injected = t3AcpPromptWithInstructions({
56 prompt: "Inspect the repository.",
57 state: { interactionMode: "default", hasT3Mcp: true },
58 });
59
60 assert.include(injected, "T3 Code interaction mode: Default");
61 assert.include(injected, "T3 Code collaborative browser");
62 assert.include(injected, "T3 Code orchestration");
63 assert.include(injected, "<user_request>\nInspect the repository.\n</user_request>");
64 });
65
66 it("reinjects ACP guidance only when mode or tool availability changes", () => {
67 const prompt = "Continue.";
68 const defaultState = { interactionMode: "default", hasT3Mcp: true } as const;
69
70 assert.equal(
71 t3AcpPromptWithInstructions({ prompt, state: defaultState, previousState: defaultState }),
72 prompt,
73 );
74 assert.include(
75 t3AcpPromptWithInstructions({
76 prompt,
77 state: { ...defaultState, interactionMode: "plan" },
78 previousState: defaultState,
79 }),
80 "T3 Code interaction mode: Plan",
81 );
82 const withoutMcp = t3AcpPromptWithInstructions({
83 prompt,
84 state: { interactionMode: "default", hasT3Mcp: false },
85 });
86 assert.include(withoutMcp, "T3 Code interaction mode: Default");
87 assert.notInclude(withoutMcp, "T3 Code collaborative browser");
88 assert.notInclude(withoutMcp, "T3 Code orchestration");
89 });
90});