- Route git workflows through source control providers - Replace git status broadcaster with VCS status service - Update orchestration, server, and web contracts for provider-aware git
Showing the changes to apps/server/src/sourceControl/GitHubSourceControlProvider.test.ts (1 of 40 files). Show all
Unified · Split
| @@ -0,0 +1,132 @@ | |||
| 1 | import { assert, it } from "@effect/vitest"; | ||
| 2 | import { Effect, Layer } from "effect"; | ||
| 3 | |||
| 4 | import { GitHubCli, type GitHubCliShape } from "../git/Services/GitHubCli.ts"; | ||
| 5 | import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts"; | ||
| 6 | |||
| 7 | const processResult = (stdout: string) => ({ | ||
| 8 | stdout, | ||
| 9 | stderr: "", | ||
| 10 | code: 0, | ||
| 11 | signal: null, | ||
| 12 | timedOut: false, | ||
| 13 | }); | ||
| 14 | |||
| 15 | function makeProvider(github: Partial<GitHubCliShape>) { | ||
| 16 | return GitHubSourceControlProvider.make().pipe(Effect.provide(Layer.mock(GitHubCli)(github))); | ||
| 17 | } | ||
| 18 | |||
| 19 | it.effect("maps GitHub PR summaries into provider-neutral change requests", () => | ||
| 20 | Effect.gen(function* () { | ||
| 21 | const provider = yield* makeProvider({ | ||
| 22 | getPullRequest: () => | ||
| 23 | Effect.succeed({ | ||
| 24 | number: 42, | ||
| 25 | title: "Add GitHub provider", | ||
| 26 | url: "https://github.com/pingdotgg/t3code/pull/42", | ||
| 27 | baseRefName: "main", | ||
| 28 | headRefName: "feature/source-control", | ||
| 29 | state: "open", | ||
| 30 | isCrossRepository: true, | ||
| 31 | headRepositoryNameWithOwner: "fork/t3code", | ||
| 32 | headRepositoryOwnerLogin: "fork", | ||
| 33 | }), | ||
| 34 | }); | ||
| 35 | |||
| 36 | const changeRequest = yield* provider.getChangeRequest({ | ||
| 37 | cwd: "/repo", | ||
| 38 | reference: "42", | ||
| 39 | }); | ||
| 40 | |||
| 41 | assert.deepStrictEqual(changeRequest, { | ||
| 42 | provider: "github", | ||
| 43 | number: 42, | ||
| 44 | title: "Add GitHub provider", | ||
| 45 | url: "https://github.com/pingdotgg/t3code/pull/42", | ||
| 46 | baseRefName: "main", | ||
| 47 | headRefName: "feature/source-control", | ||
| 48 | state: "open", | ||
| 49 | updatedAt: null, | ||
| 50 | isCrossRepository: true, | ||
| 51 | headRepositoryNameWithOwner: "fork/t3code", | ||
| 52 | headRepositoryOwnerLogin: "fork", | ||
| 53 | }); | ||
| 54 | }), | ||
| 55 | ); | ||
| 56 | |||
| 57 | it.effect("uses gh json listing for non-open change request state queries", () => | ||
| 58 | Effect.gen(function* () { | ||
| 59 | let executeArgs: ReadonlyArray<string> = []; | ||
| 60 | const provider = yield* makeProvider({ | ||
| 61 | execute: (input) => { | ||
| 62 | executeArgs = input.args; | ||
| 63 | return Effect.succeed( | ||
| 64 | processResult( | ||
| 65 | JSON.stringify([ | ||
| 66 | { | ||
| 67 | number: 7, | ||
| 68 | title: "Merged work", | ||
| 69 | url: "https://github.com/pingdotgg/t3code/pull/7", | ||
| 70 | baseRefName: "main", | ||
| 71 | headRefName: "feature/merged", | ||
| 72 | state: "merged", | ||
| 73 | updatedAt: "2026-01-02T00:00:00.000Z", | ||
| 74 | }, | ||
| 75 | ]), | ||
| 76 | ), | ||
| 77 | ); | ||
| 78 | }, | ||
| 79 | }); | ||
| 80 | |||
| 81 | const changeRequests = yield* provider.listChangeRequests({ | ||
| 82 | cwd: "/repo", | ||
| 83 | headSelector: "feature/merged", | ||
| 84 | state: "all", | ||
| 85 | limit: 10, | ||
| 86 | }); | ||
| 87 | |||
| 88 | assert.deepStrictEqual(executeArgs, [ | ||
| 89 | "pr", | ||
| 90 | "list", | ||
| 91 | "--head", | ||
| 92 | "feature/merged", | ||
| 93 | "--state", | ||
| 94 | "all", | ||
| 95 | "--limit", | ||
| 96 | "10", | ||
| 97 | "--json", | ||
| 98 | "number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner", | ||
| 99 | ]); | ||
| 100 | assert.strictEqual(changeRequests[0]?.provider, "github"); | ||
| 101 | assert.strictEqual(changeRequests[0]?.state, "merged"); | ||
| 102 | assert.strictEqual(changeRequests[0]?.updatedAt, "2026-01-02T00:00:00.000Z"); | ||
| 103 | }), | ||
| 104 | ); | ||
| 105 | |||
| 106 | it.effect("creates GitHub PRs through provider-neutral input names", () => | ||
| 107 | Effect.gen(function* () { | ||
| 108 | let createInput: Parameters<GitHubCliShape["createPullRequest"]>[0] | null = null; | ||
| 109 | const provider = yield* makeProvider({ | ||
| 110 | createPullRequest: (input) => { | ||
| 111 | createInput = input; | ||
| 112 | return Effect.void; | ||
| 113 | }, | ||
| 114 | }); | ||
| 115 | |||
| 116 | yield* provider.createChangeRequest({ | ||
| 117 | cwd: "/repo", | ||
| 118 | baseRefName: "main", | ||
| 119 | headSelector: "owner:feature/provider", | ||
| 120 | title: "Provider PR", | ||
| 121 | bodyFile: "/tmp/body.md", | ||
| 122 | }); | ||
| 123 | |||
| 124 | assert.deepStrictEqual(createInput, { | ||
| 125 | cwd: "/repo", | ||
| 126 | baseBranch: "main", | ||
| 127 | headSelector: "owner:feature/provider", | ||
| 128 | title: "Provider PR", | ||
| 129 | bodyFile: "/tmp/body.md", | ||
| 130 | }); | ||
| 131 | }), | ||
| 132 | ); | ||