+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
278 lines
10 KiB
TypeScript
278 lines
10 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
import {
|
|
EnvironmentId,
|
|
ProjectId,
|
|
CommandId,
|
|
SourceControlDiscoveryResult,
|
|
} from "@t3tools/contracts";
|
|
import * as Option from "effect/Option";
|
|
|
|
import {
|
|
buildAddProjectRemoteSourceReadiness,
|
|
buildProjectCreateCommand,
|
|
canCreateProjectInEnvironment,
|
|
findExistingAddProject,
|
|
getAddProjectInitialQuery,
|
|
getCloneDestinationBrowsePath,
|
|
getCloneDestinationPath,
|
|
getCloneDirectoryName,
|
|
getDefaultCloneUrl,
|
|
normalizePastedCloneUrl,
|
|
resolveAddProjectPath,
|
|
sortAddProjectProviderSources,
|
|
} from "./projects.ts";
|
|
import type { EnvironmentProject } from "../state/models.ts";
|
|
|
|
describe("add project shared logic", () => {
|
|
it("only allows project creation in connected environments", () => {
|
|
expect(canCreateProjectInEnvironment("connected")).toBe(true);
|
|
expect(canCreateProjectInEnvironment("available")).toBe(false);
|
|
expect(canCreateProjectInEnvironment("offline")).toBe(false);
|
|
expect(canCreateProjectInEnvironment("connecting")).toBe(false);
|
|
expect(canCreateProjectInEnvironment("reconnecting")).toBe(false);
|
|
expect(canCreateProjectInEnvironment("error")).toBe(false);
|
|
});
|
|
|
|
it("resolves initial browse paths from settings", () => {
|
|
expect(getAddProjectInitialQuery("")).toBe("~/");
|
|
expect(getAddProjectInitialQuery("/work")).toBe("/work/");
|
|
expect(getAddProjectInitialQuery("C:\\work")).toBe("C:\\work\\");
|
|
});
|
|
|
|
it("derives the clone folder name from the repository name with owner", () => {
|
|
expect(getCloneDirectoryName("owner/repo")).toBe("repo");
|
|
expect(getCloneDirectoryName("org/project/repo")).toBe("repo");
|
|
expect(getCloneDirectoryName("repo")).toBe("repo");
|
|
expect(getCloneDirectoryName("owner/repo/")).toBe("repo");
|
|
expect(getCloneDirectoryName("")).toBe("");
|
|
expect(getCloneDirectoryName(null)).toBe("");
|
|
});
|
|
|
|
it("routes owner/repository shorthand to GitHub over HTTPS", () => {
|
|
expect(normalizePastedCloneUrl("imputnet/helium")).toBe(
|
|
"https://github.com/imputnet/helium.git",
|
|
);
|
|
expect(normalizePastedCloneUrl(" pingdotgg/t3code ")).toBe(
|
|
"https://github.com/pingdotgg/t3code.git",
|
|
);
|
|
});
|
|
|
|
it("keeps explicit clone URLs and local paths unchanged", () => {
|
|
expect(normalizePastedCloneUrl("https://gitlab.com/group/project.git")).toBe(
|
|
"https://gitlab.com/group/project.git",
|
|
);
|
|
expect(normalizePastedCloneUrl("[email protected]:owner/repo.git")).toBe(
|
|
"[email protected]:owner/repo.git",
|
|
);
|
|
expect(normalizePastedCloneUrl("group/subgroup/project")).toBe("group/subgroup/project");
|
|
expect(normalizePastedCloneUrl("/srv/git/repo.git")).toBe("/srv/git/repo.git");
|
|
});
|
|
|
|
it("uses HTTPS for repositories selected through a provider", () => {
|
|
expect(
|
|
getDefaultCloneUrl({
|
|
provider: "github",
|
|
url: "https://github.com/imputnet/helium",
|
|
sshUrl: "[email protected]:imputnet/helium.git",
|
|
}),
|
|
).toBe("https://github.com/imputnet/helium");
|
|
expect(
|
|
getDefaultCloneUrl({
|
|
provider: "forgejo",
|
|
url: "https://forgejo.example.test:8443/owner/repo.git",
|
|
sshUrl: "ssh://[email protected]:2222/owner/repo.git",
|
|
}),
|
|
).toBe("https://forgejo.example.test:8443/owner/repo.git");
|
|
});
|
|
|
|
it("preserves existing clone transport behavior for other providers", () => {
|
|
expect(
|
|
getDefaultCloneUrl({
|
|
provider: "gitlab",
|
|
url: "https://gitlab.com/group/project.git",
|
|
sshUrl: "[email protected]:group/project.git",
|
|
}),
|
|
).toBe("[email protected]:group/project.git");
|
|
});
|
|
|
|
it("derives the clone folder name from any pasted clone URL", () => {
|
|
expect(getCloneDirectoryName("https://github.com/owner/repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("https://github.com/owner/repo")).toBe("repo");
|
|
expect(getCloneDirectoryName("https://github.com/owner/repo/")).toBe("repo");
|
|
expect(getCloneDirectoryName("[email protected]:owner/repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("ssh://[email protected]:22/owner/repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("https://[email protected]/owner/repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("https://dev.azure.com/org/project/_git/repo")).toBe("repo");
|
|
expect(getCloneDirectoryName("https://github.com/owner/repo.git?ref=main#readme")).toBe("repo");
|
|
expect(getCloneDirectoryName("/srv/git/repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("C:\\src\\repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName("[email protected]:repo.git")).toBe("repo");
|
|
expect(getCloneDirectoryName(" https://github.com/owner/repo.git ")).toBe("repo");
|
|
});
|
|
|
|
it("keeps a numeric repository name that sits on a path", () => {
|
|
expect(getCloneDirectoryName("https://github.com/acme/123.git")).toBe("123");
|
|
expect(getCloneDirectoryName("https://github.com/acme/123")).toBe("123");
|
|
expect(getCloneDirectoryName("[email protected]:acme/123.git")).toBe("123");
|
|
});
|
|
|
|
it("proposes no clone folder for a link that names no repository", () => {
|
|
expect(getCloneDirectoryName("https://github.com/")).toBe("");
|
|
expect(getCloneDirectoryName("https://github.com")).toBe("");
|
|
expect(getCloneDirectoryName("[email protected]:")).toBe("");
|
|
expect(getCloneDirectoryName("ssh://[email protected]:22")).toBe("");
|
|
expect(getCloneDirectoryName("https://")).toBe("");
|
|
});
|
|
|
|
it("proposes the clone destination inside the selected directory", () => {
|
|
expect(getCloneDestinationPath("~/Projects/", "repo")).toBe("~/Projects/repo");
|
|
expect(getCloneDestinationPath("~/Projects", "repo")).toBe("~/Projects/repo");
|
|
expect(getCloneDestinationPath("C:\\work\\", "repo")).toBe("C:\\work\\repo");
|
|
expect(getCloneDestinationPath("~/Projects/", null)).toBe("~/Projects/");
|
|
expect(getCloneDestinationPath("~/Projects/", "")).toBe("~/Projects/");
|
|
});
|
|
|
|
it("keeps pinned clone destinations anchored to the browsed directory", () => {
|
|
expect(
|
|
getCloneDestinationBrowsePath({
|
|
browseDirectoryPath: "~/Projects/",
|
|
selectedDirectoryName: "work",
|
|
cloneDirectoryName: "repo",
|
|
caseSensitive: true,
|
|
}),
|
|
).toBe("~/Projects/work/repo");
|
|
expect(
|
|
getCloneDestinationBrowsePath({
|
|
browseDirectoryPath: "~/Projects/",
|
|
selectedDirectoryName: "repo",
|
|
cloneDirectoryName: "repo",
|
|
caseSensitive: true,
|
|
}),
|
|
).toBe("~/Projects/repo/");
|
|
expect(
|
|
getCloneDestinationBrowsePath({
|
|
browseDirectoryPath: "C:\\Projects\\",
|
|
selectedDirectoryName: "Repo",
|
|
cloneDirectoryName: "repo",
|
|
caseSensitive: false,
|
|
}),
|
|
).toBe("C:\\Projects\\Repo\\");
|
|
});
|
|
|
|
it("rejects unsupported windows paths on non-windows environments", () => {
|
|
expect(
|
|
resolveAddProjectPath({
|
|
rawPath: "C:\\repo",
|
|
platform: "MacIntel",
|
|
currentProjectCwd: null,
|
|
}),
|
|
).toEqual({
|
|
ok: false,
|
|
error: "Windows-style paths are only supported on Windows environments.",
|
|
});
|
|
});
|
|
|
|
it("resolves relative paths from the active project cwd", () => {
|
|
expect(
|
|
resolveAddProjectPath({
|
|
rawPath: "../next",
|
|
platform: "Linux",
|
|
currentProjectCwd: "/work/current",
|
|
}),
|
|
).toEqual({ ok: true, path: "/work/next" });
|
|
});
|
|
|
|
it("marks authenticated source control providers as ready", () => {
|
|
const discovery: SourceControlDiscoveryResult = {
|
|
versionControlSystems: [],
|
|
sourceControlProviders: [
|
|
{
|
|
kind: "github",
|
|
label: "GitHub",
|
|
status: "available",
|
|
installHint: "Install gh",
|
|
version: Option.some("1.0.0"),
|
|
detail: Option.none(),
|
|
auth: {
|
|
status: "authenticated",
|
|
account: Option.some("octo"),
|
|
host: Option.some("github.com"),
|
|
detail: Option.none(),
|
|
},
|
|
},
|
|
{
|
|
kind: "gitlab",
|
|
label: "GitLab",
|
|
status: "available",
|
|
installHint: "Install glab",
|
|
version: Option.some("1.0.0"),
|
|
detail: Option.none(),
|
|
auth: {
|
|
status: "unauthenticated",
|
|
account: Option.none(),
|
|
host: Option.none(),
|
|
detail: Option.some("Run glab auth login"),
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
const readiness = buildAddProjectRemoteSourceReadiness(discovery);
|
|
expect(readiness.url.ready).toBe(true);
|
|
expect(readiness.github.ready).toBe(true);
|
|
expect(readiness.gitlab).toEqual({ ready: false, hint: "Run glab auth login" });
|
|
expect(sortAddProjectProviderSources(readiness)[0]).toBe("github");
|
|
});
|
|
|
|
it("finds existing projects by normalized path in the target environment", () => {
|
|
const env = EnvironmentId.make("env");
|
|
const other = EnvironmentId.make("other");
|
|
const projects: EnvironmentProject[] = [
|
|
{
|
|
environmentId: other,
|
|
id: ProjectId.make("same-path-other-env"),
|
|
title: "Other",
|
|
workspaceRoot: "/repo",
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
updatedAt: "2026-01-01T00:00:00.000Z",
|
|
repositoryIdentity: null,
|
|
defaultModelSelection: null,
|
|
scripts: [],
|
|
},
|
|
{
|
|
environmentId: env,
|
|
id: ProjectId.make("project"),
|
|
title: "Repo",
|
|
workspaceRoot: "/repo/",
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
updatedAt: "2026-01-01T00:00:00.000Z",
|
|
repositoryIdentity: null,
|
|
defaultModelSelection: null,
|
|
scripts: [],
|
|
},
|
|
];
|
|
|
|
expect(findExistingAddProject({ projects, environmentId: env, path: "/repo" })?.id).toBe(
|
|
"project",
|
|
);
|
|
});
|
|
|
|
it("builds the V2 project.create mutation", () => {
|
|
expect(
|
|
buildProjectCreateCommand({
|
|
commandId: CommandId.make("command"),
|
|
projectId: ProjectId.make("project"),
|
|
workspaceRoot: "/work/repo",
|
|
}),
|
|
).toMatchObject({
|
|
type: "project.create",
|
|
commandId: "command",
|
|
projectId: "project",
|
|
title: "repo",
|
|
workspaceRoot: "/work/repo",
|
|
createWorkspaceRootIfMissing: true,
|
|
defaultModelSelection: null,
|
|
});
|
|
});
|
|
});
|