Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 EnvironmentId,
4 ProjectId,
5 CommandId,
6 SourceControlDiscoveryResult,
7} from "@t3tools/contracts";
8import * as Option from "effect/Option";
9
10import {
11 buildAddProjectRemoteSourceReadiness,
12 buildProjectCreateCommand,
13 findExistingAddProject,
14 getAddProjectInitialQuery,
15 resolveAddProjectPath,
16 sortAddProjectProviderSources,
17} from "./addProject.ts";
18import type { EnvironmentScopedProjectShell } from "./shellTypes.ts";
19
20describe("add project shared logic", () => {
21 it("resolves initial browse paths from settings", () => {
22 expect(getAddProjectInitialQuery("")).toBe("~/");
23 expect(getAddProjectInitialQuery("/work")).toBe("/work/");
24 expect(getAddProjectInitialQuery("C:\\work")).toBe("C:\\work\\");
25 });
26
27 it("rejects unsupported windows paths on non-windows environments", () => {
28 expect(
29 resolveAddProjectPath({
30 rawPath: "C:\\repo",
31 platform: "MacIntel",
32 currentProjectCwd: null,
33 }),
34 ).toEqual({
35 ok: false,
36 error: "Windows-style paths are only supported on Windows environments.",
37 });
38 });
39
40 it("resolves relative paths from the active project cwd", () => {
41 expect(
42 resolveAddProjectPath({
43 rawPath: "../next",
44 platform: "Linux",
45 currentProjectCwd: "/work/current",
46 }),
47 ).toEqual({ ok: true, path: "/work/next" });
48 });
49
50 it("marks authenticated source control providers as ready", () => {
51 const discovery: SourceControlDiscoveryResult = {
52 versionControlSystems: [],
53 sourceControlProviders: [
54 {
55 kind: "github",
56 label: "GitHub",
57 status: "available",
58 installHint: "Install gh",
59 version: Option.some("1.0.0"),
60 detail: Option.none(),
61 auth: {
62 status: "authenticated",
63 account: Option.some("octo"),
64 host: Option.some("github.com"),
65 detail: Option.none(),
66 },
67 },
68 {
69 kind: "gitlab",
70 label: "GitLab",
71 status: "available",
72 installHint: "Install glab",
73 version: Option.some("1.0.0"),
74 detail: Option.none(),
75 auth: {
76 status: "unauthenticated",
77 account: Option.none(),
78 host: Option.none(),
79 detail: Option.some("Run glab auth login"),
80 },
81 },
82 ],
83 };
84
85 const readiness = buildAddProjectRemoteSourceReadiness(discovery);
86 expect(readiness.url.ready).toBe(true);
87 expect(readiness.github.ready).toBe(true);
88 expect(readiness.gitlab).toEqual({ ready: false, hint: "Run glab auth login" });
89 expect(sortAddProjectProviderSources(readiness)[0]).toBe("github");
90 });
91
92 it("finds existing projects by normalized path in the target environment", () => {
93 const env = EnvironmentId.make("env");
94 const other = EnvironmentId.make("other");
95 const projects: EnvironmentScopedProjectShell[] = [
96 {
97 environmentId: other,
98 id: ProjectId.make("same-path-other-env"),
99 title: "Other",
100 workspaceRoot: "/repo",
101 createdAt: "2026-01-01T00:00:00.000Z",
102 updatedAt: "2026-01-01T00:00:00.000Z",
103 repositoryIdentity: null,
104 defaultModelSelection: null,
105 scripts: [],
106 },
107 {
108 environmentId: env,
109 id: ProjectId.make("project"),
110 title: "Repo",
111 workspaceRoot: "/repo/",
112 createdAt: "2026-01-01T00:00:00.000Z",
113 updatedAt: "2026-01-01T00:00:00.000Z",
114 repositoryIdentity: null,
115 defaultModelSelection: null,
116 scripts: [],
117 },
118 ];
119
120 expect(findExistingAddProject({ projects, environmentId: env, path: "/repo" })?.id).toBe(
121 "project",
122 );
123 });
124
125 it("builds the existing project.create command shape", () => {
126 expect(
127 buildProjectCreateCommand({
128 commandId: CommandId.make("command"),
129 projectId: ProjectId.make("project"),
130 workspaceRoot: "/work/repo",
131 createdAt: "2026-01-01T00:00:00.000Z",
132 }),
133 ).toMatchObject({
134 type: "project.create",
135 commandId: "command",
136 projectId: "project",
137 title: "repo",
138 workspaceRoot: "/work/repo",
139 createWorkspaceRootIfMissing: true,
140 defaultModelSelection: {
141 instanceId: "codex",
142 model: "gpt-5.4",
143 },
144 });
145 });
146});