Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/web/src/cloud/relayClientInstallDialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
completeRelayClientInstallDialogClose,
finishRelayClientInstall,
readRelayClientInstallDialogState,
RelayClientInstallConfirmationConflictError,
reportRelayClientInstallProgress,
requestRelayClientInstallConfirmation,
resetRelayClientInstallDialogForTests,
Expand Down Expand Up @@ -67,4 +68,28 @@ describe("relay client install dialog coordinator", () => {
completeRelayClientInstallDialogClose();
expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
});

it("rejects concurrent confirmation with the active install state", async () => {
const confirmation = requestRelayClientInstallConfirmation("2026.5.2");
respondToRelayClientInstallConfirmation(true);
await expect(confirmation).resolves.toBe(true);
reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });

const error = await requestRelayClientInstallConfirmation("2026.6.0").then(
() => undefined,
(cause: unknown) => cause,
);

expect(error).toBeInstanceOf(RelayClientInstallConfirmationConflictError);
expect(error).toMatchObject({
requestedVersion: "2026.6.0",
activeVersion: "2026.5.2",
activeDialogStatus: "installing",
activeInstallStage: "downloading",
});
expect(error).not.toHaveProperty("cause");
expect((error as Error).message).toBe(
"Cannot confirm relay client installation 2026.6.0; installation 2026.5.2 has dialog status installing.",
);
});
});
34 changes: 30 additions & 4 deletions apps/web/src/cloud/relayClientInstallDialog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import type {
RelayClientInstallProgressEvent,
RelayClientInstallProgressStage,
import {
RelayClientInstallProgressStageSchema,
type RelayClientInstallProgressEvent,
type RelayClientInstallProgressStage,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";

export class RelayClientInstallConfirmationConflictError extends Schema.TaggedErrorClass<RelayClientInstallConfirmationConflictError>()(
"RelayClientInstallConfirmationConflictError",
{
requestedVersion: Schema.String,
activeVersion: Schema.String,
activeDialogStatus: Schema.Literals(["confirming", "installing", "closing"]),
activeInstallStage: Schema.optional(RelayClientInstallProgressStageSchema),
},
) {
override get message(): string {
return `Cannot confirm relay client installation ${this.requestedVersion}; installation ${this.activeVersion} has dialog status ${this.activeDialogStatus}.`;
}
}

export type RelayClientInstallDialogState =
| { readonly status: "idle" }
Expand Down Expand Up @@ -47,7 +63,17 @@ export function subscribeRelayClientInstallDialog(listener: () => void): () => v

export function requestRelayClientInstallConfirmation(version: string): Promise<boolean> {
if (state.status !== "idle") {
return Promise.reject(new Error("A relay client installation is already in progress."));
const activeInstall = state.status === "closing" ? state.view : state;
return Promise.reject(
new RelayClientInstallConfirmationConflictError({
requestedVersion: version,
activeVersion: activeInstall.version,
activeDialogStatus: state.status,
...(activeInstall.status === "installing"
? { activeInstallStage: activeInstall.stage }
: {}),
}),
);
}

publish({ status: "confirming", version });
Expand Down
Loading