Showing the changes to apps/server/src/sourceControl/SourceControlDiscovery.test.ts (1 of 14 files). Show all
Unified · Split
| @@ -0,0 +1,77 @@ | |||
| 1 | import { assert, it } from "@effect/vitest"; | ||
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| 3 | import { Effect, Layer } from "effect"; | ||
| 4 | import { ChildProcessSpawner } from "effect/unstable/process"; | ||
| 5 | import { VcsProcessSpawnError } from "@t3tools/contracts"; | ||
| 6 | |||
| 7 | import { ServerConfig } from "../config.ts"; | ||
| 8 | import * as VcsProcess from "../vcs/VcsProcess.ts"; | ||
| 9 | import { SourceControlDiscovery, layer } from "./SourceControlDiscovery.ts"; | ||
| 10 | |||
| 11 | const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({ | ||
| 12 | exitCode: ChildProcessSpawner.ExitCode(0), | ||
| 13 | stdout, | ||
| 14 | stderr: "", | ||
| 15 | stdoutTruncated: false, | ||
| 16 | stderrTruncated: false, | ||
| 17 | }); | ||
| 18 | |||
| 19 | it.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 | }); | ||