feat(linear): refine browser authorization and workspace lifecycle

This commit is contained in:
Xubin Ren committed 2026-09-26 19:19:21 +08:00
1 parent 2bacff148d
commit 5375289ecd
32 files changed
+1856 -257

No files matched your search

+54 -1
View File
@@ -1,5 +1,6 @@
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import QRCode from "qrcode";
import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow";
import { FeishuConnectFlow } from "../../../nanobot/channels/feishu/webui/FeishuConnectFlow";
@@ -30,9 +31,61 @@ beforeEach(() => {
});
});
afterEach(cleanup);
afterEach(() => { cleanup(); vi.restoreAllMocks(); });
describe("channel QR connect parameters", () => {
it.each([false, true])("keeps QR generation enabled by default (minimal=%s)", async (minimalPending) => {
const generateQr = vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,preview");
requestMutation.mockResolvedValueOnce({
session_id: "qr-session", status: "pending", qr_url: "https://example.com/connect",
});
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" labels={labels}
minimalPending={minimalPending} onFeaturesUpdate={vi.fn()} />);
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
expect(await screen.findByRole("img", { name: "Connection QR code" })).toHaveAttribute("src", "data:image/png;base64,preview");
expect(generateQr).toHaveBeenCalledOnce();
});
it("does not generate or reserve space for QR when disabled, and still allows cancellation", async () => {
const generateQr = vi.spyOn(QRCode, "toDataURL").mockRejectedValue(new Error("QR must not run"));
requestMutation
.mockResolvedValueOnce({ session_id: "browser-session", status: "pending", qr_url: "https://example.com/authorize" })
.mockResolvedValueOnce({ session_id: "browser-session", status: "cancelled" });
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" showQrCode={false}
labels={{ ...labels, scanTitle: "Authorize in browser", scanDescription: "Continue in the browser." }}
onFeaturesUpdate={vi.fn()} />);
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
expect(await screen.findByText("Continue in the browser.")).toBeVisible();
expect(screen.getByText("Waiting")).toBeVisible();
expect(generateQr).not.toHaveBeenCalled();
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(screen.getByText("Authorize in browser").parentElement?.parentElement)
.not.toHaveClass("sm:grid-cols-[auto_minmax(0,1fr)]");
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
expect(await screen.findByText("Stopped")).toBeVisible();
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.cancel", {
channel: "plugin-chat", session_id: "browser-session",
}, 20_000);
});
it("polls browser-only authorization to completion without generating QR", async () => {
const generateQr = vi.spyOn(QRCode, "toDataURL").mockResolvedValue("data:image/png;base64,unused");
const onFeaturesUpdate = vi.fn();
const features = { features: [], enabled_count: 0 };
requestMutation
.mockResolvedValueOnce({ session_id: "browser-session", status: "pending", qr_url: "https://example.com/authorize" })
.mockResolvedValueOnce({ session_id: "browser-session", status: "succeeded", nanobot_features: features });
render(<ChannelQrConnectFlow token="tok" channelName="plugin-chat" showQrCode={false}
labels={labels} onFeaturesUpdate={onFeaturesUpdate} />);
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
expect(await screen.findByText("Connected", {}, { timeout: 2000 })).toBeVisible();
expect(onFeaturesUpdate).toHaveBeenCalledWith(features);
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.poll", {
channel: "plugin-chat", session_id: "browser-session",
}, 150_000);
expect(generateQr).not.toHaveBeenCalled();
});
it("forwards current channel parameters without restarting on rerender and preserves forced retries", async () => {
const props = {
token: "tok",