π OpenHands: AI-Driven Development
APP-1325: show GitLab/Slack sections without GitHub App configured (#14097)
aivong-openhands137bede1f5e8
diff --git a/frontend/__tests__/hooks/use-websocket.test.ts b/frontend/__tests__/hooks/use-websocket.test.tsindex d00db6f856..2fde9831c5 100644--- a/frontend/__tests__/hooks/use-websocket.test.ts+++ b/frontend/__tests__/hooks/use-websocket.test.ts@@ -196,23 +196,16 @@ describe("useWebSocket", () => {const onCloseSpy = vi.fn();const options = { onClose: onCloseSpy };- const { result, unmount } = renderHook(() =>- useWebSocket("ws://acme.com/ws", options),+ const closeLink = ws.link("ws://close-test.com/ws");+ mswServer.use(+ closeLink.addEventListener("connection", ({ client, server }) => {+ server.connect();+ client.close(1000, "Normal closure");+ }),);- // Wait for connection to be established- await waitFor(() => {- expect(result.current.isConnected).toBe(true);- });-- // Reset spy after connection is established to ignore any spurious- // close events fired by the MSW mock during the handshake.- onCloseSpy.mockClear();-- // Unmount to trigger close- unmount();+ renderHook(() => useWebSocket("ws://close-test.com/ws", options));- // Wait for onClose handler to be calledawait waitFor(() => {expect(onCloseSpy).toHaveBeenCalledOnce();});diff --git a/frontend/__tests__/routes/git-settings.test.tsx b/frontend/__tests__/routes/git-settings.test.tsxindex 860bdaf1d0..0097223505 100644--- a/frontend/__tests__/routes/git-settings.test.tsx+++ b/frontend/__tests__/routes/git-settings.test.tsx@@ -35,6 +35,8 @@ const VALID_OSS_CONFIG: WebClientConfig = {error_message: null,updated_at: "2024-01-14T10:00:00Z",github_app_slug: null,+ gitlab_enabled: false,+ slack_enabled: false,};const VALID_SAAS_CONFIG: WebClientConfig = {@@ -58,6 +60,8 @@ const VALID_SAAS_CONFIG: WebClientConfig = {error_message: null,updated_at: "2024-01-14T10:00:00Z",github_app_slug: null,+ gitlab_enabled: false,+ slack_enabled: false,};const queryClient = new QueryClient();@@ -268,7 +272,10 @@ describe("Content", () => {it("should render the 'Configure GitHub Repositories' button if SaaS mode and github_app_slug exists", async () => {const getConfigSpy = vi.spyOn(OptionService, "getConfig");+ const getSettingsSpy = vi.spyOn(SettingsService, "getSettings");+getConfigSpy.mockResolvedValue(VALID_OSS_CONFIG);+ getSettingsSpy.mockResolvedValue(MOCK_DEFAULT_USER_SETTINGS);const { rerender } = renderGitSettingsScreen();@@ -283,15 +290,24 @@ describe("Content", () => {rerender();await waitFor(() => {- // wait until queries are resolved- expect(queryClient.isFetching()).toBe(0);button = screen.queryByTestId("configure-github-repositories-button");expect(button).not.toBeInTheDocument();+ expect(screen.queryByTestId("gitlab-status-text")).not.toBeInTheDocument();+ expect(+ screen.queryByTestId("install-slack-app-button"),+ ).not.toBeInTheDocument();+ expect(screen.queryByTestId("submit-button")).not.toBeInTheDocument();+ expect(+ screen.queryByTestId("disconnect-tokens-button"),+ ).not.toBeInTheDocument();});getConfigSpy.mockResolvedValue({...VALID_SAAS_CONFIG,+ providers_configured: ["gitlab"],github_app_slug: "test-slug",+ gitlab_enabled: true,+ slack_enabled: true,});queryClient.invalidateQueries();rerender();@@ -299,6 +315,8 @@ describe("Content", () => {await waitFor(() => {button = screen.getByTestId("configure-github-repositories-button");expect(button).toBeInTheDocument();+ expect(screen.getByTestId("gitlab-status-text")).toBeInTheDocument();+ expect(screen.getByTestId("install-slack-app-button")).toBeInTheDocument();expect(screen.queryByTestId("submit-button")).not.toBeInTheDocument();expect(screen.queryByTestId("disconnect-tokens-button"),@@ -614,10 +632,49 @@ describe("GitLab Webhook Manager Integration", () => {});});- it("should not render GitLab webhook manager in SaaS mode without APP_SLUG", async () => {+ it("should render configured GitLab and Slack sections in SaaS mode without APP_SLUG", async () => {// Arrangeconst getConfigSpy = vi.spyOn(OptionService, "getConfig");+ const getSettingsSpy = vi.spyOn(SettingsService, "getSettings");++ getConfigSpy.mockResolvedValue({+ ...VALID_SAAS_CONFIG,+ providers_configured: ["gitlab"],+ gitlab_enabled: true,+ slack_enabled: true,+ });+ getSettingsSpy.mockResolvedValue({+ ...MOCK_DEFAULT_USER_SETTINGS,+ provider_tokens_set: {},+ });++ // Act+ renderGitSettingsScreen();+ await screen.findByTestId("git-settings-screen");++ // Assert+ await waitFor(() => {+ expect(+ screen.queryByTestId("configure-github-repositories-button"),+ ).not.toBeInTheDocument();+ expect(screen.getByTestId("gitlab-status-text")).toBeInTheDocument();+ expect(screen.getByTestId("install-slack-app-button")).toBeInTheDocument();+ expect(+ screen.queryByText("GITLAB$WEBHOOK_MANAGER_TITLE"),+ ).not.toBeInTheDocument();+ });+ });++ it("should not render GitLab or Slack sections when the backend does not enable them", async () => {+ // Arrange+ const getConfigSpy = vi.spyOn(OptionService, "getConfig");+ const getSettingsSpy = vi.spyOn(SettingsService, "getSettings");+getConfigSpy.mockResolvedValue(VALID_SAAS_CONFIG);+ getSettingsSpy.mockResolvedValue({+ ...MOCK_DEFAULT_USER_SETTINGS,+ provider_tokens_set: {},+ });// ActrenderGitSettingsScreen();@@ -625,19 +682,25 @@ describe("GitLab Webhook Manager Integration", () => {// Assertawait waitFor(() => {+ expect(screen.queryByTestId("gitlab-status-text")).not.toBeInTheDocument();+ expect(+ screen.queryByTestId("install-slack-app-button"),+ ).not.toBeInTheDocument();expect(screen.queryByText("GITLAB$WEBHOOK_MANAGER_TITLE"),).not.toBeInTheDocument();});});- it("should not render GitLab webhook manager when token is not set", async () => {+ it("should not render GitLab webhook manager when the token is not set", async () => {// Arrangeconst getConfigSpy = vi.spyOn(OptionService, "getConfig");const getSettingsSpy = vi.spyOn(SettingsService, "getSettings");getConfigSpy.mockResolvedValue({...VALID_SAAS_CONFIG,+ providers_configured: ["gitlab"],+ gitlab_enabled: true,});getSettingsSpy.mockResolvedValue({...MOCK_DEFAULT_USER_SETTINGS,@@ -650,6 +713,7 @@ describe("GitLab Webhook Manager Integration", () => {// Assertawait waitFor(() => {+ expect(screen.getByTestId("gitlab-status-text")).toBeInTheDocument();expect(screen.queryByText("GITLAB$WEBHOOK_MANAGER_TITLE"),).not.toBeInTheDocument();diff --git a/frontend/src/api/option-service/option.types.ts b/frontend/src/api/option-service/option.types.tsindex d9440eda27..fa93a249ca 100644--- a/frontend/src/api/option-service/option.types.ts+++ b/frontend/src/api/option-service/option.types.ts@@ -43,4 +43,6 @@ export interface WebClientConfig {error_message: string | null;updated_at: string;github_app_slug: string | null;+ gitlab_enabled?: boolean;+ slack_enabled?: boolean;}diff --git a/frontend/src/mocks/settings-handlers.ts b/frontend/src/mocks/settings-handlers.tsindex 10cc432fe4..76197fa960 100644--- a/frontend/src/mocks/settings-handlers.ts+++ b/frontend/src/mocks/settings-handlers.ts@@ -62,6 +62,8 @@ export const createMockWebClientConfig = (error_message: null,updated_at: new Date().toISOString(),github_app_slug: null,+ gitlab_enabled: false,+ slack_enabled: false,...overrides,});@@ -425,6 +427,8 @@ export const SETTINGS_HANDLERS = [error_message: null,updated_at: new Date().toISOString(),github_app_slug: mockSaas ? "openhands" : null,+ gitlab_enabled: false,+ slack_enabled: false,};return HttpResponse.json(config);diff --git a/frontend/src/routes/git-settings.tsx b/frontend/src/routes/git-settings.tsxindex 7061dbe303..53212f647f 100644--- a/frontend/src/routes/git-settings.tsx+++ b/frontend/src/routes/git-settings.tsx@@ -181,8 +181,9 @@ function GitSettingsScreen() {!bitbucketDCHostInputHasValue &&!azureDevOpsHostInputHasValue &&!forgejoHostInputHasValue;- const shouldRenderExternalConfigureButtons =- isSaas && config?.github_app_slug;+ const shouldRenderGitHubConfigureButton = isSaas && config?.github_app_slug;+ const shouldRenderGitLabSection = isSaas && Boolean(config?.gitlab_enabled);+ const shouldRenderSlackSection = isSaas && Boolean(config?.slack_enabled);const shouldRenderProjectManagementIntegrations =config?.feature_flags?.enable_jira ||config?.feature_flags?.enable_jira_dc ||@@ -196,7 +197,7 @@ function GitSettingsScreen() {>{!isLoading && (<div className="flex flex-col">- {shouldRenderExternalConfigureButtons && !isLoading && (+ {shouldRenderGitHubConfigureButton && (<><div className="pb-1 flex flex-col"><h3 className="text-xl font-medium text-white">@@ -210,7 +211,7 @@ function GitSettingsScreen() {</>)}- {shouldRenderExternalConfigureButtons && !isLoading && (+ {shouldRenderGitLabSection && (<><div className="mt-6 flex flex-col gap-4 pb-8"><Typography.H3 className="text-xl">@@ -237,7 +238,7 @@ function GitSettingsScreen() {</>)}- {shouldRenderExternalConfigureButtons && !isLoading && (+ {shouldRenderSlackSection && (<><div className="pb-1 mt-6 flex flex-col"><h3 className="text-xl font-medium text-white">@@ -346,7 +347,7 @@ function GitSettingsScreen() {{isLoading && <GitSettingInputsSkeleton />}<div className="flex gap-6 p-6 justify-end">- {!shouldRenderExternalConfigureButtons && (+ {!isSaas && (<><BrandButtontestId="disconnect-tokens-button"diff --git a/openhands/app_server/web_client/default_web_client_config_injector.py b/openhands/app_server/web_client/default_web_client_config_injector.pyindex fe91d9fae0..2c78fa37bc 100644--- a/openhands/app_server/web_client/default_web_client_config_injector.py+++ b/openhands/app_server/web_client/default_web_client_config_injector.py@@ -58,6 +58,11 @@ def _get_maintenance_start_time() -> datetime | None:return None+def _is_gitlab_enabled() -> bool:+ """Return whether GitLab OAuth is configured for the web client."""+ return bool(os.getenv('GITLAB_APP_CLIENT_ID', '').strip())++def _get_providers_configured() -> list[ProviderType]:"""Get configured OAuth providers from environment variables.@@ -69,7 +74,7 @@ def _get_providers_configured() -> list[ProviderType]:if os.getenv('GITHUB_APP_CLIENT_ID', '').strip():providers.append(ProviderType.GITHUB)- if os.getenv('GITLAB_APP_CLIENT_ID', '').strip():+ if _is_gitlab_enabled():providers.append(ProviderType.GITLAB)if os.getenv('BITBUCKET_APP_CLIENT_ID', '').strip():@@ -91,6 +96,16 @@ def _get_github_app_slug() -> str | None:return slug if slug else None+def _get_slack_enabled() -> bool:+ """Return whether Slack integration is fully configured for the web client."""+ return (+ os.getenv('SLACK_WEBHOOKS_ENABLED', 'false').lower() == 'true'+ and bool(os.getenv('SLACK_CLIENT_ID', '').strip())+ and bool(os.getenv('SLACK_CLIENT_SECRET', '').strip())+ and bool(os.getenv('SLACK_SIGNING_SECRET', '').strip())+ )++def _get_feature_flags() -> WebClientFeatureFlags:"""Get feature flags from environment variables.@@ -133,6 +148,8 @@ class DefaultWebClientConfigInjector(WebClientConfigInjector):),)github_app_slug: str | None = Field(default_factory=_get_github_app_slug)+ gitlab_enabled: bool = Field(default_factory=_is_gitlab_enabled)+ slack_enabled: bool = Field(default_factory=_get_slack_enabled)async def get_web_client_config(self) -> WebClientConfig:from openhands.app_server.config import get_global_config@@ -150,5 +167,7 @@ class DefaultWebClientConfigInjector(WebClientConfigInjector):error_message=self.error_message,updated_at=self.updated_at,github_app_slug=self.github_app_slug,+ gitlab_enabled=self.gitlab_enabled,+ slack_enabled=self.slack_enabled,)return resultdiff --git a/openhands/app_server/web_client/web_client_models.py b/openhands/app_server/web_client/web_client_models.pyindex bcb57df4b1..ddb4fc53ae 100644--- a/openhands/app_server/web_client/web_client_models.py+++ b/openhands/app_server/web_client/web_client_models.py@@ -42,3 +42,5 @@ class WebClientConfig(DiscriminatedUnionMixin):error_message: str | Noneupdated_at: datetimegithub_app_slug: str | None+ gitlab_enabled: bool = False+ slack_enabled: bool = Falsediff --git a/tests/unit/app_server/test_default_web_client_config_injector.py b/tests/unit/app_server/test_default_web_client_config_injector.pyindex 1530d69eaf..fd037f8fd6 100644--- a/tests/unit/app_server/test_default_web_client_config_injector.py+++ b/tests/unit/app_server/test_default_web_client_config_injector.py@@ -466,3 +466,92 @@ class TestGetGithubAppSlug:with patch.dict(os.environ, {'GITHUB_APP_SLUG': ' '}):result = _get_github_app_slug()assert result is None+++class TestIsGitlabEnabled:+ """Test cases for _is_gitlab_enabled helper function."""++ def test_returns_true_when_gitlab_client_id_is_set(self):+ """GitLab is enabled when its OAuth client ID is configured."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _is_gitlab_enabled,+ )++ with patch.dict(os.environ, {'GITLAB_APP_CLIENT_ID': 'gitlab-client-id'}):+ assert _is_gitlab_enabled() is True++ def test_returns_false_when_gitlab_client_id_is_missing(self):+ """GitLab stays disabled when its OAuth client ID is absent."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _is_gitlab_enabled,+ )++ with patch.dict(os.environ, {}, clear=True):+ assert _is_gitlab_enabled() is False++ def test_returns_false_when_gitlab_client_id_is_whitespace(self):+ """GitLab stays disabled when its OAuth client ID is blank."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _is_gitlab_enabled,+ )++ with patch.dict(os.environ, {'GITLAB_APP_CLIENT_ID': ' '}):+ assert _is_gitlab_enabled() is False+++class TestGetSlackEnabled:+ """Test cases for _get_slack_enabled helper function."""++ def test_returns_true_when_all_slack_env_vars_are_configured(self):+ """Slack is enabled only when all required env vars are configured."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _get_slack_enabled,+ )++ with patch.dict(+ os.environ,+ {+ 'SLACK_WEBHOOKS_ENABLED': 'true',+ 'SLACK_CLIENT_ID': 'client-id',+ 'SLACK_CLIENT_SECRET': 'client-secret',+ 'SLACK_SIGNING_SECRET': 'signing-secret',+ },+ clear=True,+ ):+ assert _get_slack_enabled() is True++ def test_returns_false_when_webhooks_are_disabled(self):+ """Slack stays disabled when the webhook feature flag is off."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _get_slack_enabled,+ )++ with patch.dict(+ os.environ,+ {+ 'SLACK_WEBHOOKS_ENABLED': 'false',+ 'SLACK_CLIENT_ID': 'client-id',+ 'SLACK_CLIENT_SECRET': 'client-secret',+ 'SLACK_SIGNING_SECRET': 'signing-secret',+ },+ clear=True,+ ):+ assert _get_slack_enabled() is False++ def test_returns_false_when_a_required_slack_secret_is_missing(self):+ """Slack stays disabled when one of the required credentials is missing."""+ from openhands.app_server.web_client.default_web_client_config_injector import (+ _get_slack_enabled,+ )++ with patch.dict(+ os.environ,+ {+ 'SLACK_WEBHOOKS_ENABLED': 'true',+ 'SLACK_CLIENT_ID': 'client-id',+ 'SLACK_CLIENT_SECRET': '',+ 'SLACK_SIGNING_SECRET': 'signing-secret',+ },+ clear=True,+ ):+ assert _get_slack_enabled() is False