- Detect GitHub, GitLab, and Azure DevOps remotes in the shared parser - Cache provider resolution and return unsupported stubs for unregistered kinds - Remove deprecated git RPCs from the web IPC surface
Showing the changes to apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts (1 of 8 files). Show all
Unified · Split
| @@ -0,0 +1,82 @@ | ||
| 1 | +import { assert, it } from "@effect/vitest"; | |
| 2 | +import { Effect, Layer } from "effect"; | |
| 3 | + | |
| 4 | +import { GitHubCli } from "../git/Services/GitHubCli.ts"; | |
| 5 | +import * as GitVcsDriver from "../vcs/GitVcsDriver.ts"; | |
| 6 | +import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts"; | |
| 7 | + | |
| 8 | +const processResult = (stdout: string) => ({ | |
| 9 | + stdout, | |
| 10 | + stderr: "", | |
| 11 | + code: 0, | |
| 12 | + signal: null, | |
| 13 | + timedOut: false, | |
| 14 | + stdoutTruncated: false, | |
| 15 | + stderrTruncated: false, | |
| 16 | +}); | |
| 17 | + | |
| 18 | +function makeRegistry(input: { | |
| 19 | + readonly originUrl?: string | null; | |
| 20 | + readonly remoteVerboseOutput?: string; | |
| 21 | +}) { | |
| 22 | + const gitLayer = Layer.mock(GitVcsDriver.GitVcsDriver)({ | |
| 23 | + readConfigValue: (_cwd, key) => | |
| 24 | + key === "remote.origin.url" ? Effect.succeed(input.originUrl ?? null) : Effect.succeed(null), | |
| 25 | + execute: () => Effect.succeed(processResult(input.remoteVerboseOutput ?? "")), | |
| 26 | + }); | |
| 27 | + | |
| 28 | + return SourceControlProviderRegistry.make().pipe( | |
| 29 | + Effect.provide(Layer.mergeAll(gitLayer, Layer.mock(GitHubCli)({}))), | |
| 30 | + ); | |
| 31 | +} | |
| 32 | + | |
| 33 | +it.effect("routes GitHub remotes to the GitHub provider", () => | |
| 34 | + Effect.gen(function* () { | |
| 35 | + const registry = yield* makeRegistry({ | |
| 36 | + originUrl: "git@github.com:pingdotgg/t3code.git", | |
| 37 | + }); | |
| 38 | + | |
| 39 | + const provider = yield* registry.resolve({ cwd: "/repo" }); | |
| 40 | + | |
| 41 | + assert.strictEqual(provider.kind, "github"); | |
| 42 | + }), | |
| 43 | +); | |
| 44 | + | |
| 45 | +it.effect( | |
| 46 | + "detects GitLab remotes and returns an unsupported provider until one is registered", | |
| 47 | + () => | |
| 48 | + Effect.gen(function* () { | |
| 49 | + const registry = yield* makeRegistry({ | |
| 50 | + originUrl: "git@gitlab.com:group/project.git", | |
| 51 | + }); | |
| 52 | + | |
| 53 | + const provider = yield* registry.resolve({ cwd: "/repo" }); | |
| 54 | + | |
| 55 | + assert.strictEqual(provider.kind, "gitlab"); | |
| 56 | + const error = yield* Effect.flip( | |
| 57 | + provider.listChangeRequests({ | |
| 58 | + cwd: "/repo", | |
| 59 | + headSelector: "feature/source-control", | |
| 60 | + state: "open", | |
| 61 | + }), | |
| 62 | + ); | |
| 63 | + | |
| 64 | + assert.strictEqual(error.provider, "gitlab"); | |
| 65 | + }), | |
| 66 | +); | |
| 67 | + | |
| 68 | +it.effect("falls back to remote verbose output when origin is not configured", () => | |
| 69 | + Effect.gen(function* () { | |
| 70 | + const registry = yield* makeRegistry({ | |
| 71 | + originUrl: null, | |
| 72 | + remoteVerboseOutput: [ | |
| 73 | + "upstream\thttps://dev.azure.com/acme/project/_git/repo (fetch)", | |
| 74 | + "upstream\thttps://dev.azure.com/acme/project/_git/repo (push)", | |
| 75 | + ].join("\n"), | |
| 76 | + }); | |
| 77 | + | |
| 78 | + const provider = yield* registry.resolve({ cwd: "/repo" }); | |
| 79 | + | |
| 80 | + assert.strictEqual(provider.kind, "azure-devops"); | |
| 81 | + }), | |
| 82 | +); | |