Skip to content

Commit 4d69158

Browse files
committed
Guard missing desktop bridge SSH cleanup
1 parent 749bc07 commit 4d69158

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

apps/web/src/environments/runtime/service.addSavedEnvironment.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,40 @@ describe("addSavedEnvironment", () => {
773773
await resetEnvironmentServiceForTests();
774774
});
775775

776+
it("removes a saved ssh environment when the desktop bridge is unavailable", async () => {
777+
mockSavedRecords = [
778+
{
779+
environmentId: EnvironmentId.make("environment-1"),
780+
label: "Remote environment",
781+
httpBaseUrl: "http://127.0.0.1:3774/",
782+
wsBaseUrl: "ws://127.0.0.1:3774/",
783+
createdAt: "2026-04-14T00:00:00.000Z",
784+
lastConnectedAt: null,
785+
desktopSsh: {
786+
alias: "devbox",
787+
hostname: "devbox.example.com",
788+
username: "julius",
789+
port: 22,
790+
},
791+
},
792+
];
793+
vi.stubGlobal("window", {});
794+
795+
const { removeSavedEnvironment, resetEnvironmentServiceForTests } = await import("./service");
796+
797+
await expect(removeSavedEnvironment(EnvironmentId.make("environment-1"))).resolves.toBe(
798+
undefined,
799+
);
800+
801+
expect(mockRemovePersistedSavedEnvironment).toHaveBeenCalledWith(
802+
EnvironmentId.make("environment-1"),
803+
);
804+
expect(mockDisconnectSshEnvironment).not.toHaveBeenCalled();
805+
expect(mockSavedRecords).toEqual([]);
806+
807+
await resetEnvironmentServiceForTests();
808+
});
809+
776810
it("disconnects a saved ssh environment without removing its saved record", async () => {
777811
mockSavedRecords = [
778812
{

apps/web/src/environments/runtime/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ export async function removeSavedEnvironment(environmentId: EnvironmentId): Prom
16841684
useStore.getState().removeEnvironmentState(environmentId);
16851685

16861686
if (record?.desktopSsh && typeof window !== "undefined") {
1687-
void window.desktopBridge?.disconnectSshEnvironment(record.desktopSsh).catch((error) => {
1687+
void window.desktopBridge?.disconnectSshEnvironment(record.desktopSsh)?.catch((error) => {
16881688
console.warn("[SAVED_ENVIRONMENTS] SSH cleanup after removal failed", error);
16891689
});
16901690
}

0 commit comments

Comments
 (0)