Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
agenttx/scripts/release-verify.mjs at main · aliengineering-byte/agenttx · 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 }}
aliengineering-byte
agenttx
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
agenttx
/
scripts
/
release-verify.mjs
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
165 lines (154 loc) · 6.46 KB
main
Breadcrumbs
agenttx
/
scripts
/
release-verify.mjs
Copy path
Top
File metadata and controls
Code
Blame
165 lines (154 loc) · 6.46 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
import
{
createHash
}
from
"node:crypto"
;
import
{
spawn
}
from
"node:child_process"
;
import
{
access
,
mkdir
,
mkdtemp
,
readFile
,
rm
,
writeFile
}
from
"node:fs/promises"
;
import
{
tmpdir
}
from
"node:os"
;
import
{
join
,
resolve
}
from
"node:path"
;
import
{
fileURLToPath
}
from
"node:url"
;
function
execute
(
command
,
args
,
options
=
{
}
)
{
return
new
Promise
(
(
resolvePromise
,
reject
)
=>
{
const
child
=
spawn
(
command
,
args
,
{
cwd
:
options
.
cwd
,
env
:
options
.
env
??
process
.
env
,
shell
:
process
.
platform
===
"win32"
&&
/
\.
(?:
c
m
d
|
b
a
t
)
$
/
i
.
test
(
command
)
,
stdio
:
options
.
capture
?
[
"ignore"
,
"pipe"
,
"pipe"
]
:
"inherit"
,
windowsHide
:
true
}
)
;
let
stdout
=
""
;
let
stderr
=
""
;
child
.
stdout
?.
on
(
"data"
,
(
chunk
)
=>
{
stdout
+=
chunk
;
}
)
;
child
.
stderr
?.
on
(
"data"
,
(
chunk
)
=>
{
stderr
+=
chunk
;
}
)
;
child
.
once
(
"error"
,
reject
)
;
child
.
once
(
"close"
,
(
code
)
=>
{
const
result
=
{
code
:
code
??
1
,
stdout
,
stderr
}
;
if
(
result
.
code
!==
(
options
.
expectCode
??
0
)
)
{
reject
(
new
Error
(
`
${
command
}
${
args
.
join
(
" "
)
}
exited
${
result
.
code
}
\n
${
stderr
||
stdout
}
`
)
)
;
}
else
{
resolvePromise
(
result
)
;
}
}
)
;
}
)
;
}
async
function
commandExists
(
command
)
{
try
{
await
execute
(
command
,
[
"--version"
]
,
{
capture
:
true
}
)
;
return
true
;
}
catch
{
return
false
;
}
}
async
function
git
(
cwd
,
args
)
{
return
execute
(
"git"
,
[
"-C"
,
cwd
,
...
args
]
,
{
capture
:
true
}
)
;
}
async
function
initializeRepository
(
root
)
{
await
mkdir
(
root
,
{
recursive
:
true
}
)
;
await
writeFile
(
join
(
root
,
"file.txt"
)
,
"before\n"
)
;
await
writeFile
(
join
(
root
,
"other.txt"
)
,
"other baseline\n"
)
;
await
writeFile
(
join
(
root
,
"agent.mjs"
)
,
"import { writeFileSync } from 'node:fs';\nwriteFileSync('file.txt', `${process.argv[2]}\\n`);\n"
)
;
await
git
(
root
,
[
"init"
,
"-q"
]
)
;
await
git
(
root
,
[
"add"
,
"-A"
]
)
;
await
git
(
root
,
[
"-c"
,
"user.name=AgentTX Release Verification"
,
"-c"
,
"user.email=release@agenttx.local"
,
"commit"
,
"-q"
,
"-m"
,
"baseline"
]
)
;
}
const
project
=
resolve
(
fileURLToPath
(
new
URL
(
".."
,
import
.
meta
.
url
)
)
)
;
const
manifest
=
JSON
.
parse
(
await
readFile
(
join
(
project
,
"package.json"
)
,
"utf8"
)
)
;
if
(
manifest
.
name
!==
"agenttx"
||
typeof
manifest
.
version
!==
"string"
)
{
throw
new
Error
(
"Unexpected package identity in package.json"
)
;
}
const
expectedVersion
=
manifest
.
version
;
const
temporary
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
"agenttx-release-verify-"
)
)
;
const
packDirectory
=
join
(
temporary
,
"pack"
)
;
const
prefix
=
join
(
temporary
,
"prefix"
)
;
const
repository
=
join
(
temporary
,
"repository"
)
;
const
transactionHome
=
join
(
temporary
,
"agenttx-home"
)
;
await
mkdir
(
packDirectory
)
;
await
mkdir
(
prefix
)
;
try
{
const
hasNpm
=
await
commandExists
(
process
.
platform
===
"win32"
?
"npm.cmd"
:
"npm"
)
;
const
packageManager
=
hasNpm
?
(
process
.
platform
===
"win32"
?
"npm.cmd"
:
"npm"
)
:
(
process
.
platform
===
"win32"
?
"pnpm.cmd"
:
"pnpm"
)
;
if
(
hasNpm
)
{
await
execute
(
packageManager
,
[
"pack"
,
"--pack-destination"
,
packDirectory
]
,
{
cwd
:
project
}
)
;
}
else
{
await
execute
(
packageManager
,
[
"pack"
,
"--pack-destination"
,
packDirectory
]
,
{
cwd
:
project
}
)
;
}
const
tarball
=
join
(
packDirectory
,
`
${
manifest
.
name
}
-
${
expectedVersion
}
.tgz`
)
;
await
access
(
tarball
)
;
if
(
hasNpm
)
{
await
execute
(
packageManager
,
[
"install"
,
tarball
,
"--prefix"
,
prefix
]
)
;
}
else
{
await
execute
(
packageManager
,
[
"--dir"
,
prefix
,
"add"
,
tarball
]
)
;
}
const
cli
=
join
(
prefix
,
"node_modules"
,
"agenttx"
,
"dist"
,
"src"
,
"cli.js"
)
;
const
shebang
=
(
await
readFile
(
cli
,
"utf8"
)
)
.
split
(
"\n"
)
[
0
]
;
if
(
shebang
!==
"#!/usr/bin/env node"
)
throw
new
Error
(
`Unexpected CLI shebang:
${
shebang
}
`
)
;
const
version
=
(
await
execute
(
process
.
execPath
,
[
cli
,
"--version"
]
,
{
capture
:
true
}
)
)
.
stdout
.
trim
(
)
;
if
(
version
!==
expectedVersion
)
throw
new
Error
(
`Unexpected installed version:
${
version
}
`
)
;
await
initializeRepository
(
repository
)
;
const
env
=
{
...
process
.
env
,
AGENTTX_HOME
:
transactionHome
}
;
const
runCli
=
(
args
,
options
=
{
}
)
=>
execute
(
process
.
execPath
,
[
cli
,
...
args
]
,
{
cwd
:
repository
,
env
,
capture
:
true
,
...
options
}
)
;
await
runCli
(
[
"doctor"
]
)
;
// Scenario A: reject the transaction and prove the original stays clean.
await
runCli
(
[
"run"
,
process
.
execPath
,
"agent.mjs"
,
"rollback-value"
]
)
;
await
runCli
(
[
"diff"
,
"--stat"
]
)
;
JSON
.
parse
(
(
await
runCli
(
[
"inspect"
,
"--json"
]
)
)
.
stdout
)
;
await
runCli
(
[
"rollback"
]
)
;
if
(
(
await
readFile
(
join
(
repository
,
"file.txt"
)
,
"utf8"
)
)
!==
"before\n"
)
{
throw
new
Error
(
"Scenario A failed: rollback changed the original file."
)
;
}
if
(
(
await
git
(
repository
,
[
"status"
,
"--porcelain"
]
)
)
.
stdout
.
trim
(
)
)
{
throw
new
Error
(
"Scenario A failed: rollback left the original repository dirty."
)
;
}
// Scenario B: accept the agent file while preserving unrelated user work.
await
writeFile
(
join
(
repository
,
"other.txt"
)
,
"user work\n"
)
;
await
runCli
(
[
"run"
,
process
.
execPath
,
"agent.mjs"
,
"accepted"
]
)
;
await
runCli
(
[
"diff"
,
"--stat"
]
)
;
JSON
.
parse
(
(
await
runCli
(
[
"inspect"
,
"--json"
]
)
)
.
stdout
)
;
await
runCli
(
[
"commit"
]
)
;
if
(
(
await
readFile
(
join
(
repository
,
"file.txt"
)
,
"utf8"
)
)
!==
"accepted\n"
)
{
throw
new
Error
(
"Scenario B failed: accepted file did not arrive."
)
;
}
if
(
(
await
readFile
(
join
(
repository
,
"other.txt"
)
,
"utf8"
)
)
!==
"user work\n"
)
{
throw
new
Error
(
"Scenario B failed: unrelated user work was changed."
)
;
}
// Scenario C: change the same original path and require a safe refusal.
await
runCli
(
[
"run"
,
process
.
execPath
,
"agent.mjs"
,
"agent-conflict"
]
)
;
await
writeFile
(
join
(
repository
,
"file.txt"
)
,
"user-conflict\n"
)
;
const
conflict
=
await
runCli
(
[
"commit"
]
,
{
expectCode
:
1
}
)
;
if
(
!
conflict
.
stderr
.
includes
(
"Your existing work was not overwritten"
)
)
{
throw
new
Error
(
"Scenario C failed: conflict error was not actionable."
)
;
}
if
(
(
await
readFile
(
join
(
repository
,
"file.txt"
)
,
"utf8"
)
)
!==
"user-conflict\n"
)
{
throw
new
Error
(
"Scenario C failed: concurrent user content was overwritten."
)
;
}
await
runCli
(
[
"rollback"
]
)
;
const
packageHash
=
createHash
(
"sha256"
)
.
update
(
await
readFile
(
tarball
)
)
.
digest
(
"hex"
)
;
process
.
stdout
.
write
(
`
${
JSON
.
stringify
(
{
schemaVersion
:
1
,
packageManager
:
hasNpm
?
"npm"
:
"pnpm fallback"
,
version
,
shebang
,
sha256
:
packageHash
,
scenarios
:
{
rollback
:
"passed"
,
commitPreservesUnrelatedWork
:
"passed"
,
concurrentConflictRefused
:
"passed"
}
}
,
null
,
2
)
}
\n`
)
;
}
finally
{
await
rm
(
temporary
,
{
recursive
:
true
,
force
:
true
}
)
;
}
You can’t perform that action at this time.