Skip to content

Commit 0bccd29

Browse files
fix(desktop): disable blocked t3 CLI installation (#27286)
Co-authored-by: maria-rcks <[email protected]>
1 parent febd377 commit 0bccd29

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { RegistryContext } from "@effect/atom-react";
2+
import type { DesktopCliCommandState } from "@t3tools/contracts";
3+
import { AtomRegistry } from "effect/reactivity";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
import { act, render, stubGlobal } from "../../../test/render";
7+
import { desktopCliCommandStateAtom } from "../../state/desktopCliCommand";
8+
import { CliCommandSettingsRow } from "./CliCommandSettingsRow";
9+
10+
it("blocks installation behind another t3 without blocking removal of our installation", async () => {
11+
const state: DesktopCliCommandState = {
12+
supported: true,
13+
installedPath: null,
14+
onPath: false,
15+
launcherPath: "/home/test/.t3/bin/t3",
16+
};
17+
const getState = vi.fn(async (): Promise<DesktopCliCommandState> => ({
18+
...state,
19+
shadowedBy: "/usr/local/bin/t3",
20+
}));
21+
const uninstall = vi.fn(async () => state);
22+
using _bridge = stubGlobal("desktopBridge", {
23+
cliCommand: { getState, install: vi.fn(async () => state), uninstall },
24+
getLocalEnvironmentEnabled: () => true,
25+
getLocalEnvironmentBootstraps: () => [],
26+
});
27+
const registry = AtomRegistry.make();
28+
using _registry = { [Symbol.dispose]: () => registry.dispose() };
29+
await using screen = await render(
30+
<RegistryContext.Provider value={registry}>
31+
<CliCommandSettingsRow />
32+
</RegistryContext.Provider>,
33+
);
34+
35+
await expect.element(screen.getByRole("button", { name: "Install" })).toBeDisabled();
36+
37+
getState.mockResolvedValue(state);
38+
await act(() => registry.refresh(desktopCliCommandStateAtom));
39+
await expect.element(screen.getByRole("button", { name: "Install" })).toBeEnabled();
40+
41+
getState.mockResolvedValue({
42+
...state,
43+
installedPath: "/home/test/.local/bin/t3",
44+
shadowedBy: "/usr/local/bin/t3",
45+
});
46+
await act(() => registry.refresh(desktopCliCommandStateAtom));
47+
const remove = screen.getByRole("button", { name: "Remove" });
48+
await expect.element(remove).toBeEnabled();
49+
await remove.click();
50+
expect(uninstall).toHaveBeenCalledOnce();
51+
});

‎apps/web/src/components/settings/CliCommandSettingsRow.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function CliCommandSettingsRow() {
5252
<Button
5353
size="sm"
5454
variant="outline"
55-
disabled={pending || query.isPending}
55+
disabled={pending || query.isPending || (!installed && Boolean(state.shadowedBy))}
5656
onClick={() => change(installed ? "uninstall" : "install")}
5757
>
5858
{installed ? "Remove" : "Install"}

0 commit comments

Comments
 (0)