fix(server): forks no longer merge into their upstream repo's project group (#16353)
Fixes #4880. Originally #14639 by @Project516. Co-authored-by: Project516 <[email protected]>
This commit is contained in:
1 parent
99db70cf1a
commit
017c9a0eb5
8 files changed
+144
-15
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
MessageId,
|
||||
repositoryGroupingKeyOf,
|
||||
T3_PROJECT_FILE_NAME,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -393,7 +394,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
// whatever unrelated project happens to be first on the other machine. Repository
|
||||
// identity is the primary signal; projects that haven't reported one yet (still
|
||||
// indexing) fall back to workspace basename / title so a valid host isn't hidden.
|
||||
const selectedRepositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
|
||||
const selectedRepositoryKey = selectedProject?.repositoryIdentity
|
||||
? repositoryGroupingKeyOf(selectedProject.repositoryIdentity)
|
||||
: null;
|
||||
// `|| null` (not `??`): a pending-task placeholder project can have an empty
|
||||
// workspaceRoot, and an "" basename would reject every real host below.
|
||||
const selectedWorkspaceBasename = selectedProject?.workspaceRoot.split("/").at(-1) || null;
|
||||
@@ -414,7 +417,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
|
||||
if (selectedRepositoryKey === null && selectedWorkspaceBasename === null) {
|
||||
return true;
|
||||
}
|
||||
const projectKey = project.repositoryIdentity?.canonicalKey ?? null;
|
||||
const projectKey = project.repositoryIdentity
|
||||
? repositoryGroupingKeyOf(project.repositoryIdentity)
|
||||
: null;
|
||||
if (selectedRepositoryKey !== null && projectKey !== null) {
|
||||
return projectKey === selectedRepositoryKey;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { repositoryGroupingKeyOf, type EnvironmentId } from "@t3tools/contracts";
|
||||
|
||||
import { scopedProjectKey } from "../../lib/scopedEntities";
|
||||
import type { HomeProjectScope } from "../home/homeThreadList";
|
||||
@@ -56,7 +56,9 @@ export function resolveEnvironmentProjectMatch(
|
||||
projectsOnTarget: ReadonlyArray<EnvironmentProject>,
|
||||
selectedProject: EnvironmentProject | null,
|
||||
): EnvironmentProject | null {
|
||||
const repositoryKey = selectedProject?.repositoryIdentity?.canonicalKey ?? null;
|
||||
const repositoryKey = selectedProject?.repositoryIdentity
|
||||
? repositoryGroupingKeyOf(selectedProject.repositoryIdentity)
|
||||
: null;
|
||||
// `|| null` (not `??`): a pending-task placeholder project can have an empty
|
||||
// workspaceRoot, and an "" basename would match nothing meaningful.
|
||||
const workspaceBasename = selectedProject?.workspaceRoot.split("/").at(-1) || null;
|
||||
@@ -64,13 +66,18 @@ export function resolveEnvironmentProjectMatch(
|
||||
// side; two known, different repositories never match on a shared basename
|
||||
// or title (mirrors the environment list filter in the new-task flow).
|
||||
const isKnownMismatch = (project: EnvironmentProject) => {
|
||||
const projectKey = project.repositoryIdentity?.canonicalKey ?? null;
|
||||
const projectKey = project.repositoryIdentity
|
||||
? repositoryGroupingKeyOf(project.repositoryIdentity)
|
||||
: null;
|
||||
return repositoryKey !== null && projectKey !== null && projectKey !== repositoryKey;
|
||||
};
|
||||
return (
|
||||
(repositoryKey !== null
|
||||
? projectsOnTarget.find(
|
||||
(project) => (project.repositoryIdentity?.canonicalKey ?? null) === repositoryKey,
|
||||
(project) =>
|
||||
(project.repositoryIdentity
|
||||
? repositoryGroupingKeyOf(project.repositoryIdentity)
|
||||
: null) === repositoryKey,
|
||||
)
|
||||
: undefined) ??
|
||||
(workspaceBasename !== null
|
||||
|
||||
@@ -288,6 +288,29 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
|
||||
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
|
||||
);
|
||||
|
||||
it.effect("reports a fork's own remote as origin next to the upstream identity", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const cwd = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-repository-identity-fork-test-",
|
||||
});
|
||||
|
||||
yield* git(cwd, ["init"]);
|
||||
yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code-fork.git"]);
|
||||
yield* git(cwd, ["remote", "add", "upstream", "[email protected]:T3Tools/t3code.git"]);
|
||||
|
||||
const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
|
||||
const identity = yield* resolver.resolve(cwd);
|
||||
|
||||
expect(identity?.canonicalKey).toBe("github.com/t3tools/t3code");
|
||||
expect(identity?.displayName).toBe("t3tools/t3code");
|
||||
expect(identity?.origin).toEqual({
|
||||
canonicalKey: "github.com/julius/t3code-fork",
|
||||
displayName: "julius/t3code-fork",
|
||||
});
|
||||
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
|
||||
);
|
||||
|
||||
it.effect("uses the last remote path segment as the repository name for nested groups", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
@@ -70,17 +70,34 @@ function pickPrimaryRemote(
|
||||
return remoteName && remoteUrl ? { remoteName, remoteUrl } : null;
|
||||
}
|
||||
|
||||
function repositoryPathOf(canonicalKey: string): string {
|
||||
return canonicalKey.split("/").slice(1).join("/");
|
||||
}
|
||||
|
||||
function buildRepositoryOrigin(
|
||||
originUrl: string | undefined,
|
||||
canonicalKey: string,
|
||||
): RepositoryIdentity["origin"] {
|
||||
if (!originUrl) return undefined;
|
||||
const originKey = normalizeGitRemoteUrl(originUrl);
|
||||
if (originKey === canonicalKey) return undefined;
|
||||
const displayName = repositoryPathOf(originKey);
|
||||
return { canonicalKey: originKey, ...(displayName ? { displayName } : {}) };
|
||||
}
|
||||
|
||||
function buildRepositoryIdentity(input: {
|
||||
readonly remoteName: string;
|
||||
readonly remoteUrl: string;
|
||||
readonly originUrl: string | undefined;
|
||||
readonly rootPath: string;
|
||||
}): RepositoryIdentity {
|
||||
const canonicalKey = normalizeGitRemoteUrl(input.remoteUrl);
|
||||
const sourceControlProvider = detectSourceControlProviderFromGitRemoteUrl(input.remoteUrl);
|
||||
const repositoryPath = canonicalKey.split("/").slice(1).join("/");
|
||||
const repositoryPath = repositoryPathOf(canonicalKey);
|
||||
const repositoryPathSegments = repositoryPath.split("/").filter((segment) => segment.length > 0);
|
||||
const [owner] = repositoryPathSegments;
|
||||
const repositoryName = repositoryPathSegments.at(-1);
|
||||
const origin = buildRepositoryOrigin(input.originUrl, canonicalKey);
|
||||
|
||||
return {
|
||||
canonicalKey,
|
||||
@@ -94,6 +111,7 @@ function buildRepositoryIdentity(input: {
|
||||
...(sourceControlProvider ? { provider: sourceControlProvider.kind } : {}),
|
||||
...(owner ? { owner } : {}),
|
||||
...(repositoryName ? { name: repositoryName } : {}),
|
||||
...(origin ? { origin } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -136,8 +154,11 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
|
||||
return null;
|
||||
}
|
||||
|
||||
const remote = pickPrimaryRemote(parseRemoteFetchUrls(remoteResult.value.stdout));
|
||||
return remote ? buildRepositoryIdentity({ ...remote, rootPath: cacheKey }) : null;
|
||||
const remotes = parseRemoteFetchUrls(remoteResult.value.stdout);
|
||||
const remote = pickPrimaryRemote(remotes);
|
||||
return remote
|
||||
? buildRepositoryIdentity({ ...remote, originUrl: remotes.get("origin"), rootPath: cacheKey })
|
||||
: null;
|
||||
});
|
||||
|
||||
export const make = Effect.fn("RepositoryIdentityResolver.make")(function* (
|
||||
|
||||
Reference in new issue
Block a user