fix(feishu): restore assistant creation and pairing recovery

Refs NAN-239
This commit is contained in:
Xubin Ren committed 2026-10-12 17:38:43 +08:00
1 parent cfb0f51e78
commit 2aa98677c6
36 files changed
+369 -47

No files matched your search

+26
View File
@@ -4063,6 +4063,32 @@ describe("App layout", () => {
unmount();
});
it.each(["sending", "failed"])("explains an undelivered pairing reply (%s) without empty code slots", async (delivery_status) => {
mockFetchRoutes({ "/api/settings/pairing": { requests: [{
code: "ABCD-EFGH", channel: "feishu", sender_id: "alice", delivery_status,
}] } });
render(<App />);
const popup = await screen.findByRole("dialog", { name: "Pair account" });
expect(within(popup).getByText("Already received a code?").closest("details")).not.toHaveAttribute("open");
expect(within(popup).getByText(/another private message to retry/)).toBeVisible();
if (delivery_status === "failed") expect(within(popup).getByRole("alert")).toBeVisible();
fireEvent.click(within(popup).getByText("Already received a code?"));
expect(within(popup).getByRole("textbox", { name: "Pairing code" })).toBeEnabled();
expect(requestMutationSpy).not.toHaveBeenCalledWith("settings.pairing.approve", expect.anything(), expect.anything());
});
it.each([undefined, "sent"])("keeps legacy/delivered pairing usable behind a failed request (%s)", async (delivery_status) => {
mockFetchRoutes({ "/api/settings/pairing": { requests: [
{ code: "ABCD-EFGH", channel: "feishu", sender_id: "alice", delivery_status: "failed" },
{ code: "IJKL-MNOP", channel: "feishu.second", sender_id: "bob", delivery_status },
] } });
render(<App />);
const popup = await screen.findByRole("dialog", { name: "Pair account" });
expect(within(popup).getByRole("textbox", { name: "Pairing code" })).toBeEnabled();
expect(within(popup).queryByRole("alert")).not.toBeInTheDocument();
expect(within(popup).getByText("2 pending")).toBeVisible();
});
it("reuses an in-flight pairing poll when the page becomes visible again", async () => {
let resolvePairing!: (response: Response) => void;
const pendingPairing = new Promise<Response>((resolve) => {
@@ -4,6 +4,8 @@ import QRCode from "qrcode";
import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow";
import { FeishuConnectFlow } from "../../../nanobot/channels/feishu/webui/FeishuConnectFlow";
import { FeishuAssistantsPanel } from "../../../nanobot/channels/feishu/webui/FeishuAssistantsPanel";
import type { NanobotFeatureInfo } from "@/lib/types";
const { requestMutation } = vi.hoisted(() => ({ requestMutation: vi.fn() }));
@@ -34,6 +36,53 @@ beforeEach(() => {
afterEach(() => { cleanup(); vi.restoreAllMocks(); });
describe("channel QR connect parameters", () => {
it("adds an assistant without replacing existing ones, and supports cancellation and retry", async () => {
const feature: NanobotFeatureInfo = {
name: "feishu", display_name: "Feishu", type: "channel", webui: "webui/index.tsx",
enabled: true, configured: true, installed: true, ready: true, status: "enabled",
install_supported: true, requires_restart: false,
instances: [{
id: "default", name: "First assistant", enabled: true, configured: true,
runtime_status: "running", config_values: {}, configured_fields: [],
}],
};
const onFeaturesUpdate = vi.fn();
const props = { token: "tok", feature, showBrandLogos: false, onFeaturesUpdate };
const view = render(<FeishuAssistantsPanel {...props} />);
requestMutation.mockResolvedValueOnce({
session_id: "add-1", status: "pending", qr_url: "https://example.com/authorize",
});
fireEvent.click(screen.getByRole("button", { name: "Add another assistant" }));
expect(await screen.findByText("Scan with Feishu")).toBeVisible();
expect(requestMutation).toHaveBeenCalledWith("settings.channel.connect.start", {
channel: "feishu", domain: "feishu", instance_id: "default", mode: "create",
}, 150_000);
expect(screen.getByText("First assistant")).toBeVisible();
requestMutation.mockResolvedValueOnce({ session_id: "add-1", status: "cancelled" });
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
await screen.findByRole("button", { name: "Add another assistant" });
expect(requestMutation).toHaveBeenLastCalledWith("settings.channel.connect.cancel", {
channel: "feishu", session_id: "add-1",
}, 20_000);
expect(onFeaturesUpdate).not.toHaveBeenCalled();
requestMutation.mockRejectedValueOnce(new Error("Authorization unavailable"));
fireEvent.click(screen.getByRole("button", { name: "Add another assistant" }));
expect(await screen.findByText("Authorization unavailable")).toBeVisible();
const updated = { ...feature, instances: [...feature.instances!, {
...feature.instances![0], id: "assistant-new", name: "Second assistant",
}] };
const payload = { features: [updated], enabled_count: 1 };
requestMutation.mockResolvedValueOnce({ status: "succeeded", nanobot_features: payload });
fireEvent.click(screen.getByRole("button", { name: "Add another assistant" }));
await waitFor(() => expect(onFeaturesUpdate).toHaveBeenCalledWith(payload));
view.rerender(<FeishuAssistantsPanel {...props} feature={updated} />);
expect(screen.getByText("First assistant")).toBeVisible();
expect(screen.getByText("Second assistant")).toBeVisible();
expect(screen.getByRole("button", { name: "Add another assistant" })).toBeEnabled();
expect(screen.queryByText("Authorization unavailable")).not.toBeInTheDocument();
});
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({