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/node-runtime/managed-runtime-installation.test.ts at main · tmchow/orca · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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
/
node-runtime
/
managed-runtime-installation.test.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
140 lines (131 loc) · 5.69 KB
main
Breadcrumbs
orca
/
src
/
main
/
node-runtime
/
managed-runtime-installation.test.ts
Copy path
Top
File metadata and controls
Code
Blame
140 lines (131 loc) · 5.69 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
import
{
createHash
}
from
'node:crypto'
import
{
mkdir
,
mkdtemp
,
readdir
,
rm
,
writeFile
}
from
'node:fs/promises'
import
{
tmpdir
}
from
'node:os'
import
{
join
}
from
'node:path'
import
{
strToU8
,
zipSync
}
from
'fflate'
import
{
afterEach
,
expect
,
it
,
vi
}
from
'vitest'
import
type
*
as
ReleaseModule
from
'./managed-runtime-release'
import
{
reclaimRuntimeReleases
,
RUNTIME_RELEASE_RECEIPT
}
from
'./managed-runtime-release'
import
{
ManagedRuntimeInstallation
}
from
'./managed-runtime-installation'
vi
.
mock
(
'./managed-runtime-release'
,
async
(
importOriginal
)
=>
{
const
actual
=
await
importOriginal
<
typeof
ReleaseModule
>
(
)
return
{
...
actual
,
reclaimRuntimeReleases
:
vi
.
fn
(
actual
.
reclaimRuntimeReleases
)
}
}
)
const
sha256
=
(
bytes
:
string
|
Uint8Array
)
=>
createHash
(
'sha256'
)
.
update
(
bytes
)
.
digest
(
'hex'
)
const
ARCHIVE
=
zipSync
(
{
server
:
strToU8
(
'server bytes'
)
}
)
const
roots
:
string
[
]
=
[
]
afterEach
(
(
)
=>
Promise
.
all
(
roots
.
splice
(
0
)
.
map
(
(
r
)
=>
rm
(
r
,
{
recursive
:
true
,
force
:
true
}
)
)
)
)
async
function
rig
(
bodies
:
(
'hang'
|
'whole'
)
[
]
)
{
const
dataDirectory
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'orca-runtime-install-'
)
)
roots
.
push
(
dataDirectory
)
const
root
=
join
(
dataDirectory
,
'agent-runtimes'
,
'agent'
)
const
pin
=
{
version
:
'1.0'
,
url
:
'https://example.test/agent-1.0.zip'
,
archiveSha256
:
sha256
(
ARCHIVE
)
,
archiveBytes
:
ARCHIVE
.
length
,
members
:
[
{
path
:
'server'
,
sha256
:
sha256
(
'server bytes'
)
,
bytes
:
12
}
]
}
const
runtime
=
{
label
:
'Agent'
,
root
:
(
)
=>
root
,
pin
:
(
)
=>
pin
}
const
fetcher
=
async
(
)
=>
{
const
body
=
bodies
.
shift
(
)
return
new
Response
(
new
ReadableStream
(
{
start
(
controller
)
{
controller
.
enqueue
(
ARCHIVE
.
slice
(
0
,
5
)
)
if
(
body
===
'whole'
)
{
controller
.
enqueue
(
ARCHIVE
.
slice
(
5
)
)
controller
.
close
(
)
}
}
}
)
)
}
const
host
=
(
)
=>
new
ManagedRuntimeInstallation
(
'agent'
,
runtime
,
{
dataDirectory
,
findExternal
:
async
(
)
=>
false
,
fence
:
(
work
)
=>
work
(
)
,
fetcher
}
)
const
phase
=
async
(
installation
:
ManagedRuntimeInstallation
)
=>
(
await
installation
.
status
(
)
)
.
operation
?.
phase
return
{
root
,
host
,
phase
}
}
it
(
'installs only when asked, with progress, cancel, retry, and a status read from disk'
,
async
(
)
=>
{
const
{
root
,
host
,
phase
}
=
await
rig
(
[
'hang'
,
'whole'
]
)
const
installation
=
host
(
)
expect
(
await
installation
.
status
(
)
)
.
toMatchObject
(
{
installedVersion
:
null
,
source
:
null
}
)
const
started
=
installation
.
install
(
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
(
await
installation
.
status
(
)
)
.
operation
?.
downloadedBytes
)
.
toBe
(
5
)
)
expect
(
installation
.
install
(
)
.
id
)
.
toBe
(
started
.
id
)
expect
(
await
installation
.
cancel
(
started
.
id
)
)
.
toMatchObject
(
{
phase
:
'cancelled'
}
)
expect
(
await
readdir
(
root
)
)
.
toEqual
(
[
]
)
expect
(
installation
.
install
(
)
.
id
)
.
not
.
toBe
(
started
.
id
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
await
phase
(
installation
)
)
.
toBe
(
'succeeded'
)
)
expect
(
await
host
(
)
.
status
(
)
)
.
toMatchObject
(
{
installedVersion
:
'1.0'
,
installedCurrent
:
true
,
source
:
'managed'
,
operation
:
null
}
)
expect
(
await
readdir
(
root
)
)
.
toEqual
(
[
'1.0'
]
)
// Whole files without a receipt looped as damaged; Install now rewrites it, with no download.
await
rm
(
join
(
root
,
'1.0'
,
RUNTIME_RELEASE_RECEIPT
)
)
expect
(
await
installation
.
status
(
)
)
.
toMatchObject
(
{
damaged
:
true
}
)
const
rewrite
=
installation
.
install
(
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
(
await
installation
.
status
(
)
)
.
operation
)
.
toMatchObject
(
{
id
:
rewrite
.
id
,
phase
:
'succeeded'
}
)
)
expect
(
await
installation
.
status
(
)
)
.
toMatchObject
(
{
installedCurrent
:
true
}
)
}
)
it
(
'publishes an update only once the old releases were reclaimed'
,
async
(
)
=>
{
const
{
root
,
host
,
phase
}
=
await
rig
(
[
'whole'
]
)
for
(
const
version
of
[
'0.8'
,
'0.9'
]
)
{
await
mkdir
(
join
(
root
,
version
)
,
{
recursive
:
true
}
)
await
writeFile
(
join
(
root
,
version
,
'server'
)
,
'old server'
,
{
mode
:
0o755
}
)
const
members
=
[
{
path
:
'server'
,
bytes
:
10
}
]
const
receipt
=
{
releaseId
:
sha256
(
version
)
,
version
,
members
}
await
writeFile
(
join
(
root
,
version
,
RUNTIME_RELEASE_RECEIPT
)
,
JSON
.
stringify
(
{
...
receipt
,
platform
:
process
.
platform
,
arch
:
process
.
arch
}
)
)
}
let
resume
=
(
)
:
void
=>
{
}
const
reclaim
=
vi
.
mocked
(
reclaimRuntimeReleases
)
const
paused
=
new
Promise
<
void
>
(
(
resolve
)
=>
(
resume
=
resolve
)
)
const
{
reclaimRuntimeReleases
:
reclaimNow
}
=
await
vi
.
importActual
<
typeof
ReleaseModule
>
(
'./managed-runtime-release'
)
reclaim
.
mockImplementationOnce
(
async
(
...
args
)
=>
paused
.
then
(
(
)
=>
reclaimNow
(
...
args
)
)
)
const
installation
=
host
(
)
installation
.
install
(
)
await
new
Promise
(
(
resolve
)
=>
setTimeout
(
resolve
,
100
)
)
expect
(
(
await
installation
.
status
(
)
)
.
operation
)
.
toMatchObject
(
{
downloadedBytes
:
0
}
)
resume
(
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
await
phase
(
installation
)
)
.
toBe
(
'succeeded'
)
)
expect
(
(
await
readdir
(
root
)
)
.
sort
(
)
)
.
toEqual
(
[
'0.9'
,
'1.0'
]
)
}
)
it
(
'repairs a damaged copy when Install is clicked again'
,
async
(
)
=>
{
const
{
root
,
host
,
phase
}
=
await
rig
(
[
'whole'
,
'whole'
]
)
const
installation
=
host
(
)
installation
.
install
(
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
await
phase
(
installation
)
)
.
toBe
(
'succeeded'
)
)
await
writeFile
(
join
(
root
,
'1.0'
,
'server'
)
,
'cut'
)
expect
(
await
installation
.
status
(
)
)
.
toMatchObject
(
{
installedVersion
:
null
,
damaged
:
true
,
canRemove
:
true
}
)
installation
.
install
(
)
await
vi
.
waitFor
(
async
(
)
=>
expect
(
await
phase
(
installation
)
)
.
toBe
(
'succeeded'
)
)
const
repaired
=
await
installation
.
status
(
)
expect
(
repaired
)
.
toMatchObject
(
{
installedVersion
:
'1.0'
,
installedCurrent
:
true
}
)
expect
(
repaired
.
damaged
)
.
toBeUndefined
(
)
expect
(
await
readdir
(
root
)
)
.
toEqual
(
[
'1.0'
]
)
}
)
You can’t perform that action at this time.