History

Add source control settings discovery

Julius Marminge committed 6 months ago

Commit dc2e2651 parent 128b43214 files · +644 −3Browse files

Showing the changes to apps/server/src/sourceControl/SourceControlDiscovery.test.ts (1 of 14 files). Show all

Unified · Split

apps/server/src/sourceControl/SourceControlDiscovery.test.ts+77−0
@@ -0,0 +1,77 @@
1import { assert, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { Effect, Layer } from "effect";
4import { ChildProcessSpawner } from "effect/unstable/process";
5import { VcsProcessSpawnError } from "@t3tools/contracts";
6
7import { ServerConfig } from "../config.ts";
8import * as VcsProcess from "../vcs/VcsProcess.ts";
9import { SourceControlDiscovery, layer } from "./SourceControlDiscovery.ts";
10
11const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
12 exitCode: ChildProcessSpawner.ExitCode(0),
13 stdout,
14 stderr: "",
15 stdoutTruncated: false,
16 stderrTruncated: false,
17});
18
19it.effect("reports implemented tools separately from locally available CLIs", () => {
20 const testLayer = layer.pipe(
21 Layer.provide(
22 ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
23 ),
24 Layer.provide(
25 Layer.mock(VcsProcess.VcsProcess)({
26 run: (input) => {
27 if (input.command === "git") {
28 return Effect.succeed(processOutput("git version 2.51.0\n"));
29 }
30 if (input.command === "gh") {
31 return Effect.succeed(processOutput("gh version 2.83.0\n"));
32 }
33 return Effect.fail(
34 new VcsProcessSpawnError({
35 operation: input.operation,
36 command: input.command,
37 cwd: input.cwd,
38 cause: new Error(`${input.command} not found`),
39 }),
40 );
41 },
42 }),
43 ),
44 Layer.provideMerge(NodeServices.layer),
45 );
46
47 return Effect.gen(function* () {
48 const discovery = yield* SourceControlDiscovery;
49 const result = yield* discovery.discover;
50
51 assert.deepStrictEqual(
52 result.versionControlSystems.map((item) => ({
53 kind: item.kind,
54 implemented: item.implemented,
55 status: item.status,
56 })),
57 [
58 { kind: "git", implemented: true, status: "available" },
59 { kind: "jj", implemented: false, status: "missing" },
60 { kind: "sapling", implemented: false, status: "missing" },
61 ],
62 );
63 assert.deepStrictEqual(
64 result.sourceControlProviders.map((item) => ({
65 kind: item.kind,
66 implemented: item.implemented,
67 status: item.status,
68 })),
69 [
70 { kind: "github", implemented: true, status: "available" },
71 { kind: "gitlab", implemented: false, status: "missing" },
72 { kind: "azure-devops", implemented: false, status: "missing" },
73 { kind: "bitbucket", implemented: false, status: "missing" },
74 ],
75 );
76 }).pipe(Effect.provide(testLayer));
77});

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t