[codex] Structure relay install confirmation conflicts (#3365)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
b9e22de6a3
commit
8112aff7c2
2 files changed
+55
-4
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
completeRelayClientInstallDialogClose,
|
||||
finishRelayClientInstall,
|
||||
readRelayClientInstallDialogState,
|
||||
RelayClientInstallConfirmationConflictError,
|
||||
reportRelayClientInstallProgress,
|
||||
requestRelayClientInstallConfirmation,
|
||||
resetRelayClientInstallDialogForTests,
|
||||
@@ -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.",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -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" }
|
||||
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user