|
1 | | -import { ProjectId, type ThreadPullRequestLink } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + ProjectId, |
| 3 | + type PullRequestSummary, |
| 4 | + SourceControlProviderKind, |
| 5 | + type ThreadPullRequestLink, |
| 6 | +} from "@t3tools/contracts"; |
2 | 7 | import { describe, expect, it } from "vite-plus/test"; |
3 | 8 |
|
4 | 9 | import { |
| 10 | + knownPullRequestSummary, |
5 | 11 | presentThreadLinkedPullRequests, |
6 | 12 | rememberBounded, |
7 | 13 | resolveThreadPrSource, |
@@ -113,6 +119,49 @@ describe("resolveThreadPrSource compatibility", () => { |
113 | 119 | }); |
114 | 120 | }); |
115 | 121 |
|
| 122 | +describe("knownPullRequestSummary", () => { |
| 123 | + it("seeds from the newest summary of the same pull request, never another's", () => { |
| 124 | + const projectId = ProjectId.make("project"); |
| 125 | + const link = linkedPr(7); |
| 126 | + const threads = [ |
| 127 | + { |
| 128 | + projectId, |
| 129 | + pullRequests: [ |
| 130 | + { ...link, snapshot: { ...link.snapshot!, updatedAt: "2026-09-08T00:00:00.000Z" } }, |
| 131 | + ], |
| 132 | + }, |
| 133 | + ]; |
| 134 | + const listed: PullRequestSummary = { |
| 135 | + provider: SourceControlProviderKind.make("github"), |
| 136 | + projectId, |
| 137 | + repository: "t3tools/t3code", |
| 138 | + number: 7, |
| 139 | + title: "Listed title", |
| 140 | + url: "https://github.com/t3tools/t3code/pull/7", |
| 141 | + state: "open", |
| 142 | + headBranch: "change-7", |
| 143 | + baseBranch: "main", |
| 144 | + updatedAt: "2026-09-09T00:00:00.000Z", |
| 145 | + }; |
| 146 | + const lookup = (host: string, number: number, summaries = [listed]) => |
| 147 | + knownPullRequestSummary({ host, repository: "t3tools/t3code", number }, threads, summaries); |
| 148 | + |
| 149 | + expect(lookup("github.com", 7, [])?.title).toBe("Change 7"); |
| 150 | + expect(lookup("github.com", 7)?.title).toBe("Listed title"); |
| 151 | + expect(lookup("github.com", 8)).toBeUndefined(); |
| 152 | + expect(lookup("gitlab.com", 7)).toBeUndefined(); |
| 153 | + |
| 154 | + const sameVersion = { ...listed, updatedAt: "2026-09-08T00:00:00.000Z" }; |
| 155 | + const syncedAt = Date.parse(link.snapshot!.syncedAt); |
| 156 | + expect(lookup("github.com", 7, [{ ...sameVersion, observedAt: syncedAt - 1 }])?.title).toBe( |
| 157 | + "Change 7", |
| 158 | + ); |
| 159 | + expect(lookup("github.com", 7, [{ ...sameVersion, observedAt: syncedAt + 1 }])?.title).toBe( |
| 160 | + "Listed title", |
| 161 | + ); |
| 162 | + }); |
| 163 | +}); |
| 164 | + |
116 | 165 | describe("rememberBounded", () => { |
117 | 166 | it("moves a re-answered entry to the newest slot and evicts the oldest past the limit", () => { |
118 | 167 | let snapshots: ReadonlyMap<string, number> = new Map(); |
|
0 commit comments