Open History to see the last commit
1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as Context from "effect/Context";
5import * as Deferred from "effect/Deferred";
6import * as Effect from "effect/Effect";
7import * as Fiber from "effect/Fiber";
8import * as FileSystem from "effect/FileSystem";
9import * as Layer from "effect/Layer";
10import * as Ref from "effect/Ref";
11import * as Queue from "effect/Queue";
12import * as Tracer from "effect/Tracer";
13import {
14 ProjectId,
15 GitCommandError,
16 type PullRequestActivity,
17 type PullRequestDetail,
18 type PullRequestStack,
19 type PullRequestRef,
20 type RepositoryOrigin,
21} from "@t3tools/contracts";
22β
23import * as ServerConfig from "../config.ts";
24import * as SqlitePersistence from "../persistence/Sqlite.ts";
25import * as PullRequestReviewGuides from "../persistence/PullRequestReviewGuides.ts";
26import * as ProjectService from "../project/ProjectService.ts";
27import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
28import * as ServerSettings from "../serverSettings.ts";
29import * as TextGeneration from "../textGeneration/TextGeneration.ts";
30import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
31import * as VcsProcess from "../vcs/VcsProcess.ts";
32import { reviewGuideInputFromPullRequest } from "./pullRequestReviewGuideInput.ts";
33import * as PullRequestReviewGuideService from "./PullRequestReviewGuideService.ts";
34import * as PullRequestService from "./PullRequestService.ts";
35β
36const projectId = ProjectId.make("project-1");
37const ACME_APP = {
38 canonicalKey: "github.com/acme/app",
39 locator: {
40 source: "git-remote" as const,
41 remoteName: "origin",
42 remoteUrl: "https://github.com/acme/app.git",
43 },
44 provider: "github",
45 displayName: "acme/app",
46 owner: "acme",
47 name: "app",
48};
49β
50const reference: PullRequestRef = {
51 projectId,
52 host: "github.com",
53 repository: "acme/app",
54 number: 7,
55};
56β
57const git = (cwd: string, args: ReadonlyArray<string>) =>
58 Effect.gen(function* () {
59 const driver = yield* GitVcsDriver.GitVcsDriver;
60 const result = yield* driver.execute({ operation: "test.git", cwd, args, timeoutMs: 10_000 });
61 return result.stdout.trim();
62 });
63β
64const makeRepositories = Effect.gen(function* () {
65 const fs = yield* FileSystem.FileSystem;
66 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-guide-" });
67 const remote = `${root}/remote`;
68 const workspace = `${root}/workspace`;
69 yield* fs.makeDirectory(remote);
70 yield* git(remote, ["init", "--quiet", "--initial-branch=main"]);
71 yield* git(remote, ["config", "user.email", "test@example.com"]);
72 yield* git(remote, ["config", "user.name", "Test"]);
73 const commit = (path: string, message: string, contents = message) =>
74 fs
75 .writeFileString(`${remote}/${path}`, contents)
76 .pipe(
77 Effect.andThen(git(remote, ["add", path])),
78 Effect.andThen(git(remote, ["commit", "--quiet", "-m", message])),
79 Effect.andThen(git(remote, ["rev-parse", "HEAD"])),
80 );
81 yield* commit("base.txt", "base");
82 yield* git(remote, ["checkout", "--quiet", "-b", "stack-base"]);
83 const lowerSha = yield* commit("lower.txt", "lower layer");
84 yield* git(remote, ["checkout", "--quiet", "-b", "feature"]);
85 const headSha = yield* commit(
86 "feature.txt",
87 "the change",
88 Array.from({ length: 10 }, (_, index) => `line ${index + 1}`).join("\n") + "\n",
89 );
90 yield* git(remote, ["checkout", "--quiet", "-b", "upper"]);
91 const upperSha = yield* commit("upper.txt", "upper layer");
92 yield* git(remote, ["checkout", "--quiet", "main"]);
93 yield* commit("unrelated.txt", "main moved on");
94 yield* git(root, ["clone", "--quiet", remote, workspace]);
95 return { root, remote, workspace, headSha, lowerSha, upperSha };
96});
97β
98const detail = (workspaceRoot: string, headSha: string): PullRequestDetail =>
99 ({
100 provider: "github",
101 number: 7,
102 title: "Add the feature",
103 body: "Adds the feature.",
104 baseBranch: "stack-base",
105 headBranch: "feature",
106 headSha,
107 workspaceRoot,
108 }) as PullRequestDetail;
109β
110const activity: PullRequestActivity = {
111 comments: [],
112 commentCount: 0,
113 commentsTruncated: false,
114 reviewThreads: [],
115 commits: [],
116};
117β
118const stack = (repositories: {
119 readonly headSha: string;
120 readonly lowerSha: string;
121 readonly upperSha: string;
122}): PullRequestStack => ({
123 id: "stack",
124 number: 1,
125 url: "https://example.com/stack/1",
126 base: "main",
127 layers: [
128 {
129 number: 6,
130 title: "Lower",
131 headSha: repositories.lowerSha,
132 headBranch: "stack-base",
133 state: "open",
134 },
135 {
136 number: 7,
137 title: "Add the feature",
138 headSha: repositories.headSha,
139 headBranch: "feature",
140 state: "open",
141 },
142 {
143 number: 8,
144 title: "Upper",
145 headSha: repositories.upperSha.slice(0, 12),
146 headBranch: "upper",
147 state: "open",
148 },
149 { number: 9, title: "Unpushed", headSha: "f".repeat(40), headBranch: "gone", state: "open" },
150 ],
151});
152β
153const makeLayer = (input: {
154 readonly root: string;
155 readonly remote: string;
156 readonly workspace: string;
157 readonly headSha: string;
158 readonly lowerSha: string;
159 readonly upperSha: string;
160 readonly generate: TextGeneration.TextGeneration["Service"]["generateReviewGuide"];
161 readonly stored: Deferred.Deferred<void>;
162 readonly enabled?: boolean;
163 readonly currentHead?: Ref.Ref<string>;
164 readonly identity?: typeof ACME_APP & { readonly origin?: RepositoryOrigin };
165 readonly locator?: typeof ACME_APP.locator;
166}) =>
167 PullRequestReviewGuideService.layer.pipe(
168 Layer.provide(
169 Layer.effect(
170 PullRequestReviewGuides.PullRequestReviewGuideRepository,
171 Effect.gen(function* () {
172 const repository = yield* PullRequestReviewGuides.PullRequestReviewGuideRepository;
173 return {
174 get: repository.get,
175 put: (key, guide) =>
176 repository
177 .put(key, guide)
178 .pipe(Effect.tap(() => Deferred.succeed(input.stored, undefined))),
179 } satisfies PullRequestReviewGuides.PullRequestReviewGuideRepository["Service"];
180 }),
181 ).pipe(Layer.provide(PullRequestReviewGuides.layer)),
182 ),
183 Layer.provide(
184 Layer.succeed(PullRequestService.PullRequestService, {
185 detail: () =>
186 (input.currentHead === undefined
187 ? Effect.succeed(input.headSha)
188 : Ref.get(input.currentHead)
189 ).pipe(Effect.map((head) => detail(input.workspace, head))),
190 activity: () => Effect.succeed(activity),
191 invalidate: () => Effect.void,
192 stack: () => Effect.succeed(stack(input)),
193 } as unknown as PullRequestService.PullRequestService["Service"]),
194 ),
195 Layer.provide(
196 Layer.succeed(ProjectService.ProjectService, {
197 getShell: () =>
198 Effect.succeedSome({
199 id: projectId,
200 workspaceRoot: input.workspace,
201 repositoryIdentity: {
202 ...(input.identity ?? ACME_APP),
203 locator: input.locator ?? { ...ACME_APP.locator, remoteUrl: input.remote },
204 },
205 }),
206 } as unknown as ProjectService.ProjectService["Service"]),
207 ),
208 Layer.provide(
209 Layer.succeed(ProviderRegistry.ProviderRegistry, {
210 getProviders: Effect.succeed([]),
211 } as unknown as ProviderRegistry.ProviderRegistry["Service"]),
212 ),
213 Layer.provide(
214 Layer.succeed(TextGeneration.TextGeneration, {
215 generateReviewGuide: input.generate,
216 } as unknown as TextGeneration.TextGeneration["Service"]),
217 ),
218 Layer.provide(ServerSettings.layerTest({ reviewGuidesEnabled: input.enabled ?? true })),
219 Layer.provide(ServerConfig.layerTest(input.root, { prefix: "t3-review-guide-config-" })),
220 );
221β
222const layerBase = Layer.mergeAll(
223 GitVcsDriver.layer.pipe(
224 Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-review-guide-git-" })),
225 Layer.provideMerge(VcsProcess.layer),
226 ),
227 SqlitePersistence.layerMemory,
228).pipe(Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)));
229β
230type Repositories = Effect.Success<typeof makeRepositories>;
231β
232// A run forks into the service's scope, so a test learns it settled when the run's `write` span
233// ends; the run records its outcome synchronously right after.
234const watchRuns = Effect.gen(function* () {
235 const ended = yield* Queue.unbounded<void>();
236 const tracer = Tracer.make({
237 span: (options) => {
238 const span = new Tracer.NativeSpan(options);
239 if (options.name !== "PullRequestReviewGuideService.write") return span;
240 const end = span.end.bind(span);
241 span.end = (endTime, exit) => {
242 end(endTime, exit);
243 Queue.offerUnsafe(ended, undefined);
244 };
245 return span;
246 },
247 });
248 return {
249 generate: (
250 service: PullRequestReviewGuideService.PullRequestReviewGuideService["Service"],
251 input: PullRequestRef,
252 ) => service.generate(input).pipe(Effect.withTracer(tracer)),
253 settled: (
254 service: PullRequestReviewGuideService.PullRequestReviewGuideService["Service"],
255 input: PullRequestRef,
256 ) => Queue.take(ended).pipe(Effect.andThen(service.get(input))),
257 };
258});
259β
260const startSingleBranchRun = (input: {
261 readonly repositoryName: string;
262 readonly reportedHead: (repositories: Repositories) => string;
263 readonly refuseCommitFetch: boolean;
264 readonly prepare: (
265 repositories: Repositories,
266 workspace: string,
267 ) => Effect.Effect<void, GitCommandError, GitVcsDriver.GitVcsDriver>;
268 readonly onBranchFetch?:
269 | ((
270 repositories: Repositories,
271 ) => Effect.Effect<void, GitCommandError, GitVcsDriver.GitVcsDriver>)
272 | undefined;
273}) =>
274 Effect.gen(function* () {
275 const repositories = yield* makeRepositories;
276 const workspace = `${repositories.root}/single-branch`;
277 yield* git(repositories.root, [
278 "clone",
279 "--quiet",
280 "--no-local",
281 "--single-branch",
282 "--branch",
283 "main",
284 `${repositories.root}/remote`,
285 workspace,
286 ]);
287 yield* input.prepare(repositories, workspace);
288 const reportedHead = input.reportedHead(repositories);
289 const stored = yield* Deferred.make<void>();
290 const driver = yield* GitVcsDriver.GitVcsDriver;
291 const fetchedRefs: Array<string> = [];
292 const observed: Array<{ cwd: string; head: string; changed: string }> = [];
293 const onBranchFetch = input.onBranchFetch;
294 const observedDriver = {
295 ...driver,
296 execute: (call: GitVcsDriver.ExecuteGitInput) =>
297 Effect.gen(function* () {
298 const ref = call.args.at(-1);
299 if (call.args[0] !== "fetch" || ref === undefined) return yield* driver.execute(call);
300 fetchedRefs.push(ref);
301 if (input.refuseCommitFetch && ref === repositories.headSha) {
302 return yield* new GitCommandError({
303 operation: call.operation,
304 command: "git",
305 cwd: call.cwd,
306 detail: "The test remote refuses fetches by commit.",
307 exitCode: 128,
308 });
309 }
310 if (ref === "refs/heads/feature" && onBranchFetch !== undefined) {
311 yield* onBranchFetch(repositories).pipe(
312 Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
313 );
314 }
315 return yield* driver.execute(call);
316 }),
317 };
318 const readCheckout = (cwd: string, args: ReadonlyArray<string>) =>
319 driver
320 .execute({ operation: "test.readCheckout", cwd, args })
321 .pipe(Effect.map((result) => result.stdout.trim()));
322 const context = yield* Layer.build(
323 makeLayer({
324 ...repositories,
325 headSha: reportedHead,
326 workspace,
327 stored,
328 identity: {
329 ...ACME_APP,
330 canonicalKey: `github.com/acme/${input.repositoryName}`,
331 displayName: `acme/${input.repositoryName}`,
332 name: input.repositoryName,
333 },
334 generate: (generation) =>
335 Effect.gen(function* () {
336 observed.push({
337 cwd: generation.cwd,
338 head: yield* readCheckout(generation.cwd, ["rev-parse", "HEAD"]),
339 changed: yield* readCheckout(generation.cwd, [
340 "diff",
341 "--name-only",
342 `${generation.baseCommit}...HEAD`,
343 ]),
344 });
345 return { stops: [] };
346 }).pipe(Effect.orDie),
347 }).pipe(Layer.provide(Layer.succeed(GitVcsDriver.GitVcsDriver, observedDriver))),
348 );
349 const service = Context.get(
350 context,
351 PullRequestReviewGuideService.PullRequestReviewGuideService,
352 );
353 const guideReference = { ...reference, repository: `acme/${input.repositoryName}` };
354 const runs = yield* watchRuns;
355 yield* runs.generate(service, guideReference);
356 return {
357 repositories,
358 reportedHead,
359 service,
360 reference: guideReference,
361 stored,
362 fetchedRefs,
363 observed,
364 settled: runs.settled(service, guideReference),
365 };
366 });
367β
368it.each([
369 { prefixLength: 198, ending: "πβ¦" },
370 { prefixLength: 199, ending: "β¦" },
371])(
372 "truncates a resolved remark with an emoji after $prefixLength characters",
373 ({ prefixLength, ending }) => {
374 const prefix = "a".repeat(prefixLength);
375 const thread: PullRequestActivity["reviewThreads"][number] = {
376 id: "thread-1",
377 path: "file.ts",
378 line: 1,
379 side: "right",
380 isResolved: true,
381 isOutdated: false,
382 comments: [
383 {
384 id: "comment-1",
385 author: null,
386 body: `${prefix}π more`,
387 createdAt: "2026-01-01T00:00:00Z",
388 url: null,
389 },
390 ],
391 };
392 const input = reviewGuideInputFromPullRequest(
393 detail("/work/app", "abc123"),
394 { ...activity, reviewThreads: [thread] },
395 "abc123",
396 );
397 assert.strictEqual(input.settledReview, `- file.ts (resolved, ghost): ${prefix}${ending}`);
398 },
399);
400β
401it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideService", (it) => {
402 it.effect.each([
403 {
404 name: "a branch named like the short head",
405 reportedHead: (repositories: Repositories) => repositories.headSha.slice(0, 12),
406 shadow: "branch",
407 expected: ["a branch or tag rather than the commit"],
408 },
409 {
410 name: "a tag named like the short head",
411 reportedHead: (repositories: Repositories) => repositories.headSha.slice(0, 12),
412 shadow: "tag",
413 expected: ["a branch or tag rather than the commit"],
414 },
415 {
416 name: "a head that is not a commit hash",
417 reportedHead: (repositories: Repositories) =>
418 `--upload-pack=touch ${repositories.root}/injected`,
419 shadow: "none",
420 expected: ["not a commit hash"],
421 },
422 {
423 name: "a head no source has",
424 reportedHead: () => "e".repeat(40),
425 shadow: "none",
426 expected: ["local objects:", "the commit:", "branch feature:", "refs/pull/7/head:"],
427 },
428 ])("refuses to write a guide for $name", ({ reportedHead, shadow, expected }) =>
429 Effect.gen(function* () {
430 const run = yield* startSingleBranchRun({
431 repositoryName: "refused-head",
432 reportedHead,
433 refuseCommitFetch: false,
434 prepare: (repositories, workspace) =>
435 git(workspace, ["fetch", "--quiet", "origin", "feature"]).pipe(
436 Effect.andThen(
437 shadow === "none"
438 ? Effect.void
439 : git(workspace, [shadow, repositories.headSha.slice(0, 12), "HEAD"]),
440 ),
441 Effect.asVoid,
442 ),
443 });
444 const result = yield* run.settled;
445 assert.isFalse(yield* Deferred.isDone(run.stored), "a guide was written");
446 assert.strictEqual(result.run?._tag, "Failed");
447 const detail = result.run?._tag === "Failed" ? result.run.detail : "";
448 for (const part of expected) assert.include(detail, part);
449 // Only the host's own head ref is tried.
450 assert.notInclude(detail, "refs/merge-requests/");
451 assert.deepStrictEqual(run.observed, []);
452 assert.isFalse(run.fetchedRefs.some((ref) => ref.startsWith("-")));
453 const fs = yield* FileSystem.FileSystem;
454 assert.isFalse(yield* fs.exists(`${run.repositories.root}/injected`));
455 }),
456 );
457β
458 it.effect.each(["rewritten", "configured"] as const)(
459 "measures only the PR change through the renamed remote matched by its %s URL",
460 (locatorUrl) =>
461 Effect.gen(function* () {
462 const repositories = yield* makeRepositories;
463 const fork = `${repositories.root}/fork`;
464 yield* git(repositories.root, ["clone", "--quiet", repositories.remote, fork]);
465 yield* git(fork, ["branch", "stack-base", "main~1"]);
466 // The cached identity still names origin, which now belongs to the stale fork.
467 yield* git(repositories.workspace, ["remote", "rename", "origin", "upstream"]);
468 yield* git(repositories.workspace, ["remote", "add", "origin", fork]);
469 yield* git(repositories.workspace, [
470 "config",
471 `url.${repositories.remote}.insteadOf`,
472 "review-upstream:",
473 ]);
474 yield* git(repositories.workspace, ["remote", "set-url", "upstream", "review-upstream:"]);
475 const changed = yield* Deferred.make<string>();
476 const driver = yield* GitVcsDriver.GitVcsDriver;
477 const stored = yield* Deferred.make<void>();
478 const context = yield* Layer.build(
479 makeLayer({
480 ...repositories,
481 ...(locatorUrl === "configured"
482 ? { locator: { ...ACME_APP.locator, remoteUrl: "review-upstream:" } }
483 : {}),
484 stored,
485 generate: (input) =>
486 git(input.cwd, ["diff", "--name-only", `${input.baseCommit}...HEAD`]).pipe(
487 Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
488 Effect.orDie,
489 Effect.flatMap((names) => Deferred.succeed(changed, names)),
490 Effect.as({ stops: [] }),
491 ),
492 }),
493 );
494 const service = Context.get(
495 context,
496 PullRequestReviewGuideService.PullRequestReviewGuideService,
497 );
498 yield* service.generate(reference);
499 assert.strictEqual(yield* Deferred.await(changed), "feature.txt");
500 yield* Deferred.await(stored);
501 const result = yield* service.get(reference);
502 assert.strictEqual(result.guide?.headSha, repositories.headSha);
503 assert.deepStrictEqual(result.guide?.stops[0]?.files, [{ path: "feature.txt" }]);
504 }),
505 );
506β
507 it.effect("keeps excerpts despite the checkout's diff driver and a failing hook", () =>
508 Effect.gen(function* () {
509 const repositories = yield* makeRepositories;
510 const fs = yield* FileSystem.FileSystem;
511 yield* fs.writeFileString(
512 `${repositories.workspace}/.git/info/attributes`,
513 "feature.txt diff=blank\n",
514 );
515 yield* git(repositories.workspace, ["config", "diff.blank.textconv", "true"]);
516 const hook = `${repositories.workspace}/.git/hooks/post-checkout`;
517 yield* fs.writeFileString(hook, "#!/bin/sh\nexit 1\n");
518 yield* fs.chmod(hook, 0o755);
519 const stored = yield* Deferred.make<void>();
520 const context = yield* Layer.build(
521 makeLayer({
522 ...repositories,
523 stored,
524 generate: () =>
525 Effect.succeed({
526 stops: [
527 {
528 title: "The feature",
529 summary: "The change.",
530 attention: null,
531 excerpts: [{ path: "feature.txt", side: "new", start: 1, end: 3, caption: "" }],
532 files: [],
533 notes: [],
534 questions: [],
535 },
536 ],
537 }),
538 }),
539 );
540 const service = Context.get(
541 context,
542 PullRequestReviewGuideService.PullRequestReviewGuideService,
543 );
544 const runs = yield* watchRuns;
545 yield* runs.generate(service, reference);
546 const result = yield* runs.settled(service, reference);
547 assert.notStrictEqual(result.run?._tag, "Failed", JSON.stringify(result.run));
548 assert.deepStrictEqual(result.guide?.stops[0]?.excerpts, [
549 { path: "feature.txt", side: "new", start: 1, end: 3, caption: "" },
550 ]);
551 }),
552 );
553β
554 it.effect("refuses generation when the verified remote disappeared despite a usable origin", () =>
555 Effect.gen(function* () {
556 const repositories = yield* makeRepositories;
557 const fork = `${repositories.root}/fork`;
558 yield* git(repositories.root, ["clone", "--quiet", repositories.remote, fork]);
559 yield* git(fork, ["branch", "stack-base", repositories.lowerSha]);
560 yield* git(repositories.workspace, ["remote", "set-url", "origin", fork]);
561 const started = yield* Deferred.make<Fiber.Fiber<unknown, unknown>>();
562 const stored = yield* Deferred.make<void>();
563 const generated = yield* Ref.make(false);
564 const driver = yield* GitVcsDriver.GitVcsDriver;
565 const context = yield* Layer.build(
566 makeLayer({
567 ...repositories,
568 stored,
569 generate: () => Ref.set(generated, true).pipe(Effect.as({ stops: [] })),
570 }).pipe(
571 Layer.provide(
572 Layer.succeed(GitVcsDriver.GitVcsDriver, {
573 ...driver,
574 execute: (call) =>
575 Effect.withFiber((fiber) =>
576 Deferred.succeed(started, fiber).pipe(Effect.andThen(driver.execute(call))),
577 ),
578 }),
579 ),
580 ),
581 );
582 const service = Context.get(
583 context,
584 PullRequestReviewGuideService.PullRequestReviewGuideService,
585 );
586 const before = yield* service.get(reference);
587 yield* service.generate(reference);
588 // Join the background run so its failure is visible without polling service state.
589 yield* Fiber.await(yield* Deferred.await(started));
590 const result = yield* service.get(reference);
591 assert.strictEqual(result.run?._tag, "Failed");
592 assert.include(
593 result.run?._tag === "Failed" ? result.run.detail : "",
594 "no longer has a remote for the pull request's repository",
595 );
596 assert.deepStrictEqual(result.guide, before.guide);
597 assert.isFalse(yield* Deferred.isDone(stored));
598 assert.isFalse(yield* Ref.get(generated));
599 }),
600 );
601β
602 it.effect("writes a guide for a pull request on a fork whose canonical key is its upstream", () =>
603 Effect.gen(function* () {
604 const repositories = yield* makeRepositories;
605 const parent = `${repositories.root}/parent`;
606 yield* git(repositories.root, ["clone", "--quiet", "--bare", repositories.remote, parent]);
607 yield* git(repositories.workspace, ["remote", "add", "upstream", parent]);
608 const stored = yield* Deferred.make<void>();
609 const context = yield* Layer.build(
610 makeLayer({
611 ...repositories,
612 stored,
613 identity: {
614 ...ACME_APP,
615 canonicalKey: "github.com/parent/app",
616 displayName: "parent/app",
617 owner: "parent",
618 origin: { canonicalKey: "github.com/acme/app", remoteUrl: repositories.remote },
619 },
620 locator: { source: "git-remote", remoteName: "upstream", remoteUrl: parent },
621 generate: () => Effect.succeed({ stops: [] }),
622 }),
623 );
624 const service = Context.get(
625 context,
626 PullRequestReviewGuideService.PullRequestReviewGuideService,
627 );
628 const runs = yield* watchRuns;
629 yield* runs.generate(service, reference);
630 const result = yield* runs.settled(service, reference);
631 assert.notStrictEqual(result.run?._tag, "Failed", JSON.stringify(result.run));
632 assert.strictEqual(result.guide?.headSha, repositories.headSha);
633 }),
634 );
635β
636 it.effect("refuses a pull request from a repository the project is not a checkout of", () =>
637 Effect.gen(function* () {
638 const repositories = yield* makeRepositories;
639 const stored = yield* Deferred.make<void>();
640 const context = yield* Layer.build(
641 makeLayer({
642 ...repositories,
643 stored,
644 identity: {
645 ...ACME_APP,
646 canonicalKey: "github.com/acme/other",
647 displayName: "acme/other",
648 name: "other",
649 },
650 generate: () =>
651 Effect.die("a guide must not be written from another repository's checkout"),
652 }),
653 );
654 const service = Context.get(
655 context,
656 PullRequestReviewGuideService.PullRequestReviewGuideService,
657 );
658 const result = yield* Effect.flip(service.generate(reference));
659 assert.include(result.message, "in another repository");
660 }),
661 );
662});