Repository navigation
fix(mobile): retain requested PR environment while connecting #24262
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
447ebd2
fix(mobile): retain requested PR environment while connecting
juliusmarminge 6c78970
test(mobile): retain PR target before project hydration
juliusmarminge 521ca7c
test(mobile): reduce PR environment fallback coverage
juliusmarminge 3d2f195
refactor(mobile): consolidate PR target retention
juliusmarminge 7b8a19c
merge main into mobile PR environment fallback
juliusmarminge b5f5136
merge main into mobile PR environment fallback
juliusmarminge 2d66c44
merge main into mobile PR environment fallback
juliusmarminge 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
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
143 changes: 143 additions & 0 deletions
143
apps/mobile/src/features/pull-requests/usePullRequestEnvironmentFallback.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,143 @@ | ||
| import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection"; | ||
| import type { EnvironmentProject } from "@t3tools/client-runtime/state/models"; | ||
| import { EnvironmentId } from "@t3tools/contracts"; | ||
| import { act, useEffect, useState } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import type { WorkspaceEnvironment } from "../../state/workspaceModel"; | ||
| import type { PullRequestEnvironmentTarget } from "./pullRequestEnvironmentFallback"; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| environments: [] as ReadonlyArray<WorkspaceEnvironment>, | ||
| isReady: true, | ||
| projects: [] as ReadonlyArray<EnvironmentProject>, | ||
| navigation: { setParams: vi.fn<(params: Partial<PullRequestEnvironmentTarget>) => void>() }, | ||
| })); | ||
|
|
||
| vi.mock("@react-navigation/native", () => ({ useNavigation: () => mocks.navigation })); | ||
| vi.mock("../../state/entities", () => ({ useProjects: () => mocks.projects })); | ||
| vi.mock("../../state/workspace", () => ({ | ||
| useWorkspaceEnvironments: () => mocks.environments, | ||
| useConnectionsReady: () => mocks.isReady, | ||
| })); | ||
|
|
||
| import { usePullRequestEnvironmentFallback } from "./usePullRequestEnvironmentFallback"; | ||
|
|
||
| function environment( | ||
| environmentId: string, | ||
| connectionState: EnvironmentConnectionPhase, | ||
| isEnabled = true, | ||
| ): WorkspaceEnvironment { | ||
| return { | ||
| environmentId: EnvironmentId.make(environmentId), | ||
| environmentLabel: environmentId, | ||
| displayUrl: "", | ||
| isRelayManaged: false, | ||
| isEnabled, | ||
| connectionState, | ||
| connectionError: null, | ||
| connectionErrorTraceId: null, | ||
| }; | ||
| } | ||
|
|
||
| function setup() { | ||
| (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; | ||
| mocks.isReady = true; | ||
| mocks.environments = [environment("requested", "connecting"), environment("copy", "connected")]; | ||
| mocks.projects = [ | ||
| { environmentId: "requested", id: "original" }, | ||
| { environmentId: "copy", id: "copy-project" }, | ||
| ].map( | ||
| (project) => | ||
| ({ | ||
| ...project, | ||
| repositoryIdentity: { canonicalKey: "github.com/owner/repo" }, | ||
| }) as unknown as EnvironmentProject, | ||
| ); | ||
| const container = document.createElement("div"); | ||
| const root = createRoot(container); | ||
| mocks.navigation.setParams = vi.fn(); | ||
| function Probe() { | ||
| const [params, updateParams] = useState({ | ||
| environmentId: "requested", | ||
| projectId: "original", | ||
| repository: "owner/repo", | ||
| host: "github.com", | ||
| }); | ||
| useEffect(() => { | ||
| mocks.navigation.setParams.mockImplementation((next) => | ||
| updateParams((previous) => ({ ...previous, ...next })), | ||
| ); | ||
| }, []); | ||
| usePullRequestEnvironmentFallback(params); | ||
| return <span>{`${params.environmentId}/${params.projectId}`}</span>; | ||
| } | ||
| return { | ||
| render() { | ||
| act(() => root.render(<Probe />)); | ||
| }, | ||
| get target() { | ||
| return container.textContent; | ||
| }, | ||
| [Symbol.dispose]() { | ||
| act(() => root.unmount()); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| it("keeps the requested target while the catalog initializes or its enabled connection is pending", () => { | ||
| using screen = setup(); | ||
| mocks.isReady = false; | ||
| mocks.environments = [environment("copy", "connected")]; | ||
| screen.render(); | ||
| expect(screen.target).toBe("requested/original"); | ||
| expect(mocks.navigation.setParams).not.toHaveBeenCalled(); | ||
|
|
||
| mocks.isReady = true; | ||
| for (const phase of ["available", "connecting", "reconnecting", "connected"] as const) { | ||
| mocks.environments = [environment("requested", phase), environment("copy", "connected")]; | ||
| screen.render(); | ||
| expect(screen.target).toBe("requested/original"); | ||
| expect(mocks.navigation.setParams).not.toHaveBeenCalled(); | ||
| } | ||
| }); | ||
|
|
||
| it("falls back to a connected repository copy when the requested environment cannot connect", () => { | ||
| for (const state of ["missing", "disabled", "offline", "error", "unsupported"] as const) { | ||
| using screen = setup(); | ||
| mocks.environments = [ | ||
| ...(state === "missing" | ||
| ? [] | ||
| : [ | ||
| environment( | ||
| "requested", | ||
| state === "disabled" ? "available" : state, | ||
| state !== "disabled", | ||
| ), | ||
| ]), | ||
| environment("copy", "connected"), | ||
| ]; | ||
| screen.render(); | ||
| expect(screen.target).toBe("copy/copy-project"); | ||
| expect(mocks.navigation.setParams).toHaveBeenCalledExactlyOnceWith({ | ||
| environmentId: "copy", | ||
| projectId: "copy-project", | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| it("does not replace a connecting target with a connected repository copy before its project hydrates", () => { | ||
| using screen = setup(); | ||
| const projects = mocks.projects; | ||
| mocks.projects = projects.filter((project) => project.environmentId !== "requested"); | ||
| screen.render(); | ||
| expect(screen.target).toBe("requested/original"); | ||
| expect(mocks.navigation.setParams).not.toHaveBeenCalled(); | ||
|
|
||
| mocks.projects = projects; | ||
| mocks.environments = [environment("requested", "connected"), environment("copy", "connected")]; | ||
| screen.render(); | ||
| expect(screen.target).toBe("requested/original"); | ||
| expect(mocks.navigation.setParams).not.toHaveBeenCalled(); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 5668
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 41675
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 33380
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 41717
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 41192
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 41663
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 20352
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 16639
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 4647
Check the target project before retaining a connecting environment.
When the requested project is absent from
projects, the new early return can retain stale route parameters while an enabled environment isconnectingorreconnecting. The route then does not callnavigation.setParams, so it cannot switch to an eligible connected copy.PullRequestService.detailrequires the missing project and can fail before contacting the provider.Suggested fix
const requested = environments.find( (environment) => environment.environmentId === target.environmentId, ); + const own = projects.find( + (project) => project.environmentId === target.environmentId && project.id === target.projectId, + ); // Available is also the initial state before the connection supervisor starts. if ( + own !== undefined && requested?.isEnabled && (requested.connectionState === "available" || requested.connectionState === "connecting" || requested.connectionState === "reconnecting") ) return null; @@ - const own = projects.find( - (project) => project.environmentId === target.environmentId && project.id === target.projectId, - ); const host = target.host ?? own?.repositoryIdentity?.canonicalKey.split("/")[0];🤖 Prompt for AI Agents