Open History to see the last commit
1import Foundation
2import Testing
3@testable import T3Code
4β
5@Suite("Web V2 home thread metadata")
6struct HomeThreadMetadataTests {
7 @Test
8 func providerAccountBadgesUseTheSessionAndOwningEnvironment() throws {
9 var personal = FeatureProvider(id: "codex", name: "Personal", driver: "codex")
10 personal.accentColor = " #12aBcD "
11 let work = FeatureProvider(id: "work", name: "Work Account", driver: "codex")
12 let otherComputer = FeatureProvider(id: "codex", name: "Codex", driver: "codex")
13 var snapshot = FeatureSnapshot(
14 threads: [
15 FeatureThread(id: "one", projectID: "p", environmentID: "one", title: "One", providerID: "codex"),
16 FeatureThread(id: "session", projectID: "p", environmentID: "one", title: "Session",
17 providerID: "codex", sessionProviderID: "work"),
18 FeatureThread(id: "two", projectID: "p", environmentID: "two", title: "Two", providerID: "codex"),
19 ],
20 providersByEnvironment: ["one": [personal, work], "two": [otherComputer]]
21 )
22 let contexts = HomeThreadRowContext.index(snapshot: snapshot)
23 #expect(contexts["one"]?.providerBadge == ProviderAccountBadge(initials: "PE", accentColor: "#12aBcD"))
24 #expect(contexts["session"]?.providerName == "Work Account")
25 #expect(contexts["session"]?.providerBadge?.initials == "WA")
26 #expect(contexts["two"]?.providerBadge == nil)
27β
28 personal.accentColor = "invalid"
29 snapshot.providersByEnvironment?["one"] = [personal]
30 #expect(HomeThreadRowContext.index(snapshot: snapshot)["one"]?.providerBadge == nil)
31 }
32β
33 @Test
34 func providerInstanceNamesMatchTheSharedClientRules() {
35 #expect(ProviderInstanceDisplay.name(instanceID: "codex", driver: "codex", displayName: nil) == "Codex")
36 #expect(ProviderInstanceDisplay.name(instanceID: "codex_personal", driver: "codex", displayName: "Codex") == "Codex Personal")
37 #expect(ProviderInstanceDisplay.name(instanceID: "myWorkAccount", driver: "codex", displayName: nil) == "My Work Account")
38 #expect(ProviderInstanceDisplay.name(instanceID: "claudeAgent", driver: "claudeAgent", displayName: nil) == "Claude")
39 #expect(ProviderInstanceDisplay.initials("π©π½βπ» Team") == "π©π½βπ»T")
40 #expect(ProviderInstanceDisplay.accentColor("#fff") == nil)
41 }
42β
43 private let now = Date(timeIntervalSince1970: 10_000)
44β
45 @Test
46 func statusLabelsFollowTheWebV2RowVocabulary() {
47 let expected: [(FeatureThreadState, HomeThreadStatus, String?)] = [
48 (.idle, .ready, nil),
49 (.queued, .working, "Working"),
50 (.working, .working, "Working"),
51 (.monitoring, .monitoring, "Monitoring"),
52 (.waitingForApproval, .approval, "Approval"),
53 (.waitingForInput, .input, "Input"),
54 (.failed, .failed, "Failed"),
55 (.completed, .done, "Done"),
56 ]
57β
58 for (state, status, label) in expected {
59 let thread = FeatureThread(
60 id: state.rawValue,
61 projectID: "project",
62 title: "Task",
63 state: state
64 )
65 #expect(thread.homeStatus == status)
66 #expect(thread.homeStatusLabel == label)
67 }
68 }
69β
70 @Test
71 func completedAndIdleRowsUseQuietRelativeAges() {
72 let updatedAt = now.addingTimeInterval(-120)
73 let completed = FeatureThread(
74 id: "completed",
75 projectID: "project",
76 title: "Done task",
77 updatedAt: updatedAt,
78 state: .completed
79 )
80 let idle = FeatureThread(
81 id: "idle",
82 projectID: "project",
83 title: "Idle task",
84 updatedAt: updatedAt,
85 state: .idle
86 )
87β
88 #expect(completed.homeRowStatusLabel(at: now) == "2m")
89 #expect(idle.homeRowStatusLabel(at: now) == "2m")
90 }
91β
92 @Test
93 func completedDetailHeadersDoNotShowAStatusBadge() {
94 let completed = FeatureThread(
95 id: "completed",
96 projectID: "project",
97 title: "Completed task",
98 state: .completed
99 )
100 let working = FeatureThread(
101 id: "working",
102 projectID: "project",
103 title: "Working task",
104 state: .working
105 )
106β
107 #expect(completed.detailHeaderStatusLabel == nil)
108 #expect(completed.detailHeaderStatusIcon == nil)
109 #expect(working.detailHeaderStatusLabel == "Working")
110 #expect(working.detailHeaderStatusIcon == "circle.dotted")
111 }
112β
113 @Test
114 func workingDurationMatchesTheCompactWebFormatAndClampsFutureDates() {
115 let thread = FeatureThread(
116 id: "working",
117 projectID: "project",
118 title: "Build",
119 state: .working,
120 workingStartedAt: now.addingTimeInterval(-5_465)
121 )
122 let future = FeatureThread(
123 id: "queued",
124 projectID: "project",
125 title: "Queue",
126 state: .queued,
127 workingStartedAt: now.addingTimeInterval(5)
128 )
129 let idle = FeatureThread(
130 id: "idle",
131 projectID: "project",
132 title: "Rest",
133 state: .idle,
134 workingStartedAt: now.addingTimeInterval(-10)
135 )
136 let monitoring = FeatureThread(
137 id: "monitoring",
138 projectID: "project",
139 title: "Watch",
140 state: .monitoring,
141 workingStartedAt: now.addingTimeInterval(-10)
142 )
143β
144 #expect(thread.homeWorkingDuration(at: now) == "1h 31m")
145 #expect(future.homeWorkingDuration(at: now) == "0s")
146 #expect(idle.homeWorkingDuration(at: now) == nil)
147 #expect(monitoring.homeWorkingDuration(at: now) == nil)
148 }
149β
150 @Test
151 func accessibilityDurationSpellsOutUnitsAndClampsFutureDates() {
152 #expect(accessibilityDuration(startedAtOffset: 5) == "0 seconds")
153 #expect(accessibilityDuration(startedAtOffset: -1) == "1 second")
154 #expect(accessibilityDuration(startedAtOffset: -42) == "42 seconds")
155 #expect(accessibilityDuration(startedAtOffset: -60) == "1 minute")
156 #expect(accessibilityDuration(startedAtOffset: -120) == "2 minutes")
157 #expect(accessibilityDuration(startedAtOffset: -3_600) == "1 hour")
158 #expect(accessibilityDuration(startedAtOffset: -7_200) == "2 hours")
159 #expect(accessibilityDuration(startedAtOffset: -5_465) == "1 hour, 31 minutes")
160 }
161β
162 @Test
163 func accessibilityStatusDescribesOnlyLiveWorkingDurations() {
164 let working = thread(state: .working, startedAtOffset: -90)
165 let queuedWithoutStart = thread(state: .queued)
166 let monitoring = thread(state: .monitoring, startedAtOffset: -90)
167 let idle = thread(state: .idle)
168β
169 #expect(working.hasLiveWorkingDuration)
170 #expect(working.homeStatusAccessibilityLabel(at: now) == "Agent is working for 1 minute")
171 #expect(!queuedWithoutStart.hasLiveWorkingDuration)
172 #expect(queuedWithoutStart.homeStatusAccessibilityLabel(at: now) == "Agent is working")
173 #expect(!monitoring.hasLiveWorkingDuration)
174 #expect(monitoring.homeStatusAccessibilityLabel(at: now) == "Monitoring")
175 #expect(!idle.hasLiveWorkingDuration)
176 #expect(idle.homeStatusAccessibilityLabel(at: now) == "Ready")
177 }
178β
179 @Test
180 func completedRowsShowABareAgeMeasuredFromCompletion() {
181 let thread = FeatureThread(
182 id: "completed",
183 projectID: "project",
184 title: "Done task",
185 updatedAt: now.addingTimeInterval(-60),
186 state: .completed,
187 latestTurnCompletedAt: now.addingTimeInterval(-9_360)
188 )
189β
190 #expect(thread.homeDoneDuration(at: now) == "2h 36m")
191 #expect(thread.homeRowStatusLabel(at: now) == "2h 36m")
192 #expect(
193 thread.homeRowAccessibilityStatus(rich: true, at: now)
194 == "Completed 2 hours, 36 minutes ago"
195 )
196 #expect(thread.homeRowAccessibilityStatus(rich: false, at: now) == "Done")
197 }
198β
199 @Test
200 func doneDurationsAreMinuteGranularAndClampFutureCompletions() {
201 #expect(doneDuration(completedAtOffset: 30) == "now")
202 #expect(doneDuration(completedAtOffset: -30) == "now")
203 #expect(doneDuration(completedAtOffset: -59) == "now")
204 #expect(doneDuration(completedAtOffset: -60) == "1m")
205 #expect(doneDuration(completedAtOffset: -3_600) == "1h 0m")
206 #expect(doneDuration(completedAtOffset: -5_465) == "1h 31m")
207 #expect(doneDuration(completedAtOffset: -86_400) == "1d 0h")
208 #expect(doneDuration(completedAtOffset: -273_600) == "3d 4h")
209 #expect(doneDuration(completedAtOffset: -604_800) == "1w")
210 #expect(doneDuration(completedAtOffset: -31_449_600) == "52w")
211 #expect(doneDuration(completedAtOffset: -31_536_000) == "1y")
212 #expect(doneDuration(completedAtOffset: -63_072_000) == "2y")
213 }
214β
215 @Test
216 func doneAccessibilityLabelsSpeakTheAgeInWords() {
217 #expect(doneAccessibilityLabel(completedAtOffset: -30) == "Completed just now")
218 #expect(doneAccessibilityLabel(completedAtOffset: -60) == "Completed 1 minute ago")
219 #expect(doneAccessibilityLabel(completedAtOffset: -120) == "Completed 2 minutes ago")
220 #expect(doneAccessibilityLabel(completedAtOffset: -3_600) == "Completed 1 hour ago")
221 #expect(
222 doneAccessibilityLabel(completedAtOffset: -9_360) == "Completed 2 hours, 36 minutes ago"
223 )
224 #expect(doneAccessibilityLabel(completedAtOffset: -86_400) == "Completed 1 day ago")
225 #expect(
226 doneAccessibilityLabel(completedAtOffset: -273_600) == "Completed 3 days, 4 hours ago"
227 )
228 #expect(doneAccessibilityLabel(completedAtOffset: -604_800) == "Completed 1 week ago")
229 #expect(doneAccessibilityLabel(completedAtOffset: -31_449_600) == "Completed 52 weeks ago")
230 #expect(doneAccessibilityLabel(completedAtOffset: -31_536_000) == "Completed 1 year ago")
231 #expect(doneAccessibilityLabel(completedAtOffset: -63_072_000) == "Completed 2 years ago")
232 }
233β
234 @Test
235 func onlyCompletedThreadsWithACompletionTimeShowADoneDuration() {
236 let completedWithoutTime = FeatureThread(
237 id: "completed",
238 projectID: "project",
239 title: "Done task",
240 updatedAt: now.addingTimeInterval(-120),
241 state: .completed
242 )
243 let working = FeatureThread(
244 id: "working",
245 projectID: "project",
246 title: "Working task",
247 state: .working,
248 latestTurnCompletedAt: now.addingTimeInterval(-300)
249 )
250β
251 #expect(completedWithoutTime.homeDoneDuration(at: now) == nil)
252 #expect(completedWithoutTime.homeDoneAccessibilityLabel(at: now) == nil)
253 #expect(completedWithoutTime.homeRowStatusLabel(at: now) == "2m")
254 #expect(
255 completedWithoutTime.homeRowAccessibilityStatus(rich: true, at: now)
256 == "Done. Updated 2 minutes ago"
257 )
258 #expect(completedWithoutTime.homeRowAccessibilityStatus(rich: false, at: now) == "Done")
259 #expect(working.homeDoneDuration(at: now) == nil)
260 #expect(working.homeRowStatusLabel(at: now) == "Working")
261 }
262β
263 private func doneDuration(completedAtOffset: TimeInterval) -> String? {
264 completedThread(completedAtOffset: completedAtOffset).homeDoneDuration(at: now)
265 }
266β
267 private func doneAccessibilityLabel(completedAtOffset: TimeInterval) -> String? {
268 completedThread(completedAtOffset: completedAtOffset)
269 .homeDoneAccessibilityLabel(at: now)
270 }
271β
272 private func completedThread(completedAtOffset: TimeInterval) -> FeatureThread {
273 FeatureThread(
274 id: "completed",
275 projectID: "project",
276 title: "Done task",
277 state: .completed,
278 latestTurnCompletedAt: now.addingTimeInterval(completedAtOffset)
279 )
280 }
281β
282 private func accessibilityDuration(startedAtOffset: TimeInterval) -> String {
283 HomeWorkingDuration.accessibility(
284 since: now.addingTimeInterval(startedAtOffset),
285 now: now
286 )
287 }
288β
289 private func thread(
290 state: FeatureThreadState,
291 startedAtOffset: TimeInterval? = nil
292 ) -> FeatureThread {
293 FeatureThread(
294 id: state.rawValue,
295 projectID: "project",
296 title: "Task",
297 state: state,
298 workingStartedAt: startedAtOffset.map(now.addingTimeInterval)
299 )
300 }
301β
302 @Test
303 func rowAttributionPrefersCurrentEnvironmentNameAndWireProviderName() {
304 let thread = FeatureThread(
305 id: "thread",
306 projectID: "project",
307 environmentID: "device",
308 environmentName: "Old device name",
309 title: "Build",
310 branch: "feat/web-v2-home",
311 worktreePath: "/worktrees/web-v2-home",
312 providerID: "codex-work",
313 providerName: "Codex Work"
314 )
315 let snapshot = FeatureSnapshot(
316 environments: [
317 FeatureEnvironment(
318 id: "device",
319 name: "leftbook",
320 endpoint: "https://leftbook.example"
321 ),
322 ],
323 projects: [
324 FeatureProject(
325 id: "project",
326 environmentID: "device",
327 name: "t3code",
328 path: "/work/t3code"
329 ),
330 ],
331 providers: [FeatureProvider(id: "codex-work", name: "Config name")]
332 )
333β
334 #expect(thread.homeEnvironmentLabel(in: snapshot) == "leftbook")
335 #expect(thread.homeProviderLabel(in: snapshot) == "Codex Work")
336 #expect(thread.branch == "feat/web-v2-home")
337 #expect(thread.worktreePath == "/worktrees/web-v2-home")
338 }
339β
340 @Test
341 func rowAttributionFallsBackThroughProjectAndProviderCatalog() {
342 let thread = FeatureThread(
343 id: "thread",
344 projectID: "project",
345 title: "Build",
346 providerID: "claude"
347 )
348 let snapshot = FeatureSnapshot(
349 environments: [
350 FeatureEnvironment(
351 id: "device",
352 name: "steambox",
353 endpoint: "https://steambox.example"
354 ),
355 ],
356 projects: [
357 FeatureProject(
358 id: "project",
359 environmentID: "device",
360 name: "t3code",
361 path: "/work/t3code"
362 ),
363 ],
364 providersByEnvironment: [
365 "device": [FeatureProvider(id: "claude", name: "Claude")],
366 ]
367 )
368β
369 #expect(thread.homeEnvironmentLabel(in: snapshot) == "steambox")
370 #expect(thread.homeProviderLabel(in: snapshot) == "Claude")
371 }
372β
373 @Test
374 func rowContextCarriesHarnessIdentityAndCustomProviderFallback() throws {
375 let knownThread = FeatureThread(
376 id: "known",
377 projectID: "project",
378 title: "Use Claude",
379 providerID: "work-claude"
380 )
381 let customThread = FeatureThread(
382 id: "custom",
383 projectID: "project",
384 title: "Use a custom harness",
385 providerID: "acme-agent",
386 providerName: "Acme Agent"
387 )
388 let snapshot = FeatureSnapshot(
389 projects: [
390 FeatureProject(
391 id: "project",
392 environmentID: "device",
393 name: "t3code",
394 path: "/work/t3code"
395 ),
396 ],
397 threads: [knownThread, customThread],
398 providersByEnvironment: [
399 "device": [
400 FeatureProvider(id: "work-claude", name: "Claude Code", driver: "custom"),
401 FeatureProvider(id: "acme-agent", name: "Acme Agent", driver: "custom"),
402 ],
403 ]
404 )
405β
406 let contexts = HomeThreadRowContext.index(snapshot: snapshot)
407 let known = try #require(contexts[knownThread.id])
408 let custom = try #require(contexts[customThread.id])
409β
410 #expect(known.providerID == "work-claude")
411 #expect(known.projectEnvironmentID == "device")
412 #expect(known.projectWorkspaceRoot == "/work/t3code")
413 #expect(known.providerDriver == "custom")
414 #expect(known.providerName == "Claude Code")
415 #expect(
416 ProviderBrand.resolve(
417 driver: known.providerDriver,
418 providerID: known.providerID,
419 providerName: known.providerName
420 ) == .claude
421 )
422 #expect(custom.providerID == "acme-agent")
423 #expect(custom.providerDriver == "custom")
424 #expect(custom.providerName == "Acme Agent")
425 #expect(
426 ProviderBrand.resolve(
427 driver: custom.providerDriver,
428 providerID: custom.providerID,
429 providerName: custom.providerName
430 ) == nil
431 )
432 }
433β
434 @Test
435 func rowContextUsesRepositoryGroupNameInsteadOfStalePhysicalProjectTitle() throws {
436 let thread = FeatureThread(
437 id: "thread",
438 projectID: "project",
439 title: "Test T3 Code Functionality"
440 )
441 let snapshot = FeatureSnapshot(
442 projects: [
443 FeatureProject(
444 id: "project",
445 environmentID: "bb-1",
446 name: "wat",
447 path: "/work/t3code",
448 repositoryIdentity: FeatureRepositoryIdentity(
449 canonicalKey: "github.com/pingdotgg/t3code",
450 rootPath: "/work/t3code",
451 displayName: "pingdotgg/t3code",
452 name: "t3code"
453 )
454 ),
455 ],
456 threads: [thread],
457 preferencesByEnvironment: [
458 "bb-1": FeatureEnvironmentPreferences(projectGroupingMode: .repository),
459 ]
460 )
461β
462 let context = try #require(HomeThreadRowContext.index(snapshot: snapshot)[thread.id])
463β
464 #expect(context.projectName == "pingdotgg/t3code")
465 }
466β
467 @Test
468 func fallbackRowContextDoesNotOfferPlaceholderProjectCopy() {
469 let thread = FeatureThread(
470 id: "thread",
471 projectID: "missing-project",
472 title: "Unresolved project"
473 )
474β
475 let actions = ThreadCopyModel.actions(
476 for: thread,
477 context: HomeThreadRowContext.fallback.copyContext
478 )
479β
480 #expect(actions.contains { $0.kind == .project } == false)
481 }
482β
483 @Test
484 func rowContextFallsBackToProjectEnvironmentForBlankThreadEnvironment() throws {
485 let thread = FeatureThread(
486 id: "thread",
487 projectID: "project",
488 environmentID: " ",
489 title: "Blank environment"
490 )
491 let snapshot = FeatureSnapshot(
492 environments: [
493 FeatureEnvironment(
494 id: "device",
495 name: "Desk Mac",
496 endpoint: "http://device",
497 connectionState: .connected
498 ),
499 ],
500 projects: [
501 FeatureProject(
502 id: "project",
503 environmentID: "device",
504 name: "t3code",
505 path: "/work/t3code"
506 ),
507 ],
508 threads: [thread]
509 )
510β
511 let context = try #require(HomeThreadRowContext.index(snapshot: snapshot)[thread.id])
512β
513 #expect(context.environmentLabel == "Desk Mac")
514 #expect(context.copyContext.environmentID == "device")
515 }
516β
517 @Test
518 func pullRequestIndicatorsUseTheCurrentThreadBranchAndPreserveTheirState() {
519 let thread = FeatureThread(
520 id: "thread",
521 projectID: "project",
522 title: "Add native PR indicators",
523 branch: "feature/native-pull-requests"
524 )
525β
526 for state in ["open", "merged", "closed"] {
527 let status = FeatureSourceControlStatus(
528 branch: "feature/native-pull-requests",
529 pullRequest: FeaturePullRequest(
530 number: 42,
531 title: "Add native PR indicators",
532 state: state,
533 updatedAt: "2026-08-28T12:30:45.123Z"
534 )
535 )
536β
537 let presentation = HomeThreadPullRequestPresentation.resolve(
538 thread: thread,
539 status: status
540 )
541β
542 #expect(presentation?.label == "#42")
543 #expect(presentation?.state.rawValue == state)
544 #expect(presentation?.updatedAt != nil)
545 #expect(presentation?.accessibilityLabel == "Pull request #42, \(state)")
546 }
547β
548 let wholeSecond = FeatureSourceControlStatus(
549 branch: thread.branch,
550 pullRequest: FeaturePullRequest(
551 number: 42,
552 title: "Add native PR indicators",
553 state: "merged",
554 updatedAt: "2026-08-28T12:30:45Z"
555 )
556 )
557 #expect(HomeThreadPullRequestPresentation.resolve(
558 thread: thread,
559 status: wholeSecond
560 )?.updatedAt != nil)
561 }
562β
563 @Test
564 func pullRequestIndicatorsIgnoreOtherBranchesAndUnknownStates() {
565 let thread = FeatureThread(
566 id: "thread",
567 projectID: "project",
568 title: "Task",
569 branch: "feature/current"
570 )
571 let otherBranch = FeatureSourceControlStatus(
572 branch: "feature/other",
573 pullRequest: FeaturePullRequest(number: 42, title: "Other work", state: "open")
574 )
575 let unsupportedState = FeatureSourceControlStatus(
576 branch: "feature/current",
577 pullRequest: FeaturePullRequest(number: 42, title: "Current work", state: "draft")
578 )
579 let branchless = FeatureThread(id: "branchless", projectID: "project", title: "Task")
580β
581 #expect(HomeThreadPullRequestPresentation.resolve(thread: thread, status: otherBranch) == nil)
582 #expect(HomeThreadPullRequestPresentation.resolve(thread: thread, status: unsupportedState) == nil)
583 #expect(HomeThreadPullRequestPresentation.resolve(thread: branchless, status: otherBranch) == nil)
584 }
585β
586 @Test
587 func threadMenuOpensDurablePullRequestURL() throws {
588 let linked = ThreadLinkedPullRequest(
589 projectId: "project-wire",
590 repository: "pingdotgg/t3code",
591 number: 5178,
592 url: "https://github.com/pingdotgg/t3code/pull/5178"
593 )
594 let thread = FeatureThread(
595 id: "thread",
596 projectID: "environment:project-wire",
597 environmentID: "studio",
598 environmentName: "Studio",
599 title: "Native client",
600 linkedPullRequest: linked
601 )
602β
603 let destination = try #require(ThreadPullRequestDestination.resolve(
604 thread: thread,
605 branchPullRequest: nil
606 ))
607β
608 #expect(destination.number == 5178)
609 #expect(destination.url.absoluteString == "https://github.com/pingdotgg/t3code/pull/5178")
610 }
611β
612 @Test
613 func threadMenuOpensBranchPullRequestsWithoutADurableLink() throws {
614 let project = FeatureProject(
615 id: "scoped-project",
616 wireID: "project-wire",
617 environmentID: "studio",
618 name: "T3 Code",
619 path: "/work/t3code"
620 )
621 let thread = FeatureThread(
622 id: "thread",
623 projectID: project.id,
624 environmentID: "studio",
625 environmentName: "Studio",
626 title: "Native client",
627 branch: "feature/native"
628 )
629 let pullRequest = FeaturePullRequest(
630 number: 42,
631 title: "Native client",
632 state: "open",
633 url: URL(string: "https://github.com/pingdotgg/t3code/pull/42")
634 )
635β
636 let destination = try #require(ThreadPullRequestDestination.resolve(
637 thread: thread,
638 branchPullRequest: pullRequest
639 ))
640β
641 #expect(destination.number == 42)
642 #expect(destination.url == pullRequest.url)
643 }
644β
645 @Test
646 func threadMenuRequiresPullRequestURL() throws {
647 let url = try #require(URL(string: "https://example.com/reviews/42"))
648 let thread = FeatureThread(id: "thread", projectID: "missing", title: "Task")
649 let pullRequest = FeaturePullRequest(number: 42, title: "Task", state: "open", url: url)
650β
651 let destination = try #require(ThreadPullRequestDestination.resolve(
652 thread: thread,
653 branchPullRequest: pullRequest
654 ))
655β
656 #expect(destination.url == url)
657 #expect(ThreadPullRequestDestination.resolve(
658 thread: thread,
659 branchPullRequest: nil
660 ) == nil)
661 #expect(ThreadPullRequestDestination.resolve(
662 thread: thread,
663 branchPullRequest: FeaturePullRequest(
664 number: 42,
665 title: "Task",
666 state: "open"
667 )
668 ) == nil)
669 }
670β
671 @Test
672 func liveSourceControlSnapshotsCarryPullRequestsAndClearMissingRemoteState() {
673 let local = VCSLocalStatus(
674 isRepo: true,
675 sourceControlProvider: nil,
676 hasPrimaryRemote: true,
677 isDefaultRef: false,
678 refName: "feature/native-pull-requests",
679 hasWorkingTreeChanges: false,
680 workingTree: VCSWorkingTree(files: [], insertions: 0, deletions: 0)
681 )
682 let remote = VCSRemoteStatus(
683 hasUpstream: true,
684 aheadCount: 2,
685 behindCount: 1,
686 aheadOfDefaultCount: 2,
687 pr: VCSChangeRequest(
688 number: 42,
689 title: "Add native PR indicators",
690 url: "https://github.com/pingdotgg/t3code/pull/42",
691 baseRef: "main",
692 headRef: "feature/native-pull-requests",
693 state: "open"
694 )
695 )
696β
697 let status = NativeWorkspaceMapper.sourceControl(local: local, remote: remote)
698 let withoutRemote = NativeWorkspaceMapper.sourceControl(local: local, remote: nil)
699β
700 #expect(status.branch == "feature/native-pull-requests")
701 #expect(status.pullRequest?.number == 42)
702 #expect(status.pullRequest?.state == "open")
703 #expect(status.aheadCount == 2)
704 #expect(status.behindCount == 1)
705 #expect(withoutRemote.pullRequest == nil)
706 }
707}