Skip to content

Commit bfdc152

Browse files
committed
fix(McpHub): update e2e tests for headless mode
1 parent 5ea544d commit bfdc152

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

apps/vscode-e2e/src/suite/mcp-oauth.test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,9 @@ suite("Roo Code MCP OAuth", function () {
201201
const rooDir = path.join(workspaceDir, ".roo")
202202
await fs.mkdir(rooDir, { recursive: true })
203203

204-
const mcpConfig = {
205-
mcpServers: {
206-
"test-oauth-server": {
207-
type: "streamable-http",
208-
url: `http://localhost:${mockServerPort}/mcp`,
209-
},
210-
},
211-
}
212-
213204
testFiles = { mcpConfig: path.join(rooDir, "mcp.json") }
214-
await fs.writeFile(testFiles.mcpConfig, JSON.stringify(mcpConfig, null, 2))
205+
// Config is written by each test to control when the connection starts,
206+
// ensuring all endpoint hits are captured after endpointsHit is cleared.
215207

216208
console.log("[TEST] Mock server port:", mockServerPort)
217209
console.log("[TEST] MCP config:", testFiles.mcpConfig)
@@ -272,7 +264,7 @@ suite("Roo Code MCP OAuth", function () {
272264
})
273265

274266
test("Should complete the full OAuth flow when connecting to an OAuth-protected MCP server", async function () {
275-
// Re-write the config to trigger the file watcher and force a reconnect.
267+
// Write the config to trigger the initial connection attempt.
276268
const workspaceDir = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || tempDir
277269
const mcpConfigPath = path.join(workspaceDir, ".roo", "mcp.json")
278270

@@ -329,13 +321,8 @@ suite("Roo Code MCP OAuth", function () {
329321
})
330322

331323
test("Should reuse stored token on reconnect without re-running the full OAuth flow", async function () {
332-
// Ensure a token is in SecretStorage before testing reuse — this makes the
333-
// test self-contained regardless of execution order.
334-
await waitFor(() => endpointsHit.has("token"), { timeout: 30_000 })
335-
336-
// Clear hit tracking so we can assert the token endpoint is NOT re-hit.
337-
endpointsHit.clear()
338-
324+
// Test 1 stored a valid token in SecretStorage. The per-test setup already
325+
// cleared endpointsHit, so any hits here are from this reconnect only.
339326
const workspaceDir = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || tempDir
340327
const mcpConfigPath = path.join(workspaceDir, ".roo", "mcp.json")
341328

src/services/mcp/McpHub.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,27 @@ export class McpHub {
12041204
// Register in _oauthWatchers so deleteConnection() and dispose() can clean up
12051205
this._oauthWatchers.set(watcherKey, { unsubscribe, abortHandle: timeoutHandle })
12061206

1207+
// In test mode, skip user interaction and proceed directly to complete the OAuth flow.
1208+
if (process.env.MCP_OAUTH_TEST_MODE === "true") {
1209+
void (async () => {
1210+
cleanup()
1211+
try {
1212+
await this._completeOAuthFlow(
1213+
authProvider,
1214+
transport,
1215+
connection,
1216+
name,
1217+
source,
1218+
cancellationToken,
1219+
)
1220+
} catch {
1221+
// _completeOAuthFlow handles its own error state
1222+
}
1223+
resolve()
1224+
})()
1225+
return
1226+
}
1227+
12071228
// Non-modal toast — fires once. If dismissed without clicking Authenticate,
12081229
// the flow stays alive via the persistent progress bar (Cancel to abort).
12091230
const authenticateLabel = t("mcp:oauth.flow.authenticateButton")

0 commit comments

Comments
 (0)