@@ -28,6 +28,7 @@ import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderS
2828import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
2929import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime" ;
3030import { makeAntigravityAcpRuntime } from "../../provider/acp/AntigravityAcpSupport.ts" ;
31+ import { normalizeAntigravitySessionUpdate } from "../../provider/acp/AntigravityProtocol.ts" ;
3132import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3233import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
3334import {
@@ -540,7 +541,13 @@ describe("AntigravityAdapterV2 html_render pages", () => {
540541 height : 240 ,
541542 } ) ;
542543 const revenue = { html : "<p>Revenue</p>" , title : "Revenue" , height : 240 } ;
544+ const restated = { ...revenue , html : "<p>Revenue, restated</p>" } ;
543545 const margin = { ...revenue , html : "<p>Margin</p>" , title : "Margin" } ;
546+ const byRegion = { ...revenue , html : "<p>Revenue by region</p>" } ;
547+ const byMonth = { ...revenue , html : "<p>Revenue by month</p>" } ;
548+ // About the size of the page in the session that showed the bug.
549+ const rows = Array . from ( { length : 500 } , ( _ , row ) => `<tr><td>Row ${ row } </td></tr>` ) ;
550+ const report = { ...revenue , html : `<table>${ rows . join ( "" ) } </table>` } ;
544551 const renderError = {
545552 content : [ { type : "text" , text : "html_render failed" } ] ,
546553 isError : true ,
@@ -568,15 +575,29 @@ describe("AntigravityAdapterV2 html_render pages", () => {
568575 } ) . pipe ( Effect . andThen ( runtime . handleSessionUpdate ( handler ) ) ) ,
569576 prompt : ( ) =>
570577 Effect . gen ( function * ( ) {
578+ // Antigravity's runtime bounds each update before the
579+ // adapter sees it, html_render's html included.
571580 const send = ( update : EffectAcpSchema . SessionUpdate ) =>
572581 sessionUpdate === undefined
573582 ? Effect . die ( "the adapter must handle session updates" )
574- : sessionUpdate ( { sessionId : "mock-session-1" , update } ) ;
583+ : sessionUpdate (
584+ normalizeAntigravitySessionUpdate ( {
585+ sessionId : "mock-session-1" ,
586+ update,
587+ } ) ,
588+ ) ;
575589 // agy_acp_server 1.3.0 and 1.4.0 without a permission prompt:
576590 // the title is "Running <tool>", rawInput holds only the
577591 // tool's arguments, and the completion reports the step's
578592 // own summary as rawOutput instead of the MCP result.
579- const start = ( toolCallId : string , rawInput : typeof revenue ) =>
593+ const start = (
594+ toolCallId : string ,
595+ rawInput : {
596+ readonly html ?: string ;
597+ readonly title : string ;
598+ readonly height : number ;
599+ } ,
600+ ) =>
580601 send ( {
581602 sessionUpdate : "tool_call" ,
582603 toolCallId,
@@ -587,16 +608,23 @@ describe("AntigravityAdapterV2 html_render pages", () => {
587608 } ) ;
588609 yield * start ( "trajectory:1" , revenue ) ;
589610 yield * start ( "trajectory:2" , { ...revenue , title : "Costs" } ) ;
590- yield * start ( "trajectory:3" , revenue ) ;
611+ yield * start ( "trajectory:3" , restated ) ;
591612 yield * start ( "trajectory:4" , revenue ) ;
592613 yield * start ( "trajectory:5" , revenue ) ;
593614 yield * start ( "trajectory:6" , margin ) ;
594615 yield * start ( "trajectory:7" , margin ) ;
616+ yield * start ( "trajectory:8" , byRegion ) ;
617+ yield * start ( "trajectory:9" , byMonth ) ;
618+ yield * start ( "trajectory:10" , report ) ;
619+ yield * start ( "trajectory:11" , { title : "Revenue" , height : 240 } ) ;
595620 // T3's MCP server publishes while each call runs.
596621 yield * mcpSessions . recordHtmlRender ( threadId , revenue , page ( "first" ) ) ;
597- yield * mcpSessions . recordHtmlRender ( threadId , revenue , page ( "second" ) ) ;
622+ yield * mcpSessions . recordHtmlRender ( threadId , restated , page ( "second" ) ) ;
598623 yield * mcpSessions . recordHtmlRender ( threadId , margin , page ( "seventh" , "Margin" ) ) ;
599624 yield * mcpSessions . recordHtmlRender ( threadId , margin , page ( "sixth" , "Margin" ) ) ;
625+ yield * mcpSessions . recordHtmlRender ( threadId , byRegion , page ( "eighth" ) ) ;
626+ yield * mcpSessions . recordHtmlRender ( threadId , byMonth , page ( "ninth" ) ) ;
627+ yield * mcpSessions . recordHtmlRender ( threadId , report , page ( "tenth" ) ) ;
600628 yield * send ( {
601629 sessionUpdate : "tool_call_update" ,
602630 toolCallId : "trajectory:1" ,
@@ -664,6 +692,34 @@ describe("AntigravityAdapterV2 html_render pages", () => {
664692 status : "completed" ,
665693 rawOutput : "Render margin chart" ,
666694 } ) ;
695+ // Calls with the same title and height that complete out of
696+ // order each take the page published with their html.
697+ yield * send ( {
698+ sessionUpdate : "tool_call_update" ,
699+ toolCallId : "trajectory:9" ,
700+ status : "completed" ,
701+ rawOutput : "Render revenue by month" ,
702+ } ) ;
703+ yield * send ( {
704+ sessionUpdate : "tool_call_update" ,
705+ toolCallId : "trajectory:8" ,
706+ status : "completed" ,
707+ rawOutput : "Render revenue by region" ,
708+ } ) ;
709+ // The adapter sees only the end of a long page.
710+ yield * send ( {
711+ sessionUpdate : "tool_call_update" ,
712+ toolCallId : "trajectory:10" ,
713+ status : "completed" ,
714+ rawOutput : "Render revenue report" ,
715+ } ) ;
716+ // A call without its html cannot tell which page is its own.
717+ yield * send ( {
718+ sessionUpdate : "tool_call_update" ,
719+ toolCallId : "trajectory:11" ,
720+ status : "completed" ,
721+ rawOutput : "Render revenue chart" ,
722+ } ) ;
667723 return { stopReason : "end_turn" as const } ;
668724 } ) ,
669725 } ) ) ,
@@ -740,10 +796,15 @@ describe("AntigravityAdapterV2 html_render pages", () => {
740796 event . type === "turn_item.updated" &&
741797 event . turnItem . nativeItemRef ?. nativeId === nativeId ,
742798 ) ;
743- const tool = ( nativeId : string ) => {
799+ const toolItem = ( nativeId : string ) => {
744800 const event = finalItem ( nativeId ) ;
745- const item = event ?. type === "turn_item.updated" ? event . turnItem : undefined ;
746- return item ?. type === "dynamic_tool"
801+ return event ?. type === "turn_item.updated" && event . turnItem . type === "dynamic_tool"
802+ ? event . turnItem
803+ : undefined ;
804+ } ;
805+ const tool = ( nativeId : string ) => {
806+ const item = toolItem ( nativeId ) ;
807+ return item !== undefined
747808 ? {
748809 status : item . status ,
749810 toolName : item . toolName ,
@@ -795,8 +856,39 @@ describe("AntigravityAdapterV2 html_render pages", () => {
795856 page : page ( "seventh" , "Margin" ) ,
796857 output : { htmlRender : page ( "seventh" , "Margin" ) } ,
797858 } ) ;
859+ assert . deepEqual ( tool ( "trajectory:8" ) , {
860+ status : "completed" ,
861+ toolName : "t3-code.html_render" ,
862+ page : page ( "eighth" ) ,
863+ output : { htmlRender : page ( "eighth" ) } ,
864+ } ) ;
865+ assert . deepEqual ( tool ( "trajectory:9" ) , {
866+ status : "completed" ,
867+ toolName : "t3-code.html_render" ,
868+ page : page ( "ninth" ) ,
869+ output : { htmlRender : page ( "ninth" ) } ,
870+ } ) ;
871+ // The adapter saw only the end of the long page.
872+ assert . isAbove ( report . html . length , 8_000 ) ;
873+ assert . propertyVal (
874+ toolItem ( "trajectory:10" ) ?. input ,
875+ "html" ,
876+ `[Earlier output truncated]\n\n${ report . html . slice ( - 8_000 ) } ` ,
877+ ) ;
878+ assert . deepEqual ( tool ( "trajectory:10" ) , {
879+ status : "completed" ,
880+ toolName : "t3-code.html_render" ,
881+ page : page ( "tenth" ) ,
882+ output : { htmlRender : page ( "tenth" ) } ,
883+ } ) ;
884+ assert . deepEqual ( tool ( "trajectory:11" ) , {
885+ status : "completed" ,
886+ toolName : "t3-code.html_render" ,
887+ page : undefined ,
888+ output : "Render revenue chart" ,
889+ } ) ;
798890 // Each page goes to one call; the unclaimed one stays for a later call.
799- assert . deepEqual ( yield * mcpSessions . takeHtmlRender ( threadId , revenue ) , page ( "second" ) ) ;
891+ assert . deepEqual ( yield * mcpSessions . takeHtmlRender ( threadId , restated ) , page ( "second" ) ) ;
800892 assert . strictEqual ( yield * mcpSessions . takeHtmlRender ( threadId , margin ) , undefined ) ;
801893 } ) . pipe ( Effect . provide ( layerSession ) , Effect . scoped ) ,
802894 ) ;
0 commit comments