|
1 | 1 | import { |
2 | 2 | EnvironmentId, |
| 3 | + ProviderDriverKind, |
3 | 4 | ServerSelfUpdateError, |
4 | 5 | ProviderInstanceId, |
| 6 | + type ProviderInstallState, |
| 7 | + type ProviderSetupInput, |
5 | 8 | ServerObservability, |
6 | 9 | EnvironmentThemeId, |
7 | 10 | UsageLimitSourceId, |
@@ -34,8 +37,8 @@ import { |
34 | 37 | PrimaryConnectionTarget, |
35 | 38 | type PreparedConnection, |
36 | 39 | } from "../connection/model.ts"; |
37 | | -import * as EnvironmentSupervisor from "../connection/supervisor.ts"; |
38 | 40 | import * as EnvironmentRegistry from "../connection/registry.ts"; |
| 41 | +import * as EnvironmentSupervisor from "../connection/supervisor.ts"; |
39 | 42 | import { RpcPermissionGuard } from "../rpc/client.ts"; |
40 | 43 | import * as Persistence from "../platform/persistence.ts"; |
41 | 44 | import type { WsRpcProtocolClient } from "../rpc/protocol.ts"; |
@@ -1309,3 +1312,85 @@ describe("server state projection", () => { |
1309 | 1312 | }), |
1310 | 1313 | ); |
1311 | 1314 | }); |
| 1315 | + |
| 1316 | +describe("provider setup commands", () => { |
| 1317 | + it.effect("starts installs for two instances in one environment separately", () => |
| 1318 | + Effect.gen(function* () { |
| 1319 | + const requested = yield* Queue.unbounded<ProviderInstanceId>(); |
| 1320 | + const release = yield* Deferred.make<void>(); |
| 1321 | + const installState = (driver: string): ProviderInstallState => ({ |
| 1322 | + driver: ProviderDriverKind.make(driver), |
| 1323 | + operationId: null, |
| 1324 | + phase: "downloading", |
| 1325 | + downloadedBytes: 0, |
| 1326 | + totalBytes: null, |
| 1327 | + version: null, |
| 1328 | + installedVersion: null, |
| 1329 | + canRemove: false, |
| 1330 | + message: null, |
| 1331 | + }); |
| 1332 | + const client = { |
| 1333 | + [WS_METHODS.providerInstallStart]: ({ instanceId }: ProviderSetupInput) => |
| 1334 | + Queue.offer(requested, instanceId).pipe( |
| 1335 | + Effect.andThen(Deferred.await(release)), |
| 1336 | + Effect.as(installState(instanceId)), |
| 1337 | + ), |
| 1338 | + } as unknown as WsRpcProtocolClient; |
| 1339 | + const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({ |
| 1340 | + target: TARGET, |
| 1341 | + state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE), |
| 1342 | + session: yield* SubscriptionRef.make(Option.some(session(client))), |
| 1343 | + prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()), |
| 1344 | + connect: Effect.void, |
| 1345 | + disconnect: Effect.void, |
| 1346 | + retryNow: Effect.void, |
| 1347 | + } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]); |
| 1348 | + const runtime = Atom.runtime( |
| 1349 | + Layer.merge( |
| 1350 | + Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, { |
| 1351 | + run: (_environmentId, effect) => |
| 1352 | + Effect.provideService( |
| 1353 | + effect, |
| 1354 | + EnvironmentSupervisor.EnvironmentSupervisor, |
| 1355 | + supervisor, |
| 1356 | + ), |
| 1357 | + } as EnvironmentRegistry.EnvironmentRegistry["Service"]), |
| 1358 | + Layer.succeed( |
| 1359 | + Persistence.EnvironmentCacheStore, |
| 1360 | + {} as Persistence.EnvironmentCacheStore["Service"], |
| 1361 | + ), |
| 1362 | + ), |
| 1363 | + ); |
| 1364 | + const atoms = createServerEnvironmentAtoms(runtime, { |
| 1365 | + initialConfigValueAtom: () => Atom.make(CONFIG), |
| 1366 | + }); |
| 1367 | + const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) => |
| 1368 | + Effect.sync(() => registry.dispose()), |
| 1369 | + ); |
| 1370 | + const install = (instanceId: string) => |
| 1371 | + atoms.startProviderInstall.run(registry, { |
| 1372 | + environmentId: TARGET.environmentId, |
| 1373 | + input: { instanceId: ProviderInstanceId.make(instanceId) }, |
| 1374 | + }); |
| 1375 | + |
| 1376 | + const codex = install("codex"); |
| 1377 | + expect(yield* Queue.take(requested)).toBe("codex"); |
| 1378 | + const duplicateCodex = install("codex"); |
| 1379 | + const antigravity = install("antigravity"); |
| 1380 | + yield* Deferred.succeed(release, undefined); |
| 1381 | + |
| 1382 | + expect(yield* Effect.promise(() => codex)).toMatchObject({ |
| 1383 | + _tag: "Success", |
| 1384 | + value: { driver: "codex" }, |
| 1385 | + }); |
| 1386 | + expect(yield* Effect.promise(() => duplicateCodex)).toEqual( |
| 1387 | + yield* Effect.promise(() => codex), |
| 1388 | + ); |
| 1389 | + expect(yield* Effect.promise(() => antigravity)).toMatchObject({ |
| 1390 | + _tag: "Success", |
| 1391 | + value: { driver: "antigravity" }, |
| 1392 | + }); |
| 1393 | + expect(yield* Queue.takeAll(requested)).toEqual(["antigravity"]); |
| 1394 | + }).pipe(Effect.scoped), |
| 1395 | + ); |
| 1396 | +}); |
0 commit comments