@@ -13,6 +13,7 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
1313import { SpawnExecutableResolution } from "@t3tools/shared/shell" ;
1414import * as Deferred from "effect/Deferred" ;
1515import * as Effect from "effect/Effect" ;
16+ import * as Exit from "effect/Exit" ;
1617import * as FileSystem from "effect/FileSystem" ;
1718import * as Path from "effect/Path" ;
1819import * as Fiber from "effect/Fiber" ;
@@ -1000,6 +1001,66 @@ describe("AcpRegistrySupport", () => {
10001001 ) ;
10011002 } ) ;
10021003
1004+ it . effect (
1005+ "removes the install lock when an update is interrupted right after creating it" ,
1006+ ( ) => {
1007+ let agent = makeAgent ( {
1008+ binary : { "linux-x86_64" : { archive : archiveUrl , cmd : "./example-agent" } } ,
1009+ } ) ;
1010+ return Effect . gen ( function * ( ) {
1011+ const fs = yield * FileSystem . FileSystem ;
1012+ const path = yield * Path . Path ;
1013+ const cacheDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-acp-registry-lock-" } ) ;
1014+ const lockCreated = yield * Deferred . make < void > ( ) ;
1015+ const finishWrite = yield * Deferred . make < void > ( ) ;
1016+ const updateLock = path . join ( "1.2.4" , "linux-x86_64.lock" ) ;
1017+ const resolver = yield * AcpRegistrySupport . makeAcpRegistryCatalog ( {
1018+ cacheDir,
1019+ toolsDir : `${ cacheDir } /tools` ,
1020+ registryUrl,
1021+ } ) . pipe (
1022+ Effect . provideService ( FileSystem . FileSystem , {
1023+ ...fs ,
1024+ writeFileString : ( file , data , options ) => {
1025+ const write = fs . writeFileString ( file , data , options ) ;
1026+ return options ?. flag === "wx" && file . endsWith ( updateLock )
1027+ ? write . pipe (
1028+ Effect . andThen ( Deferred . succeed ( lockCreated , undefined ) ) ,
1029+ Effect . andThen ( Deferred . await ( finishWrite ) ) ,
1030+ )
1031+ : write ;
1032+ } ,
1033+ } ) ,
1034+ ) ;
1035+ yield * resolver . prepare ( { agentId : agent . id } ) ;
1036+ agent = { ...agent , version : "1.2.4" } ;
1037+ yield * resolver . refreshIndex ( ) ;
1038+
1039+ const first = yield * resolver . resolve ( settings ( ) , cacheDir ) . pipe ( Effect . forkChild ) ;
1040+ yield * Deferred . await ( lockCreated ) ;
1041+ const interruptor = yield * Effect . fiberId ;
1042+ first . interruptUnsafe ( interruptor ) ;
1043+ yield * Deferred . succeed ( finishWrite , undefined ) ;
1044+ expect ( Exit . hasInterrupts ( yield * Fiber . await ( first ) ) ) . toBe ( true ) ;
1045+ expect ( yield * fs . exists ( path . join ( cacheDir , "tools" , "example-agent" , updateLock ) ) ) . toBe (
1046+ false ,
1047+ ) ;
1048+ } ) . pipe (
1049+ Effect . scoped ,
1050+ Effect . provide (
1051+ layerResolver ( ( request ) =>
1052+ Effect . succeed (
1053+ HttpClientResponse . fromWeb (
1054+ request ,
1055+ new Response ( request . url === registryUrl ? makeRegistry ( agent ) : "#!/bin/sh\n" ) ,
1056+ ) ,
1057+ ) ,
1058+ ) ,
1059+ ) ,
1060+ ) ;
1061+ } ,
1062+ ) ;
1063+
10031064 it . effect ( "gives Antigravity a T3-owned temp directory that is removed with the process" , ( ) => {
10041065 const agent = {
10051066 ...makeAgent ( { binary : { "linux-x86_64" : { archive : archiveUrl , cmd : "./agy" } } } ) ,
0 commit comments