@@ -46,6 +46,57 @@ async function loadHooks(commands: ReadonlyArray<SkillCommand> = []) {
4646 return handlers ;
4747}
4848
49+ describe ( "Pi orchestration prompt section" , ( ) => {
50+ it ( "adds a stable section without overriding the prompt or skipping discovery" , async ( ) => {
51+ const bridge = await loadMcpBridge ( { modern : true , toolSearchAvailable : true } ) ;
52+ const hook = bridge . handlers . get ( "before_agent_start" ) ! ;
53+ const sections : Record < string , string > = { existing : "keep me" } ;
54+ const event = { systemPrompt : "base" , systemPromptOptions : { sections } } ;
55+ const ctx = { model : { api : "openai-completions" } , ui : { notify : assert . fail } } ;
56+
57+ assert . isUndefined ( await hook ( event , ctx ) ) ;
58+ assert . include ( sections . t3_code_orchestration , "orchestrator_capabilities" ) ;
59+ assert . equal ( event . systemPrompt , "base" ) ;
60+ assert . include ( bridge . getActiveTools ( ) , "mcp__t3-code__preview_snapshot" ) ;
61+
62+ const guidance = sections . t3_code_orchestration ! ;
63+ assert . isUndefined ( await hook ( event , ctx ) ) ;
64+ assert . deepEqual ( event . systemPromptOptions . sections , {
65+ existing : "keep me" ,
66+ t3_code_orchestration : guidance ,
67+ } ) ;
68+ } ) ;
69+
70+ it . each ( [
71+ {
72+ name : "on Pi builds without prompt sections" ,
73+ events : [
74+ { systemPrompt : "base" } ,
75+ { systemPrompt : "base" , systemPromptOptions : { } } ,
76+ { systemPrompt : "base" , systemPromptOptions : { sections : null } } ,
77+ ] ,
78+ } ,
79+ {
80+ name : "when an earlier extension forces the system prompt" ,
81+ events : [
82+ {
83+ systemPrompt : "forced" ,
84+ systemPromptOptions : { sections : { } , forceSystemPrompt : "forced" } ,
85+ } ,
86+ ] ,
87+ } ,
88+ ] ) ( "appends guidance $name" , async ( { events } ) => {
89+ const bridge = await loadMcpBridge ( ) ;
90+ const hook = bridge . handlers . get ( "before_agent_start" ) ! ;
91+ for ( const event of events ) {
92+ const result = await hook ( event , { ui : { notify : assert . fail } } ) ;
93+ assert . isDefined ( result ) ;
94+ assert . isTrue ( result ! . systemPrompt . startsWith ( `${ event . systemPrompt } \n\n` ) ) ;
95+ assert . include ( result ! . systemPrompt , "orchestrator_capabilities" ) ;
96+ }
97+ } ) ;
98+ } ) ;
99+
49100describe ( "Pi MCP tool results" , ( ) => {
50101 it ( "returns mixed screenshot blocks and typed script output without repeating structured text" , async ( ) => {
51102 const content = [
@@ -143,7 +194,7 @@ describe("Pi MCP tool exposure", () => {
143194 const start = bridge . handlers . get ( "before_agent_start" ) ;
144195 assert . isDefined ( start ) ;
145196 const prompt = await start ! ( { systemPrompt : "Pi system prompt" } , discoveryContext ) ;
146- assert . include ( prompt . systemPrompt , "orchestrator_capabilities" ) ;
197+ assert . include ( prompt ? .systemPrompt ?? "" , "orchestrator_capabilities" ) ;
147198 assert . equal ( bridge . servers . length , 0 ) ;
148199 assert . equal ( bridge . tools . length , 8 ) ;
149200 assert . deepEqual ( bridge . getActiveTools ( ) , [ "read" , "tool_search" ] ) ;
0 commit comments