Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
75 changes: 75 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,81 @@ const initRepoWithCommit = (
});

it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
describe("structured errors", () => {
it.effect("preserves structured spawn context and the platform cause", () =>
Effect.gen(function* () {
const parent = yield* makeTmpDir();
const pathService = yield* Path.Path;
const cwd = pathService.join(parent, "missing");
const driver = yield* GitVcsDriver.GitVcsDriver;

const error = yield* driver
.execute({
operation: "GitVcsDriver.test.missingCwd",
cwd,
args: ["status", "--short"],
})
.pipe(Effect.flip);

assert.deepInclude(error, {
_tag: "GitCommandError",
operation: "GitVcsDriver.test.missingCwd",
command: "git status --short",
cwd,
detail: "Failed to spawn Git process.",
});
if (!(error.cause instanceof PlatformError.PlatformError)) {
return assert.fail("expected the original platform error cause");
}
assert.equal(error.cause.reason._tag, "NotFound");
assert.notInclude(error.detail, error.cause.message);
}),
);

it.effect("recovers a structurally identified missing cwd as a non-repository", () =>
Effect.gen(function* () {
const parent = yield* makeTmpDir();
const pathService = yield* Path.Path;
const cwd = pathService.join(parent, "missing");
const driver = yield* GitVcsDriver.GitVcsDriver;

const [localStatus, remoteStatus, refs] = yield* Effect.all([
driver.statusDetails(cwd),
driver.statusDetailsRemote(cwd, { refreshUpstream: false }),
driver.listRefs({ cwd }),
]);

assert.equal(localStatus.isRepo, false);
assert.equal(remoteStatus.isRepo, false);
assert.equal(refs.isRepo, false);
assert.deepStrictEqual(refs.refs, []);
}),
);

it.effect("does not wrap a remove-worktree command failure in a synthetic error", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const pathService = yield* Path.Path;
const missingWorktree = pathService.join(cwd, "missing-worktree");
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* driver.initRepo({ cwd });

const error = yield* driver
.removeWorktree({ cwd, path: missingWorktree })
.pipe(Effect.flip);

assert.deepInclude(error, {
_tag: "GitCommandError",
operation: "GitVcsDriver.removeWorktree",
command: `git worktree remove ${missingWorktree}`,
cwd,
});
assert.notProperty(error, "cause");
assert.notInclude(error.detail, "Git command failed in");
}),
);
});

describe("review diff previews", () => {
it.effect("drops an unterminated path from truncated NUL-separated git output", () =>
Effect.sync(() => {
Expand Down
Loading
Loading