Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: codex <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
133 lines
3.7 KiB
TypeScript
133 lines
3.7 KiB
TypeScript
import { assert, it } from "@effect/vitest";
|
|
import { Effect, Layer } from "effect";
|
|
import { describe, vi } from "vitest";
|
|
|
|
import { GitManager } from "./GitManager.ts";
|
|
import { GitWorkflowService, layer as GitWorkflowServiceLayer } from "./GitWorkflowService.ts";
|
|
import { GitVcsDriver } from "../vcs/GitVcsDriver.ts";
|
|
import { VcsDriverRegistry, type VcsDriverRegistryShape } from "../vcs/VcsDriverRegistry.ts";
|
|
|
|
function makeLayer(input: { readonly detect: VcsDriverRegistryShape["detect"] }) {
|
|
return GitWorkflowServiceLayer.pipe(
|
|
Layer.provide(
|
|
Layer.mock(VcsDriverRegistry)({
|
|
detect: input.detect,
|
|
}),
|
|
),
|
|
Layer.provide(Layer.mock(GitVcsDriver)({})),
|
|
Layer.provide(Layer.mock(GitManager)({})),
|
|
);
|
|
}
|
|
|
|
describe("GitWorkflowService", () => {
|
|
it.effect("returns an empty local status when no VCS repository is detected", () =>
|
|
Effect.gen(function* () {
|
|
const workflow = yield* GitWorkflowService;
|
|
const status = yield* workflow.localStatus({ cwd: "/not-a-repo" });
|
|
|
|
assert.deepStrictEqual(status, {
|
|
isRepo: false,
|
|
hasPrimaryRemote: false,
|
|
isDefaultRef: false,
|
|
refName: null,
|
|
hasWorkingTreeChanges: false,
|
|
workingTree: {
|
|
files: [],
|
|
insertions: 0,
|
|
deletions: 0,
|
|
},
|
|
});
|
|
}).pipe(
|
|
Effect.provide(
|
|
makeLayer({
|
|
detect: () => Effect.succeed(null),
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
|
|
it.effect("returns an empty full status when no VCS repository is detected", () =>
|
|
Effect.gen(function* () {
|
|
const workflow = yield* GitWorkflowService;
|
|
const status = yield* workflow.status({ cwd: "/not-a-repo" });
|
|
|
|
assert.deepStrictEqual(status, {
|
|
isRepo: false,
|
|
hasPrimaryRemote: false,
|
|
isDefaultRef: false,
|
|
refName: null,
|
|
hasWorkingTreeChanges: false,
|
|
workingTree: {
|
|
files: [],
|
|
insertions: 0,
|
|
deletions: 0,
|
|
},
|
|
hasUpstream: false,
|
|
aheadCount: 0,
|
|
behindCount: 0,
|
|
pr: null,
|
|
});
|
|
}).pipe(
|
|
Effect.provide(
|
|
makeLayer({
|
|
detect: () => Effect.succeed(null),
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
|
|
it.effect("does not call GitManager status methods when no VCS repository is detected", () => {
|
|
const localStatus = vi.fn();
|
|
const remoteStatus = vi.fn();
|
|
const status = vi.fn();
|
|
|
|
const testLayer = GitWorkflowServiceLayer.pipe(
|
|
Layer.provide(
|
|
Layer.mock(VcsDriverRegistry)({
|
|
detect: () => Effect.succeed(null),
|
|
}),
|
|
),
|
|
Layer.provide(Layer.mock(GitVcsDriver)({})),
|
|
Layer.provide(
|
|
Layer.mock(GitManager)({
|
|
localStatus,
|
|
remoteStatus,
|
|
status,
|
|
}),
|
|
),
|
|
);
|
|
|
|
return Effect.gen(function* () {
|
|
const workflow = yield* GitWorkflowService;
|
|
yield* workflow.localStatus({ cwd: "/not-a-repo" });
|
|
yield* workflow.remoteStatus({ cwd: "/not-a-repo" });
|
|
yield* workflow.status({ cwd: "/not-a-repo" });
|
|
|
|
assert.equal(localStatus.mock.calls.length, 0);
|
|
assert.equal(remoteStatus.mock.calls.length, 0);
|
|
assert.equal(status.mock.calls.length, 0);
|
|
}).pipe(Effect.provide(testLayer));
|
|
});
|
|
|
|
it.effect("returns an empty ref list when no VCS repository is detected", () =>
|
|
Effect.gen(function* () {
|
|
const workflow = yield* GitWorkflowService;
|
|
const refs = yield* workflow.listRefs({ cwd: "/not-a-repo" });
|
|
|
|
assert.deepStrictEqual(refs, {
|
|
refs: [],
|
|
isRepo: false,
|
|
hasPrimaryRemote: false,
|
|
nextCursor: null,
|
|
totalCount: 0,
|
|
});
|
|
}).pipe(
|
|
Effect.provide(
|
|
makeLayer({
|
|
detect: () => Effect.succeed(null),
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
});
|