Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
orca/src/main/github/client-pr-lookup-coalescing.test.ts at main · tmchow/orca · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
tmchow
orca
Repository navigation
Code
Pull requests
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
orca
/
src
/
main
/
github
/
client-pr-lookup-coalescing.test.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
195 lines (187 loc) · 7.73 KB
main
Breadcrumbs
orca
/
src
/
main
/
github
/
client-pr-lookup-coalescing.test.ts
Copy path
Top
File metadata and controls
Code
Blame
195 lines (187 loc) · 7.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import
{
afterEach
,
beforeEach
,
describe
,
expect
,
it
,
vi
}
from
'vitest'
import
type
{
PRRefreshOutcome
}
from
'../../shared/github/pull-request-refresh-types'
import
type
{
GitHubRepoContext
,
LocalGitExecOptions
}
from
'./github-repository-identity'
import
{
getRepoExecutionHostId
}
from
'../../shared/execution-host'
import
{
hostedReviewInfoFromGitHubPRInfo
}
from
'../../shared/hosted-review-github'
import
{
makePR
}
from
'./pr-refresh-coordinator-test-harness'
import
{
__resetHostedReviewBranchCacheForTests
,
invalidateHostedReviewBranchCache
,
withHostedReviewBranchCache
}
from
'../source-control/hosted-review-branch-cache'
const
mocks
=
vi
.
hoisted
(
(
)
=>
(
{
resolve
:
vi
.
fn
(
)
,
acquire
:
vi
.
fn
(
)
,
release
:
vi
.
fn
(
)
}
)
)
vi
.
mock
(
'./gh-utils'
,
(
)
=>
(
{
acquire
:
mocks
.
acquire
,
release
:
mocks
.
release
,
githubRepoContext
:
(
repoPath
:
string
,
connectionId
:
string
|
null
,
options
:
LocalGitExecOptions
)
=>
(
{
repoPath
,
connectionId
,
...
options
}
)
,
ghRepoExecOptions
:
(
context
:
GitHubRepoContext
)
=>
context
}
)
)
vi
.
mock
(
'./client/lookup/branch-lookup-resolution'
,
(
)
=>
(
{
resolvePRForBranchOutcome
:
mocks
.
resolve
}
)
)
import
{
getPRForBranchOutcome
}
from
'./client/lookup/pr-for-branch-outcome'
const
outcome
:
PRRefreshOutcome
=
{
kind
:
'no-pr'
,
fetchedAt
:
1
}
beforeEach
(
(
)
=>
{
vi
.
clearAllMocks
(
)
__resetHostedReviewBranchCacheForTests
(
)
mocks
.
acquire
.
mockResolvedValue
(
undefined
)
}
)
afterEach
(
(
)
=>
{
vi
.
unstubAllEnvs
(
)
}
)
describe
(
'PR lookup coalescing'
,
(
)
=>
{
it
(
'shares pending reads across callers and releases them after settlement'
,
async
(
)
=>
{
let
finish
:
(
(
value
:
PRRefreshOutcome
)
=>
void
)
|
undefined
mocks
.
resolve
.
mockImplementation
(
(
)
=>
new
Promise
<
PRRefreshOutcome
>
(
(
resolve
)
=>
{
finish
=
resolve
}
)
)
const
first
=
getPRForBranchOutcome
(
'/repo'
,
'refs/heads/topic'
)
const
second
=
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
1
)
)
finish
?.
(
outcome
)
expect
(
await
Promise
.
all
(
[
first
,
second
]
)
)
.
toEqual
(
[
outcome
,
outcome
]
)
mocks
.
resolve
.
mockResolvedValue
(
outcome
)
await
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
2
)
}
)
it
(
'shares a background read with a foreground caller of the same lookup'
,
async
(
)
=>
{
mocks
.
resolve
.
mockResolvedValue
(
outcome
)
await
Promise
.
all
(
[
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
localGitExecOptions
:
{
admissionTier
:
'background'
}
}
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
localGitExecOptions
:
{
admissionTier
:
'interactive'
}
}
)
]
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
1
)
}
)
it
(
'isolates heads, fallback hints, accounts, execution hosts, and credentials'
,
async
(
)
=>
{
mocks
.
resolve
.
mockResolvedValue
(
outcome
)
const
requests
=
[
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
12
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
'ssh-1'
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
12
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
currentHeadOid
:
'other-head'
}
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
localGitExecOptions
:
{
wslDistro
:
'Ubuntu'
}
}
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
localGitExecOptions
:
{
ghAccount
:
{
host
:
'github.com'
,
user
:
'other'
}
}
}
)
]
vi
.
stubEnv
(
'GH_TOKEN'
,
'test-only-other-token'
)
requests
.
push
(
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
)
await
Promise
.
all
(
requests
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
8
)
}
)
it
(
'cleans up errors so later reads can recover'
,
async
(
)
=>
{
mocks
.
resolve
.
mockRejectedValueOnce
(
new
Error
(
'network down'
)
)
.
mockResolvedValue
(
outcome
)
const
results
=
await
Promise
.
all
(
[
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
,
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
]
)
expect
(
results
.
every
(
(
result
)
=>
result
.
kind
===
'upstream-error'
)
)
.
toBe
(
true
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
1
)
await
expect
(
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
)
.
resolves
.
toEqual
(
outcome
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
2
)
}
)
it
.
each
(
[
{
label
:
'native'
,
connectionId
:
null
,
options
:
{
}
}
,
{
label
:
'WSL'
,
connectionId
:
null
,
options
:
{
localGitExecOptions
:
{
wslDistro
:
'Ubuntu'
}
}
}
,
{
label
:
'SSH'
,
connectionId
:
'host / encoded'
,
options
:
{
}
}
]
)
(
'does not adopt a pre-creation no-PR read after $label invalidation'
,
async
(
{
connectionId
,
options
}
)
=>
{
const
created
:
PRRefreshOutcome
=
{
kind
:
'found'
,
pr
:
makePR
(
{
number
:
13
}
)
,
fetchedAt
:
2
}
const
createdReview
=
hostedReviewInfoFromGitHubPRInfo
(
created
.
pr
)
let
finish
:
(
value
:
PRRefreshOutcome
)
=>
void
=
(
)
=>
{
}
mocks
.
resolve
.
mockImplementationOnce
(
(
)
=>
new
Promise
<
PRRefreshOutcome
>
(
(
resolve
)
=>
{
finish
=
resolve
}
)
)
.
mockResolvedValue
(
created
)
const
executionHostId
=
getRepoExecutionHostId
(
{
connectionId
}
)
const
identity
=
{
repoPath
:
'/repo'
,
executionHostId
,
branch
:
'topic'
,
...
options
}
const
lookup
=
async
(
)
=>
{
const
result
=
await
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
connectionId
,
null
,
options
)
if
(
result
.
kind
===
'upstream-error'
)
{
throw
new
Error
(
result
.
message
)
}
return
result
.
kind
===
'found'
?
hostedReviewInfoFromGitHubPRInfo
(
result
.
pr
)
:
null
}
const
beforeCreation
=
withHostedReviewBranchCache
(
identity
,
{
headOid
:
null
}
,
lookup
)
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
1
)
)
invalidateHostedReviewBranchCache
(
'/repo'
,
executionHostId
)
const
afterCreation
=
withHostedReviewBranchCache
(
identity
,
{
headOid
:
null
}
,
lookup
)
try
{
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
2
)
)
await
expect
(
afterCreation
)
.
resolves
.
toEqual
(
createdReview
)
}
finally
{
finish
(
outcome
)
await
Promise
.
all
(
[
beforeCreation
,
afterCreation
]
)
}
await
expect
(
withHostedReviewBranchCache
(
identity
,
{
headOid
:
null
}
,
lookup
)
)
.
resolves
.
toEqual
(
createdReview
)
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
2
)
}
)
it
(
'keeps native, WSL, and SSH pending reads scoped during invalidation'
,
async
(
)
=>
{
const
completions
:
(
(
value
:
PRRefreshOutcome
)
=>
void
)
[
]
=
[
]
mocks
.
resolve
.
mockImplementation
(
(
)
=>
new
Promise
<
PRRefreshOutcome
>
(
(
resolve
)
=>
{
completions
.
push
(
resolve
)
}
)
)
const
native
=
(
)
=>
getPRForBranchOutcome
(
'/repo'
,
'topic'
)
const
wsl
=
(
)
=>
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
null
,
null
,
{
localGitExecOptions
:
{
wslDistro
:
'Ubuntu'
}
}
)
const
ssh
=
(
)
=>
getPRForBranchOutcome
(
'/repo'
,
'topic'
,
null
,
'host / encoded'
)
const
reads
=
[
native
(
)
,
wsl
(
)
,
ssh
(
)
]
try
{
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
3
)
)
invalidateHostedReviewBranchCache
(
'/other'
,
'local'
)
reads
.
push
(
native
(
)
,
wsl
(
)
,
ssh
(
)
)
invalidateHostedReviewBranchCache
(
'/repo'
,
getRepoExecutionHostId
(
{
connectionId
:
'host / encoded'
}
)
)
reads
.
push
(
native
(
)
,
wsl
(
)
,
ssh
(
)
)
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
4
)
)
invalidateHostedReviewBranchCache
(
'/repo'
,
'local'
)
reads
.
push
(
native
(
)
,
wsl
(
)
,
ssh
(
)
)
await
vi
.
waitFor
(
(
)
=>
expect
(
mocks
.
resolve
)
.
toHaveBeenCalledTimes
(
6
)
)
}
finally
{
for
(
const
finish
of
completions
)
{
finish
(
outcome
)
}
await
Promise
.
all
(
reads
)
}
}
)
}
)
You can’t perform that action at this time.