@@ -8,7 +8,11 @@ import {
88} from "@t3tools/provider-acp-registry/testing" ;
99import { AcpRegistrySettings } from "@t3tools/provider-acp-registry/settings" ;
1010import { AcpRegistryCatalog } from "@t3tools/provider-acp-registry/server/AcpRegistrySupport" ;
11- import { decodeAcpReplayTranscript , makeAcpReplayRuntime } from "./AcpAdapterV2.testkit.ts" ;
11+ import {
12+ decodeAcpReplayTranscript ,
13+ makeAcpReplayCompletenessAssertion ,
14+ makeAcpReplayRuntime ,
15+ } from "./AcpAdapterV2.testkit.ts" ;
1216// @effect -diagnostics nodeBuiltinImport:off
1317import * as NodeFS from "node:fs" ;
1418import * as NodePath from "node:path" ;
@@ -2411,6 +2415,174 @@ describe("AcpAdapterV2", () => {
24112415 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
24122416 ) ;
24132417
2418+ // regression: #27646 an agent that leaves its mode itself must not be forced back, but picking
2419+ // the old mode again must reach it, even when a v1 agent reports only the mode update.
2420+ it . live ( "reports a mode the agent left itself so picking it again is sent" , ( ) =>
2421+ Effect . gen ( function * ( ) {
2422+ const fileSystem = yield * FileSystem . FileSystem ;
2423+ const path = yield * Path . Path ;
2424+ const directory = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-acp-mode-only-" } ) ;
2425+ const statusPath = path . join ( directory , "status.json" ) ;
2426+ const sessionId = "mode-only-session" ;
2427+ const modeOption = ( currentValue : string ) => ( {
2428+ id : "mode" ,
2429+ name : "Mode" ,
2430+ category : "mode" ,
2431+ type : "select" ,
2432+ currentValue,
2433+ options : [
2434+ { value : "ask" , name : "Ask" } ,
2435+ { value : "architect" , name : "Architect" } ,
2436+ ] ,
2437+ } ) ;
2438+ const setArchitect = [
2439+ {
2440+ type : "expect_outbound" as const ,
2441+ frame : {
2442+ kind : "request" ,
2443+ method : "session/set_config_option" ,
2444+ params : { sessionId, configId : "mode" , value : "architect" } ,
2445+ } ,
2446+ } ,
2447+ {
2448+ type : "emit_inbound" as const ,
2449+ frame : {
2450+ kind : "response" ,
2451+ method : "session/set_config_option" ,
2452+ result : { configOptions : [ modeOption ( "architect" ) ] } ,
2453+ } ,
2454+ } ,
2455+ ] ;
2456+ const prompt = ( updates : ReadonlyArray < unknown > ) => [
2457+ {
2458+ type : "expect_outbound" as const ,
2459+ frame : { kind : "request" , method : "session/prompt" , params : "<any>" } ,
2460+ } ,
2461+ ...updates . map ( ( update ) => ( {
2462+ type : "emit_inbound" as const ,
2463+ frame : { kind : "notification" , method : "session/update" , params : { sessionId, update } } ,
2464+ } ) ) ,
2465+ {
2466+ type : "emit_inbound" as const ,
2467+ frame : { kind : "response" , method : "session/prompt" , result : { stopReason : "end_turn" } } ,
2468+ } ,
2469+ ] ;
2470+ const transcript = yield * decodeAcpReplayTranscript (
2471+ {
2472+ provider : ACP_TEST_DRIVER ,
2473+ protocol : "acp.ndjson-jsonrpc" ,
2474+ version : "1" ,
2475+ scenario : "mode-only-update" ,
2476+ entries : [
2477+ {
2478+ type : "expect_outbound" ,
2479+ frame : { kind : "request" , method : "initialize" , params : "<any>" } ,
2480+ } ,
2481+ {
2482+ type : "emit_inbound" ,
2483+ frame : {
2484+ kind : "response" ,
2485+ method : "initialize" ,
2486+ result : { protocolVersion : 1 , agentCapabilities : { } , authMethods : [ ] } ,
2487+ } ,
2488+ } ,
2489+ {
2490+ type : "expect_outbound" ,
2491+ frame : { kind : "request" , method : "session/new" , params : "<any>" } ,
2492+ } ,
2493+ {
2494+ type : "emit_inbound" ,
2495+ frame : {
2496+ kind : "response" ,
2497+ method : "session/new" ,
2498+ result : { sessionId, configOptions : [ modeOption ( "ask" ) ] } ,
2499+ } ,
2500+ } ,
2501+ ...setArchitect ,
2502+ ...prompt ( [ { sessionUpdate : "current_mode_update" , currentModeId : "ask" } ] ) ,
2503+ ...prompt ( [ ] ) ,
2504+ ...setArchitect ,
2505+ ...prompt ( [ ] ) ,
2506+ ] ,
2507+ } ,
2508+ ACP_TEST_DRIVER ,
2509+ ) ;
2510+ const instanceId = ProviderInstanceId . make ( "acp-test-mode-only" ) ;
2511+ const threadId = ThreadId . make ( "thread-acp-mode-only" ) ;
2512+ const adapter = yield * makeAcpAdapterV2 ( {
2513+ instanceId,
2514+ flavor : {
2515+ driver : ACP_TEST_DRIVER ,
2516+ capabilities : AcpProviderCapabilitiesV2 ,
2517+ makeRuntime : makeAcpReplayRuntime ( {
2518+ transcript,
2519+ statusPath,
2520+ fileSystem,
2521+ scriptPath : yield * path . fromFileUrl (
2522+ new URL ( "../../../scripts/acp-replay-agent.ts" , import . meta. url ) ,
2523+ ) ,
2524+ childProcessSpawner : yield * ChildProcessSpawner . ChildProcessSpawner ,
2525+ } ) ,
2526+ } ,
2527+ selfInvocation : yield * resolveSelfInvocation ( ) ,
2528+ } ) ;
2529+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
2530+ runtimeMode : "full-access" ,
2531+ interactionMode : "default" ,
2532+ cwd : directory ,
2533+ } ) ;
2534+ const architect = {
2535+ instanceId,
2536+ model : "default" ,
2537+ options : [ { id : "mode" , value : "architect" } ] ,
2538+ } as const ;
2539+ const ask = { ...architect , options : [ { id : "mode" , value : "ask" } ] } ;
2540+ const runtime = yield * adapter . openSession ( {
2541+ threadId,
2542+ providerSessionId : ProviderSessionId . make ( "provider-session-acp-mode-only" ) ,
2543+ modelSelection : architect ,
2544+ runtimePolicy,
2545+ } ) ;
2546+ const providerThread = yield * runtime . ensureThread ( {
2547+ threadId,
2548+ modelSelection : architect ,
2549+ runtimePolicy,
2550+ } ) ;
2551+ const now = yield * DateTime . now ;
2552+ const reported : Array < unknown > = [ ] ;
2553+ // The thread follows the agent to ask; only the user's renewed pick sets architect again.
2554+ for ( const [ ordinal , modelSelection ] of [
2555+ [ 1 , architect ] ,
2556+ [ 2 , ask ] ,
2557+ [ 3 , architect ] ,
2558+ ] as const ) {
2559+ yield * runtime . startTurn (
2560+ makeTurnInput ( {
2561+ threadId,
2562+ providerThread,
2563+ instanceId,
2564+ runtimePolicy,
2565+ now,
2566+ ordinal,
2567+ modelSelection,
2568+ } ) ,
2569+ ) ;
2570+ yield * runtime . events . pipe (
2571+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
2572+ Stream . runForEach ( ( event ) =>
2573+ Effect . sync ( ( ) => {
2574+ if ( event . type === "thread_model_selection.updated" ) {
2575+ reported . push ( { threadId : event . threadId , modelSelection : event . modelSelection } ) ;
2576+ }
2577+ } ) ,
2578+ ) ,
2579+ ) ;
2580+ }
2581+ assert . deepStrictEqual ( reported , [ { threadId, modelSelection : ask } ] ) ;
2582+ yield * makeAcpReplayCompletenessAssertion ( fileSystem , statusPath , transcript ) ;
2583+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
2584+ ) ;
2585+
24142586 // regression: #21499 turns blocked only on T3 thread waits must show as waiting
24152587 it . effect . each ( [ "agent_message_chunk" ] as const ) (
24162588 "keeps named ACP %s open while deriving thread wait execution state" ,
0 commit comments