GeezerVison is showing github.com — test(mobile): pairing link test runs the app's real link parsing (#26… · pingdotgg/t3code@0deb383
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/App.tsx +5-35Lines changed: 5 additions & 35 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,6 @@ import { | 13 | 13 | createPathConfigForStaticNavigation, | 14 | 14 | createStaticNavigation, | 15 | 15 | getActionFromState, | 16 | | - getStateFromPath, | 17 | 16 | type NavigationAction, | 18 | 17 | type NavigationState, | 19 | 18 | } from "@react-navigation/native"; | @@ -49,22 +48,12 @@ import { subscribeComposerDraftModelReconciliation } from "./state/use-composer- | 49 | 48 | import { environmentThreadShells } from "./state/threads"; | 50 | 49 | import { environmentShell } from "./state/shell"; | 51 | 50 | import { OverlayPortalHost } from "./components/ui/OverlayPortal"; | 52 | | -import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking"; | | 51 | +import { shouldHandleAppLink } from "./lib/appLinking"; | 53 | 52 | import { hasCloudPublicConfig } from "./features/cloud/publicConfig"; | 54 | | -import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state"; | 55 | | -import { | 56 | | - pairingFormLinkAction, | 57 | | - startDevAutoConnect, | 58 | | - withoutPairingTarget, | 59 | | -} from "./features/connection/devAutoConnect"; | 60 | | -import { | 61 | | - resolvePendingNewTaskPromptLink, | 62 | | - takeNewTaskPromptLink, | 63 | | -} from "./features/prompt-links/newTaskPromptLink"; | 64 | | -import { | 65 | | - resolvePendingThreadPromptLink, | 66 | | - takeThreadPromptLink, | 67 | | -} from "./features/prompt-links/threadPromptLink"; | | 53 | +import { pairingFormLinkAction } from "./features/connection/devAutoConnect"; | | 54 | +import { resolvePendingNewTaskPromptLink } from "./features/prompt-links/newTaskPromptLink"; | | 55 | +import { resolvePendingThreadPromptLink } from "./features/prompt-links/threadPromptLink"; | | 56 | +import { getAppStateFromPath } from "./lib/appLinkState"; | 68 | 57 | import { | 69 | 58 | disposeOnFoundationReplace, | 70 | 59 | type FoundationHotModule, | @@ -74,12 +63,10 @@ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarning | 74 | 63 | import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator"; | 75 | 64 | import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage"; | 76 | 65 | import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl"; | 77 | | -import { restoreSettingsLinkState } from "./features/settings/settings-navigation"; | 78 | 66 | import { | 79 | 67 | hydrateWorkspaceSelections, | 80 | 68 | launchWorkspaceURL, | 81 | 69 | recordWorkspaceSelections, | 82 | | - settingsLinkPage, | 83 | 70 | } from "./features/workspace/workspace-selection-store"; | 84 | 71 | import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection"; | 85 | 72 | import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics"; | @@ -107,23 +94,6 @@ const linkingConfig = { | 107 | 94 | screens: createPathConfigForStaticNavigation(RootStack, { initialRouteName: "Home" }) ?? {}, | 108 | 95 | } as const; | 109 | 96 |
| 110 | | -function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) { | 111 | | - return takeScheduledTaskNewLink( | 112 | | - startDevAutoConnect( | 113 | | - withoutPairingTarget( | 114 | | - takeNewTaskPromptLink( | 115 | | - takeThreadPromptLink( | 116 | | - restoreSettingsLinkState( | 117 | | - restoreDraftLinkState(getStateFromPath(path, options), path), | 118 | | - settingsLinkPage(), | 119 | | - ), | 120 | | - ), | 121 | | - ), | 122 | | - ), | 123 | | - ), | 124 | | - ); | 125 | | -} | 126 | | - | 127 | 97 | const appLinking = { | 128 | 98 | prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"], | 129 | 99 | config: { initialRouteName: "Home" }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/connection/devAutoConnect.test.ts -31Lines changed: 0 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,14 +63,12 @@ vi.mock("../../lib/rootNavigation", () => ({ | 63 | 63 | }, | 64 | 64 | })); | 65 | 65 |
| 66 | | -import { findLinkedRoute } from "../../lib/appLinking"; | 67 | 66 | import { appAtomRegistry } from "../../state/atom-registry"; | 68 | 67 | import { | 69 | 68 | autoConnectReport, | 70 | 69 | devAutoConnectAttemptAtom, | 71 | 70 | pairingFormLinkAction, | 72 | 71 | startDevAutoConnect, | 73 | | - withoutPairingTarget, | 74 | 72 | } from "./devAutoConnect"; | 75 | 73 |
| 76 | 74 | const PAIRING_URL = "http://192.168.1.10:3773/pair#token=abc"; | @@ -256,32 +254,3 @@ it("a pairing link fills the pairing form already on screen instead of stacking | 256 | 254 | params: { pairingUrl: PAIRING_URL }, | 257 | 255 | }); | 258 | 256 | }); | 259 | | - | 260 | | -it("a link cannot aim a pairing at a saved environment", () => { | 261 | | - vi.stubGlobal("__DEV__", true); | 262 | | - harness.pair.mockClear(); | 263 | | - harness.pair.mockResolvedValue({ ok: false, error: null }); | 264 | | - const linking = { | 265 | | - initialRouteName: "Home", | 266 | | - screens: { | 267 | | - Home: "", | 268 | | - Settings: { path: "settings", screens: { SettingsEnvironmentNew: "environment-new" } }, | 269 | | - ConnectionsNew: "connections/new", | 270 | | - }, | 271 | | - }; | 272 | | - for (const path of ["connections/new", "settings/environment-new"]) { | 273 | | - const link = withoutPairingTarget( | 274 | | - getStateFromPath( | 275 | | - `${path}?routeFor=victim&pairingUrl=${encodeURIComponent(PAIRING_URL)}&autoConnect=1`, | 276 | | - linking, | 277 | | - ), | 278 | | - ); | 279 | | - expect(findLinkedRoute(link, ["ConnectionsNew", "SettingsEnvironmentNew"])?.params).toEqual({ | 280 | | - pairingUrl: PAIRING_URL, | 281 | | - autoConnect: "1", | 282 | | - }); | 283 | | - | 284 | | - startDevAutoConnect(link); | 285 | | - expect(harness.pair).toHaveBeenLastCalledWith(PAIRING_URL); | 286 | | - } | 287 | | -}); |
Collapse file Copy file name to clipboard +72Lines changed: 72 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as NodeModule from "node:module"; | | 2 | +import { expect, it, vi } from "vite-plus/test"; | | 3 | + | | 4 | +const harness = vi.hoisted(() => { | | 5 | + vi.stubGlobal("__DEV__", true); | | 6 | + return { pair: vi.fn() }; | | 7 | +}); | | 8 | + | | 9 | +// The native package pulls in React Native; its link parsing and actions live in core and routers. | | 10 | +vi.mock("@react-navigation/native", () => { | | 11 | + const requireFromNative = NodeModule.createRequire( | | 12 | + NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"), | | 13 | + ); | | 14 | + const requireFromCore = NodeModule.createRequire( | | 15 | + requireFromNative.resolve("@react-navigation/core/package.json"), | | 16 | + ); | | 17 | + const { getStateFromPath } = requireFromNative("@react-navigation/core"); | | 18 | + const { CommonActions, StackActions } = requireFromCore("@react-navigation/routers"); | | 19 | + return { getStateFromPath, CommonActions, StackActions }; | | 20 | +}); | | 21 | + | | 22 | +vi.mock("./rootNavigation", () => ({ | | 23 | + rootNavigationRef: { isReady: () => false }, | | 24 | + whenRootNavigationReady: () => {}, | | 25 | +})); | | 26 | +vi.mock("../components/ui/Dialog", () => ({ alert: () => {} })); | | 27 | +vi.mock("../features/prompt-links/prompt-link-actions", () => ({})); | | 28 | +// Stores the prompt-link steps read only when a link carries a prompt; they load the native runtime. | | 29 | +vi.mock("../state/projects", () => ({})); | | 30 | +vi.mock("../state/pull-requests", () => ({})); | | 31 | +vi.mock("../state/server", () => ({})); | | 32 | +vi.mock("../state/threads", () => ({})); | | 33 | +vi.mock("../state/use-composer-drafts", () => ({})); | | 34 | +vi.mock("../state/workspace", () => ({})); | | 35 | +vi.mock("../state/use-remote-environment-registry", () => ({ pairEnvironment: harness.pair })); | | 36 | +vi.mock("../features/workspace/workspace-selection-store", () => ({ | | 37 | + settingsLinkPage: () => undefined, | | 38 | + workspaceHasColumns: () => false, | | 39 | +})); | | 40 | + | | 41 | +import { findLinkedRoute } from "./appLinking"; | | 42 | +import { getAppStateFromPath } from "./appLinkState"; | | 43 | + | | 44 | +const PAIRING_URL = "http://192.168.1.10:3773/pair#token=abc"; | | 45 | + | | 46 | +// RootStack imports every screen, which Node cannot load; these are its paths for the pairing form. | | 47 | +const linking = { | | 48 | + initialRouteName: "Home", | | 49 | + screens: { | | 50 | + Home: "", | | 51 | + Settings: "settings", | | 52 | + SettingsEnvironmentNew: "settings/environment-new", | | 53 | + ConnectionsNew: "connections/new", | | 54 | + }, | | 55 | +}; | | 56 | + | | 57 | +it("a link cannot aim a pairing at a saved environment", () => { | | 58 | + harness.pair.mockResolvedValue({ ok: false, error: null }); | | 59 | + for (const path of ["connections/new", "settings/environment-new"]) { | | 60 | + harness.pair.mockClear(); | | 61 | + const state = getAppStateFromPath( | | 62 | + `${path}?routeFor=victim&pairingUrl=${encodeURIComponent(PAIRING_URL)}&autoConnect=1`, | | 63 | + linking, | | 64 | + ); | | 65 | + | | 66 | + expect(findLinkedRoute(state, ["ConnectionsNew", "SettingsEnvironmentNew"])?.params).toEqual({ | | 67 | + pairingUrl: PAIRING_URL, | | 68 | + autoConnect: "1", | | 69 | + }); | | 70 | + expect(harness.pair).toHaveBeenCalledExactlyOnceWith(PAIRING_URL); | | 71 | + } | | 72 | +}); |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { getStateFromPath } from "@react-navigation/native"; | | 2 | + | | 3 | +import { startDevAutoConnect, withoutPairingTarget } from "../features/connection/devAutoConnect"; | | 4 | +import { takeNewTaskPromptLink } from "../features/prompt-links/newTaskPromptLink"; | | 5 | +import { takeThreadPromptLink } from "../features/prompt-links/threadPromptLink"; | | 6 | +import { takeScheduledTaskNewLink } from "../features/settings/scheduled-task-editor-state"; | | 7 | +import { restoreSettingsLinkState } from "../features/settings/settings-navigation"; | | 8 | +import { settingsLinkPage } from "../features/workspace/workspace-selection-store"; | | 9 | +import { restoreDraftLinkState } from "./appLinking"; | | 10 | + | | 11 | +/** Parses an app link into navigation state, taking each link-owned side effect on the way. */ | | 12 | +export function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) { | | 13 | + return takeScheduledTaskNewLink( | | 14 | + startDevAutoConnect( | | 15 | + withoutPairingTarget( | | 16 | + takeNewTaskPromptLink( | | 17 | + takeThreadPromptLink( | | 18 | + restoreSettingsLinkState( | | 19 | + restoreDraftLinkState(getStateFromPath(path, options), path), | | 20 | + settingsLinkPage(), | | 21 | + ), | | 22 | + ), | | 23 | + ), | | 24 | + ), | | 25 | + ), | | 26 | + ); | | 27 | +} |
|