11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { assert , describe , it } from "@effect/vitest" ;
33import {
4+ ANTIGRAVITY_DEFAULT_MODEL ,
45 MessageId ,
56 NodeId ,
67 ProjectId ,
@@ -15,6 +16,8 @@ import * as Crypto from "effect/Crypto";
1516import * as DateTime from "effect/DateTime" ;
1617import * as Effect from "effect/Effect" ;
1718import * as Exit from "effect/Exit" ;
19+ import * as Fiber from "effect/Fiber" ;
20+ import * as Scope from "effect/Scope" ;
1821import * as FileSystem from "effect/FileSystem" ;
1922import * as Layer from "effect/Layer" ;
2023import * as Path from "effect/Path" ;
@@ -25,9 +28,12 @@ import type * as EffectAcpSchema from "effect-acp/compat";
2528import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost" ;
2629import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
2730import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
28- import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime" ;
31+ import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime" ;
2932import { makeAntigravityAcpRuntime } from "../../provider/acp/AntigravityAcpSupport.ts" ;
30- import { antigravity140Session } from "../../provider/acp/antigravity140.fixture.ts" ;
33+ import {
34+ antigravity140AgentSource ,
35+ decodeAntigravity140Request ,
36+ } from "../../provider/acp/antigravity140.fixture.ts" ;
3137import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3238import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
3339import {
@@ -59,41 +65,6 @@ function permissionRequest(
5965}
6066
6167describe ( "AntigravityAdapterV2 flavor" , ( ) => {
62- it . effect ( "restores an ACP 1.4 concrete model instead of selecting the family" , ( ) => {
63- const selected : string [ ] = [ ] ;
64- return Effect . gen ( function * ( ) {
65- const runtime = yield * AcpSessionRuntime . AcpSessionRuntime ;
66- const model = yield * flavor . applyModelSelection ! ( {
67- runtime,
68- startResult : {
69- sessionId : antigravity140Session . sessionId ,
70- sessionSetupResult : antigravity140Session ,
71- initializeResult : { protocolVersion : 1 } ,
72- modelConfigId : "model" ,
73- } ,
74- modelSelection : {
75- instanceId : ProviderInstanceId . make ( "antigravity-test" ) ,
76- model : "gemini-3.8-flash-low" ,
77- } ,
78- } ) ;
79- assert . equal ( model , "gemini-3.8-flash-low" ) ;
80- assert . deepEqual ( selected , [ "gemini-3.8-flash-low" ] ) ;
81- } ) . pipe (
82- Effect . provide (
83- Layer . mock ( AcpSessionRuntime . AcpSessionRuntime ) ( {
84- processContainment : "none" ,
85- getConfigOptions : Effect . succeed ( antigravity140Session . configOptions ) ,
86- setModel : ( ) => Effect . die ( "The model config only accepts a family ID" ) ,
87- setSessionModel : ( model ) =>
88- Effect . sync ( ( ) => {
89- selected . push ( model ) ;
90- return { } ;
91- } ) ,
92- } ) ,
93- ) ,
94- ) ;
95- } ) ;
96-
9768 it ( "keeps a successful subagent launch running until the parent turn becomes idle" , ( ) => {
9869 const batch = flavor . extractSubagentUpdate ?.( {
9970 toolCallId : "trajectory:4" ,
@@ -170,6 +141,159 @@ const layerSession = Layer.mergeAll(
170141 TestProviderHost . layer ( ) . pipe ( Layer . provide ( NodeServices . layer ) ) ,
171142) ;
172143
144+ describe ( "AntigravityAdapterV2 ACP 1.4 models" , ( ) => {
145+ it . effect (
146+ "uses concrete models for fresh and resumed chat and restores the default after thinking changes" ,
147+ ( ) =>
148+ Effect . gen ( function * ( ) {
149+ const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
150+ const fileSystem = yield * FileSystem . FileSystem ;
151+ const path = yield * Path . Path ;
152+ const crypto = yield * Crypto . Crypto ;
153+ const workspace = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3-ag-models-" } ) ;
154+ const agentPath = path . join ( workspace , "agent.mjs" ) ;
155+ const logPath = path . join ( workspace , "requests.ndjson" ) ;
156+ yield * fileSystem . writeFileString ( agentPath , antigravity140AgentSource ) ;
157+ const instanceId = ProviderInstanceId . make ( "antigravity-model-test" ) ;
158+ const adapter = yield * makeAntigravityAdapterV2 ( {
159+ instanceId,
160+ selfInvocation : yield * resolveSelfInvocation ( ) ,
161+ makeRuntime : ( input ) =>
162+ makeAntigravityAcpRuntime ( {
163+ ...input ,
164+ childProcessSpawner,
165+ spawn : {
166+ command : process . execPath ,
167+ args : [ agentPath ] ,
168+ cwd : workspace ,
169+ env : { T3_ACP_REQUEST_LOG_PATH : logPath } ,
170+ } ,
171+ } ) . pipe ( Effect . provideService ( Crypto . Crypto , crypto ) ) ,
172+ withProcess : ( _stop , task ) => task ,
173+ defaultModel : Effect . succeed ( "gemini-3.8-flash-high" ) ,
174+ } ) ;
175+ const threadId = ThreadId . make ( "thread-antigravity-models" ) ;
176+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
177+ runtimeMode : "full-access" ,
178+ interactionMode : "default" ,
179+ cwd : workspace ,
180+ } ) ;
181+ const savedModel = { instanceId, model : "gemini-3.8-flash-low" } ;
182+ const open = {
183+ threadId,
184+ providerSessionId : ProviderSessionId . make ( "provider-session-antigravity-models" ) ,
185+ modelSelection : savedModel ,
186+ runtimePolicy,
187+ } ;
188+ const freshScope = yield * Scope . fork ( yield * Effect . scope ) ;
189+ let session = yield * adapter
190+ . openSession ( open )
191+ . pipe ( Effect . provideService ( Scope . Scope , freshScope ) ) ;
192+ const providerThread = yield * session . ensureThread ( open ) ;
193+ const now = yield * DateTime . now ;
194+ const turn = Effect . fnUntraced ( function * (
195+ ordinal : number ,
196+ modelSelection : typeof savedModel & { options ?: Array < { id : string ; value : string } > } ,
197+ ) {
198+ const completed = yield * session . events . pipe (
199+ Stream . takeUntil (
200+ ( event ) =>
201+ event . type === "provider_turn.updated" && event . providerTurn . status === "completed" ,
202+ ) ,
203+ Stream . runCollect ,
204+ Effect . forkChild ,
205+ ) ;
206+ yield * session . startTurn ( {
207+ appThread : {
208+ createdBy : "user" ,
209+ creationSource : "web" ,
210+ id : threadId ,
211+ projectId : ProjectId . make ( "project-antigravity-models" ) ,
212+ title : "Antigravity models" ,
213+ providerInstanceId : instanceId ,
214+ modelSelection,
215+ runtimeMode : "full-access" ,
216+ interactionMode : "default" ,
217+ branch : null ,
218+ worktreePath : null ,
219+ activeProviderThreadId : providerThread . id ,
220+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
221+ forkedFrom : null ,
222+ createdAt : now ,
223+ updatedAt : now ,
224+ archivedAt : null ,
225+ settledOverride : null ,
226+ settledAt : null ,
227+ lastVisitedAt : null ,
228+ deletedAt : null ,
229+ } ,
230+ threadId,
231+ runId : RunId . make ( `run-model-${ ordinal } ` ) ,
232+ runOrdinal : ordinal ,
233+ providerTurnOrdinal : ordinal ,
234+ attemptId : RunAttemptId . make ( `attempt-model-${ ordinal } ` ) ,
235+ rootNodeId : NodeId . make ( `node-model-${ ordinal } ` ) ,
236+ providerThread,
237+ message : {
238+ createdBy : "user" ,
239+ creationSource : "web" ,
240+ messageId : MessageId . make ( `message-model-${ ordinal } ` ) ,
241+ text : "Report the selected model" ,
242+ attachments : [ ] ,
243+ } ,
244+ modelSelection,
245+ runtimePolicy,
246+ } ) ;
247+ const events = yield * Fiber . join ( completed ) ;
248+ return events
249+ . filter (
250+ ( event ) => event . type === "message.updated" && event . message . role === "assistant" ,
251+ )
252+ . map ( ( event ) => ( event . type === "message.updated" ? event . message . text : undefined ) )
253+ . at ( - 1 ) ;
254+ } ) ;
255+ assert . equal ( yield * turn ( 1 , savedModel ) , "gemini-3.8-flash-low" ) ;
256+ yield * Scope . close ( freshScope , Exit . void ) ;
257+ assert . isNotNull ( providerThread . nativeThreadRef ?. nativeId ) ;
258+ session = yield * adapter . openSession ( {
259+ ...open ,
260+ initialNativeThreadId : providerThread . nativeThreadRef ! . nativeId ! ,
261+ } ) ;
262+ yield * session . resumeThread ( { providerThread } ) ;
263+ assert . equal ( yield * turn ( 2 , savedModel ) , "gemini-3.8-flash-low" ) ;
264+ assert . equal (
265+ yield * turn ( 3 , {
266+ instanceId,
267+ model : ANTIGRAVITY_DEFAULT_MODEL ,
268+ options : [ { id : "thinking_level" , value : "low" } ] ,
269+ } ) ,
270+ "gemini-3.8-flash-low" ,
271+ ) ;
272+ assert . equal (
273+ yield * turn ( 4 , { instanceId, model : ANTIGRAVITY_DEFAULT_MODEL } ) ,
274+ "gemini-3.8-flash-high" ,
275+ ) ;
276+ const requests = yield * Effect . forEach (
277+ ( yield * fileSystem . readFileString ( logPath ) ) . trim ( ) . split ( "\n" ) ,
278+ ( line ) => decodeAntigravity140Request ( line ) ,
279+ ) ;
280+ assert . equal ( requests . filter ( ( request ) => request . method === "session/new" ) . length , 1 ) ;
281+ assert . equal ( requests . filter ( ( request ) => request . method === "session/resume" ) . length , 1 ) ;
282+ assert . deepEqual (
283+ requests
284+ . filter ( ( request ) => request . method === "session/set_model" )
285+ . map ( ( request ) => request . params ?. modelId ) ,
286+ [
287+ "gemini-3.8-flash-low" ,
288+ "gemini-3.8-flash-low" ,
289+ "gemini-3.8-flash-high" ,
290+ "gemini-3.8-flash-high" ,
291+ ] ,
292+ ) ;
293+ } ) . pipe ( Effect . provide ( layerSession ) , Effect . scoped ) ,
294+ ) ;
295+ } ) ;
296+
173297describe ( "AntigravityAdapterV2 client file system" , ( ) => {
174298 it . effect ( "confines agent file requests to the workspace under full access" , ( ) =>
175299 Effect . gen ( function * ( ) {
0 commit comments