@@ -63,6 +63,8 @@ import {
6363} from "@t3tools/provider-acp/server/sessionConfig" ;
6464import {
6565 extractXAiAcpSubagentUpdate ,
66+ makeGrokAdapterV2 ,
67+ makeXAiPromptCompletionRuntime ,
6668 normalizeXAiAcpToolCallState ,
6769 registerXAiBackgroundTaskTracking ,
6870} from "@t3tools/provider-grok/testing" ;
@@ -3079,6 +3081,193 @@ describe("AcpAdapterV2", () => {
30793081 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
30803082 ) ;
30813083
3084+ // Oracle: Grok incident frames. Command completion must release the turn even
3085+ // when the CLI keeps the prompt RPC and process alive. Command polls stay visible.
3086+ it . live (
3087+ "completes a structured Grok background command from poll with an unanswered prompt RPC" ,
3088+ ( ) =>
3089+ Effect . gen ( function * ( ) {
3090+ const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
3091+ const path = yield * Path . Path ;
3092+ const mockAgentPath = yield * path . fromFileUrl (
3093+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
3094+ ) ;
3095+ const instanceId = ProviderInstanceId . make ( "grok-background-completion" ) ;
3096+ const adapter = yield * makeGrokAdapterV2 ( {
3097+ instanceId,
3098+ settings : DEFAULT_GROK_SETTINGS ,
3099+ environment : { } ,
3100+ hostPlatform : yield * HostProcess . Platform ,
3101+ selfInvocation : yield * resolveSelfInvocation ( ) ,
3102+ makeRuntime : ( input ) =>
3103+ makeMockRuntime ( {
3104+ childProcessSpawner,
3105+ mockAgentPath,
3106+ environment : { T3_ACP_GROK_BACKGROUND_TASK_COMPLETION : "poll" } ,
3107+ } ) ( input ) . pipe ( Effect . flatMap ( makeXAiPromptCompletionRuntime ) ) ,
3108+ } ) ;
3109+ const threadId = ThreadId . make ( "grok-background-completion" ) ;
3110+ const modelSelection = { instanceId, model : "default" } as const ;
3111+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
3112+ runtimeMode : "full-access" ,
3113+ interactionMode : "default" ,
3114+ cwd : process . cwd ( ) ,
3115+ } ) ;
3116+ const runtime = yield * adapter . openSession ( {
3117+ threadId,
3118+ providerSessionId : ProviderSessionId . make ( "grok-background-completion" ) ,
3119+ modelSelection,
3120+ runtimePolicy,
3121+ } ) ;
3122+ const providerThread = yield * runtime . ensureThread ( {
3123+ threadId,
3124+ modelSelection,
3125+ runtimePolicy,
3126+ } ) ;
3127+ const events = yield * Queue . unbounded < ProviderAdapter . ProviderAdapterV2Event > ( ) ;
3128+ yield * runtime . events . pipe (
3129+ Stream . runForEach ( ( event ) => Queue . offer ( events , event ) ) ,
3130+ Effect . forkScoped ,
3131+ ) ;
3132+ yield * runtime . startTurn (
3133+ makeTurnInput ( {
3134+ threadId,
3135+ providerThread,
3136+ instanceId,
3137+ runtimePolicy,
3138+ now : yield * DateTime . now ,
3139+ } ) ,
3140+ ) ;
3141+ const observed = yield * Stream . fromQueue ( events ) . pipe (
3142+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
3143+ Stream . runCollect ,
3144+ ) ;
3145+ const allEvents = [ ...observed ] ;
3146+ let next = yield * Queue . poll ( events ) ;
3147+ while ( Option . isSome ( next ) ) {
3148+ allEvents . push ( next . value ) ;
3149+ next = yield * Queue . poll ( events ) ;
3150+ }
3151+ const terminals = allEvents . filter ( ( event ) => event . type === "turn.terminal" ) ;
3152+ assert . deepEqual (
3153+ terminals . map ( ( event ) => event . status ) ,
3154+ [ "completed" ] ,
3155+ ) ;
3156+ const items = allEvents . flatMap ( ( event ) =>
3157+ event . type === "turn_item.updated" ? [ event . turnItem ] : [ ] ,
3158+ ) ;
3159+ assert . isFalse ( items . some ( ( item ) => item . type === "subagent" ) ) ;
3160+ const command = items . findLast (
3161+ ( item ) => item . nativeItemRef ?. nativeId === "call-fb9d0000-0000-0000-0000-000000000026-29" ,
3162+ ) ;
3163+ assert . equal ( command ?. type , "command_execution" ) ;
3164+ assert . equal ( command ?. status , "completed" ) ;
3165+ assert . isTrue (
3166+ items . some ( ( item ) => item . nativeItemRef ?. nativeId === "call-background-poll" ) ,
3167+ "command TaskOutput must retain its normal tool frame" ,
3168+ ) ;
3169+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
3170+ ) ;
3171+
3172+ // Oracle: #15888 KillTask reports. Command completion must release the turn even
3173+ // when the CLI keeps the prompt RPC and process alive. Kill calls stay visible.
3174+ it . live . each ( [
3175+ { shape : "output_only" , expectedCommand : { type : "command_execution" , status : "completed" } } ,
3176+ { shape : "variant_only" , expectedCommand : { type : "command_execution" , status : "completed" } } ,
3177+ { shape : "killed" , expectedCommand : { type : "command_execution" , status : "completed" } } ,
3178+ {
3179+ shape : "already_exited" ,
3180+ expectedCommand : { type : "command_execution" , status : "completed" } ,
3181+ } ,
3182+ {
3183+ shape : "known_failure" ,
3184+ expectedCommand : { type : "command_execution" , status : "failed" , output : "known failure\n" } ,
3185+ } ,
3186+ ] as const ) (
3187+ "completes a Grok KillTask command ($shape) and preserves any known result" ,
3188+ ( { shape, expectedCommand } ) =>
3189+ Effect . gen ( function * ( ) {
3190+ const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
3191+ const path = yield * Path . Path ;
3192+ const mockAgentPath = yield * path . fromFileUrl (
3193+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
3194+ ) ;
3195+ const instanceId = ProviderInstanceId . make ( "grok-kill-completion" ) ;
3196+ const adapter = yield * makeGrokAdapterV2 ( {
3197+ instanceId,
3198+ settings : DEFAULT_GROK_SETTINGS ,
3199+ environment : { } ,
3200+ hostPlatform : yield * HostProcess . Platform ,
3201+ selfInvocation : yield * resolveSelfInvocation ( ) ,
3202+ makeRuntime : ( input ) =>
3203+ makeMockRuntime ( {
3204+ childProcessSpawner,
3205+ mockAgentPath,
3206+ environment : { T3_ACP_GROK_KILL_TASK_SHAPE : shape } ,
3207+ } ) ( input ) . pipe ( Effect . flatMap ( makeXAiPromptCompletionRuntime ) ) ,
3208+ } ) ;
3209+ const threadId = ThreadId . make ( "grok-kill-completion" ) ;
3210+ const modelSelection = { instanceId, model : "default" } as const ;
3211+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
3212+ runtimeMode : "full-access" ,
3213+ interactionMode : "default" ,
3214+ cwd : process . cwd ( ) ,
3215+ } ) ;
3216+ const runtime = yield * adapter . openSession ( {
3217+ threadId,
3218+ providerSessionId : ProviderSessionId . make ( "grok-kill-completion" ) ,
3219+ modelSelection,
3220+ runtimePolicy,
3221+ } ) ;
3222+ const providerThread = yield * runtime . ensureThread ( {
3223+ threadId,
3224+ modelSelection,
3225+ runtimePolicy,
3226+ } ) ;
3227+ const events = yield * Queue . unbounded < ProviderAdapter . ProviderAdapterV2Event > ( ) ;
3228+ yield * runtime . events . pipe (
3229+ Stream . runForEach ( ( event ) => Queue . offer ( events , event ) ) ,
3230+ Effect . forkScoped ,
3231+ ) ;
3232+ yield * runtime . startTurn (
3233+ makeTurnInput ( {
3234+ threadId,
3235+ providerThread,
3236+ instanceId,
3237+ runtimePolicy,
3238+ now : yield * DateTime . now ,
3239+ } ) ,
3240+ ) ;
3241+ const observed = yield * Stream . fromQueue ( events ) . pipe (
3242+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
3243+ Stream . runCollect ,
3244+ ) ;
3245+ const allEvents = [ ...observed ] ;
3246+ let next = yield * Queue . poll ( events ) ;
3247+ while ( Option . isSome ( next ) ) {
3248+ allEvents . push ( next . value ) ;
3249+ next = yield * Queue . poll ( events ) ;
3250+ }
3251+ const terminals = allEvents . filter ( ( event ) => event . type === "turn.terminal" ) ;
3252+ assert . deepEqual (
3253+ terminals . map ( ( event ) => event . status ) ,
3254+ [ "completed" ] ,
3255+ ) ;
3256+ const items = allEvents . flatMap ( ( event ) =>
3257+ event . type === "turn_item.updated" ? [ event . turnItem ] : [ ] ,
3258+ ) ;
3259+ assert . isFalse ( items . some ( ( item ) => item . type === "subagent" ) ) ;
3260+ const command = items . findLast (
3261+ ( item ) => item . nativeItemRef ?. nativeId === "kill-target-command" ,
3262+ ) ;
3263+ assert . deepInclude ( command , expectedCommand ) ;
3264+ assert . isTrue (
3265+ items . some ( ( item ) => item . nativeItemRef ?. nativeId === "kill-command" ) ,
3266+ "KillTask must retain its normal tool frame" ,
3267+ ) ;
3268+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
3269+ ) ;
3270+
30823271 it . effect ( "keeps an agent's empty-valued default choice selectable" , ( ) =>
30833272 Effect . gen ( function * ( ) {
30843273 const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
0 commit comments