Skip to content

Commit 52b65aa

Browse files
only21milclaudemaria-rcks
authored
fix(web): installing two providers at once starts both (pingdotgg#24655)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent a0d08d7 commit 52b65aa

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

‎packages/client-runtime/src/state/server.test.ts‎

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import {
22
EnvironmentId,
3+
ProviderDriverKind,
34
ServerSelfUpdateError,
45
ProviderInstanceId,
6+
type ProviderInstallState,
7+
type ProviderSetupInput,
58
ServerObservability,
69
EnvironmentThemeId,
710
UsageLimitSourceId,
@@ -34,8 +37,8 @@ import {
3437
PrimaryConnectionTarget,
3538
type PreparedConnection,
3639
} from "../connection/model.ts";
37-
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
3840
import * as EnvironmentRegistry from "../connection/registry.ts";
41+
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
3942
import { RpcPermissionGuard } from "../rpc/client.ts";
4043
import * as Persistence from "../platform/persistence.ts";
4144
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
@@ -1309,3 +1312,85 @@ describe("server state projection", () => {
13091312
}),
13101313
);
13111314
});
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+
});

‎packages/client-runtime/src/state/server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ export function createServerEnvironmentAtoms<R, E>(
12501250
tag: WS_METHODS.providerInstallStart,
12511251
concurrency: {
12521252
mode: "singleFlight",
1253-
key: ({ environmentId }) => environmentId,
1253+
key: ({ environmentId, input }) => JSON.stringify([environmentId, input]),
12541254
},
12551255
}),
12561256
cancelProviderInstall: createEnvironmentRpcCommand(runtime, {

0 commit comments

Comments
 (0)