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

ThreadPullRequestService.test.ts

72 lines2.6 KB

1import { ProjectId, type OrchestrationProjectShell } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as Option from "effect/Option";
5​
6import {
7 projectWorkspaceMatchesSnapshot,
8 resolveProjectForPullRequestDiscovery,
9} from "./ThreadPullRequestService.ts";
10​
11describe("ThreadPullRequestServiceV2 project guard", () => {
12 it.effect("discovers a repository from a project shell without enrichment", () =>
13 Effect.gen(function* () {
14 const project: OrchestrationProjectShell = {
15 id: ProjectId.make("project-1"),
16 title: "Project",
17 workspaceRoot: "/workspace/project",
18 defaultModelSelection: null,
19 scripts: [],
20 repositoryIdentity: null,
21 createdAt: "2026-08-01T00:00:00.000Z",
22 updatedAt: "2026-08-01T00:00:00.000Z",
23 };
24 let resolvedRoot: string | null = null;
25 const result = yield* resolveProjectForPullRequestDiscovery(project, {
26 resolve: (root) => {
27 resolvedRoot = root;
28 return Effect.succeed({
29 canonicalKey: "github.com/pingdotgg/t3code",
30 locator: {
31 source: "git-remote" as const,
32 remoteName: "origin",
33 remoteUrl: "git@github.com:pingdotgg/t3code.git",
34 },
35 provider: "github" as const,
36 displayName: "pingdotgg/t3code",
37 owner: "pingdotgg",
38 name: "t3code",
39 });
40 },
41 });
42 expect(resolvedRoot).toBe("/workspace/project");
43 expect(result.repository).toBe("pingdotgg/t3code");
44 expect(result.project.repositoryIdentity?.canonicalKey).toBe("github.com/pingdotgg/t3code");
45 }),
46 );
47​
48 it("rejects a pull-request result when the project root changes before dispatch", () => {
49 const currentProject = Option.some({
50 workspaceRoot: "/workspace/replaced",
51 } satisfies Pick<OrchestrationProjectShell, "workspaceRoot">);
52​
53 expect(projectWorkspaceMatchesSnapshot(currentProject, "/workspace/original")).toBe(false);
54 });
55​
56 it("rejects a pull-request result when the project was deleted before dispatch", () => {
57 expect(
58 projectWorkspaceMatchesSnapshot(
59 Option.none<Pick<OrchestrationProjectShell, "workspaceRoot">>(),
60 "/workspace/original",
61 ),
62 ).toBe(false);
63 });
64​
65 it("accepts a pull-request result while the project root is unchanged", () => {
66 const currentProject = Option.some({
67 workspaceRoot: "/workspace/original",
68 } satisfies Pick<OrchestrationProjectShell, "workspaceRoot">);
69​
70 expect(projectWorkspaceMatchesSnapshot(currentProject, "/workspace/original")).toBe(true);
71 });
72});