Skip to content

Commit 1089253

Browse files
authored
fix feishu login qr rendering (#97087)
Co-authored-by: NianJiuZst <180004567+users.noreply.github.com>
1 parent e5123e4 commit 1089253

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

extensions/feishu/src/app-registration.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
// Feishu tests cover app registration plugin behavior.
22
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
33
import { afterEach, describe, expect, it, vi } from "vitest";
4-
import { beginAppRegistration, pollAppRegistration } from "./app-registration.js";
4+
import { beginAppRegistration, pollAppRegistration, printQrCode } from "./app-registration.js";
55

6-
const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({
6+
const { fetchWithSsrFGuardMock, renderQrTerminalMock } = vi.hoisted(() => ({
77
fetchWithSsrFGuardMock: vi.fn(),
8+
renderQrTerminalMock: vi.fn(async () => "terminal-qr"),
89
}));
910

1011
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
1112
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
1213
}));
1314

15+
vi.mock("./qr-terminal.js", () => ({
16+
renderQrTerminal: renderQrTerminalMock,
17+
}));
18+
1419
function mockFeishuJson(payload: unknown) {
1520
fetchWithSsrFGuardMock.mockResolvedValueOnce({
1621
response: new Response(JSON.stringify(payload), { status: 200 }),
@@ -23,6 +28,7 @@ describe("Feishu app registration", () => {
2328
vi.useRealTimers();
2429
vi.restoreAllMocks();
2530
fetchWithSsrFGuardMock.mockReset();
31+
renderQrTerminalMock.mockClear();
2632
});
2733

2834
it("defaults unsafe begin polling lifetimes from provider responses", async () => {
@@ -59,4 +65,16 @@ describe("Feishu app registration", () => {
5965
await vi.runOnlyPendingTimersAsync();
6066
await expect(poll).resolves.toEqual({ status: "timeout" });
6167
});
68+
69+
it("prints scan-to-create QR codes with compact terminal rendering", async () => {
70+
const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
71+
72+
await printQrCode("https://accounts.feishu.cn/verify?device_code=long-device-code");
73+
74+
expect(renderQrTerminalMock).toHaveBeenCalledWith(
75+
"https://accounts.feishu.cn/verify?device_code=long-device-code",
76+
{ small: true },
77+
);
78+
expect(writeSpy).toHaveBeenCalledWith("terminal-qr\n");
79+
});
6280
});

extensions/feishu/src/app-registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export async function pollAppRegistration(params: {
266266
* otherwise the pattern is corrupted and cannot be scanned.
267267
*/
268268
export async function printQrCode(url: string): Promise<void> {
269-
const output = await renderQrTerminal(url);
269+
const output = await renderQrTerminal(url, { small: true });
270270
process.stdout.write(output.endsWith("\n") ? output : `${output}\n`);
271271
}
272272

0 commit comments

Comments
 (0)