Files
Kilo-Org_kilocode/packages/opencode/test/kilocode/mcp-oauth-callback.test.ts
T
Emilian Olbrych 8472f90528 Fix/vscode mcp oauth sign in (#8910)
* fix(vscode): restore MCP OAuth sign-in from settings UI

- Add Sign in control when MCP status is needs_auth; posts authenticateMcp
  to run CLI POST /mcp/{name}/auth/authenticate.
- On SSE mcp.browser.open.failed, open the auth URL via
  vscode.env.openExternal (CLI subprocess open() often fails under VS Code).
- Dedupe openExternal when multiple webviews receive the same event.

Fixes UI regression described in GitHub issue #8904.

Made-with: Cursor

* fix(vscode): satisfy ESLint max-lines and complexity for MCP OAuth

- Move MCP connect/disconnect/authenticate and openExternal dedupe to
  kilo-provider/mcp-oauth.ts.
- eslint-disable-next-line complexity for the webview message router.

Made-with: Cursor

* fix: restore MCP OAuth sign-in in VS Code

* fix: simplify MCP OAuth callback delegation

* fix: clarify MCP OAuth callback delegation

---------

Co-authored-by: e.olbrych <e.olbrych@mkmc.pl>
Co-authored-by: marius-kilocode <marius@kilocode.ai>
2026-05-04 11:54:07 +00:00

34 lines
1.0 KiB
TypeScript

import { describe, expect, test, afterEach } from "bun:test"
import { createServer } from "http"
import { McpOAuthCallback } from "../../src/mcp/oauth-callback"
describe("Kilo MCP OAuth callback", () => {
afterEach(async () => {
await McpOAuthCallback.stop()
})
test("fails fast when the callback port belongs to another process", async () => {
const blocker = createServer((_req, res) => {
res.writeHead(200)
res.end("occupied")
})
await new Promise<void>((resolve, reject) => {
blocker.once("error", reject)
blocker.listen(0, "127.0.0.1", resolve)
})
try {
const address = blocker.address()
if (!address || typeof address === "string") throw new Error("missing blocker address")
await expect(
McpOAuthCallback.ensureRunning(`http://127.0.0.1:${address.port}/mcp/oauth/callback`),
).rejects.toThrow("already in use")
expect(McpOAuthCallback.isRunning()).toBe(false)
} finally {
await new Promise<void>((resolve) => blocker.close(() => resolve()))
}
})
})