Skip to content
TypeScript

test: remove stale tests for unused thread and onboarding helpers (#30817)

t3-code-bot[bot]c72de5249a27
diff --git a/apps/mobile/src/state/use-selected-thread-worktree.test.ts b/apps/mobile/src/state/use-selected-thread-worktree.test.ts
deleted file mode 100644
index 70577dbcb9d..00000000000
--- a/apps/mobile/src/state/use-selected-thread-worktree.test.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
-import { describe, expect, it, vi } from "vite-plus/test";
-
-const state = vi.hoisted(() => ({
- shell: null as { projectId: string; worktreePath: string | null } | null,
- detail: null as { thread: { projectId: string } } | null,
- detailWorktreePath: null as string | null,
- projects: new Map<string, { workspaceRoot: string }>(),
-}));
-
-vi.mock("./entities", () => ({
- useQuietThreadShell: (ref: unknown) => (ref === null ? null : state.shell),
- useProject: (ref: { projectId: string } | null) =>
- ref === null ? null : (state.projects.get(ref.projectId) ?? null),
-}));
-vi.mock("./threads", async () => {
- const { some, none } = await import("effect/Option");
- return {
- useEnvironmentThread: (environmentId: unknown, threadId: unknown) => ({
- data:
- environmentId !== null && threadId !== null && state.detail ? some(state.detail) : none(),
- }),
- };
-});
-vi.mock("./use-thread-detail", () => ({
- useThreadWorktreePath: (ref: unknown) => (ref === null ? null : state.detailWorktreePath),
- useSelectedThreadWorktreePath: () => null,
-}));
-vi.mock("./use-thread-selection", () => ({ useThreadSelection: () => ({}) }));
-
-const { useThreadCwd } = await import("./use-selected-thread-worktree");
-
-const ref = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
-
-function setup(input: Partial<Omit<typeof state, "projects">>) {
- Object.assign(state, { shell: null, detail: null, detailWorktreePath: null }, input);
- state.projects = new Map([[ProjectId.make("project"), { workspaceRoot: "/repo" }]]);
-}
-
-describe("useThreadCwd", () => {
- it("falls back to the project root from the loaded detail when the shell is missing", () => {
- setup({ detail: { thread: { projectId: "project" } } });
- expect(useThreadCwd(ref)).toBe("/repo");
- });
-
- it("prefers the thread worktree over the project root", () => {
- setup({ shell: { projectId: "project", worktreePath: "/repo/.worktrees/a" } });
- expect(useThreadCwd(ref)).toBe("/repo/.worktrees/a");
- });
-
- it("is null without a thread", () => {
- setup({ detail: { thread: { projectId: "project" } } });
- expect(useThreadCwd(null)).toBeNull();
- });
-});
diff --git a/apps/mobile/src/state/use-selected-thread-worktree.ts b/apps/mobile/src/state/use-selected-thread-worktree.ts
index aeec00a9ff4..74d45cc83f8 100644
--- a/apps/mobile/src/state/use-selected-thread-worktree.ts
+++ b/apps/mobile/src/state/use-selected-thread-worktree.ts
@@ -1,9 +1,4 @@
-import type { ScopedThreadRef } from "@t3tools/contracts";
-import * as Option from "effect/Option";
-
-import { useProject, useQuietThreadShell } from "./entities";
-import { useEnvironmentThread } from "./threads";
-import { useSelectedThreadWorktreePath, useThreadWorktreePath } from "./use-thread-detail";
+import { useSelectedThreadWorktreePath } from "./use-thread-detail";
import { useThreadSelection } from "./use-thread-selection";
import { resolvePreferredThreadWorktreePath } from "../features/terminal/terminalLaunchContext";
@@ -21,29 +16,3 @@ export function useSelectedThreadWorktree() {
selectedThreadCwd: selectedThreadWorktreePath ?? selectedThreadProject?.workspaceRoot ?? null,
};
}
-
-/**
- * Resolves a thread's cwd the way the selected thread's does, for a thread that is not the
- * current route's: the shell, or the loaded detail when the shell is missing, picks the project.
- */
-export function useThreadCwd(ref: ScopedThreadRef | null): string | null {
- const shell = useQuietThreadShell(ref);
- const detailState = useEnvironmentThread(
- shell === null ? (ref?.environmentId ?? null) : null,
- shell === null ? (ref?.threadId ?? null) : null,
- );
- const detailThread = Option.getOrNull(detailState.data)?.thread ?? null;
- const detailWorktreePath = useThreadWorktreePath(ref);
- const projectId = shell?.projectId ?? detailThread?.projectId ?? null;
- const project = useProject(
- ref === null || projectId === null ? null : { environmentId: ref.environmentId, projectId },
- );
- return (
- resolvePreferredThreadWorktreePath({
- threadShellWorktreePath: shell?.worktreePath ?? null,
- threadDetailWorktreePath: detailWorktreePath,
- }) ??
- project?.workspaceRoot ??
- null
- );
-}
diff --git a/apps/web/src/onboarding/targetEnvironment.logic.test.ts b/apps/web/src/onboarding/targetEnvironment.logic.test.ts
index b98318402f8..3a882ff92fb 100644
--- a/apps/web/src/onboarding/targetEnvironment.logic.test.ts
+++ b/apps/web/src/onboarding/targetEnvironment.logic.test.ts
@@ -1,171 +1,7 @@
-import {
- BearerConnectionTarget,
- PrimaryConnectionTarget,
- RelayConnectionTarget,
- SshConnectionTarget,
-} from "@t3tools/client-runtime/connection";
import { EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
-import {
- resolveOnboardingSetup,
- resolveOnboardingTargetEnvironment,
-} from "./targetEnvironment.logic";
-
-const primaryEnvironment = {
- environmentId: EnvironmentId.make("primary"),
- connection: { phase: "connected" },
- entry: {
- target: new PrimaryConnectionTarget({
- environmentId: EnvironmentId.make("primary"),
- label: "This computer",
- httpBaseUrl: "http://127.0.0.1:3773",
- wsBaseUrl: "ws://127.0.0.1:3773",
- }),
- },
- label: "This computer",
-} as const;
-
-const olderRelay = {
- environmentId: EnvironmentId.make("older-remote"),
- connection: { phase: "connected" },
- entry: {
- target: new RelayConnectionTarget({
- environmentId: EnvironmentId.make("older-remote"),
- label: "Older computer",
- }),
- },
- label: "Older computer",
-} as const;
-
-const newerRelay = {
- environmentId: EnvironmentId.make("newer-relay"),
- connection: { phase: "connected" },
- entry: {
- target: new RelayConnectionTarget({
- environmentId: EnvironmentId.make("newer-relay"),
- label: "New computer",
- }),
- },
- label: "New computer",
-} as const;
-
-const pairedRemote = {
- environmentId: EnvironmentId.make("paired-remote"),
- connection: { phase: "connected" },
- entry: {
- target: new BearerConnectionTarget({
- environmentId: EnvironmentId.make("paired-remote"),
- label: "Direct computer",
- connectionId: "paired-remote",
- }),
- },
- label: "Direct computer",
-} as const;
-
-const sshEnvironment = {
- environmentId: EnvironmentId.make("ssh-remote"),
- connection: { phase: "connected" },
- entry: {
- target: new SshConnectionTarget({
- environmentId: EnvironmentId.make("ssh-remote"),
- label: "SSH computer",
- connectionId: "ssh-remote",
- }),
- },
- label: "SSH computer",
-} as const;
-
-const desktopLocalEnvironment = {
- environmentId: EnvironmentId.make("desktop-local-wsl"),
- connection: { phase: "connected" },
- entry: {
- target: new BearerConnectionTarget({
- environmentId: EnvironmentId.make("desktop-local-wsl"),
- label: "WSL",
- connectionId: "local:wsl:Ubuntu",
- }),
- },
- label: "WSL",
-} as const;
-
-describe("resolveOnboardingTargetEnvironment", () => {
- it("waits for the exact paired machine instead of using an older connected machine", () => {
- const pendingPairedRemote = { ...pairedRemote, connection: { phase: "connecting" } };
-
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "direct",
- environments: [primaryEnvironment, olderRelay, pendingPairedRemote],
- primaryEnvironment,
- pairedEnvironmentId: pairedRemote.environmentId,
- }),
- ).toBeNull();
- });
-
- it("uses the exact paired machine once it connects", () => {
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "direct",
- environments: [primaryEnvironment, olderRelay, pairedRemote],
- primaryEnvironment,
- pairedEnvironmentId: pairedRemote.environmentId,
- }),
- ).toBe(pairedRemote);
- });
-
- it("does not substitute a remote machine when the local primary is offline", () => {
- const offlinePrimary = { ...primaryEnvironment, connection: { phase: "disconnected" } };
-
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "local",
- environments: [offlinePrimary, olderRelay],
- primaryEnvironment: offlinePrimary,
- pairedEnvironmentId: null,
- }),
- ).toBeNull();
- });
-
- it("uses the newest connected remote when no exact machine was selected", () => {
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "connect",
- environments: [primaryEnvironment, olderRelay, newerRelay],
- primaryEnvironment,
- pairedEnvironmentId: null,
- }),
- ).toBe(newerRelay);
- });
-
- it("ignores direct, SSH, and desktop-managed connections in Connect mode", () => {
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "connect",
- environments: [
- primaryEnvironment,
- olderRelay,
- pairedRemote,
- sshEnvironment,
- desktopLocalEnvironment,
- ],
- primaryEnvironment,
- pairedEnvironmentId: null,
- }),
- ).toBe(olderRelay);
- });
-
- it("uses the primary computer when no relay connection exists", () => {
- expect(
- resolveOnboardingTargetEnvironment({
- mode: "connect",
- environments: [primaryEnvironment, pairedRemote, sshEnvironment, desktopLocalEnvironment],
- primaryEnvironment,
- pairedEnvironmentId: null,
- }),
- ).toBe(primaryEnvironment);
- });
-});
+import { resolveOnboardingSetup } from "./targetEnvironment.logic";
describe("resolveOnboardingSetup", () => {
const computer = (id: string, phase: string) => ({
diff --git a/apps/web/src/onboarding/targetEnvironment.logic.ts b/apps/web/src/onboarding/targetEnvironment.logic.ts
index 3995d4f2f3d..a217018dbb6 100644
--- a/apps/web/src/onboarding/targetEnvironment.logic.ts
+++ b/apps/web/src/onboarding/targetEnvironment.logic.ts
@@ -13,40 +13,6 @@ export function isOnboardingRelayEnvironment(
return hasRelayRoute(environment.entry);
}
-export function resolveOnboardingTargetEnvironment<TEnvironment extends OnboardingEnvironment>({
- mode,
- environments,
- primaryEnvironment,
- pairedEnvironmentId,
-}: {
- readonly mode: "local" | "connect" | "direct";
- readonly environments: ReadonlyArray<TEnvironment>;
- readonly primaryEnvironment: TEnvironment | null;
- readonly pairedEnvironmentId: EnvironmentId | null;
-}): TEnvironment | null {
- if (mode === "direct" && pairedEnvironmentId !== null) {
- const pairedEnvironment = environments.find(
- (environment) => environment.environmentId === pairedEnvironmentId,
- );
- return pairedEnvironment?.connection.phase === "connected" ? pairedEnvironment : null;
- }
-
- const connectedRelayEnvironments = environments.filter(
- (environment) =>
- environment.connection.phase === "connected" && isOnboardingRelayEnvironment(environment),
- );
-
- if (mode === "connect" && connectedRelayEnvironments.length > 0) {
- return connectedRelayEnvironments[connectedRelayEnvironments.length - 1] ?? null;
- }
-
- if (primaryEnvironment?.connection.phase === "connected") {
- return primaryEnvironment;
- }
-
- return mode === "local" ? null : (connectedRelayEnvironments[0] ?? null);
-}
-
/** Waits only for first connection attempts; offline, failing, or unsupported computers cannot block setup. */
export function resolveOnboardingSetup(
environments: ReadonlyArray<Pick<OnboardingEnvironment, "environmentId" | "connection">>,