TypeScript
fix(web): Integrations settings show one Browser section, not two (#18264)
Rakshith Bhat7e1a5a38b5d2
diff --git a/apps/web/src/components/settings/IntegrationsSettings.browser.test.tsx b/apps/web/src/components/settings/IntegrationsSettings.browser.test.tsxindex eda958c161f..abb14f61b47 100644--- a/apps/web/src/components/settings/IntegrationsSettings.browser.test.tsx+++ b/apps/web/src/components/settings/IntegrationsSettings.browser.test.tsx@@ -8,6 +8,9 @@ import {import { act, StrictMode } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";+import { page } from "vite-plus/test/browser";++import "../../index.css";const { listBrowserImportSources } = vi.hoisted(() => ({listBrowserImportSources: vi.fn().mockResolvedValue([]),@@ -36,10 +39,6 @@ vi.mock(import("../../hooks/useSettings"), async (original) => ({usePrimarySettings: (() => DEFAULT_UNIFIED_SETTINGS) as never,useUpdatePrimarySettings: (() => vi.fn()) as never,}));-vi.mock(import("./ProjectDefaultsSettings"), async (original) => ({- ...(await original()),- ProjectDefaultsSettings: (() => null) as never,-}));vi.mock(import("./SettingsScopeContext"), async (original) => ({...(await original()),useSettingsScope: (() => ({@@ -90,6 +89,16 @@ async function openSettings() {}describe("Integrations browser discovery", () => {+ it("keeps agent browser access in the single Browser section", async () => {+ await openSettings();++ expect(page.getByRole("heading", { name: "Browser", exact: true }).elements()).toHaveLength(1);+ const access = page.getByRole("switch", { name: "Agent browser access", exact: true });+ await expect.element(access).toBeVisible();+ expect(access.element().closest("section")).toBe(container.querySelector("section#browser"));+ expect(access.element().closest("#agent-browser-access")).not.toBeNull();+ });+it("does not scan browser files when entering or revisiting settings", async () => {await openSettings();expect(listBrowserImportSources).not.toHaveBeenCalled();diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsxindex 723887f0094..a5b028557f5 100644--- a/apps/web/src/components/settings/IntegrationsSettings.tsx+++ b/apps/web/src/components/settings/IntegrationsSettings.tsx@@ -19,6 +19,7 @@ import {DEFAULT_BROWSER_VIEWPORT,DEFAULT_PREVIEW_APPEARANCE,DEFAULT_PREVIEW_ZOOM_FACTOR,+ DEFAULT_SERVER_SETTINGS,FILL_PREVIEW_VIEWPORT,PREVIEW_VIEWPORT_MAX_AREA,PREVIEW_VIEWPORT_MAX_DIMENSION,@@ -111,7 +112,6 @@ import {SettingsSection,} from "./settingsLayout";import { searchableSetting } from "./settingsSearch";-import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";import { useSettingsScope } from "./SettingsScopeContext";import { BrowserImportWizard, type WizardTarget } from "./BrowserImportWizard";import type { ImportOutcome } from "./browserImportWizard.logic";@@ -971,6 +971,46 @@ export function DeviceIntegrationControls({);}+function AgentBrowserAccessSetting() {+ const { scope } = useSettingsScope();+ const settings = useScopedSettings();+ const updateSettings = useUpdateScopedSettings();+ const isProjectScope = scope.kind === "project" || scope.kind === "checkout";++ return (+ <SettingsRow+ serverScoped+ settingKeys={["enableAgentBrowserAccess"]}+ {...searchableSetting("agent-browser-access")}+ description={+ isProjectScope+ ? "Allow agents in this project to use the shared browser. Applies when the agent session next starts."+ : "Allow agents to use the shared browser. Projects can override it."+ }+ resetAction={+ settings.enableAgentBrowserAccess !== DEFAULT_SERVER_SETTINGS.enableAgentBrowserAccess ? (+ <SettingResetButton+ label="default browser access"+ onClick={() =>+ updateSettings({+ enableAgentBrowserAccess: DEFAULT_SERVER_SETTINGS.enableAgentBrowserAccess,+ })+ }+ />+ ) : null+ }+ control={+ <ScopedSwitch+ settingKeys={["enableAgentBrowserAccess"]}+ aria-label="Agent browser access"+ checked={settings.enableAgentBrowserAccess}+ onCheckedChange={(enabled) => updateSettings({ enableAgentBrowserAccess: enabled })}+ />+ }+ />+ );+}+function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled: boolean }) {const autoShow = useClientSettings((settings) => settings.browserAutoShowFloatingPreview);const updateSettings = useUpdatePrimarySettings();@@ -1485,8 +1525,8 @@ export function IntegrationsSettingsPanel() {return (<SettingsPageContainer>- <ProjectDefaultsSettings category="integrations" /><SettingsSection id="browser" title="Browser">+ <AgentBrowserAccessSetting />{previewDefaultsDisabled ? (<SettingsUnavailableGroup message="Only available in the desktop app.">{previewDefaults}diff --git a/apps/web/src/components/settings/ProjectDefaultsSettings.tsx b/apps/web/src/components/settings/ProjectDefaultsSettings.tsxindex 33c7125636f..3e6284282dc 100644--- a/apps/web/src/components/settings/ProjectDefaultsSettings.tsx+++ b/apps/web/src/components/settings/ProjectDefaultsSettings.tsx@@ -81,7 +81,6 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSettingconst PermissionIcon = runtimeModeConfig[settings.defaultRuntimeMode].icon;const mixedWorkspace = useScopedSettingsMixed(["defaultThreadEnvMode"]);const mixedSubmodules = useScopedSettingsMixed(["worktreeSubmodules"]);- const mixedBrowser = useScopedSettingsMixed(["enableAgentBrowserAccess"]);const mixedAutoPull = useScopedSettingsMixed(["defaultAutoPull"]);const mixedAgentCredits = useScopedSettingsMixed(["removeAgentCreditsOnMerge"]);const mixedMergeMethod = useScopedSettingsMixed(["pullRequestMergeMethod"]);@@ -251,20 +250,8 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSettingreturn (<SettingsSection- id={- category === "general" || category === "project"- ? "project-defaults"- : category === "integrations"- ? "browser-access"- : "source-control-defaults"- }- title={- category === "general" || category === "project"- ? "New threads"- : category === "integrations"- ? "Browser"- : "Repositories"- }+ id={category === "source-control" ? "source-control-defaults" : "project-defaults"}+ title={category === "source-control" ? "Repositories" : "New threads"}>{category === "project" ? (<>@@ -383,7 +370,7 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting}/></>- ) : category === "source-control" ? (+ ) : (<><SettingsRowserverScoped@@ -489,42 +476,6 @@ export function ProjectDefaultsSettings({ category }: { category: ProjectSetting}/></>- ) : (- <>- <SettingsRow- serverScoped- settingKeys={["enableAgentBrowserAccess"]}- mixed={mixedBrowser}- id={searchableSetting("agent-browser-access").id}- title="Agent browser access"- description={- isProjectScope- ? "Allow agents in this project to use the shared browser. Applies when the agent session next starts."- : "Allow agents to use the shared browser. Projects can override it."- }- resetAction={- settings.enableAgentBrowserAccess !==- DEFAULT_SERVER_SETTINGS.enableAgentBrowserAccess ? (- <SettingResetButton- label="default browser access"- onClick={() =>- updateSettings({- enableAgentBrowserAccess: DEFAULT_SERVER_SETTINGS.enableAgentBrowserAccess,- })- }- />- ) : null- }- control={- <Switch- aria-label="Agent browser access"- mixed={mixedBrowser}- checked={mixedBrowser ? false : settings.enableAgentBrowserAccess}- onCheckedChange={(enabled) => updateSettings({ enableAgentBrowserAccess: enabled })}- />- }- />- </>)}</SettingsSection>);diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.tsxindex 24d2d60084a..fbd0b5206ac 100644--- a/apps/web/src/components/settings/ProjectSettingsPanel.tsx+++ b/apps/web/src/components/settings/ProjectSettingsPanel.tsx@@ -59,7 +59,7 @@ function memberKey(member: { environmentId: string; id: string }): string {return `${member.environmentId}:${member.id}`;}-export type ProjectSettingsCategory = "general" | "integrations" | "source-control" | "project";+export type ProjectSettingsCategory = "general" | "source-control" | "project";export function ProjectSettingsPanel({projectKey,