@@ -867,6 +867,20 @@ describe("ClaudeAdapterV2 context usage", () => {
867867} ) ;
868868
869869describe ( "ClaudeAdapterV2 session permissions" , ( ) => {
870+ it ( "keeps explicit user refusals classified as user_reject" , ( ) => {
871+ const result = ClaudeAdapterV2 . permissionResultFromDecision ( {
872+ toolName : "Bash" ,
873+ decision : "decline" ,
874+ toolInput : { command : "make" } ,
875+ toolUseID : "denied-build" ,
876+ } ) ;
877+ assert . equal ( result . behavior , "deny" ) ;
878+ if ( result . behavior !== "deny" ) return ;
879+ assert . equal ( result . decisionClassification , "user_reject" ) ;
880+ assert . equal ( result . message , "User declined tool execution." ) ;
881+ assert . equal ( result . interrupt , undefined ) ;
882+ } ) ;
883+
870884 it ( "forces suggested permission updates to session scope" , ( ) => {
871885 const result = ClaudeAdapterV2 . permissionResultFromDecision ( {
872886 toolName : "Bash" ,
@@ -2300,6 +2314,77 @@ describe("ClaudeAdapterV2 background wake turns", () => {
23002314 } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
23012315 ) ;
23022316
2317+ it . effect . each ( [ "cancelled" , "denied" , "permission_denied" , undefined ] ) (
2318+ "preserves native tool non-execution metadata %s without inferring a denial from text" ,
2319+ ( kind ) =>
2320+ Effect . scoped (
2321+ Effect . gen ( function * ( ) {
2322+ const harness = yield * makeWakeHarness ;
2323+ yield * harness . runtime . startTurn (
2324+ makeClaudeTestTurnInput ( {
2325+ threadId : harness . threadId ,
2326+ providerThread : harness . providerThread ,
2327+ now : yield * DateTime . now ,
2328+ attemptId : RunAttemptId . make ( "attempt-tool-non-execution" ) ,
2329+ text : "Run the tool." ,
2330+ attachments : [ ] ,
2331+ } ) ,
2332+ ) ;
2333+ // Same error text can describe a cancellation or a real refusal.
2334+ // Each result must use its own metadata, even in a multi-result frame.
2335+ yield * harness . offerAndWait (
2336+ claudeSdkFrame ( {
2337+ type : "user" ,
2338+ uuid : "tool-non-execution" ,
2339+ session_id : WAKE_NATIVE_SESSION ,
2340+ parent_tool_use_id : null ,
2341+ message : {
2342+ role : "user" ,
2343+ content : [
2344+ {
2345+ type : "tool_result" ,
2346+ tool_use_id : "tool-error" ,
2347+ is_error : true ,
2348+ content : "STOP and wait for the user." ,
2349+ } ,
2350+ { type : "tool_result" , tool_use_id : "tool-ok" , is_error : false , content : "OK" } ,
2351+ ] ,
2352+ } ,
2353+ ...( kind === undefined
2354+ ? { }
2355+ : {
2356+ tool_result_meta : [
2357+ { id : "tool-error" , non_execution_kind : kind } ,
2358+ { id : "tool-ok" , non_execution_kind : null } ,
2359+ ] ,
2360+ } ) ,
2361+ } ) ,
2362+ ) ;
2363+ yield * Queue . offer (
2364+ harness . sdkMessages ,
2365+ makeResultFrame ( { uuid : "result-non-execution" , result : "Done" } ) ,
2366+ ) ;
2367+ yield * Queue . take ( harness . terminalReceipts ) ;
2368+ const items = harness . events . flatMap ( ( event ) =>
2369+ event . type === "turn_item.updated" && event . turnItem . type === "dynamic_tool"
2370+ ? [ event . turnItem ]
2371+ : [ ] ,
2372+ ) ;
2373+ const failed = items . findLast ( ( item ) => item . nativeItemRef ?. nativeId === "tool-error" ) ! ;
2374+ assert . equal ( failed . status , kind === "cancelled" ? "cancelled" : "failed" ) ;
2375+ assert . equal ( failed . toolNonExecutionKind , kind ) ;
2376+ const ok = items . findLast ( ( item ) => item . nativeItemRef ?. nativeId === "tool-ok" ) ! ;
2377+ assert . equal ( ok . status , "completed" ) ;
2378+ assert . equal ( ok . toolNonExecutionKind , undefined ) ;
2379+ const node = harness . events . findLast (
2380+ ( event ) =>
2381+ event . type === "node.updated" && event . node . nativeItemRef ?. nativeId === "tool-error" ,
2382+ ) ;
2383+ assert . equal ( node ?. type === "node.updated" ? node . node . status : undefined , failed . status ) ;
2384+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
2385+ ) ,
2386+ ) ;
2387+
23032388 it . effect . each (
23042389 ( [ "aborted_tools" , "aborted_streaming" ] as const ) . flatMap ( ( terminalReason ) =>
23052390 [ true , false ] . map ( ( steered ) => ( { terminalReason, steered } ) ) ,
0 commit comments