@@ -1665,6 +1665,78 @@ describe("provider setup commands", () => {
16651665 expect ( yield * Queue . takeAll ( requested ) ) . toEqual ( [ "antigravity" ] ) ;
16661666 } ) . pipe ( Effect . scoped ) ,
16671667 ) ;
1668+
1669+ it . effect ( "toggles a provider while another provider's update is still running" , ( ) =>
1670+ Effect . gen ( function * ( ) {
1671+ const updateStarted = yield * Deferred . make < void > ( ) ;
1672+ const settingsSaved = yield * Deferred . make < void > ( ) ;
1673+ const client = {
1674+ [ WS_METHODS . serverUpdateProvider ] : ( ) =>
1675+ Deferred . succeed ( updateStarted , undefined ) . pipe ( Effect . andThen ( Effect . never ) ) ,
1676+ [ WS_METHODS . serverUpdateSettings ] : ( ) =>
1677+ Deferred . succeed ( settingsSaved , undefined ) . pipe ( Effect . as ( CONFIG . settings ) ) ,
1678+ } as unknown as WsRpcProtocolClient ;
1679+ const supervisor = EnvironmentSupervisor . EnvironmentSupervisor . of ( {
1680+ target : TARGET ,
1681+ state : yield * SubscriptionRef . make ( AVAILABLE_CONNECTION_STATE ) ,
1682+ session : yield * SubscriptionRef . make ( Option . some ( session ( client ) ) ) ,
1683+ prepared : yield * SubscriptionRef . make ( Option . none < PreparedConnection > ( ) ) ,
1684+ connect : Effect . void ,
1685+ disconnect : Effect . void ,
1686+ retryNow : Effect . void ,
1687+ } satisfies EnvironmentSupervisor . EnvironmentSupervisor [ "Service" ] ) ;
1688+ const runtime = Atom . runtime (
1689+ Layer . merge (
1690+ Layer . succeed ( EnvironmentRegistry . EnvironmentRegistry , {
1691+ run : ( _environmentId , effect ) =>
1692+ Effect . provideService (
1693+ effect ,
1694+ EnvironmentSupervisor . EnvironmentSupervisor ,
1695+ supervisor ,
1696+ ) ,
1697+ } as EnvironmentRegistry . EnvironmentRegistry [ "Service" ] ) ,
1698+ Layer . succeed (
1699+ Persistence . EnvironmentCacheStore ,
1700+ { } as Persistence . EnvironmentCacheStore [ "Service" ] ,
1701+ ) ,
1702+ ) ,
1703+ ) ;
1704+ const atoms = createServerEnvironmentAtoms ( runtime , {
1705+ initialConfigValueAtom : ( ) => Atom . make ( CONFIG ) ,
1706+ } ) ;
1707+ const registry = yield * Effect . acquireRelease ( Effect . sync ( AtomRegistry . make ) , ( registry ) =>
1708+ Effect . sync ( ( ) => registry . dispose ( ) ) ,
1709+ ) ;
1710+
1711+ void atoms . updateProvider . run ( registry , {
1712+ environmentId : TARGET . environmentId ,
1713+ input : { provider : ProviderDriverKind . make ( "opencode" ) } ,
1714+ } ) ;
1715+ yield * Deferred . await ( updateStarted ) ;
1716+ void atoms . mutateProviderInstance . run ( registry , {
1717+ environmentId : TARGET . environmentId ,
1718+ input : {
1719+ patch : { } ,
1720+ providerInstanceMutation : {
1721+ operation : "upsert" ,
1722+ instanceId : ProviderInstanceId . make ( "codex" ) ,
1723+ instance : { driver : ProviderDriverKind . make ( "codex" ) , enabled : false } ,
1724+ } ,
1725+ } ,
1726+ } ) ;
1727+
1728+ const saved = yield * Deferred . await ( settingsSaved ) . pipe (
1729+ Effect . as ( true ) ,
1730+ Effect . timeoutOrElse ( {
1731+ duration : Duration . seconds ( 1 ) ,
1732+ orElse : ( ) => Effect . succeed ( false ) ,
1733+ } ) ,
1734+ Effect . forkChild ,
1735+ ) ;
1736+ yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
1737+ expect ( yield * Fiber . join ( saved ) ) . toBe ( true ) ;
1738+ } ) . pipe ( Effect . scoped ) ,
1739+ ) ;
16681740} ) ;
16691741
16701742describe ( "resource telemetry history" , ( ) => {
0 commit comments