From 8df24e61037062ef37485c487ccc2bda8fbdfc30 Mon Sep 17 00:00:00 2001 From: Matt Rubens <2600+mrubens@users.noreply.github.com> Date: Tue, 14 Jul 2026 16:00:11 +0000 Subject: [PATCH] [Improve] Default homepage to the sole environment instead of Auto --- .../SelectEnvironmentOrRepository.test.tsx | 80 ++++++++++++++++++- .../tasks/SelectEnvironmentOrRepository.tsx | 8 +- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/tasks/SelectEnvironmentOrRepository.test.tsx b/apps/web/src/components/tasks/SelectEnvironmentOrRepository.test.tsx index bae8a5e2e..cb4f1dfc0 100644 --- a/apps/web/src/components/tasks/SelectEnvironmentOrRepository.test.tsx +++ b/apps/web/src/components/tasks/SelectEnvironmentOrRepository.test.tsx @@ -4,6 +4,7 @@ import { render, waitFor } from '@testing-library/react'; import type { CreateTaskFormValues } from '@/types'; +import { AUTO_WORKSPACE_VALUE } from './constants'; import { SelectEnvironmentOrRepository } from './SelectEnvironmentOrRepository'; vi.mock('@/hooks/environments', () => ({ @@ -106,10 +107,12 @@ const WorkspaceValuesProbe = ({ const SelectEnvironmentOrRepositoryHarness = ({ allowAuto = false, + repositoryFilter = REPOSITORY, defaultValues, onValuesChange, }: { allowAuto?: boolean; + repositoryFilter?: string; defaultValues: Partial; onValuesChange: (values: WorkspaceSelectionValues) => void; }) => { @@ -124,7 +127,7 @@ const SelectEnvironmentOrRepositoryHarness = ({ { expect(setWorkspace).not.toHaveBeenCalled(); }); + it('defaults Auto mode to the sole environment when only one is configured', async () => { + let latestValues: WorkspaceSelectionValues | undefined; + + render( + { + latestValues = values; + }} + />, + ); + + await waitFor(() => { + expect(latestValues?.environmentId).toBe('env_123'); + }); + + expect(latestValues).toMatchObject({ + environmentId: 'env_123', + repository: 'env_123', + branch: '', + }); + expect(setWorkspace).toHaveBeenCalledWith({ + workspace: { type: 'environment', id: 'env_123' }, + }); + }); + + it('keeps Auto when multiple environments are configured', async () => { + let latestValues: WorkspaceSelectionValues | undefined; + + mockedUseEnvironments.mockReturnValue({ + data: [ + { + id: 'env_123', + name: 'Alpha', + config: { + repositories: [{ repository: REPOSITORY }], + }, + }, + { + id: 'env_456', + name: 'Beta', + config: { + repositories: [{ repository: REPOSITORY }], + }, + }, + ], + isPending: false, + isSuccess: true, + } as ReturnType); + + render( + { + latestValues = values; + }} + />, + ); + + await waitFor(() => { + expect(latestValues?.repository).toBe(AUTO_WORKSPACE_VALUE); + }); + + expect(latestValues).toMatchObject({ + environmentId: undefined, + repository: AUTO_WORKSPACE_VALUE, + branch: '', + }); + expect(setWorkspace).not.toHaveBeenCalled(); + }); + it('renders Auto in its own section below All Repositories', async () => { mockedUseAuthorizedUser.mockReturnValue({ isAdmin: true, diff --git a/apps/web/src/components/tasks/SelectEnvironmentOrRepository.tsx b/apps/web/src/components/tasks/SelectEnvironmentOrRepository.tsx index 7030222c6..de2fb60b2 100644 --- a/apps/web/src/components/tasks/SelectEnvironmentOrRepository.tsx +++ b/apps/web/src/components/tasks/SelectEnvironmentOrRepository.tsx @@ -116,7 +116,13 @@ export const SelectEnvironmentOrRepository = ({ return; } - if (allowAuto && repository) { + // Keep non-Auto allowAuto selections. When homepage starts on Auto with + // exactly one environment, fall through and default to that environment. + if ( + allowAuto && + repository && + (repository !== AUTO_WORKSPACE_VALUE || sortedEnvironments.length !== 1) + ) { setHasAppliedDefaultWorkspace(true); return; }