Skip to content

Commit a4404ae

Browse files
fix(mobile): Files reveal resolves the project from loaded thread detail
useThreadCwd picked the project only from the thread shell, so a thread whose shell was missing but whose detail was loaded got no cwd and no reveal, while the Files screen fell back to the project root. It now reads the project from the detail too. A compiler coverage case pins that the inspector registration stays cached on its renderer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3727278 commit a4404ae

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎apps/mobile/src/reactCompilerCoverage.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ describe("React Compiler coverage", () => {
182182
).toEqual([true]);
183183
});
184184

185+
// An uncached registration would re-register the workspace inspector on every render.
186+
it("registers the workspace inspector only when its renderer changes", () => {
187+
expect(
188+
compilerCachedCalls(
189+
"src/features/layout/AdaptiveWorkspaceLayout.tsx",
190+
"registerWorkspaceInspector",
191+
),
192+
).toEqual([true]);
193+
});
194+
185195
it("lists only files that exist", () => {
186196
expect(Object.keys(KNOWN_BAILOUTS).filter((file) => !sourceFiles.includes(file))).toEqual([]);
187197
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
2+
import { describe, expect, it, vi } from "vite-plus/test";
3+
4+
const state = vi.hoisted(() => ({
5+
shell: null as { projectId: string; worktreePath: string | null } | null,
6+
detail: null as { thread: { projectId: string } } | null,
7+
detailWorktreePath: null as string | null,
8+
projects: new Map<string, { workspaceRoot: string }>(),
9+
}));
10+
11+
vi.mock("./entities", () => ({
12+
useQuietThreadShell: (ref: unknown) => (ref === null ? null : state.shell),
13+
useProject: (ref: { projectId: string } | null) =>
14+
ref === null ? null : (state.projects.get(ref.projectId) ?? null),
15+
}));
16+
vi.mock("./threads", async () => {
17+
const { some, none } = await import("effect/Option");
18+
return {
19+
useEnvironmentThread: (environmentId: unknown, threadId: unknown) => ({
20+
data:
21+
environmentId !== null && threadId !== null && state.detail ? some(state.detail) : none(),
22+
}),
23+
};
24+
});
25+
vi.mock("./use-thread-detail", () => ({
26+
useThreadWorktreePath: (ref: unknown) => (ref === null ? null : state.detailWorktreePath),
27+
useSelectedThreadWorktreePath: () => null,
28+
}));
29+
vi.mock("./use-thread-selection", () => ({ useThreadSelection: () => ({}) }));
30+
31+
const { useThreadCwd } = await import("./use-selected-thread-worktree");
32+
33+
const ref = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
34+
35+
function setup(input: Partial<Omit<typeof state, "projects">>) {
36+
Object.assign(state, { shell: null, detail: null, detailWorktreePath: null }, input);
37+
state.projects = new Map([[ProjectId.make("project"), { workspaceRoot: "/repo" }]]);
38+
}
39+
40+
describe("useThreadCwd", () => {
41+
it("falls back to the project root from the loaded detail when the shell is missing", () => {
42+
setup({ detail: { thread: { projectId: "project" } } });
43+
expect(useThreadCwd(ref)).toBe("/repo");
44+
});
45+
46+
it("prefers the thread worktree over the project root", () => {
47+
setup({ shell: { projectId: "project", worktreePath: "/repo/.worktrees/a" } });
48+
expect(useThreadCwd(ref)).toBe("/repo/.worktrees/a");
49+
});
50+
51+
it("is null without a thread", () => {
52+
setup({ detail: { thread: { projectId: "project" } } });
53+
expect(useThreadCwd(null)).toBeNull();
54+
});
55+
});

‎apps/mobile/src/state/use-selected-thread-worktree.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ScopedThreadRef } from "@t3tools/contracts";
2+
import * as Option from "effect/Option";
23
import { useMemo } from "react";
34

45
import { useProject, useQuietThreadShell } from "./entities";
6+
import { useEnvironmentThread } from "./threads";
57
import { useSelectedThreadWorktreePath, useThreadWorktreePath } from "./use-thread-detail";
68
import { useThreadSelection } from "./use-thread-selection";
79
import { resolvePreferredThreadWorktreePath } from "../features/terminal/terminalLaunchContext";
@@ -25,12 +27,21 @@ export function useSelectedThreadWorktree() {
2527
};
2628
}
2729

28-
/** The selected-thread cwd resolution for a thread that is not the current route's. */
30+
/**
31+
* Resolves a thread's cwd the way the selected thread's does, for a thread that is not the
32+
* current route's: the shell, or the loaded detail when the shell is missing, picks the project.
33+
*/
2934
export function useThreadCwd(ref: ScopedThreadRef | null): string | null {
3035
const shell = useQuietThreadShell(ref);
36+
const detailState = useEnvironmentThread(
37+
shell === null ? (ref?.environmentId ?? null) : null,
38+
shell === null ? (ref?.threadId ?? null) : null,
39+
);
40+
const detailThread = Option.getOrNull(detailState.data)?.thread ?? null;
3141
const detailWorktreePath = useThreadWorktreePath(ref);
42+
const projectId = shell?.projectId ?? detailThread?.projectId ?? null;
3243
const project = useProject(
33-
shell === null ? null : { environmentId: shell.environmentId, projectId: shell.projectId },
44+
ref === null || projectId === null ? null : { environmentId: ref.environmentId, projectId },
3445
);
3546
return (
3647
resolvePreferredThreadWorktreePath({

0 commit comments

Comments
 (0)