Skip to content

Commit 9a801c3

Browse files
Merge origin/main into factory/pr-25880-a1794597635
Keeps main's turn-start base for the working-tree diff next to the fetched-commit filter, and both new listAuthoredPaths tests. Co-Authored-By: Claude Fable 5.2 <[email protected]>
2 parents dbd896d + 7bd9134 commit 9a801c3

25 files changed

Lines changed: 1090 additions & 131 deletions

‎apps/mobile/modules/t3-native-controls/ios/T3ScrollEdgeBleedView.swift‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class T3ScrollEdgeBleedView: ExpoView {
1919
/// React Native's clipping, saved while bleeding. React Native only rewrites it when the
2020
/// `overflow` style changes, so it stays off while bleeding.
2121
private var containerClipped: Bool?
22+
private var indicatorObservations: [NSKeyValueObservation] = []
2223

2324
required init(appContext: AppContext? = nil) {
2425
super.init(appContext: appContext)
@@ -136,12 +137,29 @@ final class T3ScrollEdgeBleedView: ExpoView {
136137
containerClipped = containerClipped ?? true
137138
container.layer.masksToBounds = false
138139
}
140+
applyIndicatorInset()
141+
// React Native rewrites every indicator inset when its `scrollIndicatorInsets` prop changes,
142+
// which the keyboard-aware list animates while a reply streams; put the inset back at once.
143+
if bleeding, indicatorObservations.isEmpty {
144+
let keyPaths = [\UIScrollView.verticalScrollIndicatorInsets, \.scrollIndicatorInsets]
145+
indicatorObservations = keyPaths.map {
146+
scrollView.observe($0) { [weak self] _, _ in
147+
MainActor.assumeIsolated { self?.applyIndicatorInset() }
148+
}
149+
}
150+
} else if !bleeding {
151+
indicatorObservations = []
152+
}
153+
applied = bleeding
154+
}
155+
156+
private func applyIndicatorInset() {
157+
guard let scrollView else { return }
139158
var indicators = scrollView.verticalScrollIndicatorInsets
140159
if indicators.right != bleed.right {
141160
indicators.right = bleed.right
142161
scrollView.verticalScrollIndicatorInsets = indicators
143162
}
144-
applied = bleeding
145163
}
146164

147165
private func detach() {

‎apps/mobile/src/features/projects/AddProjectScreen.test.ts‎

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import * as NodeModule from "node:module";
66
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
77
import { workspaceDetailRouter } from "../layout/workspace/workspace-detail-selection";
88
import type { NavigationState } from "@react-navigation/native";
9-
import { AuthOrchestrationOperateScope, AuthSourceControlWriteScope } from "@t3tools/contracts";
9+
import {
10+
AuthFilesystemReadScope,
11+
AuthOrchestrationOperateScope,
12+
AuthSourceControlWriteScope,
13+
} from "@t3tools/contracts";
1014
import * as Cause from "effect/Cause";
1115
import { AsyncResult } from "effect/reactivity";
1216
import { act, createElement, isValidElement, type ReactNode } from "react";
@@ -22,7 +26,9 @@ const state = vi.hoisted(() => ({
2226
id: string;
2327
title: string;
2428
workspaceRoot: string;
29+
repositoryIdentity?: { canonicalKey: string };
2530
}[],
31+
cloneDestinations: [] as string[],
2632
createResult: null as Promise<unknown> | null,
2733
createNewResult: null as Promise<unknown> | null,
2834
startCloneResult: null as Promise<unknown> | null,
@@ -134,7 +140,15 @@ vi.mock("../../state/use-remote-environment-registry", () => ({
134140
}),
135141
}));
136142
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
137-
vi.mock("../../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => () => {} }));
143+
// Only filesystem.browse of `~` answers, with the host's home as its parentPath.
144+
vi.mock("../../state/use-atom-query-runner", () => ({
145+
useAtomQueryRunner:
146+
() =>
147+
async ({ input }: { input?: { partialPath?: string } }) =>
148+
input?.partialPath === "~"
149+
? AsyncResult.success({ parentPath: "/home/tester", entries: [] })
150+
: undefined,
151+
}));
138152
vi.mock("../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null }) }));
139153
vi.mock("../../state/presentation", () => ({
140154
useEnvironmentPresentation: () => ({ isReady: true, presentation: null }),
@@ -144,6 +158,7 @@ vi.mock("../../state/sourceControl", () => ({
144158
sourceControlEnvironment: {
145159
discovery: (input: unknown) => input,
146160
startProjectClone: async ({ input }: { input: { destinationPath: string } }) => {
161+
state.cloneDestinations.push(input.destinationPath);
147162
if (state.startCloneResult) return state.startCloneResult;
148163
NodeFS.mkdirSync(input.destinationPath);
149164
return AsyncResult.success(undefined);
@@ -230,7 +245,7 @@ function cloneAction() {
230245
renderScreen(() =>
231246
AddProjectDestinationScreen({
232247
environmentId: "environment",
233-
remoteUrl: "https://example.com/repo.git",
248+
remoteUrl: "https://example.com/owner/repo.git",
234249
repositoryName: "repo",
235250
}),
236251
),
@@ -274,6 +289,38 @@ describe("clone project permissions", () => {
274289
expect(state.projects).toEqual([]);
275290
},
276291
);
292+
293+
it.each([
294+
[
295+
"opens the existing project of that repository instead of cloning into its folder",
296+
"example.com/owner/repo",
297+
false,
298+
],
299+
["leaves a folder holding another repository to the clone", "example.com/owner/other", true],
300+
])("%s", async (_name, canonicalKey, clones) => {
301+
state.scopes.add(AuthOrchestrationOperateScope);
302+
state.cloneDestinations = [];
303+
state.startCloneResult = Promise.resolve(
304+
AsyncResult.failure(Cause.fail(new Error("Destination is not empty"))),
305+
);
306+
state.existingProjects = [
307+
{
308+
environmentId: "environment",
309+
id: "existing",
310+
title: "repo",
311+
workspaceRoot: NodePath.join(state.baseDirectory, "repo"),
312+
repositoryIdentity: { canonicalKey },
313+
},
314+
];
315+
try {
316+
await cloneAction()();
317+
318+
expect(state.cloneDestinations.length > 0).toBe(clones);
319+
} finally {
320+
state.existingProjects = [];
321+
state.startCloneResult = null;
322+
}
323+
});
277324
});
278325

279326
function mountProjectFlow(
@@ -488,10 +535,10 @@ describe("add project source environment", () => {
488535
});
489536

490537
describe("local project navigation", () => {
491-
function setup() {
538+
function setup(baseDirectory = "/tmp/t3-mobile-audit-fixture") {
492539
state.navigationState = undefined;
493540
state.scopes = new Set([AuthOrchestrationOperateScope]);
494-
state.baseDirectory = "/tmp/t3-mobile-audit-fixture";
541+
state.baseDirectory = baseDirectory;
495542
state.projects = [];
496543
state.dispatch.mockReset();
497544
state.alert.mockReset();
@@ -523,6 +570,28 @@ describe("local project navigation", () => {
523570
);
524571
});
525572

573+
it("opens an existing project typed as a home-relative path instead of creating it", async () => {
574+
state.existingProjects = [
575+
{
576+
environmentId: "environment",
577+
id: "existing",
578+
title: "bike-documents",
579+
workspaceRoot: "/home/tester/projects/bike-documents",
580+
},
581+
];
582+
try {
583+
const { created, projected, submit } = setup("~/projects/bike-documents/");
584+
state.scopes.add(AuthFilesystemReadScope);
585+
created.resolve(AsyncResult.success(undefined));
586+
projected.resolve(null);
587+
await submit();
588+
589+
expect(state.projects).toEqual([]);
590+
} finally {
591+
state.existingProjects = [];
592+
}
593+
});
594+
526595
it("does not replace a reopened flow when the previous submission finishes", async () => {
527596
const { created, projected, submit } = setup();
528597
const navigation = mountProjectFlow(false);

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 104 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,26 @@ function useBrowsePathInput(
387387
[browseNavigation],
388388
);
389389

390-
return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath };
390+
// Registered roots are absolute and `~` expands on the host, so ask the host for its home.
391+
const resolveHomePath = async (path: string): Promise<string> => {
392+
if (
393+
!/^~(?:[\\/]|$)/.test(path) ||
394+
!environment ||
395+
!readEnvironmentScope(environment.environmentId, AuthFilesystemReadScope) ||
396+
!canPreloadBrowsePath(environmentRuntime?.connectionState)
397+
) {
398+
return path;
399+
}
400+
const home = await loadBrowsePath({
401+
environmentId: environment.environmentId,
402+
input: { partialPath: "~" },
403+
});
404+
return AsyncResult.isSuccess(home) && home.value
405+
? `${home.value.parentPath.replace(/[\\/]+$/, "")}${path.slice(1)}`
406+
: path;
407+
};
408+
409+
return { isBrowseNavigating, pathInput, setPathInput, navigateToBrowsePath, resolveHomePath };
391410
}
392411

393412
function useEnvironmentOptions(
@@ -730,16 +749,76 @@ async function draftWithPrompt(
730749
return draftId;
731750
}
732751

733-
function useCreateProject(environment: EnvironmentOption | null) {
752+
function useOpenExistingProject(environment: EnvironmentOption | null) {
734753
const openNewTaskDraft = useOpenNewTaskDraft();
735-
const navigation = useNavigation();
736-
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
737754
const updateProject = useAtomCommand(projectEnvironment.update, {
738755
label: "project unarchive",
739756
});
740757
const projects = useProjects();
741758

742-
return async (workspaceRoot: string, originRoute = getActiveRoute(navigation)) => {
759+
return async (
760+
path: string,
761+
originRoute: ReturnType<typeof getActiveRoute>,
762+
clone?: { readonly remoteUrl: string; readonly prompt: string | null },
763+
): Promise<boolean> => {
764+
if (!environment) return false;
765+
const existing = findExistingAddProject({
766+
projects,
767+
environmentId: environment.environmentId,
768+
path,
769+
});
770+
if (!existing) return false;
771+
// A folder holding another repository is not this clone; let the clone report it occupied.
772+
if (
773+
clone &&
774+
existing.repositoryIdentity?.canonicalKey !==
775+
sourceControlClients.repositoryKeyFromRemote(clone.remoteUrl)
776+
) {
777+
return false;
778+
}
779+
const prompt = clone?.prompt;
780+
// Adding an archived project's folder again brings the project back.
781+
const unarchived =
782+
existing.archivedAt == null ||
783+
(
784+
await updateProject({
785+
environmentId: existing.environmentId,
786+
input: { projectId: existing.id, archived: false },
787+
})
788+
)._tag === "Success";
789+
Dialog.alert(
790+
"Project already exists",
791+
unarchived ? existing.title : `${existing.title} is still archived. Try again later.`,
792+
);
793+
openNewTaskDraft(
794+
{
795+
environmentId: existing.environmentId,
796+
projectId: existing.id,
797+
title: existing.title,
798+
...(prompt
799+
? await draftWithPrompt(existing.environmentId, existing.id, prompt).then(
800+
(draftId) => ({ draftId }),
801+
() => ({}),
802+
)
803+
: {}),
804+
},
805+
originRoute,
806+
);
807+
return true;
808+
};
809+
}
810+
811+
function useCreateProject(environment: EnvironmentOption | null) {
812+
const openNewTaskDraft = useOpenNewTaskDraft();
813+
const navigation = useNavigation();
814+
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
815+
const openExistingProject = useOpenExistingProject(environment);
816+
817+
return async (
818+
workspaceRoot: string,
819+
originRoute = getActiveRoute(navigation),
820+
lookupPath = workspaceRoot,
821+
) => {
743822
if (
744823
!environment ||
745824
!canCreateProjectInEnvironment(environment.connectionState) ||
@@ -752,33 +831,7 @@ function useCreateProject(environment: EnvironmentOption | null) {
752831
return;
753832
}
754833

755-
const existing = findExistingAddProject({
756-
projects,
757-
environmentId: environment.environmentId,
758-
path: workspaceRoot,
759-
});
760-
if (existing) {
761-
// Adding an archived project's folder again brings the project back.
762-
const unarchived =
763-
existing.archivedAt == null ||
764-
(
765-
await updateProject({
766-
environmentId: existing.environmentId,
767-
input: { projectId: existing.id, archived: false },
768-
})
769-
)._tag === "Success";
770-
Dialog.alert(
771-
"Project already exists",
772-
unarchived ? existing.title : `${existing.title} is still archived. Try again later.`,
773-
);
774-
openNewTaskDraft(
775-
{
776-
environmentId: existing.environmentId,
777-
projectId: existing.id,
778-
title: existing.title,
779-
},
780-
originRoute,
781-
);
834+
if (await openExistingProject(lookupPath, originRoute)) {
782835
return;
783836
}
784837

@@ -1313,8 +1366,9 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
13131366
environment?.environmentId ?? null,
13141367
AuthOrchestrationOperateScope,
13151368
);
1369+
const navigation = useNavigation();
13161370
const createProject = useCreateProject(environment);
1317-
const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } =
1371+
const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput, resolveHomePath } =
13181372
useBrowsePathInput(environment);
13191373
const [isSubmitting, setIsSubmitting] = useState(false);
13201374
const [error, setError] = useState<string | null>(null);
@@ -1333,7 +1387,11 @@ export function AddProjectLocalFolderScreen(props: { readonly environmentId?: st
13331387
}
13341388

13351389
setIsSubmitting(true);
1336-
const result = await createProject(resolved.path);
1390+
const originRoute = getActiveRoute(navigation);
1391+
const lookupPath = resolved.path.startsWith("~")
1392+
? await resolveHomePath(resolved.path)
1393+
: resolved.path;
1394+
const result = await createProject(resolved.path, originRoute, lookupPath);
13371395
if (result && AsyncResult.isFailure(result)) {
13381396
setError(errorMessage(Cause.squash(result.cause)));
13391397
}
@@ -1404,11 +1462,9 @@ export function AddProjectDestinationScreen(props: {
14041462
? getCloneDirectoryPath(remoteUrl, true, repositoryName)
14051463
: null;
14061464
const cloneDirectoryName = ghqDirectoryPath?.split("/").at(-1) ?? repositoryName;
1407-
const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput } = useBrowsePathInput(
1408-
environment,
1409-
cloneDirectoryName,
1410-
ghqDirectoryPath ?? repositoryName,
1411-
);
1465+
const { isBrowseNavigating, navigateToBrowsePath, pathInput, setPathInput, resolveHomePath } =
1466+
useBrowsePathInput(environment, cloneDirectoryName, ghqDirectoryPath ?? repositoryName);
1467+
const openExistingProject = useOpenExistingProject(environment);
14121468
const [isSubmitting, setIsSubmitting] = useState(false);
14131469
const [error, setError] = useState<string | null>(null);
14141470

@@ -1436,6 +1492,15 @@ export function AddProjectDestinationScreen(props: {
14361492

14371493
const originRoute = getActiveRoute(navigation);
14381494
setIsSubmitting(true);
1495+
if (
1496+
await openExistingProject(await resolveHomePath(resolved.path), originRoute, {
1497+
remoteUrl,
1498+
prompt: prompt ?? null,
1499+
})
1500+
) {
1501+
setIsSubmitting(false);
1502+
return;
1503+
}
14391504
const title = inferProjectTitleFromPath(resolved.path);
14401505
const startResult = await startProjectClone({
14411506
environmentId: environment.environmentId,

0 commit comments

Comments
 (0)