Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 05b399b

Browse files
committed
test: feedback
1 parent f0e1121 commit 05b399b

3 files changed

Lines changed: 38 additions & 29 deletions

File tree

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,15 @@ suite("Roo Code MCP OAuth", function () {
238238
}
239239
}
240240

241+
// Only remove .roo/mcp.json if it's inside the ephemeral tempDir — never
242+
// touch a real workspace's config.
241243
const workspaceDir = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || tempDir
242-
try {
243-
await fs.rm(path.join(workspaceDir, ".roo"), { recursive: true, force: true })
244-
} catch {
245-
// ignore
244+
if (workspaceDir === tempDir || workspaceDir.startsWith(tempDir + path.sep)) {
245+
try {
246+
await fs.unlink(path.join(workspaceDir, ".roo", "mcp.json"))
247+
} catch {
248+
// ignore
249+
}
246250
}
247251

248252
await fs.rm(tempDir, { recursive: true, force: true })
@@ -325,11 +329,11 @@ suite("Roo Code MCP OAuth", function () {
325329
})
326330

327331
test("Should reuse stored token on reconnect without re-running the full OAuth flow", async function () {
328-
// This test runs after the previous one, so a token is already stored in SecretStorage.
329-
// Trigger another reconnect — the SDK should inject the cached token directly and skip the
330-
// browser-based auth flow (no new register or token endpoints should be hit).
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 })
331335

332-
// Clear only mcp-related hit tracking (token endpoint should NOT be re-hit)
336+
// Clear hit tracking so we can assert the token endpoint is NOT re-hit.
333337
endpointsHit.clear()
334338

335339
const workspaceDir = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || tempDir

src/services/mcp/__tests__/McpOAuthClientProvider.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from "vitest"
1+
import { describe, it, expect, vi, beforeEach, afterAll } from "vitest"
22

33
// Mock vscode
44
vi.mock("vscode", () => ({
@@ -21,6 +21,7 @@ vi.mock("../utils/callbackServer", () => ({
2121

2222
// Mock fetch for auth discovery so tests don't make real network calls
2323
const mockFetch = vi.fn()
24+
const originalFetch = global.fetch
2425
global.fetch = mockFetch
2526

2627
// Mock SDK auth discovery functions
@@ -86,6 +87,10 @@ describe("McpOAuthClientProvider", () => {
8687
McpOAuthClientProvider.clearNonOAuthCache()
8788
})
8889

90+
afterAll(() => {
91+
global.fetch = originalFetch
92+
})
93+
8994
describe("static negative cache", () => {
9095
it("isKnownNonOAuth returns false for unknown servers", () => {
9196
expect(McpOAuthClientProvider.isKnownNonOAuth("https://unknown.com/mcp")).toBe(false)

src/services/mcp/__tests__/SecretStorageService.spec.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,35 @@ describe("SecretStorageService", () => {
131131
const result = await service.getOAuthData("https://example.com/mcp")
132132
expect(result).toBeUndefined()
133133
})
134+
})
134135

135-
describe("onDidChange", () => {
136-
it("should call the callback when the key for the given URL changes", () => {
137-
const cb = vi.fn()
138-
service.onDidChange("https://example.com/mcp", cb)
136+
describe("onDidChange", () => {
137+
it("should call the callback when the key for the given URL changes", () => {
138+
const cb = vi.fn()
139+
service.onDidChange("https://example.com/mcp", cb)
139140

140-
context.secrets._emit("mcp.oauth.example.com.L21jcA.data")
141+
context.secrets._emit("mcp.oauth.example.com.L21jcA.data")
141142

142-
expect(cb).toHaveBeenCalledTimes(1)
143-
})
143+
expect(cb).toHaveBeenCalledTimes(1)
144+
})
144145

145-
it("should not call the callback for a different URL's key", () => {
146-
const cb = vi.fn()
147-
service.onDidChange("https://example.com/mcp", cb)
146+
it("should not call the callback for a different URL's key", () => {
147+
const cb = vi.fn()
148+
service.onDidChange("https://example.com/mcp", cb)
148149

149-
context.secrets._emit("mcp.oauth.other.com.L21jcA.data")
150+
context.secrets._emit("mcp.oauth.other.com.L21jcA.data")
150151

151-
expect(cb).not.toHaveBeenCalled()
152-
})
152+
expect(cb).not.toHaveBeenCalled()
153+
})
153154

154-
it("should stop calling the callback after the returned dispose function is called", () => {
155-
const cb = vi.fn()
156-
const unsubscribe = service.onDidChange("https://example.com/mcp", cb)
155+
it("should stop calling the callback after the returned dispose function is called", () => {
156+
const cb = vi.fn()
157+
const unsubscribe = service.onDidChange("https://example.com/mcp", cb)
157158

158-
unsubscribe()
159-
context.secrets._emit("mcp.oauth.example.com.L21jcA.data")
159+
unsubscribe()
160+
context.secrets._emit("mcp.oauth.example.com.L21jcA.data")
160161

161-
expect(cb).not.toHaveBeenCalled()
162-
})
162+
expect(cb).not.toHaveBeenCalled()
163163
})
164164
})
165165

0 commit comments

Comments
 (0)