Compare commits

..
Author SHA1 Message Date
Julius Marmingeandcodex 387a577e3c Fix Windows gh PR title args
Co-authored-by: codex <[email protected]>
2026-04-29 16:37:52 -07:00
11 changed files with 77 additions and 306 deletions

No files matched your search

@@ -205,6 +205,50 @@ layer("GitHubCliLive", (it) => {
}),
);
it.effect("creates pull requests with the title passed as a single argv value", () =>
Effect.gen(function* () {
mockedRunProcess.mockResolvedValueOnce({
stdout: "https://github.com/pingdotgg/codething-mvp/pull/42\n",
stderr: "",
code: 0,
signal: null,
timedOut: false,
});
yield* Effect.gen(function* () {
const gh = yield* GitHubCli;
yield* gh.createPullRequest({
cwd: "/repo",
baseBranch: "main",
headSelector: "dev",
title: "Stabilize map selection, pricing badges, and camera handling",
bodyFile:
"C:\\Users\\leo20\\AppData\\Local\\Temp\\t3code-pr-body-38228-73481782-d57c-4b4d-ab5e-9906dc728b2b.md",
});
});
expect(mockedRunProcess).toHaveBeenCalledWith(
"gh",
[
"pr",
"create",
"--base",
"main",
"--head",
"dev",
"--title",
"Stabilize map selection, pricing badges, and camera handling",
"--body-file",
"C:\\Users\\leo20\\AppData\\Local\\Temp\\t3code-pr-body-38228-73481782-d57c-4b4d-ab5e-9906dc728b2b.md",
],
expect.objectContaining({
cwd: "/repo",
shell: false,
}),
);
}),
);
it.effect("surfaces a friendly error when the pull request is not found", () =>
Effect.gen(function* () {
mockedRunProcess.mockRejectedValueOnce(
+1
View File
@@ -107,6 +107,7 @@ const makeGitHubCli = Effect.sync(() => {
try: () =>
runProcess("gh", input.args, {
cwd: input.cwd,
shell: false,
timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
}),
catch: (error) => normalizeGitHubCliError("execute", error),
+2 -1
View File
@@ -5,6 +5,7 @@ export interface ProcessRunOptions {
timeoutMs?: number | undefined;
env?: NodeJS.ProcessEnv | undefined;
stdin?: string | undefined;
shell?: boolean | string | undefined;
allowNonZeroExit?: boolean | undefined;
maxBufferBytes?: number | undefined;
outputMode?: "error" | "truncate" | undefined;
@@ -152,7 +153,7 @@ export async function runProcess(
cwd: options.cwd,
env: options.env,
stdio: "pipe",
shell: process.platform === "win32",
shell: options.shell ?? process.platform === "win32",
});
let stdout = "";
+7 -20
View File
@@ -117,11 +117,7 @@ import { getProviderModelCapabilities, resolveSelectableProvider } from "../prov
import { useSettings } from "../hooks/useSettings";
import { resolveAppModelSelection } from "../modelSelection";
import { isTerminalFocused } from "../lib/terminalFocus";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
} from "../logicalProject";
import { deriveLogicalProjectKeyFromSettings } from "../logicalProject";
import {
useSavedEnvironmentRegistryStore,
useSavedEnvironmentRuntimeStore,
@@ -860,19 +856,11 @@ export default function ChatView(props: ChatViewProps) {
sidebarProjectGroupingMode: settings.sidebarProjectGroupingMode,
sidebarProjectGroupingOverrides: settings.sidebarProjectGroupingOverrides,
}));
const logicalProjectKeyByPhysicalKey = useMemo(
() => buildLogicalProjectKeyMap(allProjects, projectGroupingSettings),
[allProjects, projectGroupingSettings],
);
const logicalProjectEnvironments = useMemo(() => {
if (!activeProject) return [];
const logicalKey =
logicalProjectKeyByPhysicalKey.get(derivePhysicalProjectKey(activeProject)) ??
deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings);
const logicalKey = deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings);
const memberProjects = allProjects.filter(
(p) =>
(logicalProjectKeyByPhysicalKey.get(derivePhysicalProjectKey(p)) ??
deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings)) === logicalKey,
(p) => deriveLogicalProjectKeyFromSettings(p, projectGroupingSettings) === logicalKey,
);
const seen = new Set<string>();
const envs: Array<{
@@ -909,7 +897,6 @@ export default function ChatView(props: ChatViewProps) {
}, [
activeProject,
allProjects,
logicalProjectKeyByPhysicalKey,
projectGroupingSettings,
primaryEnvironmentId,
savedEnvironmentRegistry,
@@ -940,9 +927,10 @@ export default function ChatView(props: ChatViewProps) {
throw new Error("No active project is available for this pull request.");
}
const activeProjectRef = scopeProjectRef(activeProject.environmentId, activeProject.id);
const logicalProjectKey =
logicalProjectKeyByPhysicalKey.get(derivePhysicalProjectKey(activeProject)) ??
deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings);
const logicalProjectKey = deriveLogicalProjectKeyFromSettings(
activeProject,
projectGroupingSettings,
);
const storedDraftSession = getDraftSessionByLogicalProjectKey(logicalProjectKey);
if (storedDraftSession) {
setDraftThreadContext(storedDraftSession.draftId, input);
@@ -1003,7 +991,6 @@ export default function ChatView(props: ChatViewProps) {
getDraftSessionByLogicalProjectKey,
isServerThread,
navigate,
logicalProjectKeyByPhysicalKey,
projectGroupingSettings,
routeKind,
setDraftThreadContext,
+6 -30
View File
@@ -216,17 +216,6 @@ function formatProjectMemberActionLabel(
return member.environmentLabel ? `${member.environmentLabel} — ${member.cwd}` : member.cwd;
}
function hasDuplicateMemberEnvironment(members: readonly SidebarProjectGroupMember[]): boolean {
const seen = new Set<string>();
for (const member of members) {
if (seen.has(member.environmentId)) {
return true;
}
seen.add(member.environmentId);
}
return false;
}
function projectGroupingModeDescription(mode: SidebarProjectGroupingMode): string {
switch (mode) {
case "repository":
@@ -1685,15 +1674,8 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
event.preventDefault();
event.stopPropagation();
if (
project.memberProjects.length === 1 ||
!hasDuplicateMemberEnvironment(project.memberProjects)
) {
const representative =
project.memberProjects.find(
(member) => member.environmentId === project.environmentId && member.id === project.id,
) ?? project.memberProjects[0]!;
createThreadForProjectMember(representative);
if (project.memberProjects.length === 1) {
createThreadForProjectMember(project.memberProjects[0]!);
return;
}
@@ -1724,13 +1706,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
createThreadForProjectMember(targetMember);
})();
},
[
createThreadForProjectMember,
project.environmentId,
project.groupedProjectCount,
project.id,
project.memberProjects,
],
[createThreadForProjectMember, project.groupedProjectCount, project.memberProjects],
);
const attemptArchiveThread = useCallback(
@@ -2759,9 +2735,9 @@ export default function Sidebar() {
});
}, [projectOrder, projects]);
// Build a mapping from physical project key -> logical project key. Matching
// projects can group across environments, but each rendered group keeps at
// most one member per environment so thread creation remains unambiguous.
// Build a mapping from physical project key → logical project key for
// cross-environment grouping. Projects that share a repositoryIdentity
// canonicalKey are treated as one logical project in the sidebar.
const physicalToLogicalKey = useMemo(() => {
return buildPhysicalToLogicalProjectKeyMap({
projects: orderedProjects,
-120
View File
@@ -11,7 +11,6 @@ import {
type EnvironmentState,
} from "./store";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKey,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
@@ -450,125 +449,6 @@ describe("environment grouping", () => {
});
});
describe("buildLogicalProjectKeyMap", () => {
it("groups matching projects across environments without merging distinct projects in one environment", () => {
const localRoot = makeProject({
id: sharedProjectPrimaryId,
environmentId: primaryEnvId,
name: "shared-repo",
cwd: "/workspace/repo",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const localWeb = makeProject({
id: localOnlyProjectId,
environmentId: primaryEnvId,
name: "web",
cwd: "/workspace/repo/apps/web",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const remoteRoot = makeProject({
id: sharedProjectRemoteId,
environmentId: remoteEnvId,
name: "shared-repo",
cwd: "/srv/checkout",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/srv/checkout",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const remoteWeb = makeProject({
id: remoteOnlyProjectId,
environmentId: remoteEnvId,
name: "web",
cwd: "/srv/checkout/apps/web",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/srv/checkout",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const keys = buildLogicalProjectKeyMap(
[localRoot, localWeb, remoteRoot, remoteWeb],
DEFAULT_GROUPING_SETTINGS,
);
expect(keys.get(derivePhysicalProjectKey(localRoot))).toBe(
keys.get(derivePhysicalProjectKey(remoteRoot)),
);
expect(keys.get(derivePhysicalProjectKey(localWeb))).toBe(
keys.get(derivePhysicalProjectKey(remoteWeb)),
);
expect(keys.get(derivePhysicalProjectKey(localRoot))).not.toBe(
keys.get(derivePhysicalProjectKey(localWeb)),
);
});
it("keeps duplicate clones in the same environment separate when repo-relative paths match", () => {
const firstClone = makeProject({
id: sharedProjectPrimaryId,
environmentId: primaryEnvId,
name: "first",
cwd: "/workspace/first/repo",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/first/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const secondClone = makeProject({
id: localOnlyProjectId,
environmentId: primaryEnvId,
name: "second",
cwd: "/workspace/second/repo",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/second/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const keys = buildLogicalProjectKeyMap([firstClone, secondClone], DEFAULT_GROUPING_SETTINGS);
expect(keys.get(derivePhysicalProjectKey(firstClone))).not.toBe(
keys.get(derivePhysicalProjectKey(secondClone)),
);
});
});
describe("selectProjectsAcrossEnvironments", () => {
it("returns all projects from all environments", () => {
const state = makeFixtureState();
+2 -9
View File
@@ -62,7 +62,6 @@ import { useUiStateStore } from "~/uiStateStore";
import { WsTransport } from "../../rpc/wsTransport";
import { createWsRpcClient, type WsRpcClient } from "../../rpc/wsRpcClient";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
} from "../../logicalProject";
@@ -474,13 +473,10 @@ function coalesceOrchestrationUiEvents(
function syncProjectUiFromStore() {
const projects = selectProjectsAcrossEnvironments(useStore.getState());
const clientSettings = getClientSettings();
const logicalKeyByPhysicalKey = buildLogicalProjectKeyMap(projects, clientSettings);
useUiStateStore.getState().syncProjects(
projects.map((project) => ({
key: derivePhysicalProjectKey(project),
logicalKey:
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, clientSettings),
logicalKey: deriveLogicalProjectKeyFromSettings(project, clientSettings),
cwd: project.cwd,
})),
);
@@ -552,13 +548,10 @@ function applyRecoveredEventBatch(
if (needsProjectUiSync) {
const projects = selectProjectsAcrossEnvironments(useStore.getState());
const clientSettings = getClientSettings();
const logicalKeyByPhysicalKey = buildLogicalProjectKeyMap(projects, clientSettings);
useUiStateStore.getState().syncProjects(
projects.map((project) => ({
key: derivePhysicalProjectKey(project),
logicalKey:
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, clientSettings),
logicalKey: deriveLogicalProjectKeyFromSettings(project, clientSettings),
cwd: project.cwd,
})),
);
+3 -13
View File
@@ -10,12 +10,7 @@ import {
} from "../composerDraftStore";
import { newDraftId, newThreadId } from "../lib/utils";
import { orderItemsByPreferredIds } from "../components/Sidebar.logic";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
getProjectOrderKey,
} from "../logicalProject";
import { deriveLogicalProjectKeyFromSettings, getProjectOrderKey } from "../logicalProject";
import { selectProjectsAcrossEnvironments, useStore } from "../store";
import { createThreadSelectorByRef } from "../storeSelectors";
import { resolveThreadRouteTarget } from "../threadRoutes";
@@ -28,10 +23,6 @@ function useNewThreadState() {
sidebarProjectGroupingMode: settings.sidebarProjectGroupingMode,
sidebarProjectGroupingOverrides: settings.sidebarProjectGroupingOverrides,
}));
const logicalKeyByPhysicalKey = useMemo(
() => buildLogicalProjectKeyMap(projects, projectGroupingSettings),
[projectGroupingSettings, projects],
);
const router = useRouter();
const getCurrentRouteTarget = useCallback(() => {
const currentRouteParams = router.state.matches[router.state.matches.length - 1]?.params ?? {};
@@ -62,8 +53,7 @@ function useNewThreadState() {
candidate.environmentId === projectRef.environmentId,
);
const logicalProjectKey = project
? (logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings))
? deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings)
: scopedProjectKey(projectRef);
const hasBranchOption = options?.branch !== undefined;
const hasWorktreePathOption = options?.worktreePath !== undefined;
@@ -144,7 +134,7 @@ function useNewThreadState() {
});
})();
},
[getCurrentRouteTarget, logicalKeyByPhysicalKey, projectGroupingSettings, router, projects],
[getCurrentRouteTarget, projectGroupingSettings, router, projects],
);
}
-97
View File
@@ -51,21 +51,6 @@ function deriveRepositoryRelativeProjectPath(
return normalizedProjectPath.slice(rootPrefix.length).replaceAll("\\", "/");
}
function formatProjectGroupDiscriminator(value: string): string {
return value.length === 0 ? "." : value;
}
function hasDuplicateEnvironment(projects: ReadonlyArray<Pick<Project, "environmentId">>): boolean {
const seen = new Set<string>();
for (const project of projects) {
if (seen.has(project.environmentId)) {
return true;
}
seen.add(project.environmentId);
}
return false;
}
export function derivePhysicalProjectKeyFromPath(environmentId: string, cwd: string): string {
return `${environmentId}:${normalizeProjectPathForComparison(cwd)}`;
}
@@ -147,88 +132,6 @@ export function deriveLogicalProjectKeyFromSettings(
});
}
export function buildLogicalProjectKeyMap(
projects: ReadonlyArray<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>,
settings: ProjectGroupingSettings,
): Map<string, string> {
const baseBuckets = new Map<
string,
Array<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>
>();
const physicalKeyByProject = new Map<
Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">,
string
>();
for (const project of projects) {
const physicalKey = derivePhysicalProjectKey(project);
physicalKeyByProject.set(project, physicalKey);
const baseKey = deriveLogicalProjectKeyFromSettings(project, settings);
const bucket = baseBuckets.get(baseKey);
if (bucket) {
bucket.push(project);
} else {
baseBuckets.set(baseKey, [project]);
}
}
const result = new Map<string, string>();
const assignBucket = (
baseKey: string,
bucket: ReadonlyArray<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>,
discriminatorIndex: number,
) => {
if (!hasDuplicateEnvironment(bucket)) {
for (const project of bucket) {
result.set(physicalKeyByProject.get(project)!, baseKey);
}
return;
}
const discriminatorFns = [
(project: Pick<Project, "cwd" | "repositoryIdentity">) => {
const relativePath = deriveRepositoryRelativeProjectPath(project);
return relativePath === null ? null : formatProjectGroupDiscriminator(relativePath);
},
(project: Pick<Project, "cwd">) => normalizeProjectPathForComparison(project.cwd),
(project: Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">) =>
physicalKeyByProject.get(project) ?? derivePhysicalProjectKey(project),
] as const;
const discriminator = discriminatorFns[discriminatorIndex];
if (!discriminator) {
for (const project of bucket) {
result.set(physicalKeyByProject.get(project)!, physicalKeyByProject.get(project)!);
}
return;
}
const buckets = new Map<
string,
Array<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>
>();
for (const project of bucket) {
const value = discriminator(project) ?? normalizeProjectPathForComparison(project.cwd);
const key = `${baseKey}::${value}`;
const existing = buckets.get(key);
if (existing) {
existing.push(project);
} else {
buckets.set(key, [project]);
}
}
for (const [key, projectsForKey] of buckets) {
assignBucket(key, projectsForKey, discriminatorIndex + 1);
}
};
for (const [baseKey, bucket] of baseBuckets) {
assignBucket(baseKey, bucket, 0);
}
return result;
}
export function deriveLogicalProjectKeyFromRef(
projectRef: ScopedProjectRef,
project: Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity"> | null | undefined,
+2 -7
View File
@@ -29,9 +29,7 @@ import { resolveAndPersistPreferredEditor } from "../editorPreferences";
import { readLocalApi } from "../localApi";
import { useSettings } from "../hooks/useSettings";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
derivePhysicalProjectKeyFromPath,
} from "../logicalProject";
import {
@@ -42,7 +40,7 @@ import {
useServerConfigUpdatedSubscription,
useServerWelcomeSubscription,
} from "../rpc/serverState";
import { selectProjectsAcrossEnvironments, useStore } from "../store";
import { useStore } from "../store";
import { useUiStateStore } from "../uiStateStore";
import { syncBrowserChromeTheme } from "../hooks/useTheme";
import {
@@ -244,12 +242,9 @@ function EventRouter() {
useStore.getState().environmentStateById[payload.environment.environmentId];
const bootstrapProject =
bootstrapEnvironmentState?.projectById[payload.bootstrapProjectId] ?? null;
const projects = selectProjectsAcrossEnvironments(useStore.getState());
const logicalKeyByPhysicalKey = buildLogicalProjectKeyMap(projects, projectGroupingSettings);
const bootstrapProjectKey =
(bootstrapProject
? (logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(bootstrapProject)) ??
deriveLogicalProjectKeyFromSettings(bootstrapProject, projectGroupingSettings))
? deriveLogicalProjectKeyFromSettings(bootstrapProject, projectGroupingSettings)
: null) ??
(serverConfig?.cwd
? derivePhysicalProjectKeyFromPath(payload.environment.environmentId, serverConfig.cwd)
+10 -9
View File
@@ -1,7 +1,6 @@
import { scopeProjectRef } from "@t3tools/client-runtime";
import type { EnvironmentId, ScopedProjectRef } from "@t3tools/contracts";
import {
buildLogicalProjectKeyMap,
deriveLogicalProjectKeyFromSettings,
derivePhysicalProjectKey,
deriveProjectGroupLabel,
@@ -30,7 +29,14 @@ export function buildPhysicalToLogicalProjectKeyMap(input: {
projects: ReadonlyArray<Project>;
settings: ProjectGroupingSettings;
}): Map<string, string> {
return buildLogicalProjectKeyMap(input.projects, input.settings);
const mapping = new Map<string, string>();
for (const project of input.projects) {
mapping.set(
derivePhysicalProjectKey(project),
deriveLogicalProjectKeyFromSettings(project, input.settings),
);
}
return mapping;
}
export function buildSidebarProjectSnapshots(input: {
@@ -39,12 +45,9 @@ export function buildSidebarProjectSnapshots(input: {
primaryEnvironmentId: EnvironmentId | null;
resolveEnvironmentLabel: (environmentId: EnvironmentId) => string | null;
}): SidebarProjectSnapshot[] {
const logicalKeyByPhysicalKey = buildLogicalProjectKeyMap(input.projects, input.settings);
const groupedMembers = new Map<string, SidebarProjectGroupMember[]>();
for (const project of input.projects) {
const logicalKey =
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, input.settings);
const logicalKey = deriveLogicalProjectKeyFromSettings(project, input.settings);
const member: SidebarProjectGroupMember = {
...project,
physicalProjectKey: derivePhysicalProjectKey(project),
@@ -61,9 +64,7 @@ export function buildSidebarProjectSnapshots(input: {
const result: SidebarProjectSnapshot[] = [];
const seen = new Set<string>();
for (const project of input.projects) {
const logicalKey =
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(project)) ??
deriveLogicalProjectKeyFromSettings(project, input.settings);
const logicalKey = deriveLogicalProjectKeyFromSettings(project, input.settings);
if (seen.has(logicalKey)) {
continue;
}