fix(site): close terminal window on command confirmation cancel (#24765)

Follow-up to #24650.

Canceling the terminal command confirmation dialog now calls
`window.close()` instead of stripping the `?command=` query parameter
and opening a plain terminal. The terminal always opens in a new tab,
so closing it is the expected UX when the user declines.

> 🤖 Generated by Coder Agents
This commit is contained in:
Jakub Domeracki
2026-04-28 10:37:16 +02:00
committed by GitHub
parent 70d6efa311
commit 06ebde3894
2 changed files with 4 additions and 7 deletions
@@ -238,17 +238,15 @@ describe("TerminalPage", () => {
expect(resizeReq.width).toBeGreaterThan(0);
});
it("removes command param on cancel", async () => {
createWorkspaceTerminalWebSocket();
it("closes window on cancel", async () => {
const closeSpy = vi.spyOn(window, "close").mockImplementation(() => {});
renderTerminalRaw(
`/${MockUserOwner.username}/${MockWorkspace.name}/terminal?command=echo+hello`,
);
await userEvent.click(
await screen.findByRole("button", { name: "Cancel" }),
);
await waitFor(() =>
expect(screen.queryByRole("dialog")).not.toBeInTheDocument(),
);
expect(closeSpy).toHaveBeenCalled();
});
it("skips confirmation dialog for trusted app commands", async () => {
+1 -2
View File
@@ -213,8 +213,7 @@ const TerminalPage: FC = () => {
setCommandConfirmed(true);
}}
onDeny={() => {
searchParams.delete("command");
navigate({ search: searchParams.toString() }, { replace: true });
window.close();
}}
/>
)}