From a5fcb33d62d1cb76792856f1dfaef712957c7e85 Mon Sep 17 00:00:00 2001 From: kirillk Date: Tue, 25 Aug 2026 11:56:03 -0400 Subject: [PATCH] test(jetbrains): stop frontend tests opening a real browser ProvidersSettingsUiTest drove the real OAuth UI with a fixture URL of https://auth.openai.com/device, and ProvidersSettingsUi calls BrowserUtil.browse unstubbed. BrowserUtil is a static facade over the BrowserLauncher application service, so every run of the frontend suite launched an actual Chrome tab on the developer's machine. Replace BrowserLauncher with a recording fake via replaceService instead of adding a production seam, and assert the recorded URL so the browser handoff is verified rather than performed. Install the same fake in the GitHub/PR tests that reach other direct BrowserUtil call sites. --- .../agentManager/AgentManagerPanelTest.kt | 2 + .../agentManager/worktree/GhBannerTest.kt | 2 + .../worktree/GhStatusCoordinatorTest.kt | 2 + .../providers/ProvidersSettingsUiTest.kt | 3 ++ .../client/testing/FakeBrowserLauncher.kt | 37 +++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeBrowserLauncher.kt diff --git a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt index f436a11ab0d..8bc0864ed9c 100644 --- a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt +++ b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt @@ -24,6 +24,7 @@ import ai.kilocode.client.testing.TestCoroutines import ai.kilocode.client.testing.pumpEdt import ai.kilocode.client.testing.TestUiTimers import ai.kilocode.client.testing.fire +import ai.kilocode.client.testing.installBrowser import ai.kilocode.client.ui.list.ActiveListBadge import ai.kilocode.client.ui.list.ActiveListItem import ai.kilocode.client.ui.list.ActiveListMetrics @@ -69,6 +70,7 @@ class AgentManagerPanelTest : BasePlatformTestCase() { override fun setUp() { super.setUp() + installBrowser() coroutines = TestCoroutines() rpc = FakeWorktreeRpcApi() service = KiloWorktreeService(coroutines.scope, rpc) diff --git a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhBannerTest.kt b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhBannerTest.kt index 65282cabf0c..b878a7ba3ed 100644 --- a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhBannerTest.kt +++ b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhBannerTest.kt @@ -4,6 +4,7 @@ import ai.kilocode.client.testing.FakeWorktreeRpcApi import ai.kilocode.client.testing.TestCoroutines import ai.kilocode.client.testing.pumpEdt import ai.kilocode.client.testing.TestUiTimers +import ai.kilocode.client.testing.installBrowser import ai.kilocode.client.util.edtWait import ai.kilocode.rpc.dto.GhAvailability import com.intellij.openapi.application.ApplicationManager @@ -22,6 +23,7 @@ class GhBannerTest : BasePlatformTestCase() { override fun setUp() { super.setUp() + installBrowser() coroutines = TestCoroutines() rpc = FakeWorktreeRpcApi() timers = TestUiTimers() diff --git a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt index c5f185a231c..309614052c2 100644 --- a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt +++ b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt @@ -4,6 +4,7 @@ import ai.kilocode.client.testing.FakeWorktreeRpcApi import ai.kilocode.client.testing.TestCoroutines import ai.kilocode.client.testing.pumpEdt import ai.kilocode.client.testing.TestUiTimers +import ai.kilocode.client.testing.installBrowser import ai.kilocode.client.util.edtWait import ai.kilocode.rpc.dto.GhAvailability import com.intellij.openapi.application.ApplicationManager @@ -21,6 +22,7 @@ class GhStatusCoordinatorTest : BasePlatformTestCase() { override fun setUp() { super.setUp() + installBrowser() coroutines = TestCoroutines() rpc = FakeWorktreeRpcApi() timers = TestUiTimers() diff --git a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/settings/providers/ProvidersSettingsUiTest.kt b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/settings/providers/ProvidersSettingsUiTest.kt index 69911d94967..aed6ce37bca 100644 --- a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/settings/providers/ProvidersSettingsUiTest.kt +++ b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/settings/providers/ProvidersSettingsUiTest.kt @@ -4,6 +4,7 @@ import ai.kilocode.client.util.edtWait import ai.kilocode.client.app.KiloProviderService import ai.kilocode.client.plugin.KiloBundle import ai.kilocode.client.testing.FakeProviderRpcApi +import ai.kilocode.client.testing.installBrowser import ai.kilocode.client.ui.UiStyle import ai.kilocode.client.ui.list.ActiveListActionCell import ai.kilocode.client.ui.list.ActiveListConfig @@ -985,6 +986,7 @@ class ProvidersSettingsUiTest : BasePlatformTestCase() { fun `test provider oauth auto response shows device auth panel`() { val callback = CompletableDeferred() + val browser = installBrowser() val rpc = installProvider( ProviderSettingsDto( providers = listOf(provider("openai", "OpenAI")), @@ -1016,6 +1018,7 @@ class ProvidersSettingsUiTest : BasePlatformTestCase() { assertTrue(t, t.contains("Open Browser")) assertTrue(t, t.contains("Cancel")) assertEquals("https://auth.openai.com/device", fieldsByName(panel, "kilo.provider.oauth.url").single().text) + assertEquals(listOf("https://auth.openai.com/device"), browser.urls) val qr = components(panel).filterIsInstance().single { it.name == "kilo.provider.oauth.qr" } assertNotNull(qr.icon) } diff --git a/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeBrowserLauncher.kt b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeBrowserLauncher.kt new file mode 100644 index 00000000000..8870f98427b --- /dev/null +++ b/packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeBrowserLauncher.kt @@ -0,0 +1,37 @@ +package ai.kilocode.client.testing + +import com.intellij.ide.browsers.BrowserLauncher +import com.intellij.ide.browsers.WebBrowser +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.project.Project +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import com.intellij.testFramework.replaceService +import java.nio.file.Path + +class FakeBrowserLauncher : BrowserLauncher() { + val urls = mutableListOf() + val files = mutableListOf() + + override fun open(url: String) { + urls.add(url) + } + + @Suppress("DEPRECATION") + override fun browse(file: java.io.File) { + files.add(file.toPath()) + } + + override fun browse(file: Path) { + files.add(file) + } + + override fun browse(url: String, browser: WebBrowser?, project: Project?) { + urls.add(url) + } +} + +fun BasePlatformTestCase.installBrowser(): FakeBrowserLauncher { + val fake = FakeBrowserLauncher() + ApplicationManager.getApplication().replaceService(BrowserLauncher::class.java, fake, testRootDisposable) + return fake +}