Repository navigation
fix(web): Restore device defaults resets server settings even after picking a project on another settings page #32729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
only21mil
wants to merge
5
commits into
pingdotgg:main
from
only21mil:fix/web-restore-defaults-scope
+214
−3
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96c02f2
fix(web): Restore device defaults resets server settings even after p…
only21mil 4fc3bda
test(web): Restore defaults test starts from default client settings
only21mil 4f05033
fix(web): Restore defaults lists settings changed on any environment
only21mil 26306e0
Merge branch 'main' into fix/web-restore-defaults-scope
only21mil 950d207
Merge branch 'main' into fix/web-restore-defaults-scope
only21mil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
apps/web/src/components/settings/SettingsRestore.browser.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import { RegistryContext } from "@effect/atom-react"; | ||
| import { | ||
| DEFAULT_SERVER_SETTINGS, | ||
| EnvironmentId, | ||
| ProjectId, | ||
| type ServerSettings, | ||
| } from "@t3tools/contracts"; | ||
| import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; | ||
| import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; | ||
| import { AsyncResult } from "effect/reactivity"; | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
| import { userEvent } from "vite-plus/test/browser"; | ||
|
|
||
| import { render } from "../../../test/render"; | ||
| import type { Project } from "../../types"; | ||
|
|
||
| const state = vi.hoisted(() => ({ | ||
| projects: [] as Project[], | ||
| environments: [] as unknown[], | ||
| updateSettings: | ||
| vi.fn< | ||
| (request: { | ||
| environmentId: unknown; | ||
| input: { patch: Record<string, unknown> }; | ||
| }) => Promise<unknown> | ||
| >(), | ||
| confirm: vi.fn<() => Promise<boolean>>(), | ||
| })); | ||
|
|
||
| vi.mock(import("~/state/environments"), async (original) => ({ | ||
| ...(await original()), | ||
| useEnvironments: (() => ({ environments: state.environments })) as never, | ||
| usePrimaryEnvironmentId: () => primaryId, | ||
| })); | ||
| vi.mock(import("~/state/entities"), async (original) => ({ | ||
| ...(await original()), | ||
| useProjects: (() => state.projects) as never, | ||
| })); | ||
| vi.mock(import("~/state/use-atom-command"), async (original) => ({ | ||
| ...(await original()), | ||
| useAtomCommand: (() => state.updateSettings) as never, | ||
| })); | ||
| vi.mock(import("~/state/session"), async (original) => ({ | ||
| ...(await original()), | ||
| readEnvironmentScope: () => true, | ||
| })); | ||
| vi.mock(import("~/localApi"), async (original) => ({ | ||
| ...(await original()), | ||
| readLocalApi: (() => ({ dialogs: { confirm: state.confirm } })) as never, | ||
| })); | ||
|
|
||
| import { writeBrowserClientSettings } from "../../clientPersistenceStorage"; | ||
| import { appAtomRegistry } from "../../rpc/atomRegistry"; | ||
| import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping"; | ||
| import { useSettingsRestore } from "./SettingsPanels"; | ||
| import { SettingsScopeProvider } from "./SettingsScopeContext"; | ||
|
|
||
| const primaryId = EnvironmentId.make("primary"); | ||
| const remoteId = EnvironmentId.make("remote"); | ||
| const customized = { | ||
| ...DEFAULT_SERVER_SETTINGS, | ||
| sidebarAutoSettleAfterDays: 30, | ||
| enableProviderUpdateChecks: !DEFAULT_SERVER_SETTINGS.enableProviderUpdateChecks, | ||
| }; | ||
|
|
||
| function setup(primarySettings: ServerSettings) { | ||
| vi.clearAllMocks(); | ||
| // Browser test files share localStorage, and an earlier file may leave client settings changed. | ||
| writeBrowserClientSettings(DEFAULT_CLIENT_SETTINGS); | ||
| state.environments = ( | ||
| [ | ||
| [primaryId, primarySettings], | ||
| [remoteId, customized], | ||
| ] as const | ||
| ).map(([environmentId, settings]) => ({ | ||
| environmentId, | ||
| label: environmentId, | ||
| connection: { phase: "connected" }, | ||
| serverConfig: { | ||
| keybindings: DEFAULT_RESOLVED_KEYBINDINGS, | ||
| settings, | ||
| environment: { platform: { machine: "server" }, capabilities: { projectOrganization: true } }, | ||
| }, | ||
| })); | ||
| state.projects = [primaryId, remoteId].map((environmentId) => ({ | ||
| id: ProjectId.make(`project-${environmentId}`), | ||
| environmentId, | ||
| title: "Shared repo", | ||
| workspaceRoot: `/work/${environmentId}`, | ||
| repositoryIdentity: { | ||
| canonicalKey: "github.com/example/shared-repo", | ||
| locator: { | ||
| source: "git-remote", | ||
| remoteName: "origin", | ||
| remoteUrl: "https://github.com/example/shared-repo.git", | ||
| }, | ||
| }, | ||
| defaultModelSelection: null, | ||
| createdAt: "2026-01-01T00:00:00.000Z", | ||
| updatedAt: "2026-01-01T00:00:00.000Z", | ||
| scripts: [], | ||
| })); | ||
| state.updateSettings.mockResolvedValue(AsyncResult.success(customized)); | ||
| state.confirm.mockResolvedValue(true); | ||
| return buildSidebarProjectSnapshots({ | ||
| projects: state.projects, | ||
| settings: DEFAULT_CLIENT_SETTINGS, | ||
| primaryEnvironmentId: primaryId, | ||
| resolveEnvironmentLabel: (id) => id, | ||
| })[0]!.projectKey; | ||
| } | ||
|
|
||
| describe("useSettingsRestore", () => { | ||
| it.each([ | ||
| { name: "a project scope", primarySettings: customized, search: "project" }, | ||
| { | ||
| name: "a machine scope, changed only on a remote environment", | ||
| primarySettings: DEFAULT_SERVER_SETTINGS, | ||
| search: "machine", | ||
| }, | ||
| ] as const)("restores every environment's defaults under $name", async (row) => { | ||
| const projectKey = setup(row.primarySettings); | ||
| let restored!: () => void; | ||
| const done = new Promise<void>((resolve) => { | ||
| restored = resolve; | ||
| }); | ||
| function RestoreHarness() { | ||
| const { changedSettingLabels, restoreDefaults } = useSettingsRestore(restored); | ||
| return ( | ||
| <> | ||
| <p data-testid="labels">{changedSettingLabels.join("|")}</p> | ||
| <button type="button" onClick={() => void restoreDefaults()}> | ||
| Restore device defaults | ||
| </button> | ||
| </> | ||
| ); | ||
| } | ||
| await using screen = await render( | ||
| <RegistryContext.Provider value={appAtomRegistry}> | ||
| <SettingsScopeProvider | ||
| search={row.search === "project" ? { project: projectKey } : { machine: remoteId }} | ||
| onChange={() => {}} | ||
| > | ||
| <RestoreHarness /> | ||
| </SettingsScopeProvider> | ||
| </RegistryContext.Provider>, | ||
| ); | ||
|
|
||
| await vi.waitFor(() => | ||
| expect(screen.getByTestId("labels").element().textContent).toBe( | ||
| "Auto-settle inactive threads|Provider update checks", | ||
| ), | ||
| ); | ||
| await userEvent.click(screen.getByRole("button", { name: "Restore device defaults" })); | ||
| await done; | ||
|
|
||
| expect( | ||
| state.updateSettings.mock.calls.map(([request]) => [ | ||
| request.environmentId, | ||
| request.input.patch.sidebarAutoSettleAfterDays, | ||
| request.input.patch.projectSettingsOverrides, | ||
| ]), | ||
| ).toEqual([ | ||
| [primaryId, DEFAULT_SERVER_SETTINGS.sidebarAutoSettleAfterDays, undefined], | ||
| [remoteId, DEFAULT_SERVER_SETTINGS.sidebarAutoSettleAfterDays, undefined], | ||
| ]); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.