Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitHubSourceControlProvider.test.ts

1,387 lines46.4 KB

1import { SourceControlProviderKind } from "@t3tools/contracts";
2import * as HostProcess from "@t3tools/shared/HostProcess";
3import { assert, describe, it } from "@effect/vitest";
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import * as Effect from "effect/Effect";
6import * as Fiber from "effect/Fiber";
7import * as FileSystem from "effect/FileSystem";
8import * as Layer from "effect/Layer";
9import * as Option from "effect/Option";
10import * as Redacted from "effect/Redacted";
11import * as Schema from "effect/Schema";
12import { HttpClient, HttpClientResponse } from "effect/http";
13import { ChildProcessSpawner } from "effect/process";
14import * as TestClock from "effect/testing/TestClock";
15import { userFacingSourceControlDetail } from "@t3tools/source-control-core/server/SourceControlProvider";
16import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
17​
18import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
19import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
20import * as GitHubRest from "./GitHubRest.ts";
21import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
22import * as GitHubCredentials from "./GitHubCredentials.ts";
23import * as GitHubQuota from "./GitHubQuota.ts";
24import { parseGitHubAuthStatus } from "./gitHubAuthStatus.ts";
25import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
26import * as GitHubAppSignIn from "./GitHubAppSignIn.ts";
27​
28const appSignedOut = Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({
29 enabled: false,
30 token: () => Effect.succeedNone,
31 invalidate: () => Effect.void,
32});
33​
34const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
35​
36const processResult = (
37 stdout: string,
38 options?: {
39 readonly stderr?: string;
40 readonly exitCode?: ChildProcessSpawner.ExitCode;
41 },
42): SourceControlHost.SourceControlProcessOutput => ({
43 exitCode: options?.exitCode ?? ChildProcessSpawner.ExitCode(0),
44 stdout,
45 stderr: options?.stderr ?? "",
46 stdoutTruncated: false,
47 stderrTruncated: false,
48});
49​
50const processOutput = (
51 stdout: string,
52 exitCode = 0,
53): SourceControlHost.SourceControlProcessOutput => ({
54 exitCode: ChildProcessSpawner.ExitCode(exitCode),
55 stdout,
56 stderr: "",
57 stdoutTruncated: false,
58 stderrTruncated: false,
59});
60​
61const remotesOutput = (...entries: ReadonlyArray<readonly [string, string]>) =>
62 entries
63 .flatMap(([name, url]) => [`${name}\t${url} (fetch)`, `${name}\t${url} (push)`])
64 .join("\n");
65​
66const restResponse = (body: unknown, status = 200): GitHubRest.GitHubRestResponse => ({
67 status,
68 headers: {},
69 body: body === undefined ? "" : encodeJson(body),
70 truncated: false,
71 invalidUtf8: false,
72});
73​
74const node = (number: number, headRefName: string, owner = "acme") => ({
75 number,
76 title: `PR ${number}`,
77 url: `https://github.com/acme/web/pull/${number}`,
78 baseRefName: "main",
79 headRefName,
80 headRefOid: "f".repeat(40),
81 state: "OPEN",
82 isDraft: false,
83 mergedAt: null,
84 closedAt: null,
85 isCrossRepository: owner !== "acme",
86 updatedAt: "2026-01-02T00:00:00Z",
87 headRepository: { name: "web", nameWithOwner: `${owner}/web` },
88 headRepositoryOwner: { __typename: "User", login: owner },
89});
90​
91interface GraphQlCall {
92 readonly host: string;
93 readonly operationName: string;
94 readonly query: string;
95 readonly lookups: ReadonlyArray<Readonly<Record<string, unknown>>>;
97​
98type GraphQlAnswer = unknown;
99type GraphQlRespond = (
100 lookup: Readonly<Record<string, unknown>>,
101 call: GraphQlCall,
102) => GraphQlAnswer | Response;
103​
104function graphQlHttp(respond: GraphQlRespond, calls: Array<GraphQlCall>) {
105 return HttpClient.make((request) =>
106 Effect.sync(() => {
107 const sent =
108 request.body._tag === "Uint8Array"
109 ? (JSON.parse(new TextDecoder().decode(request.body.body)) as {
110 readonly query: string;
111 readonly operationName: string;
112 readonly variables: Readonly<Record<string, unknown>>;
113 })
114 : { query: "", operationName: "", variables: {} };
115 const prefixes = [
116 ...new Set(Object.keys(sent.variables).flatMap((key) => /^_\d+_/.exec(key) ?? [])),
117 ];
118 const lookups =
119 prefixes.length === 0
120 ? [sent.variables]
121 : prefixes.map((prefix) =>
122 Object.fromEntries(
123 Object.entries(sent.variables)
124 .filter(([key]) => key.startsWith(prefix))
125 .map(([key, value]) => [key.slice(prefix.length), value]),
126 ),
127 );
128 const call: GraphQlCall = {
129 host: new URL(request.url).hostname.replace(/^api\./, ""),
130 operationName: sent.operationName,
131 query: sent.query,
132 lookups,
133 };
134 calls.push(call);
135 const answers = lookups.map((lookup) => respond(lookup, call));
136 const refusal = answers.find((answer) => answer instanceof Response);
137 const response =
138 refusal ??
139 new Response(
140 encodeJson({
141 data: Object.fromEntries(
142 answers.map((answer, index) => [
143 prefixes.length === 0 ? "repository" : `${prefixes[index]}repository`,
144 answer,
145 ]),
146 ),
147 }),
148 { headers: { "content-type": "application/json" } },
149 );
150 return HttpClientResponse.fromWeb(request, response);
151 }),
152 );
154​
155function harness(input: {
156 readonly remotes: string;
157 readonly api?: Partial<GitHubRest.GitHubRest["Service"]>;
158 readonly graphql?: GraphQlRespond;
159 readonly credential?: (
160 host: string,
161 ) => Effect.Effect<
162 GitHubCredentials.GitHubCredential,
163 GitHubCredentials.GitHubCredentialUnavailableError
164 >;
165 readonly localBranches?: ReadonlyArray<string>;
166 readonly resolved?: string;
167 readonly gitFailure?: unknown;
168 readonly originUrls?: string;
169}) {
170 const git: Array<readonly [string, unknown]> = [];
171 const graphqlCalls: Array<GraphQlCall> = [];
172 const record =
173 <A>(name: string, value: A) =>
174 (args: unknown) =>
175 Effect.sync(() => {
176 git.push([name, args]);
177 return value;
178 });
179 const hostGit: Partial<SourceControlHost.SourceControlHost["Service"]["git"]> = {
180 execute: (args) =>
181 Effect.sync(() => {
182 git.push(["execute", args.args]);
183 return processOutput(
184 args.args[0] === "config" ? (input.originUrls ?? "git@github.com:acme/web.git\n") : "",
185 );
186 }),
187 resolvePrimaryRemoteName: () => Effect.succeed("origin"),
188 readConfigValue: () => Effect.succeed("git@github.com:acme/web.git"),
189 ensureRemote: (args) =>
190 Effect.sync(() => {
191 git.push(["ensureRemote", args]);
192 return args.preferredName;
193 }),
194 fetchRemoteTrackingBranch: (args) => record("fetchRemoteTrackingBranch", undefined)(args),
195 setBranchUpstream: (args) => record("setBranchUpstream", undefined)(args),
196 createBranch: (args) => record("createBranch", undefined)(args),
197 writeConfigValue: (args) => record("writeConfigValue", undefined)(args),
198 switchRef: (args) => record("switchRef", { refName: args.refName })(args) as never,
199 listLocalBranchNames: () =>
200 input.gitFailure === undefined
201 ? Effect.succeed([...(input.localBranches ?? [])])
202 : Effect.fail(input.gitFailure as never),
203 resolveCommit: () => Effect.succeed({ commitSha: "abc123" }),
204 };
205 const host = TestSourceControlHost.layer({
206 git: hostGit,
207 process: {
208 run: (args) =>
209 Effect.succeed(
210 args.args[0] === "remote"
211 ? processOutput(input.remotes)
212 : processOutput(input.resolved ?? "", input.resolved ? 0 : 1),
213 ),
214 },
215 });
216 const graphql =
217 input.graphql ??
218 (() => {
219 throw new Error("Unexpected GraphQL read");
220 });
221 const policy = GitHubRequestPolicy.layer.pipe(
222 Layer.provide(
223 Layer.mergeAll(
224 Layer.succeed(GitHubCredentials.GitHubCredentials, {
225 get:
226 input.credential ??
227 ((host) =>
228 Effect.succeed({
229 host,
230 token: Redacted.make("token"),
231 source: "gh" as const,
232 fingerprint: `${host}:token`,
233 })),
234 saved: () => Effect.succeedNone,
235 fingerprint: (host, token) => Effect.succeed(`${host}:${token}`),
236 invalidate: () => Effect.void,
237 }),
238 GitHubQuota.layer,
239 SourceControlRateLimit.layer,
240 appSignedOut,
241 ),
242 ),
243 );
244 const layer = Layer.mergeAll(
245 host,
246 appSignedOut,
247 Layer.mock(GitHubRest.GitHubRest)(input.api ?? {}),
248 policy,
249 Layer.succeed(HttpClient.HttpClient, graphQlHttp(graphql, graphqlCalls)),
250 NodeServices.layer,
251 );
252 return { layer, git, graphqlCalls };
254​
255const makeProvider = (api: Partial<GitHubRest.GitHubRest["Service"]>) =>
256 GitHubSourceControlProvider.make.pipe(Effect.provide(harness({ remotes: "", api }).layer));
257​
258const githubContext = (host: string) => ({
259 provider: {
260 kind: SourceControlProviderKind.make("github"),
261 name: "GitHub",
262 baseUrl: `https://${host}`,
263 },
264 remoteName: "origin",
265 remoteUrl: `git@${host}:acme/web.git`,
266});
267​
268describe("GitHubSourceControlProvider repository resolution", () => {
269 // regression: #38251 an Enterprise Server's hostname need not say "github"; a gh login vouches for it
270 it.effect.each([
271 ["github", "github"],
272 ["unknown", "unknown"],
273 ] as const)("refines a remote on an unknown host the gh login reads as %s", ([seen, expected]) =>
274 Effect.gen(function* () {
275 const provider = yield* makeProvider({});
276 const remoteUrl = "https://code.acme.test/acme/web.git";
277 const identity = {
278 canonicalKey: "code.acme.test/acme/web",
279 locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl },
280 rootPath: "/repo",
281 provider: SourceControlProviderKind.make("unknown"),
282 };
283 const refined = yield* provider.refineRepositoryIdentity!({
284 identity,
285 resolveContext: ({ context }) =>
286 Effect.succeed({
287 ...context,
288 provider: { ...context.provider, kind: SourceControlProviderKind.make(seen) },
289 }),
290 });
291 assert.deepStrictEqual(refined, {
292 ...identity,
293 provider: SourceControlProviderKind.make(expected),
294 });
295 }),
296 );
297​
298 it.effect("reads the repository gh would pick from the remotes", () => {
299 const paths: string[] = [];
300 const { layer } = harness({
301 remotes: remotesOutput(
302 ["origin", "git@github.com:me/web.git"],
303 ["upstream", "https://github.com/acme/web.git"],
304 ),
305 api: {
306 rest: (input) =>
307 Effect.sync(() => {
308 paths.push(`${input.host} ${input.path}`);
309 return restResponse({
310 full_name: "acme/web",
311 html_url: "https://github.com/acme/web",
312 ssh_url: "git@github.com:acme/web.git",
313 default_branch: "trunk",
314 });
315 }),
316 },
317 });
318 return Effect.gen(function* () {
319 const gh = yield* GitHubSourceControlProvider.make;
320 assert.strictEqual(yield* gh.getDefaultBranch({ cwd: "/repo" }), "trunk");
321 assert.deepStrictEqual(paths, ["github.com repos/acme/web"]);
322 }).pipe(Effect.provide(layer));
323 });
324​
325 it.effect("reads clone URLs on the given host before the checkout's", () => {
326 const paths: string[] = [];
327 const { layer } = harness({
328 remotes: remotesOutput(["origin", "https://github.com/acme/web.git"]),
329 api: {
330 rest: (input) =>
331 Effect.sync(() => {
332 paths.push(`${input.host} ${input.path}`);
333 return restResponse({
334 full_name: "acme/web",
335 html_url: `https://${input.host}/acme/web`,
336 ssh_url: `git@${input.host}:acme/web.git`,
337 });
338 }),
339 },
340 });
341 return Effect.gen(function* () {
342 const gh = yield* GitHubSourceControlProvider.make;
343 const cloneUrls = yield* gh.getRepositoryCloneUrls({
344 cwd: "/repo",
345 repository: "acme/web",
346 host: "GitHub.Enterprise.test",
347 });
348 yield* gh.getRepositoryCloneUrls({ cwd: "/repo", repository: "acme/web" });
349 assert.strictEqual(cloneUrls.url, "https://github.enterprise.test/acme/web");
350 assert.deepStrictEqual(paths, [
351 "github.enterprise.test repos/acme/web",
352 "github.com repos/acme/web",
353 ]);
354 }).pipe(Effect.provide(layer));
355 });
356​
357 it.effect.each([
358 ["github", "git@github:acme/web.git"],
359 ["github.com-scale", "git@github.com-scale:acme/web.git"],
360 ["github.com-scale", "ssh://git@github.com-scale:22/acme/web.git"],
361 ] as const)("reads an SSH alias on %s through github.com (%s)", ([host, remoteUrl]) => {
362 const hosts: string[] = [];
363 const { layer } = harness({
364 remotes: remotesOutput(["origin", remoteUrl]),
365 api: {
366 rest: (input) =>
367 Effect.sync(() => {
368 hosts.push(`${input.host} ${input.path}`);
369 return restResponse({
370 full_name: "acme/web",
371 html_url: "https://github.com/acme/web",
372 ssh_url: "git@github.com:acme/web.git",
373 default_branch: "main",
374 });
375 }),
376 },
377 });
378 return Effect.gen(function* () {
379 const gh = yield* GitHubSourceControlProvider.make;
380 const resolveWebHost = gh.resolveRemoteWebHost;
381 assert.ok(resolveWebHost);
382 assert.strictEqual(
383 yield* resolveWebHost({
384 cwd: "/repo",
385 context: { ...githubContext(host), remoteUrl },
386 resolveContext: () => Effect.succeed(null),
387 }),
388 "github.com",
389 );
390 yield* gh.getDefaultBranch({ cwd: "/repo" });
391 yield* gh.getDefaultBranch({
392 cwd: "/repo",
393 context: { ...githubContext(host), remoteUrl },
394 });
395 assert.deepStrictEqual(hosts, ["github.com repos/acme/web", "github.com repos/acme/web"]);
396 }).pipe(Effect.provide(layer));
397 });
398​
399 it.effect.each(["sole", "upstream", "missing"])(
400 "preserves an HTTPS context host with %s remotes",
401 (mode) => {
402 const paths: string[] = [];
403 const remoteUrl = "https://github.com-scale/me/web.git";
404 const { layer } = harness({
405 remotes:
406 mode === "missing"
407 ? ""
408 : remotesOutput(
409 ["origin", remoteUrl],
410 ...(mode === "upstream"
411 ? ([["upstream", "https://github.com/acme/web.git"]] as const)
412 : []),
413 ),
414 api: {
415 rest: (input) =>
416 Effect.sync(() => {
417 paths.push(`${input.host} ${input.path}`);
418 return restResponse({
419 full_name: "me/web",
420 html_url: "https://github.com-scale/me/web",
421 ssh_url: "git@github.com-scale:me/web.git",
422 default_branch: "trunk",
423 });
424 }),
425 },
426 });
427 return Effect.gen(function* () {
428 const gh = yield* GitHubSourceControlProvider.make;
429 const resolveWebHost = gh.resolveRemoteWebHost;
430 assert.ok(resolveWebHost);
431 for (const url of [remoteUrl, "git@github.com-evil.example:me/web.git"]) {
432 assert.strictEqual(
433 yield* resolveWebHost({
434 cwd: "/repo",
435 context: { ...githubContext("github.com-scale"), remoteUrl: url },
436 resolveContext: () => Effect.succeed(null),
437 }),
438 url === remoteUrl ? "github.com-scale" : "github.com-evil.example",
439 );
440 }
441 assert.strictEqual(
442 yield* gh.getDefaultBranch({
443 cwd: "/repo",
444 context: { ...githubContext("github.com-scale"), remoteUrl },
445 }),
446 "trunk",
447 );
448 assert.deepStrictEqual(paths, ["github.com-scale repos/me/web"]);
449 }).pipe(Effect.provide(layer));
450 },
451 );
452});
453​
454describe("GitHubSourceControlProvider change request lookups by head", () => {
455 const remotes = remotesOutput(["origin", "git@github.com:acme/web.git"]);
456​
457 it.effect("filters an owner:branch selector by owner through REST", () => {
458 const paths: string[] = [];
459 const restNode = (number: number, mergedAt: string | null) => ({
460 number,
461 title: `PR ${number}`,
462 html_url: `https://github.com/acme/web/pull/${number}`,
463 state: mergedAt === null ? "open" : "closed",
464 merged_at: mergedAt,
465 closed_at: mergedAt,
466 updated_at: "2026-01-02T00:00:00Z",
467 base: { ref: "main", repo: { full_name: "acme/web" } },
468 head: {
469 ref: "main",
470 sha: "f".repeat(40),
471 repo: { name: "web", full_name: "me/web", owner: { login: "me", type: "User" } },
472 },
473 });
474 const { layer, graphqlCalls } = harness({
475 remotes,
476 api: {
477 rest: (input) =>
478 Effect.sync(() => {
479 paths.push(input.path);
480 return restResponse([restNode(8, null), restNode(7, "2026-01-01T00:00:00Z")]);
481 }),
482 },
483 });
484 return Effect.gen(function* () {
485 const gh = yield* GitHubSourceControlProvider.make;
486 const probe = (ownerHeadSelector?: string) =>
487 gh.headBranchProbe?.({
488 headSelectors: ["me:main", "main"],
489 state: "all",
490 ownerHeadSelector,
491 }).headSelectors;
492 assert.deepStrictEqual([probe(), probe("me:main")], [["main"], ["me:main"]]);
493 const read = (state: "open" | "merged") =>
494 gh.listChangeRequests({ cwd: "/repo", headSelector: "me:main", state, limit: 1 });
495 const [open] = yield* read("open");
496 const [merged] = yield* read("merged");
497 assert.deepStrictEqual(
498 [open, merged].map((pr) => [pr?.number, pr?.state, pr?.headRepositoryOwnerLogin]),
499 [
500 [8, "open", "me"],
501 [7, "merged", "me"],
502 ],
503 );
504 assert.deepStrictEqual(
505 paths.map((path) => new URL(path, "https://api.test/").searchParams.get("state")),
506 ["open", "closed"],
507 );
508 assert.include(paths[0], "repos/acme/web/pulls?head=me%3Amain");
509 yield* gh.listChangeRequests({
510 cwd: "/repo",
511 headSelector: "me:main",
512 state: "open",
513 repository: "me/web",
514 });
515 assert.include(paths[2], "repos/me/web/pulls?head=me%3Amain");
516 assert.lengthOf(graphqlCalls, 0);
517 }).pipe(Effect.provide(layer));
518 });
519​
520 it.effect("maps API failures onto the errors callers handle", () => {
521 let signedIn = false;
522 const { layer } = harness({
523 remotes,
524 credential: (host) =>
525 signedIn
526 ? Effect.succeed({
527 host,
528 token: Redacted.make("token"),
529 source: "gh" as const,
530 fingerprint: "fp",
531 })
532 : Effect.fail(new GitHubCredentials.GitHubCliMissingError({ host })),
533 graphql: () =>
534 new Response(encodeJson({ message: "API rate limit exceeded" }), {
535 status: 403,
536 headers: { "x-ratelimit-remaining": "0", "x-ratelimit-reset": "123" },
537 }),
538 });
539 return Effect.gen(function* () {
540 const gh = yield* GitHubSourceControlProvider.make;
541 const read = (headSelector: string) =>
542 gh
543 .listChangeRequests({ cwd: "/repo", headSelector, state: "open", limit: 1 })
544 .pipe(Effect.flip, Effect.forkChild);
545 const missing = yield* read("missing");
546 yield* TestClock.adjust("500 millis");
547 assert.include((yield* Fiber.join(missing)).detail, "No GitHub credential on the server");
548 signedIn = true;
549 const limited = yield* read("limited");
550 yield* TestClock.adjust("500 millis");
551 const error = yield* Fiber.join(limited);
552 assert.include(error.detail, "rate limit exceeded");
553 assert.propertyVal(error.cause, "retryAt", 123_000);
554 }).pipe(Effect.provide(layer));
555 });
556});
557​
558describe("GitHubSourceControlProvider.getChangeRequest", () => {
559 it.effect("reads a pull request by number, and by URL on its own repository", () => {
560 const { layer, graphqlCalls } = harness({
561 remotes: remotesOutput(["origin", "git@github.com:acme/web.git"]),
562 graphql: () => ({ pullRequest: node(42, "feature") }),
563 });
564 return Effect.gen(function* () {
565 const gh = yield* GitHubSourceControlProvider.make;
566 assert.strictEqual(
567 (yield* gh.getChangeRequest({ cwd: "/repo", reference: "#42" })).number,
568 42,
569 );
570 yield* gh.getChangeRequest({
571 cwd: "/repo",
572 reference: "https://github.com/other/thing/pull/42",
573 });
574 assert.deepStrictEqual(
575 graphqlCalls.flatMap((call) => call.lookups),
576 [
577 { owner: "acme", name: "web", number: 42 },
578 { owner: "other", name: "thing", number: 42 },
579 ],
580 );
581 }).pipe(Effect.provide(layer));
582 });
583});
584​
585describe("GitHubSourceControlProvider writes", () => {
586 it.effect("creates a cross-repository pull request with an owner:branch head", () => {
587 const requests: Array<GitHubRest.GitHubRestInput> = [];
588 const { layer } = harness({
589 remotes: remotesOutput(
590 ["origin", "git@github.com:me/web.git"],
591 ["upstream", "git@github.com:acme/web.git"],
592 ),
593 api: {
594 rest: (input) =>
595 Effect.sync(() => {
596 requests.push(input);
597 return restResponse({ number: 1 }, 201);
598 }),
599 },
600 });
601 return Effect.gen(function* () {
602 const fs = yield* FileSystem.FileSystem;
603 const bodyFile = yield* fs.makeTempFileScoped({ suffix: ".md" });
604 yield* fs.writeFileString(bodyFile, "Body");
605 const gh = yield* GitHubSourceControlProvider.make;
606 yield* gh.createChangeRequest({
607 cwd: "/repo",
608 baseRefName: "main",
609 headSelector: "me:feature",
610 title: "Title",
611 bodyFile,
612 });
613 assert.strictEqual(requests[0]!.method, "POST");
614 assert.strictEqual(requests[0]!.path, "repos/acme/web/pulls");
615 assert.strictEqual(requests[0]!.allowReserve, true);
616 assert.deepStrictEqual(requests[0]!.body, {
617 base: "main",
618 head: "me:feature",
619 title: "Title",
620 body: "Body",
621 maintainer_can_modify: true,
622 });
623 yield* gh.createChangeRequest({
624 cwd: "/repo",
625 baseRefName: "main",
626 headSelector: "me:feature",
627 title: "Title",
628 bodyFile,
629 draft: true,
630 });
631 assert.strictEqual((requests[1]!.body as { draft?: unknown }).draft, true);
632 }).pipe(Effect.provide(Layer.merge(layer, NodeServices.layer)));
633 });
634​
635 it.effect("creates a repository under an organization the viewer is not", () => {
636 const requests: Array<string> = [];
637 const { layer } = harness({
638 remotes: "",
639 api: {
640 rest: (input) =>
641 Effect.sync(() => {
642 requests.push(`${input.method ?? "GET"} ${input.path}`);
643 return input.path === "user"
644 ? restResponse({ login: "me" })
645 : restResponse({
646 full_name: "acme/new",
647 html_url: "https://github.com/acme/new",
648 ssh_url: "git@github.com:acme/new.git",
649 });
650 }),
651 },
652 });
653 return Effect.gen(function* () {
654 const gh = yield* GitHubSourceControlProvider.make;
655 const urls = yield* gh.createRepository({
656 cwd: "/repo",
657 repository: "acme/new",
658 visibility: "private",
659 });
660 assert.deepStrictEqual(urls, {
661 nameWithOwner: "acme/new",
662 url: "https://github.com/acme/new",
663 sshUrl: "git@github.com:acme/new.git",
664 });
665 assert.deepStrictEqual(requests, ["GET user", "POST orgs/acme/repos"]);
666 }).pipe(Effect.provide(layer));
667 });
668​
669 it.effect("looks up a bare repository name under the signed-in account on that host", () => {
670 const requests: Array<string> = [];
671 return Effect.gen(function* () {
672 const gh = yield* makeProvider({
673 rest: (input) =>
674 Effect.sync(() => {
675 requests.push(`${input.host} ${input.method ?? "GET"} ${input.path}`);
676 return input.path === "user"
677 ? restResponse({ login: "me" })
678 : restResponse({
679 full_name: "me/notes",
680 html_url: `https://${input.host}/me/notes`,
681 ssh_url: `git@${input.host}:me/notes.git`,
682 });
683 }),
684 });
685​
686 const urls = yield* gh.getRepositoryCloneUrls({
687 cwd: "/repo",
688 context: githubContext("code.example.test"),
689 repository: " notes.git ",
690 });
691​
692 assert.deepStrictEqual(urls, {
693 nameWithOwner: "me/notes",
694 url: "https://code.example.test/me/notes",
695 sshUrl: "git@code.example.test:me/notes.git",
696 });
697 assert.deepStrictEqual(requests, [
698 "code.example.test GET user",
699 "code.example.test GET repos/me/notes",
700 ]);
701 for (const repository of ["me/", "/notes", "a/b/c/d", "", "two words"]) {
702 const error = yield* Effect.flip(gh.getRepositoryCloneUrls({ cwd: "/repo", repository }));
703 assert.include(error.message, "Repositories are named owner/name.");
704 assert.strictEqual(
705 userFacingSourceControlDetail(error.cause),
706 "Repositories are named owner/name.",
707 );
708 }
709 assert.strictEqual(requests.length, 2);
710 });
711 });
712 it.effect("exposes only fixed repository lookup details with the resolved owner", () =>
713 Effect.gen(function* () {
714 const gh = yield* makeProvider({
715 rest: (input) =>
716 input.path === "user"
717 ? Effect.succeed(restResponse({ login: "me" }))
718 : input.path === "repos/me/private"
719 ? Effect.fail(
720 new GitHubRequestPolicy.GitHubApiAuthenticationError({
721 host: input.host,
722 operation: input.operation,
723 }),
724 )
725 : Effect.fail(
726 new GitHubRequestPolicy.GitHubApiNotFoundError({
727 host: input.host,
728 operation: input.operation,
729 }),
730 ),
731 });
732 for (const repository of ["vouch", "other/vouch"]) {
733 const error = yield* Effect.flip(gh.getRepositoryCloneUrls({ cwd: "/repo", repository }));
734 assert.strictEqual(
735 userFacingSourceControlDetail(error.cause),
736 `Repository ${repository === "vouch" ? "me/vouch" : repository} was not found. Check the owner and name and try again.`,
737 );
738 }
739 const authError = yield* Effect.flip(
740 gh.getRepositoryCloneUrls({ cwd: "/repo", repository: "me/private" }),
741 );
742 assert.strictEqual(userFacingSourceControlDetail(authError.cause), undefined);
743 }),
744 );
745});
746​
747describe("GitHubSourceControlProvider.checkoutChangeRequest", () => {
748 it.effect("refuses a fork checkout when the base's default branch cannot be read", () => {
749 const { layer, git } = harness({
750 remotes: remotesOutput(["origin", "git@github.com:acme/web.git"]),
751 localBranches: ["main"],
752 graphql: () => ({ pullRequest: node(6, "main", "someone") }),
753 api: {
754 rest: () =>
755 Effect.fail(
756 new GitHubRequestPolicy.GitHubApiRequestError({
757 host: "github.com",
758 operation: "x",
759 cause: "offline",
760 }),
761 ),
762 },
763 });
764 return Effect.gen(function* () {
765 const gh = yield* GitHubSourceControlProvider.make;
766 yield* Effect.flip(gh.checkoutChangeRequest({ cwd: "/repo", reference: "6", force: true }));
767 assert.deepStrictEqual(git, []);
768 }).pipe(Effect.provide(layer));
769 });
770​
771 it.effect("adds a fork remote with the protocol of the URL origin fetches from", () => {
772 // `git remote -v` shows origin's SSH `insteadOf` rewrite; config holds HTTPS, then an SSH push URL.
773 const { layer, git } = harness({
774 remotes: [
775 "origin\tgit@github.com:acme/web.git (fetch)",
776 "origin\tgit@github.com:acme/web.git (push)",
777 "origin\tgit@github.com:acme/web.git (push)",
778 ].join("\n"),
779 originUrls: "https://github.com/acme/web.git\ngit@github.com:acme/web.git\n",
780 graphql: () => ({ pullRequest: node(7, "feature", "someone") }),
781 api: {
782 rest: (input) => {
783 const fullName = input.path.slice("repos/".length);
784 return Effect.succeed(
785 restResponse({
786 full_name: fullName,
787 html_url: `https://github.com/${fullName}`,
788 ssh_url: `git@github.com:${fullName}.git`,
789 default_branch: "main",
790 }),
791 );
792 },
793 },
794 });
795 return Effect.gen(function* () {
796 const gh = yield* GitHubSourceControlProvider.make;
797 yield* gh.checkoutChangeRequest({ cwd: "/repo", reference: "7" });
798 assert.deepStrictEqual(git.find(([name]) => name === "ensureRemote")?.[1], {
799 cwd: "/repo",
800 preferredName: "someone",
801 url: "https://github.com/someone/web",
802 });
803 }).pipe(Effect.provide(layer));
804 });
805​
806 it.effect("keeps git's own output out of what a failed checkout reports", () => {
807 const { layer } = harness({
808 remotes: remotesOutput(["origin", "git@github.com:acme/web.git"]),
809 gitFailure: new Error("fatal: /home/me/secret-path: permission denied"),
810 graphql: () => ({ pullRequest: node(5, "feature/x") }),
811 });
812 return Effect.gen(function* () {
813 const gh = yield* GitHubSourceControlProvider.make;
814 const error = yield* gh
815 .checkoutChangeRequest({ cwd: "/repo", reference: "5" })
816 .pipe(Effect.flip);
817 assert.strictEqual(error.detail, "The pull request could not be checked out with git.");
818 assert.notInclude(error.message, "secret-path");
819 }).pipe(Effect.provide(layer));
820 });
821​
822 it.effect("records the branch base for gh through the host's config write", () => {
823 const { layer, git } = harness({
824 remotes: remotesOutput(["origin", "git@github.com:acme/web.git"]),
825 });
826 return Effect.gen(function* () {
827 const gh = yield* GitHubSourceControlProvider.make;
828 yield* gh.recordBranchBase!({ cwd: "/repo", branch: "feature", baseBranch: "main" });
829 assert.deepStrictEqual(git, [
830 ["writeConfigValue", { cwd: "/repo", key: "branch.feature.gh-merge-base", value: "main" }],
831 ]);
832 }).pipe(Effect.provide(layer));
833 });
834​
835 it("names the local branch the way gh pr checkout does", () => {
836 const name = (headRefName: string, isCrossRepository: boolean) =>
837 GitHubSourceControlProvider.pullRequestCheckoutBranchName({
838 headRefName,
839 headOwner: "someone",
840 isCrossRepository,
841 defaultBranch: "main",
842 });
843 assert.strictEqual(name("main", true), "someone/main");
844 assert.strictEqual(name("feature", true), "feature");
845 assert.strictEqual(name("main", false), "main");
846 });
847});
848​
849it("accepts active authenticated GitHub accounts when another account fails", () => {
850 const auth = GitHubSourceControlProvider.discovery.parseAuth(
851 processResult(
852 JSON.stringify({
853 hosts: {
854 "github.com": [
855 {
856 state: "success",
857 active: true,
858 host: "github.com",
859 login: "active-user",
860 tokenSource: "keyring",
861 gitProtocol: "ssh",
862 },
863 {
864 state: "error",
865 active: false,
866 host: "github.com",
867 login: "stale-user",
868 tokenSource: "keyring",
869 gitProtocol: "ssh",
870 error: "The token in keyring is invalid.",
871 },
872 ],
873 },
874 }),
875 ),
876 );
877​
878 assert.deepStrictEqual(
879 {
880 status: auth.status,
881 account: auth.account,
882 host: auth.host,
883 },
884 {
885 status: "authenticated",
886 account: Option.some("active-user"),
887 host: Option.some("github.com"),
888 },
889 );
890});
891​
892it("parses GitHub auth JSON from stdout when stderr has warnings", () => {
893 const auth = GitHubSourceControlProvider.discovery.parseAuth(
894 processResult(
895 JSON.stringify({
896 hosts: {
897 "github.com": [
898 {
899 state: "success",
900 active: true,
901 host: "github.com",
902 login: "active-user",
903 tokenSource: "keyring",
904 gitProtocol: "ssh",
905 },
906 ],
907 },
908 }),
909 { stderr: "warning: ignored diagnostic from gh\n" },
910 ),
911 );
912​
913 assert.deepStrictEqual(
914 {
915 status: auth.status,
916 account: auth.account,
917 host: auth.host,
918 },
919 {
920 status: "authenticated",
921 account: Option.some("active-user"),
922 host: Option.some("github.com"),
923 },
924 );
925});
926​
927it("parses GitHub auth status accounts by host and active state", () => {
928 assert.deepStrictEqual(
929 parseGitHubAuthStatus(
930 JSON.stringify({
931 hosts: {
932 "github.com": [
933 {
934 state: "success",
935 active: true,
936 host: "github.com",
937 login: "active-user",
938 tokenSource: "keyring",
939 gitProtocol: "ssh",
940 },
941 {
942 state: "error",
943 active: false,
944 host: "github.com",
945 login: "stale-user",
946 tokenSource: "keyring",
947 gitProtocol: "ssh",
948 },
949 ],
950 "github.example.test": [
951 {
952 state: "success",
953 active: false,
954 host: "github.example.test",
955 login: "enterprise-user",
956 tokenSource: "keyring",
957 gitProtocol: "ssh",
958 },
959 ],
960 },
961 }),
962 ).accounts,
963 [
964 {
965 host: "github.com",
966 account: "active-user",
967 authenticated: true,
968 active: true,
969 error: null,
970 environmentVariable: null,
971 },
972 {
973 host: "github.com",
974 account: "stale-user",
975 authenticated: false,
976 active: false,
977 error: null,
978 environmentVariable: null,
979 },
980 {
981 host: "github.example.test",
982 account: "enterprise-user",
983 authenticated: true,
984 active: false,
985 error: null,
986 environmentVariable: null,
987 },
988 ],
989 );
990});
991​
992it("reports unauthenticated when GitHub JSON has accounts but none are valid", () => {
993 const auth = GitHubSourceControlProvider.discovery.parseAuth(
994 processResult(
995 JSON.stringify({
996 hosts: {
997 "github.com": [
998 {
999 state: "error",
1000 active: true,
1001 host: "github.com",
1002 login: "stale-user",
1003 tokenSource: "keyring",
1004 gitProtocol: "ssh",
1005 error: "The token in keyring is invalid.",
1006 },
1007 ],
1008 },
1009 }),
1010 ),
1011 );
1012​
1013 assert.deepStrictEqual(
1015 status: auth.status,
1016 host: auth.host,
1017 detail: auth.detail,
1018 },
1020 status: "unauthenticated",
1021 host: Option.some("github.com"),
1022 detail: Option.some("The token in keyring is invalid."),
1023 },
1024 );
1025});
1026​
1027it("reports an update hint instead of unauthenticated when gh predates --json", () => {
1028 const auth = GitHubSourceControlProvider.discovery.parseAuth(
1029 processResult("", {
1030 stderr: "unknown flag: --json\n\nUsage: gh auth status [flags]\n",
1031 exitCode: ChildProcessSpawner.ExitCode(1),
1032 }),
1033 );
1034​
1035 assert.strictEqual(auth.status, "unknown");
1036 assert.match(
1037 Option.getOrElse(auth.detail, () => ""),
1038 /2\.81\.0/,
1039 );
1040});
1041​
1042it.effect.each(["pull", "issues"])(
1043 "resolves %s subjects on the linked host without using the checkout",
1044 (kind) =>
1045 Effect.gen(function* () {
1046 const provider = yield* makeProvider({
1047 rest: (input) => {
1048 assert.strictEqual(input.host, "github.com");
1049 assert.strictEqual(input.path, "repos/owner/repo/issues/42");
1050 return Effect.succeed(
1051 restResponse({ title: "Pairing expiry", body: "Preserve remote access", id: 1 }),
1052 );
1053 },
1054 });
1055 const lookup = provider.resolveLink?.({
1056 cwd: "/unrelated",
1057 url: new URL(`https://github.com/owner/repo/${kind}/42`),
1058 });
1059 assert.ok(lookup);
1060 assert.deepStrictEqual(yield* lookup, {
1061 title: "Pairing expiry",
1062 body: "Preserve remote access",
1063 });
1064 for (const url of [
1065 "https://github.com/owner/repo",
1066 "https://github.attacker.test/owner/repo/issues/42",
1067 ]) {
1068 assert.strictEqual(
1069 provider.resolveLink?.({ cwd: "/unrelated", url: new URL(url) }),
1070 undefined,
1071 );
1073 }),
1075​
1076it.effect.each(["read", "decode"] as const)(
1077 "retains the %s failure without exposing its raw contents",
1078 (stage) =>
1079 Effect.gen(function* () {
1080 const cause = new GitHubRequestPolicy.GitHubApiResponseError({
1081 host: "github.com",
1082 operation: "resolveLink",
1083 status: 500,
1084 });
1085 const provider = yield* makeProvider({
1086 rest: () =>
1087 stage === "read"
1088 ? Effect.fail(cause)
1089 : Effect.succeed({ ...restResponse(undefined), body: "private response text" }),
1090 });
1091 const lookup = provider.resolveLink?.({
1092 cwd: "/repo",
1093 url: new URL("https://github.com/owner/repo/issues/42"),
1094 });
1095 assert.ok(lookup);
1096 const error = yield* Effect.flip(lookup);
1097 assert.strictEqual(error.operation, stage === "read" ? "resolveLink" : "resolveLink.decode");
1098 assert.strictEqual(error.detail, "The linked subject could not be read.");
1099 assert.notInclude(error.message, "private response text");
1100 if (stage === "read") assert.strictEqual(error.cause, cause);
1101 else assert.propertyVal(error.cause, "_tag", "SchemaError");
1102 }),
1104​
1105const multiAccountStatus = (extra: ReadonlyArray<Record<string, unknown>> = []) =>
1106 processResult(
1107 JSON.stringify({
1108 hosts: {
1109 "github.com": [
1110 { state: "success", active: true, host: "github.com", login: "personal" },
1111 { state: "success", active: false, host: "github.com", login: "work" },
1112 ...extra,
1113 ],
1114 "ghe.acme.test": [
1115 { state: "error", active: true, host: "ghe.acme.test", login: "jm", error: "expired" },
1116 ],
1117 },
1118 }),
1119 );
1120​
1121it("reports every gh login and leads with the account Settings pin", () => {
1122 const auth = GitHubSourceControlProvider.parseGitHubAuth(multiAccountStatus(), {
1123 hosts: { "github.com": { account: "work", enabled: true } },
1124 tokens: {},
1125 signIns: {},
1126 });
1127 assert.deepStrictEqual(auth.account, Option.some("work"));
1128 assert.deepStrictEqual(auth.accounts, [
1129 { host: "github.com", account: "personal", active: true, authenticated: true },
1130 { host: "github.com", account: "work", active: false, authenticated: true },
1131 { host: "ghe.acme.test", account: "jm", active: true, authenticated: false, error: "expired" },
1132 ]);
1133});
1134​
1135it("reports unauthenticated when Settings turn off every signed-in host", () => {
1136 const auth = GitHubSourceControlProvider.parseGitHubAuth(multiAccountStatus(), {
1137 hosts: { "github.com": { enabled: false } },
1138 tokens: {},
1139 signIns: {},
1140 });
1141 assert.strictEqual(auth.status, "unauthenticated");
1142 assert.deepStrictEqual(
1143 auth.detail,
1144 Option.some(
1145 "Every GitHub host gh is signed in to is turned off in Settings → Source control & issues.",
1146 ),
1147 );
1148});
1149​
1150it("names the environment token that overrides the Settings choice", () => {
1151 const auth = GitHubSourceControlProvider.parseGitHubAuth(
1152 multiAccountStatus([
1154 state: "success",
1155 active: false,
1156 host: "github.com",
1157 login: "bot",
1158 tokenSource: "GH_TOKEN",
1159 },
1160 ]),
1161 { hosts: { "github.com": { account: "work", enabled: true } }, tokens: {}, signIns: {} },
1162 );
1163 assert.deepStrictEqual(auth.account, Option.some("bot"));
1164 assert.deepStrictEqual(
1165 auth.detail,
1166 Option.some(
1167 "Using GH_TOKEN from the server environment; it overrides the account chosen in Settings.",
1168 ),
1169 );
1170 assert.strictEqual(auth.accounts?.[2]?.environmentVariable, "GH_TOKEN");
1171});
1172​
1173it.live.each([
1174 "git@code.example.test:team/project.git",
1175 "ssh://git@code.example.test/team/project.git",
1176 "https://code.example.test/team/project.git",
1177])("keeps Enterprise operations on the selected remote: %s", (remoteUrl) => {
1178 const rest: GitHubRest.GitHubRestInput[] = [];
1179 const pr = {
1180 ...node(42, "feature", "team"),
1181 url: "https://code.example.test/team/project/pull/42",
1182 isCrossRepository: false,
1183 headRepository: { name: "project", nameWithOwner: "team/project" },
1184 };
1185 const api = {
1186 rest: (input: GitHubRest.GitHubRestInput) =>
1187 Effect.sync(() => {
1188 rest.push(input);
1189 return restResponse({
1190 full_name: "team/project",
1191 html_url: `https://${input.host}/team/project`,
1192 ssh_url: `git@${input.host}:team/project.git`,
1193 default_branch: "main",
1194 });
1195 }),
1196 };
1197 const { layer, git, graphqlCalls } = harness({
1198 remotes: remotesOutput(
1199 ["origin", "git@github.com:team/project.git"],
1200 ["enterprise", remoteUrl],
1201 ),
1202 api,
1203 graphql: (_, call) =>
1204 call.operationName === "PullRequestByNumber"
1205 ? { pullRequest: pr }
1206 : { pullRequests: { nodes: [pr] } },
1207 });
1208 return Effect.gen(function* () {
1209 const provider = yield* GitHubSourceControlProvider.make;
1210 const fs = yield* FileSystem.FileSystem;
1211 const bodyFile = yield* fs.makeTempFileScoped({ suffix: ".md" });
1212 yield* fs.writeFileString(bodyFile, "Enterprise PR");
1213 const input = {
1214 cwd: "/repo",
1215 context: {
1216 provider: {
1217 kind: SourceControlProviderKind.make("github"),
1218 name: "GitHub Self-Hosted",
1219 baseUrl: "https://code.example.test",
1220 },
1221 remoteName: "enterprise",
1222 remoteUrl,
1223 },
1224 };
1225 for (const state of ["open", "closed"] as const) {
1226 const prs = yield* provider.listChangeRequests({
1227 ...input,
1228 state,
1229 headSelector: "feature",
1230 });
1231 assert.strictEqual(prs[0]?.url, "https://code.example.test/team/project/pull/42");
1233 yield* provider.getChangeRequest({ ...input, reference: "42" });
1234 yield* provider.getChangeRequest({ ...input, reference: "feature" });
1235 yield* provider.createChangeRequest({
1236 ...input,
1237 baseRefName: "main",
1238 headSelector: "feature",
1239 title: "PR",
1240 bodyFile,
1241 });
1242 assert.strictEqual(yield* provider.getDefaultBranch(input), "main");
1243 yield* provider.checkoutChangeRequest({ ...input, reference: "42" });
1244 yield* provider.getRepositoryCloneUrls({ ...input, repository: "team/other" });
1245 yield* provider.getRepositoryCloneUrls({ ...input, repository: "github.com/team/explicit" });
1246 const lookups = graphqlCalls.flatMap((call) =>
1247 call.lookups.map(({ owner, name }) => [call.host, owner, name]),
1248 );
1249 assert.deepStrictEqual(
1250 lookups,
1251 Array.from({ length: 5 }, () => ["code.example.test", "team", "project"]),
1252 );
1253 assert.deepStrictEqual(
1254 rest.map(({ host, path }) => [host, path]),
1256 ["code.example.test", "repos/team/project/pulls"],
1257 ["code.example.test", "repos/team/project"],
1258 ["code.example.test", "repos/team/other"],
1259 ["github.com", "repos/team/explicit"],
1260 ],
1261 );
1262 assert.deepStrictEqual(git.find(([name]) => name === "createBranch")?.[1], {
1263 cwd: "/repo",
1264 branch: "feature",
1265 startPoint: "refs/remotes/enterprise/feature",
1266 });
1267 assert.deepStrictEqual(git.find(([name]) => name === "fetchRemoteTrackingBranch")?.[1], {
1268 cwd: "/repo",
1269 remoteName: "enterprise",
1270 remoteBranch: "feature",
1271 });
1272 }).pipe(Effect.provide(layer), Effect.provideService(HostProcess.Environment, {}));
1273});
1274​
1275it.effect.each([
1276 { host: "github.com", resolved: "", envRepository: "", expected: "acme/web" },
1278 host: "code.example.test",
1279 resolved: "remote.origin.gh-resolved base",
1280 envRepository: "",
1281 expected: "me/web",
1282 },
1284 host: "github.com",
1285 resolved: "remote.upstream.gh-resolved acme/other",
1286 envRepository: "",
1287 expected: "acme/other",
1288 },
1290 host: "code.example.test",
1291 resolved: "",
1292 envRepository: "chosen/repo",
1293 expected: "chosen/repo",
1294 },
1295])(
1296 "preserves repository precedence on $host: $resolved $envRepository",
1297 ({ host, resolved, envRepository, expected }) => {
1298 const targets: string[] = [];
1299 const { layer } = harness({
1300 remotes: remotesOutput(
1301 ["origin", `git@${host}:me/web.git`],
1302 ["upstream", `git@${host}:acme/web.git`],
1303 ),
1304 resolved,
1305 api: {
1306 rest: (input) =>
1307 Effect.sync(() => {
1308 targets.push(`${input.host}/${input.path}`);
1309 return restResponse({
1310 full_name: expected,
1311 html_url: `https://${host}/${expected}`,
1312 ssh_url: `git@${host}:${expected}.git`,
1313 default_branch: "main",
1314 });
1315 }),
1316 },
1317 });
1318 return Effect.gen(function* () {
1319 const provider = yield* GitHubSourceControlProvider.make;
1320 const fs = yield* FileSystem.FileSystem;
1321 const bodyFile = yield* fs.makeTempFileScoped();
1322 yield* fs.writeFileString(bodyFile, "Body");
1323 const input = {
1324 cwd: "/repo",
1325 context: {
1326 provider: {
1327 kind: SourceControlProviderKind.make("github"),
1328 name: "GitHub",
1329 baseUrl: `https://${host}`,
1330 },
1331 remoteName: "origin",
1332 remoteUrl: `git@${host}:me/web.git`,
1333 },
1334 };
1335 yield* provider.getDefaultBranch(input);
1336 yield* provider.createChangeRequest({
1337 ...input,
1338 baseRefName: "main",
1339 headSelector: "me:feature",
1340 title: "PR",
1341 bodyFile,
1342 });
1343 assert.deepStrictEqual(targets, [
1344 `${host}/repos/${expected}`,
1345 `${host}/repos/${expected}/pulls`,
1346 ]);
1347 assert.deepStrictEqual(
1348 yield* provider.createsChangeRequestsIn!({ ...input, repository: "me/web" }),
1349 expected === "me/web",
1350 );
1351 }).pipe(
1352 Effect.provide(layer),
1353 Effect.provideService(HostProcess.Environment, { GH_REPO: envRepository }),
1354 );
1355 },
1357​
1358it.effect(
1359 "says a GH_REPO naming an unparseable host falls back to the remotes, as creation does",
1360 () => {
1361 const { layer } = harness({
1362 remotes: remotesOutput(["upstream", "git@github.com:acme/web.git"]),
1363 resolved: "",
1364 api: {},
1365 });
1366 return Effect.gen(function* () {
1367 const provider = yield* GitHubSourceControlProvider.make;
1368 const targets = yield* provider.createsChangeRequestsIn!({
1369 cwd: "/repo",
1370 context: {
1371 provider: {
1372 kind: SourceControlProviderKind.make("github"),
1373 name: "GitHub",
1374 baseUrl: "https://github.com",
1375 },
1376 remoteName: "upstream",
1377 remoteUrl: "git@github.com:acme/web.git",
1378 },
1379 repository: "acme/web",
1380 });
1381 assert.isTrue(targets);
1382 }).pipe(
1383 Effect.provide(layer),
1384 Effect.provideService(HostProcess.Environment, { GH_REPO: "bad host/acme/web" }),
1385 );
1386 },