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

threadPullRequestCompatibility.test.ts

115 lines3.5 KB

1import { ProjectId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import {
4 planThreadPullRequestMutation,
5 threadPullRequestLinkMode,
6} from "./threadPullRequestCompatibility.ts";
7​
8const reference = {
9 host: "github.example",
10 repository: "team/repo",
11 number: 7,
12 url: "https://github.example/team/repo/pull/7",
13};
14const input = {
15 threadId: ThreadId.make("thread"),
16 reference,
17 legacyProjectId: ProjectId.make("exact-checkout"),
18 linked: true,
19};
20​
21describe("thread pull request capability negotiation", () => {
22 it.each([undefined, {}, { threadPullRequests: false, threadPullRequestLinking: false }])(
23 "does not dispatch when linking is unadvertised: %j",
24 (capabilities) => {
25 expect(threadPullRequestLinkMode(capabilities)).toBe("unsupported");
26 expect(planThreadPullRequestMutation({ ...input, capabilities })).toBeNull();
27 },
28 );
29 it("uses metadata updates for old single-link servers, including unlink", () => {
30 const capabilities = { threadPullRequestLinking: true };
31 expect(planThreadPullRequestMutation({ ...input, capabilities })).toEqual({
32 type: "thread.meta.update",
33 input: {
34 threadId: input.threadId,
35 linkedPullRequest: {
36 projectId: input.legacyProjectId,
37 repository: reference.repository,
38 number: 7,
39 url: reference.url,
40 },
41 },
42 });
43 expect(
44 planThreadPullRequestMutation({
45 ...input,
46 capabilities,
47 linked: false,
48 legacyProjectId: null,
49 }),
50 ).toEqual({
51 type: "thread.meta.update",
52 input: { threadId: input.threadId, linkedPullRequest: null },
53 });
54 });
55 it("uses the checkout's Azure selector only for legacy metadata commands", () => {
56 const azure = {
57 ...input,
58 reference: {
59 host: "dev.azure.com",
60 repository: "org/project/_git/web",
61 number: 42,
62 url: "https://dev.azure.com/org/project/_git/web/pullrequest/42",
63 },
64 legacyRepository: "web",
65 };
66 expect(
67 planThreadPullRequestMutation({
68 ...azure,
69 capabilities: { threadPullRequestLinking: true },
70 }),
71 ).toMatchObject({
72 type: "thread.meta.update",
73 input: { linkedPullRequest: { repository: "web", number: 42 } },
74 });
75 expect(
76 planThreadPullRequestMutation({
77 ...azure,
78 capabilities: { threadPullRequests: true },
79 }),
80 ).toMatchObject({
81 type: "thread.pull-request.link",
82 input: { repository: "org/project/_git/web", number: 42 },
83 });
84 });
85​
86 it("never sends a same-host route as an exact repository to an old server", () => {
87 expect(
88 planThreadPullRequestMutation({
89 ...input,
90 capabilities: { threadPullRequestLinking: true },
91 legacyProjectId: null,
92 }),
93 ).toBeNull();
94 });
95 it.each([
96 { threadPullRequests: true },
97 { threadPullRequests: true, threadPullRequestLinking: true },
98 ])("prefers multi-link commands when available: %j", (capabilities) => {
99 expect(
100 planThreadPullRequestMutation({ ...input, capabilities, legacyProjectId: null }),
101 ).toEqual({
102 type: "thread.pull-request.link",
103 input: { threadId: input.threadId, ...reference, source: "manual" },
104 });
105 expect(planThreadPullRequestMutation({ ...input, capabilities, linked: false })).toEqual({
106 type: "thread.pull-request.unlink",
107 input: {
108 threadId: input.threadId,
109 host: reference.host,
110 repository: reference.repository,
111 number: reference.number,
112 },
113 });
114 });
115});