fix(qq): clarify QR binding states and setup actions (#6340)

* fix(qq): clarify QR binding states and setup actions

* fix(qq): confirm rebinding instead of showing a persistent warning

* fix(qq): make rebind credential warning conditional

* docs(qq): align rebind guide with conditional warning
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 01:55:20 +08:00
1 parent 51a0fc83a2
commit 130f4edefe
27 files changed
+634 -168

No files matched your search

+66 -3
View File
@@ -2114,20 +2114,83 @@ describe("Settings channels", () => {
renderSettingsView({ initialSection: "channels" });
fireEvent.click(await screen.findByRole("button", { name: "View QQ settings" }));
expect(await screen.findByRole("img", { name: "QQ login QR code" })).toBeInTheDocument();
expect(await screen.findByRole("img", { name: "QQ binding QR code" })).toBeInTheDocument();
expect(requestMutationMock).toHaveBeenCalledWith(
"settings.channel.connect.start", { channel: "qq" }, 150_000,
);
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.channel.connect.poll", { channel: "qq", session_id: "qq-1" }, 150_000,
));
expect(await screen.findByText("QQ is connected.")).toBeInTheDocument();
expect(screen.getByText(/previous App Secret stops working/)).toBeInTheDocument();
expect(await screen.findByText("Configured")).toBeInTheDocument();
expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
expect(screen.queryByText(/Rebinding may interrupt other apps/)).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Advanced" }));
expect(screen.getByLabelText("App ID")).toHaveValue("1024");
expect(screen.getByLabelText("Acknowledgement message")).toHaveValue("⏳ Processing...");
});
it("keeps saved QQ setup distinct from a running connection when reopening settings", async () => {
const qqFeature: NanobotFeatureInfo = {
...catalogFeature("qq", false),
display_name: "QQ",
webui: "webui/index.tsx",
configured: true,
runtime_status: "stopped",
config_values: { "channels.qq.appId": "1024" },
configured_fields: ["channels.qq.appId", "channels.qq.secret"],
setup: channelSetupContract("qq"),
};
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings") return jsonResponse(settingsPayload());
if (url === "/api/settings/nanobot-features") {
return jsonResponse({ features: [qqFeature], enabled_count: 0 });
}
return { ok: false, status: 404, json: async () => ({}) } as Response;
}));
renderSettingsView({ initialSection: "channels" });
fireEvent.click(await screen.findByRole("button", { name: "View QQ settings" }));
expect(await screen.findByText("Configured")).toBeInTheDocument();
expect(within(screen.getByRole("dialog")).getByText("Not running")).toBeInTheDocument();
expect(within(screen.getByRole("dialog")).queryByText("Running")).not.toBeInTheDocument();
expect(screen.getByText("1024")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Rebind bot" })).toBeInTheDocument();
expect(screen.queryByRole("img", { name: "QQ binding QR code" })).not.toBeInTheDocument();
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole("button", { name: "Enter credentials manually" }));
expect(screen.getByRole("group", { name: "Manual credentials" })).toBeInTheDocument();
expect(screen.getByRole("group", { name: "Access" })).toBeInTheDocument();
expect(screen.getByRole("group", { name: "Behavior" })).toBeInTheDocument();
expect(screen.getByRole("group", { name: "Advanced" })).toBeInTheDocument();
expect(screen.getByLabelText("App ID")).toHaveValue("1024");
fireEvent.click(screen.getByRole("button", { name: "Close" }));
fireEvent.click(screen.getByRole("button", { name: "View QQ settings" }));
const rebind = await screen.findByRole("button", { name: "Rebind bot" });
expect(screen.queryByText(/Rebinding may interrupt other apps/)).not.toBeInTheDocument();
expect(requestMutationMock).not.toHaveBeenCalled();
rebind.focus();
fireEvent.click(rebind);
const confirmation = await screen.findByRole("alertdialog", { name: "Rebind bot" });
expect(confirmation).toHaveTextContent("Rebinding may interrupt other apps using this QQ bot. If the App Secret is reset, the old secret becomes invalid and those apps need the new secret.");
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.click(within(confirmation).getByRole("button", { name: "Cancel" }));
await waitFor(() => expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument());
expect(screen.queryByText(/Rebinding may interrupt other apps/)).not.toBeInTheDocument();
expect(rebind).toHaveFocus();
expect(requestMutationMock).not.toHaveBeenCalled();
requestMutationMock.mockResolvedValue({ status: "pending", session_id: "qq-rebind", qr_url: "https://example.com/qq-rebind" });
fireEvent.click(rebind);
fireEvent.click(within(await screen.findByRole("alertdialog", { name: "Rebind bot" }))
.getByRole("button", { name: "Rebind bot" }));
expect(await screen.findByRole("img", { name: "QQ binding QR code" })).toBeInTheDocument();
expect(requestMutationMock).toHaveBeenCalledTimes(1);
expect(requestMutationMock).toHaveBeenCalledWith("settings.channel.connect.start", { channel: "qq" }, 150_000);
expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
});
it("keeps the WebUI websocket channel enabled without opening a setup dialog", async () => {
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);