@@ -871,6 +871,20 @@ describe("ClaudeAdapterV2 context usage", () => {
871871} ) ;
872872
873873describe ( "ClaudeAdapterV2 session permissions" , ( ) => {
874+ it ( "keeps explicit user refusals classified as user_reject" , ( ) => {
875+ const result = ClaudeAdapterV2 . permissionResultFromDecision ( {
876+ toolName : "Bash" ,
877+ decision : "decline" ,
878+ toolInput : { command : "make" } ,
879+ toolUseID : "denied-build" ,
880+ } ) ;
881+ assert . equal ( result . behavior , "deny" ) ;
882+ if ( result . behavior !== "deny" ) return ;
883+ assert . equal ( result . decisionClassification , "user_reject" ) ;
884+ assert . equal ( result . message , "User declined tool execution." ) ;
885+ assert . equal ( result . interrupt , undefined ) ;
886+ } ) ;
887+
874888 it ( "forces suggested permission updates to session scope" , ( ) => {
875889 const result = ClaudeAdapterV2 . permissionResultFromDecision ( {
876890 toolName : "Bash" ,
@@ -2480,6 +2494,77 @@ describe("ClaudeAdapterV2 background wake turns", () => {
24802494 } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
24812495 ) ;
24822496
2497+ it . effect . each ( [ "cancelled" , "denied" , "permission_denied" , undefined ] ) (
2498+ "preserves native tool non-execution metadata %s without inferring a denial from text" ,
2499+ ( kind ) =>
2500+ Effect . scoped (
2501+ Effect . gen ( function * ( ) {
2502+ const harness = yield * makeWakeHarness ;
2503+ yield * harness . runtime . startTurn (
2504+ makeClaudeTestTurnInput ( {
2505+ threadId : harness . threadId ,
2506+ providerThread : harness . providerThread ,
2507+ now : yield * DateTime . now ,
2508+ attemptId : RunAttemptId . make ( "attempt-tool-non-execution" ) ,
2509+ text : "Run the tool." ,
2510+ attachments : [ ] ,
2511+ } ) ,
2512+ ) ;
2513+ // Same error text can describe a cancellation or a real refusal.
2514+ // Each result must use its own metadata, even in a multi-result frame.
2515+ yield * harness . offerAndWait (
2516+ claudeSdkFrame ( {
2517+ type : "user" ,
2518+ uuid : "tool-non-execution" ,
2519+ session_id : WAKE_NATIVE_SESSION ,
2520+ parent_tool_use_id : null ,
2521+ message : {
2522+ role : "user" ,
2523+ content : [
2524+ {
2525+ type : "tool_result" ,
2526+ tool_use_id : "tool-error" ,
2527+ is_error : true ,
2528+ content : "STOP and wait for the user." ,
2529+ } ,
2530+ { type : "tool_result" , tool_use_id : "tool-ok" , is_error : false , content : "OK" } ,
2531+ ] ,
2532+ } ,
2533+ ...( kind === undefined
2534+ ? { }
2535+ : {
2536+ tool_result_meta : [
2537+ { id : "tool-error" , non_execution_kind : kind } ,
2538+ { id : "tool-ok" , non_execution_kind : null } ,
2539+ ] ,
2540+ } ) ,
2541+ } ) ,
2542+ ) ;
2543+ yield * Queue . offer (
2544+ harness . sdkMessages ,
2545+ makeResultFrame ( { uuid : "result-non-execution" , result : "Done" } ) ,
2546+ ) ;
2547+ yield * Queue . take ( harness . terminalReceipts ) ;
2548+ const items = harness . events . flatMap ( ( event ) =>
2549+ event . type === "turn_item.updated" && event . turnItem . type === "dynamic_tool"
2550+ ? [ event . turnItem ]
2551+ : [ ] ,
2552+ ) ;
2553+ const failed = items . findLast ( ( item ) => item . nativeItemRef ?. nativeId === "tool-error" ) ! ;
2554+ assert . equal ( failed . status , kind === "cancelled" ? "cancelled" : "failed" ) ;
2555+ assert . equal ( failed . toolNonExecutionKind , kind ) ;
2556+ const ok = items . findLast ( ( item ) => item . nativeItemRef ?. nativeId === "tool-ok" ) ! ;
2557+ assert . equal ( ok . status , "completed" ) ;
2558+ assert . equal ( ok . toolNonExecutionKind , undefined ) ;
2559+ const node = harness . events . findLast (
2560+ ( event ) =>
2561+ event . type === "node.updated" && event . node . nativeItemRef ?. nativeId === "tool-error" ,
2562+ ) ;
2563+ assert . equal ( node ?. type === "node.updated" ? node . node . status : undefined , failed . status ) ;
2564+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
2565+ ) ,
2566+ ) ;
2567+
24832568 it . effect . each (
24842569 ( [ "aborted_tools" , "aborted_streaming" ] as const ) . flatMap ( ( terminalReason ) =>
24852570 [ true , false ] . map ( ( steered ) => ( { terminalReason, steered } ) ) ,
0 commit comments