@@ -17,12 +17,16 @@ import * as Schema from "effect/Schema";
1717import * as Scope from "effect/Scope" ;
1818import * as Sink from "effect/Sink" ;
1919import * as Stream from "effect/Stream" ;
20+ import * as TestClock from "effect/testing/TestClock" ;
2021import { HttpClient , HttpClientError , HttpClientResponse } from "effect/http" ;
2122import * as ChildProcess from "effect/process/ChildProcess" ;
2223import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
2324
25+ import { ACP_REGISTRY_URL } from "@t3tools/provider-acp-registry/server/AcpRegistrySupport" ;
26+
2427import * as AntigravityInstallation from "./AntigravityInstallation.ts" ;
2528import { type AntigravityReleaseAsset } from "./antigravityRelease.ts" ;
29+ import * as ModelManifest from "./ModelManifest.ts" ;
2630
2731const serverContents = "antigravity runtime\n" ;
2832const harnessContents = "local harness\n" ;
@@ -126,6 +130,11 @@ interface HarnessOptions {
126130 readonly spawner ?: ChildProcessSpawner . ChildProcessSpawner [ "Service" ] ;
127131 readonly validate ?: AntigravityInstallation . AntigravityInstallationOptions [ "validate" ] ;
128132 readonly useDefaultValidation ?: boolean ;
133+ /** Served for the ACP Registry index. */
134+ readonly registry ?: unknown ;
135+ /** Served by URL instead of the pinned archive. */
136+ readonly archives ?: Readonly < Record < string , Uint8Array > > ;
137+ readonly manifest ?: Effect . Effect < ModelManifest . ModelManifestData > ;
129138 readonly connectTimeout ?: boolean ;
130139}
131140
@@ -186,11 +195,31 @@ const makeHarness = Effect.fn("test.makeAntigravityInstallation")(function* (
186195 Effect . provideService ( HostProcess . Platform , platform ) ,
187196 Effect . provideService ( HostProcess . Architecture , arch ) ,
188197 Effect . provideService ( HostProcess . Environment , { PATH : options . path ?? "" } ) ,
198+ Effect . provideService ( ModelManifest . ModelManifest , {
199+ current : options . manifest ?? Effect . succeed ( ModelManifest . BUNDLED_MODEL_MANIFEST ) ,
200+ refresh : Effect . succeed ( ModelManifest . BUNDLED_MODEL_MANIFEST ) ,
201+ forceRefresh : Effect . succeed ( ModelManifest . BUNDLED_MODEL_MANIFEST ) ,
202+ refreshOnDemand : Effect . succeed ( ModelManifest . BUNDLED_MODEL_MANIFEST ) ,
203+ refreshInBackground : Effect . void ,
204+ } ) ,
189205 Effect . provideService (
190206 HttpClient . HttpClient ,
191207 HttpClient . make ( ( request ) =>
192208 Effect . suspend ( ( ) => {
193209 requests . push ( request . url ) ;
210+ if ( request . url === ACP_REGISTRY_URL ) {
211+ return Effect . succeed (
212+ HttpClientResponse . fromWeb (
213+ request ,
214+ options . registry === undefined
215+ ? new Response ( null , { status : 503 } )
216+ : Response . json ( options . registry ) ,
217+ ) ,
218+ ) ;
219+ }
220+ const served = options . archives ?. [ request . url ] ;
221+ if ( served )
222+ return Effect . succeed ( HttpClientResponse . fromWeb ( request , new Response ( served ) ) ) ;
194223 if ( options . connectTimeout ) {
195224 return Effect . fail (
196225 new HttpClientError . HttpClientError ( {
@@ -254,6 +283,43 @@ const expectPreviousRelease = Effect.fn("test.expectPreviousAntigravityRelease")
254283 expect ( ( yield * installation . state ) . installedVersion ) . toBe ( previousVersion ) ;
255284} ) ;
256285
286+ // A zip comment changes the archive's hash without changing its members.
287+ const withZipComment = ( archive : Buffer , comment : string ) => {
288+ const bytes = Buffer . concat ( [ archive , Buffer . from ( comment ) ] ) ;
289+ bytes . writeUInt16LE ( Buffer . byteLength ( comment ) , archive . byteLength - 2 ) ;
290+ return bytes ;
291+ } ;
292+ const upstreamArchive = withZipComment ( completeArchive , "upstream" ) ;
293+ const upstreamUrl = "https://dl.google.com/agy-extensions/releases/test/agy-acp-server-1.4.1.zip" ;
294+ const registryListing = ( archive = upstreamUrl ) => ( {
295+ version : "1.0.0" ,
296+ agents : [
297+ { id : "other-agent" , version : "9.9.9" , distribution : { npx : { package : "other" } } } ,
298+ {
299+ id : "antigravity-acp" ,
300+ version : "1.4.1" ,
301+ distribution : {
302+ binary : Object . fromEntries (
303+ [ "linux-x86_64" , "windows-x86_64" ] . map ( ( target ) => [ target , { archive, cmd : "./agy" } ] ) ,
304+ ) ,
305+ } ,
306+ } ,
307+ ] ,
308+ } ) ;
309+ const withdrawnManifest : ModelManifest . ModelManifestData = {
310+ ...ModelManifest . BUNDLED_MODEL_MANIFEST ,
311+ compatibility : [
312+ {
313+ driver : "antigravity" ,
314+ t3CodeRange : ">=0.0.42" ,
315+ ranges : [ { range : ">=1.4.0" , status : "broken" } ] ,
316+ } ,
317+ ] ,
318+ } ;
319+ const pinnedAsset = Effect . fn ( "test.pinnedAntigravityAsset" ) ( function * ( ) {
320+ return { ...( yield * releaseAsset ( ) ) , version : "1.3.0" } ;
321+ } ) ;
322+
257323it . layer ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ( "Antigravity installation" , ( it ) => {
258324 it . effect ( "reports missing Node before downloading the standalone provider runtime" , ( ) =>
259325 Effect . gen ( function * ( ) {
@@ -764,7 +830,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
764830 } ) ;
765831
766832 const { installation : windows } = yield * makeHarness ( { baseDir, platform : "win32" } ) ;
767- for ( const name of [ "agy.EXE" , "agy.cmd " ] ) {
833+ for ( const name of [ "agy.EXE" , "agy.CMD " ] ) {
768834 const windowsDirectory = path . join ( baseDir , `windows-${ name } ` ) ;
769835 yield * fs . makeDirectory ( windowsDirectory ) ;
770836 yield * fs . writeFileString ( path . join ( windowsDirectory , name ) , "cli" ) ;
@@ -1018,4 +1084,167 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
10181084 expect ( requests ) . toEqual ( [ ] ) ;
10191085 } ) ,
10201086 ) ;
1087+
1088+ it . effect ( "updates past the pinned release to the registry release and never downgrades" , ( ) =>
1089+ Effect . gen ( function * ( ) {
1090+ const asset = yield * pinnedAsset ( ) ;
1091+ const h = yield * makeHarness ( {
1092+ asset,
1093+ registry : registryListing ( ) ,
1094+ archives : { [ upstreamUrl ] : upstreamArchive } ,
1095+ } ) ;
1096+ yield * h . installation . checkForUpdate ;
1097+ // A fresh install still gets the pinned release.
1098+ expect ( yield * h . installation . state ) . toMatchObject ( { version : "1.3.0" } ) ;
1099+ yield * h . installation . start ;
1100+ expect ( yield * terminalState ( h . installation ) ) . toMatchObject ( {
1101+ phase : "succeeded" ,
1102+ installedVersion : "1.3.0" ,
1103+ version : "1.4.1" ,
1104+ totalBytes : null ,
1105+ } ) ;
1106+
1107+ yield * h . installation . start ;
1108+ expect ( yield * terminalState ( h . installation ) ) . toMatchObject ( {
1109+ phase : "succeeded" ,
1110+ installedVersion : "1.4.1" ,
1111+ version : "1.4.1" ,
1112+ } ) ;
1113+ expect ( h . validations . at ( - 1 ) ?. version ) . toBe ( "1.4.1" ) ;
1114+ expect ( h . requests ) . toEqual ( [ ACP_REGISTRY_URL , asset . url , upstreamUrl ] ) ;
1115+ const selected = yield * h . installation . resolve ( ) ;
1116+ expect ( selected . version ) . toBe ( "1.4.1" ) ;
1117+ expect ( yield * h . fs . readFileString ( selected . executablePath ) ) . toBe ( serverContents ) ;
1118+
1119+ // Without registry information the older pin is not offered as a reinstall.
1120+ const restarted = yield * makeHarness ( { baseDir : h . baseDir , asset } ) ;
1121+ expect ( yield * restarted . installation . state ) . toMatchObject ( {
1122+ installedVersion : "1.4.1" ,
1123+ version : "1.4.1" ,
1124+ } ) ;
1125+ yield * restarted . installation . start ;
1126+ expect ( yield * terminalState ( restarted . installation ) ) . toMatchObject ( {
1127+ phase : "succeeded" ,
1128+ installedVersion : "1.4.1" ,
1129+ } ) ;
1130+ expect ( restarted . requests ) . toEqual ( [ ] ) ;
1131+ expect ( restarted . validations . map ( ( entry ) => entry . version ) ) . toEqual ( [ "1.4.1" ] ) ;
1132+ } ) ,
1133+ ) ;
1134+
1135+ it . effect . each ( [
1136+ {
1137+ name : "hosted outside Google's downloads" ,
1138+ registry : registryListing ( "https://example.com/agy.zip" ) ,
1139+ } ,
1140+ {
1141+ name : "from an oversized registry index" ,
1142+ registry : { ...registryListing ( ) , padding : "x" . repeat ( 1024 * 1024 ) } ,
1143+ } ,
1144+ {
1145+ name : "escaping Google's releases path" ,
1146+ registry : registryListing (
1147+ "https://dl.google.com/agy-extensions/releases/%2e%2e/%2e%2e/other.zip" ,
1148+ ) ,
1149+ } ,
1150+ {
1151+ name : "withdrawn by the model manifest" ,
1152+ registry : registryListing ( ) ,
1153+ manifest : Effect . succeed ( withdrawnManifest ) ,
1154+ } ,
1155+ ] ) ( "does not offer a registry release $name" , ( { registry, manifest } ) =>
1156+ Effect . gen ( function * ( ) {
1157+ const h = yield * makeHarness ( {
1158+ asset : yield * pinnedAsset ( ) ,
1159+ registry,
1160+ ...( manifest ? { manifest } : { } ) ,
1161+ } ) ;
1162+ yield * h . installation . start ;
1163+ yield * terminalState ( h . installation ) ;
1164+ yield * h . installation . checkForUpdate ;
1165+ expect ( yield * h . installation . state ) . toMatchObject ( {
1166+ installedVersion : "1.3.0" ,
1167+ version : "1.3.0" ,
1168+ } ) ;
1169+ } ) ,
1170+ ) ;
1171+
1172+ it . effect ( "does not retry a failed registry lookup within the hour" , ( ) =>
1173+ Effect . gen ( function * ( ) {
1174+ const h = yield * makeHarness ( ) ;
1175+ yield * h . installation . checkForUpdate ;
1176+ yield * h . installation . checkForUpdate ;
1177+ expect ( h . requests ) . toEqual ( [ ACP_REGISTRY_URL ] ) ;
1178+ yield * TestClock . adjust ( "1 hour" ) ;
1179+ yield * h . installation . checkForUpdate ;
1180+ expect ( h . requests ) . toEqual ( [ ACP_REGISTRY_URL , ACP_REGISTRY_URL ] ) ;
1181+ } ) ,
1182+ ) ;
1183+
1184+ it . effect . each ( [ "update" , "reinstall" ] as const ) (
1185+ "rejects withdrawal during $0 validation" ,
1186+ ( operation ) =>
1187+ Effect . gen ( function * ( ) {
1188+ let manifest = ModelManifest . BUNDLED_MODEL_MANIFEST ;
1189+ let withdraw = operation === "update" ;
1190+ const h = yield * makeHarness ( {
1191+ asset : yield * pinnedAsset ( ) ,
1192+ registry : registryListing ( ) ,
1193+ archives : { [ upstreamUrl ] : upstreamArchive } ,
1194+ manifest : Effect . sync ( ( ) => manifest ) ,
1195+ validate : ( _executable , version ) =>
1196+ Effect . sync ( ( ) => {
1197+ if ( withdraw && version === "1.4.1" ) manifest = withdrawnManifest ;
1198+ } ) ,
1199+ } ) ;
1200+ yield * h . installation . start ;
1201+ yield * terminalState ( h . installation ) ;
1202+ yield * h . installation . checkForUpdate ;
1203+ if ( operation === "reinstall" ) {
1204+ yield * h . installation . start ;
1205+ expect ( ( yield * terminalState ( h . installation ) ) . phase ) . toBe ( "succeeded" ) ;
1206+ withdraw = true ;
1207+ }
1208+ yield * h . installation . start ;
1209+ expect ( ( yield * terminalState ( h . installation ) ) . phase ) . toBe ( "failed" ) ;
1210+ if ( operation === "update" ) {
1211+ expect ( ( yield * h . installation . resolve ( ) ) . version ) . toBe ( "1.3.0" ) ;
1212+ } else {
1213+ expect ( ( yield * h . installation . state ) . version ) . toBe ( "1.3.0" ) ;
1214+ yield * Effect . flip ( h . installation . resolve ( ) ) ;
1215+ }
1216+ } ) ,
1217+ ) ;
1218+
1219+ it . effect ( "returns an install the manifest withdraws to the pinned release" , ( ) =>
1220+ Effect . gen ( function * ( ) {
1221+ let manifest = ModelManifest . BUNDLED_MODEL_MANIFEST ;
1222+ const h = yield * makeHarness ( {
1223+ asset : yield * pinnedAsset ( ) ,
1224+ registry : registryListing ( ) ,
1225+ archives : { [ upstreamUrl ] : upstreamArchive } ,
1226+ manifest : Effect . sync ( ( ) => manifest ) ,
1227+ } ) ;
1228+ yield * h . installation . checkForUpdate ;
1229+ yield * h . installation . start ;
1230+ yield * terminalState ( h . installation ) ;
1231+ yield * h . installation . start ;
1232+ expect ( yield * terminalState ( h . installation ) ) . toMatchObject ( { installedVersion : "1.4.1" } ) ;
1233+
1234+ manifest = withdrawnManifest ;
1235+ expect ( ( yield * Effect . flip ( h . installation . resolve ( ) ) ) . detail ) . toContain ( "no longer works" ) ;
1236+ yield * h . installation . checkForUpdate ;
1237+ expect ( yield * h . installation . state ) . toMatchObject ( {
1238+ installedVersion : "1.4.1" ,
1239+ version : "1.3.0" ,
1240+ } ) ;
1241+ yield * h . installation . start ;
1242+ expect ( yield * terminalState ( h . installation ) ) . toMatchObject ( {
1243+ phase : "succeeded" ,
1244+ installedVersion : "1.3.0" ,
1245+ version : "1.3.0" ,
1246+ } ) ;
1247+ expect ( ( yield * h . installation . resolve ( ) ) . version ) . toBe ( "1.3.0" ) ;
1248+ } ) ,
1249+ ) ;
10211250} ) ;
0 commit comments