mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
The OAuth flow in pi-mcp takes a signal for every request, and an aborted refresh no longer falls back to a new authorization. The streamable HTTP transport closes its session with the last request's token instead of asking the auth provider, which could refresh first. The MCP extension owns one signal per session: it aborts sign-ins on Esc and on session shutdown, replaces the generation counter, and shutdown waits for aborted sign-ins to clean up. Requests to the authorization server time out after 15s, and pi mcp login --timeout limits the whole sign-in. closes #10565
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { setKeybindings, type TUI } from "@earendil-works/pi-tui";
|
|
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
|
|
import { KeybindingsManager } from "../src/core/keybindings.ts";
|
|
import { McpManagerView } from "../src/extensions/mcp/ui.ts";
|
|
import { initTheme, theme } from "../src/modes/interactive/theme/theme.ts";
|
|
import { stripAnsi } from "../src/utils/ansi.ts";
|
|
|
|
const ESCAPE = "\x1b";
|
|
const tui = { requestRender: vi.fn() } as unknown as TUI;
|
|
|
|
function rendered(view: McpManagerView): string {
|
|
return stripAnsi(view.render(80).join("\n"));
|
|
}
|
|
|
|
describe("MCP manager status screen", () => {
|
|
beforeAll(() => {
|
|
initTheme("dark");
|
|
});
|
|
|
|
beforeEach(() => {
|
|
setKeybindings(new KeybindingsManager());
|
|
});
|
|
|
|
// #10565
|
|
test("cancels the running operation with the cancel key", () => {
|
|
const view = new McpManagerView(tui, theme, new KeybindingsManager());
|
|
const onCancel = vi.fn();
|
|
view.status("Sign in to issues", "Contacting the authorization server…", onCancel);
|
|
expect(rendered(view)).toContain("cancel");
|
|
view.handleInput(ESCAPE);
|
|
expect(onCancel).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
test("ignores the cancel key for operations that cannot be cancelled", () => {
|
|
const view = new McpManagerView(tui, theme, new KeybindingsManager());
|
|
view.status("Sign in to issues", "Connecting…");
|
|
expect(rendered(view)).not.toContain("cancel");
|
|
view.handleInput(ESCAPE);
|
|
});
|
|
});
|