@@ -82,6 +82,7 @@ import {
8282 acpPostSettleContinuationOfferEvidence ,
8383 acpPostSettleWakeEvidence ,
8484 acpToolCallDiffPatch ,
85+ acpToolCallSnippetEdit ,
8586 makeAcpAdapterV2 ,
8687 type AcpAdapterV2ExtensionContext ,
8788 type AcpAdapterV2Flavor ,
@@ -138,6 +139,32 @@ describe("acpPerTurnPromptUsage", () => {
138139 reasoningTokens : 3 ,
139140 } ,
140141 ) ;
142+ // Antigravity 1.4.5: its harness reports prompt tokens without the 24 cached ones.
143+ assert . deepEqual (
144+ acpPerTurnPromptUsage (
145+ {
146+ inputTokens : 42 ,
147+ outputTokens : 3 ,
148+ totalTokens : 54 ,
149+ cachedReadTokens : 24 ,
150+ cachedWriteTokens : 0 ,
151+ thoughtTokens : 9 ,
152+ } ,
153+ false ,
154+ "completed" ,
155+ true ,
156+ ) ,
157+ {
158+ usageScope : "main_agent" ,
159+ usageStatus : "complete" ,
160+ hasSubagents : false ,
161+ inputTokens : 66 ,
162+ outputTokens : 12 ,
163+ cachedInputTokens : 24 ,
164+ cacheCreationTokens : 0 ,
165+ reasoningTokens : 9 ,
166+ } ,
167+ ) ;
141168 } ) ;
142169
143170 it ( "clamps subsets that exceed their parents and drops unset counters" , ( ) => {
@@ -231,6 +258,45 @@ describe("acpPerTurnPromptUsage", () => {
231258} ) ;
232259
233260describe ( "acpToolCallDiffPatch" , ( ) => {
261+ it ( "keeps an unplaced snippet as recorded text instead of numbering it from line 1" , ( ) => {
262+ const content = [
263+ {
264+ type : "diff" ,
265+ path : "/repo/a.ts" ,
266+ oldText : "const target = 10;" ,
267+ newText : "const target = 100;" ,
268+ patch : { format : "snippet" , text : "@@ -1,1 +1,1 @@ snippet, line unknown\n" } ,
269+ } ,
270+ ] ;
271+ assert . isUndefined ( acpToolCallDiffPatch ( content ) ) ;
272+ // An omitted preview is not re-diffed from the bare snippets either.
273+ assert . isUndefined ( acpToolCallDiffPatch ( [ { ...content [ 0 ] , patch : { format : "omitted" } } ] ) ) ;
274+ // A status block beside the snippet must not hide it.
275+ for ( const blocks of [
276+ content ,
277+ [ { type : "content" , content : { type : "text" , text : "Edited." } } , ...content ] ,
278+ ] ) {
279+ assert . isUndefined ( acpToolCallDiffPatch ( blocks ) ) ;
280+ assert . deepEqual ( acpToolCallSnippetEdit ( blocks ) , {
281+ oldStr : "const target = 10;" ,
282+ newStr : "const target = 100;" ,
283+ } ) ;
284+ }
285+ // Beside another diff, the snippet is neither a patch nor a placed edit.
286+ const twoDiffs = [
287+ ...content ,
288+ {
289+ type : "diff" ,
290+ path : "/repo/b.ts" ,
291+ oldText : "b\n" ,
292+ newText : "B\n" ,
293+ patch : { text : "@@ -1 +1 @@\n-b\n+B\n" } ,
294+ } ,
295+ ] ;
296+ assert . isUndefined ( acpToolCallDiffPatch ( twoDiffs ) ) ;
297+ assert . isUndefined ( acpToolCallSnippetEdit ( twoDiffs ) ) ;
298+ } ) ;
299+
234300 it ( "builds per-file patches from ACP hunks and recorded old/new text" , ( ) => {
235301 for ( const operation of [ "add" , "delete" ] ) {
236302 const text = operation === "add" ? "@@ -0,0 +1 @@\n+content\n" : "@@ -1 +0,0 @@\n-content\n" ;
@@ -661,6 +727,97 @@ describe("AcpAdapterV2", () => {
661727 assert . equal ( promptOrdinal , 2 , "continuation turn must not dispatch session/prompt" ) ;
662728 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
663729 ) ;
730+ it . live ( "fails an end_turn the outcome check rejects and restarts before the next turn" , ( ) =>
731+ Effect . gen ( function * ( ) {
732+ const path = yield * Path . Path ;
733+ const instanceId = ProviderInstanceId . make ( "acp-test-prompt-outcome" ) ;
734+ const threadId = ThreadId . make ( "thread-acp-prompt-outcome" ) ;
735+ const quota = {
736+ class : "usage_limit" ,
737+ message : "Quota reached." ,
738+ code : "RESOURCE_EXHAUSTED" ,
739+ retryable : true ,
740+ resetAt : "2030-01-01T00:00:00.000Z" ,
741+ } as const ;
742+ // The runtime ordinal of each prompt, and the session each check watched.
743+ const promptRuntimes : Array < number > = [ ] ;
744+ const watchedSessions : Array < string > = [ ] ;
745+ const adapter = yield * makeAcpAdapterV2 ( {
746+ instanceId,
747+ selfInvocation : yield * resolveSelfInvocation ( ) ,
748+ flavor : {
749+ driver : ACP_TEST_DRIVER ,
750+ capabilities : AcpProviderCapabilitiesV2 ,
751+ watchPromptOutcome : ( sessionId ) =>
752+ Effect . sync ( ( ) => {
753+ watchedSessions . push ( sessionId ) ;
754+ const failed = watchedSessions . length === 1 ;
755+ return ( ) => Effect . succeed ( failed ? quota : undefined ) ;
756+ } ) ,
757+ makeRuntime : makeMockRuntime ( {
758+ childProcessSpawner : yield * ChildProcessSpawner . ChildProcessSpawner ,
759+ mockAgentPath : yield * path . fromFileUrl (
760+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
761+ ) ,
762+ wrapRuntime : ( runtime , runtimeOrdinal ) => ( {
763+ ...runtime ,
764+ prompt : ( ) =>
765+ Effect . sync ( ( ) => {
766+ promptRuntimes . push ( runtimeOrdinal ) ;
767+ return { stopReason : "end_turn" as const } ;
768+ } ) ,
769+ } ) ,
770+ } ) ,
771+ } ,
772+ } ) ;
773+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
774+ runtimeMode : "full-access" ,
775+ interactionMode : "default" ,
776+ cwd : process . cwd ( ) ,
777+ } ) ;
778+ const modelSelection = { instanceId, model : "default" } as const ;
779+ const runtime = yield * adapter . openSession ( {
780+ threadId,
781+ providerSessionId : ProviderSessionId . make ( "provider-session-acp-prompt-outcome" ) ,
782+ modelSelection,
783+ runtimePolicy,
784+ } ) ;
785+ const providerThread = yield * runtime . ensureThread ( {
786+ threadId,
787+ modelSelection,
788+ runtimePolicy,
789+ } ) ;
790+ const runTurn = ( ordinal : number ) =>
791+ Effect . gen ( function * ( ) {
792+ yield * runtime . startTurn (
793+ makeTurnInput ( {
794+ threadId,
795+ providerThread,
796+ instanceId,
797+ runtimePolicy,
798+ now : yield * DateTime . now ,
799+ ordinal,
800+ } ) ,
801+ ) ;
802+ const events = yield * runtime . events . pipe (
803+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
804+ Stream . runCollect ,
805+ ) ;
806+ return events . at ( - 1 ) ;
807+ } ) ;
808+
809+ const failed = yield * runTurn ( 1 ) ;
810+ if ( failed ?. type !== "turn.terminal" || failed . status !== "failed" ) {
811+ return assert . fail ( "expected a failed terminal" ) ;
812+ }
813+ assert . deepEqual ( failed . failure , quota ) ;
814+ const completed = yield * runTurn ( 2 ) ;
815+ assert . equal ( completed ?. type === "turn.terminal" ? completed . status : null , "completed" ) ;
816+ assert . deepEqual ( promptRuntimes , [ 1 , 2 ] , "the next turn runs on a fresh runtime" ) ;
817+ assert . equal ( watchedSessions . length , 2 ) ;
818+ assert . equal ( watchedSessions [ 0 ] , watchedSessions [ 1 ] ) ;
819+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
820+ ) ;
664821 it . live ( "retains returned usage when Stop finalizes before the prompt callback" , ( ) =>
665822 Effect . gen ( function * ( ) {
666823 const path = yield * Path . Path ;
0 commit comments