Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions apps/server/src/bin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
import {
CommandId,
EnvironmentOrchestrationHttpApi,
ProjectId,
ProviderInstanceId,
ThreadId,
} from "@t3tools/contracts";
Expand Down Expand Up @@ -46,6 +47,7 @@ import {
persistServerRuntimeState,
} from "./serverRuntimeState.ts";
import * as WorkspacePaths from "./workspace/WorkspacePaths.ts";
import { normalizeDispatchCommand } from "./orchestration/Normalizer.ts";
import * as ServerSecretStore from "./auth/ServerSecretStore.ts";
import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
import { environmentAuthenticatedAuthLayer } from "./auth/http.ts";
Expand Down Expand Up @@ -138,6 +140,62 @@ const readPersistedSnapshot = (baseDir: string) =>
}).pipe(Effect.provide(makeProjectPersistenceLayer(config)));
});

it.effect.each(["bare", "bare-index", "separate", "converted"] as const)(
"project add and normalization respect current Git bare status: %s",
(layout) =>
Effect.gen(function* () {
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-cli-bare-state-"));
const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-cli-bare-root-"));
const gitDir = NodePath.join(root, "store");
const git = (...args: string[]) =>
NodeChildProcess.execFileSync("git", args, { cwd: root, stdio: "ignore" });
if (layout === "separate") {
git("init", "--separate-git-dir", gitDir);
} else {
git("init", "--bare", gitDir);
NodeFS.writeFileSync(NodePath.join(root, ".git"), "gitdir: ./store\n");
}
git("worktree", "add", "--orphan", "-b", "feature", "feature");
if (layout === "bare-index") git("--git-dir", gitDir, "read-tree", "--empty");
if (layout === "converted") git("init");

const cliResult = yield* runCliWithRuntime([
"project",
"add",
root,
"--base-dir",
baseDir,
]).pipe(Effect.result);
const config = yield* makeCliTestServerConfig(baseDir);
const normalized = yield* normalizeDispatchCommand({
type: "project.create",
commandId: CommandId.make("bare-create-command"),
projectId: ProjectId.make("bare-create-project"),
title: "Bare layout fixture",
workspaceRoot: root,
createdAt: "2026-09-05T04:00:00.000Z",
}).pipe(
Effect.provide(
Layer.mergeAll(WorkspacePaths.layer, ServerConfig.layer(config)).pipe(
Layer.provide(NodeServices.layer),
),
),
Effect.result,
);
const snapshot = yield* readPersistedSnapshot(baseDir);
const projects = snapshot.projects.filter((project) => project.workspaceRoot === root);
if (layout === "bare" || layout === "bare-index") {
assert.strictEqual(cliResult._tag, "Failure");
assert.strictEqual(normalized._tag, "Failure");
assert.lengthOf(projects, 0);
} else {
assert.strictEqual(cliResult._tag, "Success");
assert.strictEqual(normalized._tag, "Success");
assert.lengthOf(projects, 1);
}
}).pipe(Effect.provide(NodeServices.layer)),
);

const makeProjectLookupFixture = Effect.fn("makeProjectLookupFixture")(function* (
withThread: boolean,
removeWorkspace: boolean,
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/cli/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ const projectAddCommand = Command.make("add", {
command: ProjectCliDispatchCommand,
) => Effect.Effect<void, Error, FileSystem.FileSystem | HttpClient.HttpClient | Path.Path>;
}) {
const workspaceRoot = yield* normalizeWorkspaceRootForProjectCommand(flags.workspaceRoot);
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
const workspaceRoot = yield* normalizeWorkspaceRootForProjectCommand(
flags.workspaceRoot,
).pipe(Effect.flatMap(workspacePaths.ensureNotBareRepositoryLayout));
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Resolved
const existingProject = snapshot.projects.find(
(project) => project.deletedAt === null && project.workspaceRoot === workspaceRoot,
);
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/orchestration/Normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
createIfMissing: createIfMissing === true,
})
.pipe(
Effect.flatMap(workspacePaths.ensureNotBareRepositoryLayout),
Effect.mapError(
(cause) =>
new OrchestrationDispatchCommandError({
Expand Down
Loading
Loading