Skip to content

Commit ae929fb

Browse files
fix(mobile): skip known-different repositories in environment match fallbacks
The basename and title fallbacks in resolveEnvironmentProjectMatch could pick a project whose repository identity is known and differs from the selected one, carrying the draft into an unrelated repo. Those signals now only apply where identity is unknown on at least one side, matching the environment list filter. Co-Authored-By: Claude Code <[email protected]>
1 parent af30434 commit ae929fb

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎apps/mobile/src/features/threads/new-task-project-selection.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ describe("resolveEnvironmentProjectMatch", () => {
9494
expect(resolveEnvironmentProjectMatch(byTitle, selected)).toBe(byTitle[1]);
9595
});
9696

97+
it("does not treat a known different repository as a basename or title match", () => {
98+
const selected = makeProject("t3code", "mac", {
99+
repositoryKey: "github.com/t3tools/t3code",
100+
workspaceRoot: "/Users/me/t3code",
101+
});
102+
const fork = makeProject("fork", "server", {
103+
repositoryKey: "github.com/someone/t3code",
104+
title: "t3code",
105+
workspaceRoot: "/home/me/t3code",
106+
});
107+
const unindexed = makeProject("unindexed", "server", { workspaceRoot: "/srv/t3code" });
108+
expect(resolveEnvironmentProjectMatch([fork, unindexed], selected)).toBe(unindexed);
109+
// Without any weaker match the fork is still the first-project fallback.
110+
expect(resolveEnvironmentProjectMatch([fork], selected)).toBe(fork);
111+
});
112+
97113
it("falls back to the first project on the target so the draft has a key to carry over to", () => {
98114
const selected = makeProject("t3code", "mac", { repositoryKey: "github.com/t3tools/t3code" });
99115
const target = [makeProject("unrelated", "server"), makeProject("also-unrelated", "server")];

‎apps/mobile/src/features/threads/new-task-project-selection.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export function resolveEnvironmentProjectMatch(
4343
// `|| null` (not `??`): a pending-task placeholder project can have an empty
4444
// workspaceRoot, and an "" basename would match nothing meaningful.
4545
const workspaceBasename = selectedProject?.workspaceRoot.split("/").at(-1) || null;
46+
// The weaker signals only apply where identity is unknown on at least one
47+
// side; two known, different repositories never match on a shared basename
48+
// or title (mirrors the environment list filter in the new-task flow).
49+
const isKnownMismatch = (project: EnvironmentProject) => {
50+
const projectKey = project.repositoryIdentity?.canonicalKey ?? null;
51+
return repositoryKey !== null && projectKey !== null && projectKey !== repositoryKey;
52+
};
4653
return (
4754
(repositoryKey !== null
4855
? projectsOnTarget.find(
@@ -51,11 +58,15 @@ export function resolveEnvironmentProjectMatch(
5158
: undefined) ??
5259
(workspaceBasename !== null
5360
? projectsOnTarget.find(
54-
(project) => project.workspaceRoot.split("/").at(-1) === workspaceBasename,
61+
(project) =>
62+
!isKnownMismatch(project) &&
63+
project.workspaceRoot.split("/").at(-1) === workspaceBasename,
5564
)
5665
: undefined) ??
5766
(selectedProject !== null
58-
? projectsOnTarget.find((project) => project.title === selectedProject.title)
67+
? projectsOnTarget.find(
68+
(project) => !isKnownMismatch(project) && project.title === selectedProject.title,
69+
)
5970
: undefined) ??
6071
projectsOnTarget[0] ??
6172
null

0 commit comments

Comments
 (0)