@@ -2521,6 +2521,67 @@ describe("PiAdapterV2", () => {
25212521 ) ,
25222522 ) ;
25232523
2524+ it . effect . each ( [
2525+ { toolName : "bash" , exitCode : 0 , legacy : false } ,
2526+ { toolName : "powershell" , exitCode : 2 , legacy : false } ,
2527+ { toolName : "bash" , exitCode : 1 , legacy : true } ,
2528+ { toolName : "powershell" , exitCode : 0 , legacy : true } ,
2529+ ] ) (
2530+ "normalizes $toolName command results, exit=$exitCode legacy=$legacy" ,
2531+ ( { toolName, exitCode, legacy } ) =>
2532+ Effect . gen ( function * ( ) {
2533+ const fake = yield * makeFakePi ;
2534+ const { runtime, takeEvent } = yield * openRuntime ( fake ) ;
2535+ const providerThread = yield * runtime . ensureThread ( {
2536+ threadId : THREAD_ID ,
2537+ modelSelection : modelSelection ( "default" ) ,
2538+ runtimePolicy,
2539+ } ) ;
2540+ yield * startTurn ( runtime , providerThread ) ;
2541+ yield * fake . takeRequest ( "prompt" ) ;
2542+ yield * fake . emit ( {
2543+ type : "tool_execution_start" ,
2544+ toolCallId : "shell-call" ,
2545+ toolName,
2546+ args : { command : "echo hello" } ,
2547+ } ) ;
2548+ const running = yield * takeEvent (
2549+ ( event ) =>
2550+ event . type === "turn_item.updated" && event . turnItem . type === "command_execution" ,
2551+ ) ;
2552+ assert . isTrue (
2553+ running . type === "turn_item.updated" &&
2554+ running . turnItem . type === "command_execution" &&
2555+ running . turnItem . status === "running" &&
2556+ running . turnItem . input === "echo hello" ,
2557+ ) ;
2558+ yield * fake . emit ( {
2559+ type : "tool_execution_end" ,
2560+ toolCallId : "shell-call" ,
2561+ toolName,
2562+ isError : exitCode !== 0 ,
2563+ result : {
2564+ content : [ { type : "text" , text : "hello" } ] ,
2565+ details : { exitCode : legacy ? exitCode : 99 } ,
2566+ ...( legacy ? { } : { structuredContent : { exit_code : exitCode } } ) ,
2567+ } ,
2568+ } ) ;
2569+ const completed = yield * takeEvent (
2570+ ( event ) =>
2571+ event . type === "turn_item.updated" && event . turnItem . type === "command_execution" ,
2572+ ) ;
2573+ assert . isTrue (
2574+ completed . type === "turn_item.updated" &&
2575+ completed . turnItem . type === "command_execution" &&
2576+ completed . turnItem . title === toolName &&
2577+ completed . turnItem . input === "echo hello" &&
2578+ completed . turnItem . output === "hello" &&
2579+ completed . turnItem . exitCode === exitCode &&
2580+ completed . turnItem . status === ( exitCode === 0 ? "completed" : "failed" ) ,
2581+ ) ;
2582+ } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
2583+ ) ;
2584+
25242585 it . effect ( "emits session-start dialogs before a turn exists" , ( ) =>
25252586 Effect . gen ( function * ( ) {
25262587 const fake = yield * makeFakePi ;
0 commit comments