@useconvoy/cli 0.63.0 → 0.81.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/dist/bin/convoy.js +13 -1
- package/dist/bin/convoy.js.map +1 -1
- package/dist/src/agent/app/chunk-scrub.js +12 -0
- package/dist/src/agent/app/chunk-scrub.js.map +1 -1
- package/dist/src/agent/app/runner.d.ts +2 -0
- package/dist/src/agent/app/runner.js +2 -1
- package/dist/src/agent/app/runner.js.map +1 -1
- package/dist/src/agent/app/thread-processor.js +38 -10
- package/dist/src/agent/app/thread-processor.js.map +1 -1
- package/dist/src/agent/app/worktree-op-processor.js +28 -2
- package/dist/src/agent/app/worktree-op-processor.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +5 -1
- package/dist/src/agent/runtimes/claudeCode/interactions.js +36 -0
- package/dist/src/agent/runtimes/claudeCode/interactions.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/models.d.ts +1 -1
- package/dist/src/agent/runtimes/claudeCode/models.js +1 -0
- package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/runner.js +110 -51
- package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -1
- package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +2 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.js +75 -44
- package/dist/src/agent/runtimes/codex/app-server-runner.js.map +1 -1
- package/dist/src/agent/runtimes/codex/auth.d.ts +9 -0
- package/dist/src/agent/runtimes/codex/auth.js +90 -0
- package/dist/src/agent/runtimes/codex/auth.js.map +1 -0
- package/dist/src/agent/runtimes/codex/errors.d.ts +7 -0
- package/dist/src/agent/runtimes/codex/errors.js +60 -0
- package/dist/src/agent/runtimes/codex/errors.js.map +1 -0
- package/dist/src/agent/runtimes/codex/interactions.js +2 -52
- package/dist/src/agent/runtimes/codex/interactions.js.map +1 -1
- package/dist/src/agent/runtimes/codex/lifecycle.d.ts +12 -1
- package/dist/src/agent/runtimes/codex/lifecycle.js +97 -6
- package/dist/src/agent/runtimes/codex/lifecycle.js.map +1 -1
- package/dist/src/agent/runtimes/codex/runtime.js +2 -1
- package/dist/src/agent/runtimes/codex/runtime.js.map +1 -1
- package/dist/src/agent/runtimes/contracts.d.ts +4 -0
- package/dist/src/agent/runtimes/contracts.js.map +1 -1
- package/dist/src/agent/runtimes/cursor/models.js +1 -0
- package/dist/src/agent/runtimes/cursor/models.js.map +1 -1
- package/dist/src/agent/runtimes/message-format.js +3 -1
- package/dist/src/agent/runtimes/message-format.js.map +1 -1
- package/dist/src/agent/runtimes/registry.js +17 -1
- package/dist/src/agent/runtimes/registry.js.map +1 -1
- package/dist/src/agent/runtimes/validators.d.ts +4 -0
- package/dist/src/agent/runtimes/validators.js +101 -0
- package/dist/src/agent/runtimes/validators.js.map +1 -0
- package/dist/src/cli.js +10 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/browser/command.d.ts +2 -0
- package/dist/src/commands/browser/command.js +42 -0
- package/dist/src/commands/browser/command.js.map +1 -0
- package/dist/src/commands/browser/smoke.d.ts +10 -0
- package/dist/src/commands/browser/smoke.js +67 -0
- package/dist/src/commands/browser/smoke.js.map +1 -0
- package/dist/src/commands/browser/validators.d.ts +18 -0
- package/dist/src/commands/browser/validators.js +2 -0
- package/dist/src/commands/browser/validators.js.map +1 -0
- package/dist/src/commands/browser/workflow.d.ts +4 -0
- package/dist/src/commands/browser/workflow.js +86 -0
- package/dist/src/commands/browser/workflow.js.map +1 -0
- package/dist/src/commands/connect/command.js +1 -0
- package/dist/src/commands/connect/command.js.map +1 -1
- package/dist/src/commands/connect/workflow.d.ts +7 -0
- package/dist/src/commands/connect/workflow.js +68 -4
- package/dist/src/commands/connect/workflow.js.map +1 -1
- package/dist/src/commands/devcontainer/command.js +3 -1
- package/dist/src/commands/devcontainer/command.js.map +1 -1
- package/dist/src/commands/devcontainer/install.d.ts +1 -0
- package/dist/src/commands/devcontainer/install.js +17 -7
- package/dist/src/commands/devcontainer/install.js.map +1 -1
- package/dist/src/commands/environment/command.d.ts +5 -0
- package/dist/src/commands/environment/command.js +123 -0
- package/dist/src/commands/environment/command.js.map +1 -0
- package/dist/src/commands/environment/docker.d.ts +13 -0
- package/dist/src/commands/environment/docker.js +65 -0
- package/dist/src/commands/environment/docker.js.map +1 -0
- package/dist/src/commands/environment/index.d.ts +60 -0
- package/dist/src/commands/environment/index.js +36 -0
- package/dist/src/commands/environment/index.js.map +1 -0
- package/dist/src/commands/environment/paths.d.ts +6 -0
- package/dist/src/commands/environment/paths.js +58 -0
- package/dist/src/commands/environment/paths.js.map +1 -0
- package/dist/src/commands/environment/projects.d.ts +3 -0
- package/dist/src/commands/environment/projects.js +46 -0
- package/dist/src/commands/environment/projects.js.map +1 -0
- package/dist/src/commands/environment/resolution.d.ts +11 -0
- package/dist/src/commands/environment/resolution.js +4 -0
- package/dist/src/commands/environment/resolution.js.map +1 -0
- package/dist/src/commands/environment/setup-entrypoint.d.ts +1 -0
- package/dist/src/commands/environment/setup-entrypoint.js +17 -0
- package/dist/src/commands/environment/setup-entrypoint.js.map +1 -0
- package/dist/src/commands/environment/validators.d.ts +65 -0
- package/dist/src/commands/environment/validators.js +36 -0
- package/dist/src/commands/environment/validators.js.map +1 -0
- package/dist/src/commands/environment/workflow.d.ts +48 -0
- package/dist/src/commands/environment/workflow.js +172 -0
- package/dist/src/commands/environment/workflow.js.map +1 -0
- package/dist/src/commands/keys/command.js +99 -13
- package/dist/src/commands/keys/command.js.map +1 -1
- package/dist/src/commands/keys/workflow.d.ts +68 -0
- package/dist/src/commands/keys/workflow.js +147 -0
- package/dist/src/commands/keys/workflow.js.map +1 -0
- package/dist/src/commands/project/command.d.ts +2 -0
- package/dist/src/commands/project/command.js +53 -0
- package/dist/src/commands/project/command.js.map +1 -0
- package/dist/src/commands/project/launcher.d.ts +44 -0
- package/dist/src/commands/project/launcher.js +100 -0
- package/dist/src/commands/project/launcher.js.map +1 -0
- package/dist/src/commands/project/validators.d.ts +87 -0
- package/dist/src/commands/project/validators.js +53 -0
- package/dist/src/commands/project/validators.js.map +1 -0
- package/dist/src/commands/project/worker.d.ts +2 -0
- package/dist/src/commands/project/worker.js +90 -0
- package/dist/src/commands/project/worker.js.map +1 -0
- package/dist/src/commands/project/workflow.d.ts +47 -0
- package/dist/src/commands/project/workflow.js +238 -0
- package/dist/src/commands/project/workflow.js.map +1 -0
- package/dist/src/commands/service/attach.d.ts +3 -0
- package/dist/src/commands/service/attach.js +155 -0
- package/dist/src/commands/service/attach.js.map +1 -0
- package/dist/src/commands/service/bridge.d.ts +3 -0
- package/dist/src/commands/service/bridge.js +105 -0
- package/dist/src/commands/service/bridge.js.map +1 -0
- package/dist/src/commands/service/client.d.ts +26 -0
- package/dist/src/commands/service/client.js +154 -0
- package/dist/src/commands/service/client.js.map +1 -0
- package/dist/src/commands/service/command.d.ts +3 -0
- package/dist/src/commands/service/command.js +186 -0
- package/dist/src/commands/service/command.js.map +1 -0
- package/dist/src/commands/service/errors.d.ts +9 -0
- package/dist/src/commands/service/errors.js +13 -0
- package/dist/src/commands/service/errors.js.map +1 -0
- package/dist/src/commands/service/formatters.d.ts +5 -0
- package/dist/src/commands/service/formatters.js +58 -0
- package/dist/src/commands/service/formatters.js.map +1 -0
- package/dist/src/commands/service/logs.d.ts +19 -0
- package/dist/src/commands/service/logs.js +64 -0
- package/dist/src/commands/service/logs.js.map +1 -0
- package/dist/src/commands/service/output.d.ts +18 -0
- package/dist/src/commands/service/output.js +60 -0
- package/dist/src/commands/service/output.js.map +1 -0
- package/dist/src/commands/service/parsers.d.ts +4 -0
- package/dist/src/commands/service/parsers.js +41 -0
- package/dist/src/commands/service/parsers.js.map +1 -0
- package/dist/src/commands/service/paths.d.ts +7 -0
- package/dist/src/commands/service/paths.js +44 -0
- package/dist/src/commands/service/paths.js.map +1 -0
- package/dist/src/commands/service/resolution.d.ts +5 -0
- package/dist/src/commands/service/resolution.js +36 -0
- package/dist/src/commands/service/resolution.js.map +1 -0
- package/dist/src/commands/service/runs.d.ts +3 -0
- package/dist/src/commands/service/runs.js +58 -0
- package/dist/src/commands/service/runs.js.map +1 -0
- package/dist/src/commands/service/server.d.ts +7 -0
- package/dist/src/commands/service/server.js +206 -0
- package/dist/src/commands/service/server.js.map +1 -0
- package/dist/src/commands/service/service-entrypoint.d.ts +1 -0
- package/dist/src/commands/service/service-entrypoint.js +32 -0
- package/dist/src/commands/service/service-entrypoint.js.map +1 -0
- package/dist/src/commands/service/validators.d.ts +257 -0
- package/dist/src/commands/service/validators.js +48 -0
- package/dist/src/commands/service/validators.js.map +1 -0
- package/dist/src/commands/service/workflow.d.ts +12 -0
- package/dist/src/commands/service/workflow.js +355 -0
- package/dist/src/commands/service/workflow.js.map +1 -0
- package/dist/src/commands/setup/command.js +5 -0
- package/dist/src/commands/setup/command.js.map +1 -1
- package/dist/src/commands/setup/prompts.d.ts +1 -1
- package/dist/src/commands/setup/prompts.js +3 -1
- package/dist/src/commands/setup/prompts.js.map +1 -1
- package/dist/src/commands/setup/resolution.d.ts +14 -0
- package/dist/src/commands/setup/resolution.js +87 -0
- package/dist/src/commands/setup/resolution.js.map +1 -0
- package/dist/src/commands/setup/validators.d.ts +15 -0
- package/dist/src/commands/setup/validators.js +15 -0
- package/dist/src/commands/setup/validators.js.map +1 -0
- package/dist/src/commands/setup/workflow.d.ts +3 -1
- package/dist/src/commands/setup/workflow.js +56 -47
- package/dist/src/commands/setup/workflow.js.map +1 -1
- package/dist/src/commands/threads/done.d.ts +2 -0
- package/dist/src/commands/threads/done.js +20 -0
- package/dist/src/commands/threads/done.js.map +1 -0
- package/dist/src/commands/threads/index.js +3 -1
- package/dist/src/commands/threads/index.js.map +1 -1
- package/dist/src/lib/config/convex-client.d.ts +5 -0
- package/dist/src/lib/config/convex-client.js +27 -1
- package/dist/src/lib/config/convex-client.js.map +1 -1
- package/dist/src/lib/config/credentials/resolution.d.ts +11 -0
- package/dist/src/lib/config/credentials/resolution.js +101 -0
- package/dist/src/lib/config/credentials/resolution.js.map +1 -0
- package/dist/src/lib/config/credentials/store.d.ts +9 -0
- package/dist/src/lib/config/credentials/store.js +147 -0
- package/dist/src/lib/config/credentials/store.js.map +1 -0
- package/dist/src/lib/config/credentials/validators.d.ts +152 -0
- package/dist/src/lib/config/credentials/validators.js +87 -0
- package/dist/src/lib/config/credentials/validators.js.map +1 -0
- package/dist/src/lib/config/index.d.ts +1 -1
- package/dist/src/lib/config/index.js +1 -1
- package/dist/src/lib/config/index.js.map +1 -1
- package/dist/src/lib/config/toml.d.ts +4 -4
- package/dist/src/lib/config/toml.js +149 -83
- package/dist/src/lib/config/toml.js.map +1 -1
- package/dist/src/lib/config/types.d.ts +8 -0
- package/dist/src/lib/config/types.js +5 -0
- package/dist/src/lib/config/types.js.map +1 -1
- package/dist/src/lib/connect-events.d.ts +5 -0
- package/dist/src/lib/connect-events.js.map +1 -1
- package/dist/src/lib/git/checkpoint.d.ts +18 -3
- package/dist/src/lib/git/checkpoint.js +57 -24
- package/dist/src/lib/git/checkpoint.js.map +1 -1
- package/dist/src/lib/git/index.d.ts +1 -0
- package/dist/src/lib/git/index.js +1 -0
- package/dist/src/lib/git/index.js.map +1 -1
- package/dist/src/lib/git/working-tree.d.ts +12 -0
- package/dist/src/lib/git/working-tree.js +38 -0
- package/dist/src/lib/git/working-tree.js.map +1 -0
- package/dist/templates/devcontainer/Dockerfile +7 -0
- package/dist/templates/devcontainer/README.md +17 -0
- package/dist/templates/project-isolation/Dockerfile +28 -0
- package/dist/templates/project-isolation/README.md +206 -0
- package/dist/templates/project-isolation/devcontainer.json +20 -0
- package/dist/templates/project-isolation/environment.py +257 -0
- package/dist/templates/project-isolation/environment.test.py +156 -0
- package/dist/templates/project-isolation/install.py +69 -0
- package/dist/templates/project-isolation/launcher.py +401 -0
- package/dist/templates/project-isolation/launcher.test.py +265 -0
- package/dist/templates/project-isolation/seccomp-source.md +20 -0
- package/dist/templates/project-isolation/seccomp.LICENSE +202 -0
- package/dist/templates/project-isolation/seccomp.json +1173 -0
- package/dist/templates/project-isolation/start.sh +8 -0
- package/package.json +3 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/usr/bin/python3 -I
|
|
2
|
+
"""Host-only Docker lifecycle helper. Not a sudo capability for project users."""
|
|
3
|
+
import fcntl
|
|
4
|
+
import importlib.machinery
|
|
5
|
+
import importlib.util
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import re
|
|
10
|
+
import shutil
|
|
11
|
+
import signal
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
ROOT = Path('/opt/convoy')
|
|
18
|
+
STATE = Path('/var/lib/convoy-projects')
|
|
19
|
+
PACKAGE = ROOT / 'node_modules/@useconvoy/cli'
|
|
20
|
+
JOURNAL = ROOT / 'update.json'
|
|
21
|
+
RUNTIMES = ROOT / 'runtimes.json'
|
|
22
|
+
NETWORK = ROOT / 'network.json'
|
|
23
|
+
CLI = str(PACKAGE / 'dist/bin/convoy.js')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run(args, **kwargs):
|
|
27
|
+
timeout = kwargs.pop('timeout', 300)
|
|
28
|
+
process = subprocess.Popen(args, start_new_session=True, **kwargs)
|
|
29
|
+
try:
|
|
30
|
+
stdout, stderr = process.communicate(timeout=timeout)
|
|
31
|
+
except BaseException:
|
|
32
|
+
try:
|
|
33
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
34
|
+
except ProcessLookupError:
|
|
35
|
+
pass
|
|
36
|
+
process.wait()
|
|
37
|
+
raise
|
|
38
|
+
if process.returncode:
|
|
39
|
+
raise subprocess.CalledProcessError(process.returncode, args, stdout, stderr)
|
|
40
|
+
return subprocess.CompletedProcess(args, process.returncode, stdout, stderr)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def cli(*args, capture=True):
|
|
44
|
+
return run(['runuser', '-u', 'node', '--', 'env', 'HOME=/home/node',
|
|
45
|
+
'PATH=/usr/local/bin:/usr/bin:/bin', 'node', CLI, *args],
|
|
46
|
+
text=True, stdout=subprocess.PIPE if capture else None,
|
|
47
|
+
stderr=subprocess.PIPE if capture else None, timeout=60).stdout
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def version():
|
|
51
|
+
return json.loads((PACKAGE / 'package.json').read_text())['version']
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def free_lock():
|
|
55
|
+
lock = Path('/home/node/.convoy/service/owner.lock')
|
|
56
|
+
if not lock.exists():
|
|
57
|
+
return True
|
|
58
|
+
with lock.open('r') as stream:
|
|
59
|
+
try:
|
|
60
|
+
fcntl.flock(stream, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
61
|
+
return True
|
|
62
|
+
except BlockingIOError:
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def require_idle_projects():
|
|
67
|
+
for path in STATE.glob('*.lease'):
|
|
68
|
+
with path.open('r') as lease:
|
|
69
|
+
try:
|
|
70
|
+
fcntl.flock(lease, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
71
|
+
except BlockingIOError:
|
|
72
|
+
raise RuntimeError('A project shell or direct connection is active. Close it before changing the environment.') from None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def stop():
|
|
76
|
+
if free_lock():
|
|
77
|
+
require_idle_projects()
|
|
78
|
+
return
|
|
79
|
+
cli('service', 'stop')
|
|
80
|
+
deadline = time.monotonic() + 45
|
|
81
|
+
while not free_lock():
|
|
82
|
+
if time.monotonic() >= deadline:
|
|
83
|
+
raise RuntimeError('Service did not release its execution lock. Container retained.')
|
|
84
|
+
time.sleep(.1)
|
|
85
|
+
require_idle_projects()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def install():
|
|
89
|
+
run(['python3', '-I', str(PACKAGE / 'dist/templates/project-isolation/install.py'),
|
|
90
|
+
'--control-user', 'node', '--workspace', '/workspace', '--package-root', str(PACKAGE)])
|
|
91
|
+
config_path = Path('/etc/convoy-projects.json')
|
|
92
|
+
config = json.loads(config_path.read_text())
|
|
93
|
+
config['verified_runtimes'] = json.loads(RUNTIMES.read_text()) if RUNTIMES.exists() else []
|
|
94
|
+
config_path.write_text(json.dumps(config))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def start_service():
|
|
98
|
+
if free_lock():
|
|
99
|
+
cli('service', 'start', '-b')
|
|
100
|
+
status = json.loads(cli('service', 'status', '--json'))
|
|
101
|
+
if 'host-cli-v1' not in status.get('capabilities', []):
|
|
102
|
+
raise RuntimeError('Service lacks compatible host management support. Restore a compatible CLI version.')
|
|
103
|
+
if status.get('stopping') or status.get('configurationError'):
|
|
104
|
+
raise RuntimeError('Service health check failed; inspect registration configuration.')
|
|
105
|
+
return status
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def recover():
|
|
109
|
+
if not JOURNAL.exists():
|
|
110
|
+
return
|
|
111
|
+
stop()
|
|
112
|
+
backup = ROOT / 'previous-node_modules'
|
|
113
|
+
if backup.exists():
|
|
114
|
+
shutil.rmtree(ROOT / 'node_modules', ignore_errors=True)
|
|
115
|
+
backup.rename(ROOT / 'node_modules')
|
|
116
|
+
install()
|
|
117
|
+
start_service()
|
|
118
|
+
JOURNAL.unlink()
|
|
119
|
+
print('Recovered the previous CLI installation.', file=sys.stderr)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def firewall(domain=None):
|
|
123
|
+
stored = json.loads(NETWORK.read_text()) if NETWORK.exists() else []
|
|
124
|
+
if domain:
|
|
125
|
+
if not re.fullmatch(r'[a-zA-Z0-9.-]{1,253}', domain):
|
|
126
|
+
raise ValueError('Invalid backend hostname')
|
|
127
|
+
additions = [domain]
|
|
128
|
+
if domain.endswith('.convex.cloud'):
|
|
129
|
+
additions.append(domain.removesuffix('.convex.cloud') + '.convex.site')
|
|
130
|
+
stored = sorted(set(stored + additions))
|
|
131
|
+
NETWORK.write_text(json.dumps(stored))
|
|
132
|
+
extra = ','.join(filter(None, [os.environ.get('DEVCONTAINER_EXTRA_ALLOWED_DOMAINS', ''), *stored]))
|
|
133
|
+
run(['/usr/local/bin/init-firewall.sh'], env={**os.environ, 'DEVCONTAINER_EXTRA_ALLOWED_DOMAINS': extra})
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def start():
|
|
137
|
+
marker = Path('/run/convoy-initialized')
|
|
138
|
+
if not marker.exists():
|
|
139
|
+
firewall()
|
|
140
|
+
for path in ['/workspace', '/home/node/.config/convoy', '/home/node/.convoy']:
|
|
141
|
+
os.chown(path, 1000, 1000)
|
|
142
|
+
os.chmod('/home/node/.config/convoy', 0o700)
|
|
143
|
+
os.chmod('/home/node/.convoy', 0o700)
|
|
144
|
+
marker.touch()
|
|
145
|
+
recover()
|
|
146
|
+
install()
|
|
147
|
+
start_service()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def update(target):
|
|
151
|
+
if not re.fullmatch(r'\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?', target):
|
|
152
|
+
raise ValueError('An exact package version is required')
|
|
153
|
+
recover()
|
|
154
|
+
staging = ROOT / 'staging'
|
|
155
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
156
|
+
# Stage without interrupting workers; a download failure leaves them running.
|
|
157
|
+
run(['npm', 'install', '--prefix', str(staging), '@useconvoy/cli@' + target], timeout=1200)
|
|
158
|
+
candidate = staging / 'node_modules/@useconvoy/cli'
|
|
159
|
+
if json.loads((candidate / 'package.json').read_text())['version'] != target:
|
|
160
|
+
raise RuntimeError('Staged package version does not match the requested version')
|
|
161
|
+
if not (candidate / 'dist/templates/project-isolation/install.py').is_file():
|
|
162
|
+
raise RuntimeError('Staged package does not support project isolation')
|
|
163
|
+
stop()
|
|
164
|
+
backup = ROOT / 'previous-node_modules'
|
|
165
|
+
shutil.rmtree(backup, ignore_errors=True)
|
|
166
|
+
JOURNAL.write_text(json.dumps({'previous': version(), 'requested': target}))
|
|
167
|
+
try:
|
|
168
|
+
(ROOT / 'node_modules').rename(backup)
|
|
169
|
+
(staging / 'node_modules').rename(ROOT / 'node_modules')
|
|
170
|
+
install()
|
|
171
|
+
run([str(ROOT / 'node_modules/.bin/playwright'), 'install', 'chromium'],
|
|
172
|
+
env={**os.environ, 'PLAYWRIGHT_BROWSERS_PATH': '/usr/local/share/convoy-browsers', 'PLAYWRIGHT_SKIP_BROWSER_GC': '1'}, timeout=1200)
|
|
173
|
+
start_service()
|
|
174
|
+
JOURNAL.unlink()
|
|
175
|
+
print('Updated service to ' + target, file=sys.stderr)
|
|
176
|
+
except BaseException:
|
|
177
|
+
recover()
|
|
178
|
+
raise
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def verify(runtime):
|
|
182
|
+
if runtime not in ['codex', 'claude-code']:
|
|
183
|
+
raise ValueError('Only preinstalled codex and claude-code may be enabled')
|
|
184
|
+
loader = importlib.machinery.SourceFileLoader('launcher', '/usr/local/libexec/convoy-project-launcher')
|
|
185
|
+
module = importlib.util.module_from_spec(importlib.util.spec_from_loader(loader.name, loader))
|
|
186
|
+
loader.exec_module(module)
|
|
187
|
+
config = json.loads(Path('/etc/convoy-projects.json').read_text())
|
|
188
|
+
# Temporary UIDs are never registered or reused for real projects.
|
|
189
|
+
uid = 65000
|
|
190
|
+
workspace = Path(tempfile.mkdtemp(prefix='convoy-probe-', dir='/workspace'))
|
|
191
|
+
home = Path(tempfile.mkdtemp(prefix='convoy-probe-', dir=config['state']))
|
|
192
|
+
entry = {'uid': uid, 'identity': home.name, 'path': str(workspace)}
|
|
193
|
+
trees = Path(str(workspace) + '-worktrees')
|
|
194
|
+
trees.mkdir()
|
|
195
|
+
other = Path(tempfile.mkdtemp(prefix='convoy-other-', dir='/workspace'))
|
|
196
|
+
try:
|
|
197
|
+
for path in [workspace, home, trees]:
|
|
198
|
+
os.chown(path, uid, uid)
|
|
199
|
+
path.chmod(0o700)
|
|
200
|
+
module.write_identity_files(config, entry)
|
|
201
|
+
script = '''import os, pathlib
|
|
202
|
+
assert os.getuid() == 65000
|
|
203
|
+
assert not os.getgroups()
|
|
204
|
+
s = pathlib.Path('/proc/self/status').read_text()
|
|
205
|
+
assert 'NoNewPrivs:\\t1' in s
|
|
206
|
+
assert int(s.split('CapEff:\\t')[1].splitlines()[0], 16) == 0
|
|
207
|
+
assert not pathlib.Path('/home/node').exists()
|
|
208
|
+
assert not pathlib.Path('/var/run/docker.sock').exists()
|
|
209
|
+
assert not pathlib.Path(os.environ['OTHER_PROJECT']).exists()
|
|
210
|
+
pathlib.Path('probe.txt').write_text('private')
|
|
211
|
+
'''
|
|
212
|
+
command = module.sandbox_args(config, entry) + ['--setenv', 'OTHER_PROJECT', str(other), 'python3', '-c', script]
|
|
213
|
+
run(command, preexec_fn=lambda: module.drop_privileges(uid), env=module.SAFE_ENV)
|
|
214
|
+
enabled = json.loads(RUNTIMES.read_text()) if RUNTIMES.exists() else []
|
|
215
|
+
RUNTIMES.write_text(json.dumps(sorted(set(enabled + [runtime]))))
|
|
216
|
+
install()
|
|
217
|
+
print('Boundary probes passed. Enabled candidate runtime ' + runtime + '. Complete real A/B agent acceptance.', file=sys.stderr)
|
|
218
|
+
finally:
|
|
219
|
+
for path in [workspace, home, trees, other]:
|
|
220
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
221
|
+
for suffix in ['passwd', 'group']:
|
|
222
|
+
(Path(config['state']) / (home.name + '.' + suffix)).unlink(missing_ok=True)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def main():
|
|
226
|
+
if os.geteuid() != 0:
|
|
227
|
+
raise RuntimeError('This helper is only invoked by the host Docker controller')
|
|
228
|
+
with open('/run/convoy-environment.lock', 'w') as lock:
|
|
229
|
+
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
230
|
+
operation = sys.argv[1]
|
|
231
|
+
if operation == 'start':
|
|
232
|
+
start()
|
|
233
|
+
elif operation == 'stop':
|
|
234
|
+
stop()
|
|
235
|
+
elif operation == 'restart':
|
|
236
|
+
stop()
|
|
237
|
+
start_service()
|
|
238
|
+
elif operation == 'update':
|
|
239
|
+
update(sys.argv[2])
|
|
240
|
+
elif operation == 'allow-domain':
|
|
241
|
+
firewall(sys.argv[2])
|
|
242
|
+
elif operation == 'verify':
|
|
243
|
+
verify(sys.argv[2])
|
|
244
|
+
elif operation == 'status':
|
|
245
|
+
print(json.dumps({'serviceVersion': version() if (PACKAGE / 'package.json').exists() else None, 'serviceRunning': not free_lock(),
|
|
246
|
+
'recoveryPending': JOURNAL.exists(),
|
|
247
|
+
'runtimes': json.loads(RUNTIMES.read_text()) if RUNTIMES.exists() else []}))
|
|
248
|
+
else:
|
|
249
|
+
raise ValueError('Unknown environment operation')
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
if __name__ == '__main__':
|
|
253
|
+
try:
|
|
254
|
+
main()
|
|
255
|
+
except Exception as error:
|
|
256
|
+
print('Environment operation failed: ' + str(error), file=sys.stderr)
|
|
257
|
+
sys.exit(1)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import importlib.util
|
|
2
|
+
import json
|
|
3
|
+
import fcntl
|
|
4
|
+
import os
|
|
5
|
+
import signal
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import tempfile
|
|
10
|
+
import unittest
|
|
11
|
+
from unittest.mock import patch, mock_open
|
|
12
|
+
|
|
13
|
+
spec = importlib.util.spec_from_file_location('environment', Path(__file__).with_name('environment.py'))
|
|
14
|
+
environment = importlib.util.module_from_spec(spec)
|
|
15
|
+
spec.loader.exec_module(environment)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class UpdateTests(unittest.TestCase):
|
|
19
|
+
def setUp(self):
|
|
20
|
+
self.temporary = tempfile.TemporaryDirectory()
|
|
21
|
+
self.root = Path(self.temporary.name)
|
|
22
|
+
self.package = self.root / 'node_modules/@useconvoy/cli'
|
|
23
|
+
self.package.mkdir(parents=True)
|
|
24
|
+
(self.package / 'package.json').write_text(json.dumps({'version': '0.75.0'}))
|
|
25
|
+
self.patches = [patch.object(environment, 'ROOT', self.root),
|
|
26
|
+
patch.object(environment, 'PACKAGE', self.package),
|
|
27
|
+
patch.object(environment, 'JOURNAL', self.root / 'update.json'),
|
|
28
|
+
patch.object(environment, 'install'), patch.object(environment, 'stop'),
|
|
29
|
+
patch.object(environment, 'start_service')]
|
|
30
|
+
self.mocks = [p.start() for p in self.patches]
|
|
31
|
+
|
|
32
|
+
def tearDown(self):
|
|
33
|
+
for p in reversed(self.patches):
|
|
34
|
+
p.stop()
|
|
35
|
+
self.temporary.cleanup()
|
|
36
|
+
|
|
37
|
+
def stage(self, args, **kwargs):
|
|
38
|
+
if args[0] == 'npm':
|
|
39
|
+
package = self.root / 'staging/node_modules/@useconvoy/cli'
|
|
40
|
+
(package / 'dist/templates/project-isolation').mkdir(parents=True)
|
|
41
|
+
(package / 'package.json').write_text(json.dumps({'version': '0.76.0'}))
|
|
42
|
+
(package / 'dist/templates/project-isolation/install.py').touch()
|
|
43
|
+
|
|
44
|
+
def test_download_failure_does_not_stop_service(self):
|
|
45
|
+
with patch.object(environment, 'run', side_effect=RuntimeError('download failed')):
|
|
46
|
+
with self.assertRaisesRegex(RuntimeError, 'download failed'):
|
|
47
|
+
environment.update('0.76.0')
|
|
48
|
+
self.mocks[4].assert_not_called()
|
|
49
|
+
self.assertEqual(environment.version(), '0.75.0')
|
|
50
|
+
|
|
51
|
+
def test_failed_health_check_restores_previous_package(self):
|
|
52
|
+
self.mocks[5].side_effect = [RuntimeError('health failed'), {}]
|
|
53
|
+
with patch.object(environment, 'run', side_effect=self.stage):
|
|
54
|
+
with self.assertRaisesRegex(RuntimeError, 'health failed'):
|
|
55
|
+
environment.update('0.76.0')
|
|
56
|
+
self.assertEqual(environment.version(), '0.75.0')
|
|
57
|
+
self.assertFalse(environment.JOURNAL.exists())
|
|
58
|
+
|
|
59
|
+
def test_update_does_not_require_apt_through_the_runtime_firewall(self):
|
|
60
|
+
with patch.object(environment, 'run', side_effect=self.stage) as execute:
|
|
61
|
+
environment.update('0.76.0')
|
|
62
|
+
downloads = [call.args[0] for call in execute.call_args_list if 'playwright' in call.args[0][0]]
|
|
63
|
+
self.assertEqual(len(downloads), 1)
|
|
64
|
+
self.assertNotIn('--with-deps', downloads[0])
|
|
65
|
+
|
|
66
|
+
def test_update_retains_old_browser_revision_for_rollback(self):
|
|
67
|
+
with patch.object(environment, 'run', side_effect=self.stage) as execute:
|
|
68
|
+
environment.update('0.76.0')
|
|
69
|
+
download = next(call for call in execute.call_args_list if 'playwright' in call.args[0][0])
|
|
70
|
+
self.assertEqual(download.kwargs['env'].get('PLAYWRIGHT_SKIP_BROWSER_GC'), '1')
|
|
71
|
+
|
|
72
|
+
def test_success_keeps_new_package_and_previous_recovery_copy(self):
|
|
73
|
+
with patch.object(environment, 'run', side_effect=self.stage):
|
|
74
|
+
environment.update('0.76.0')
|
|
75
|
+
self.assertEqual(environment.version(), '0.76.0')
|
|
76
|
+
self.assertTrue((self.root / 'previous-node_modules').exists())
|
|
77
|
+
self.assertFalse(environment.JOURNAL.exists())
|
|
78
|
+
|
|
79
|
+
def test_recover_interrupted_swap_without_current_package(self):
|
|
80
|
+
(self.root / 'node_modules').rename(self.root / 'previous-node_modules')
|
|
81
|
+
environment.JOURNAL.write_text('{}')
|
|
82
|
+
environment.recover()
|
|
83
|
+
self.assertEqual(environment.version(), '0.75.0')
|
|
84
|
+
self.assertFalse(environment.JOURNAL.exists())
|
|
85
|
+
|
|
86
|
+
def test_recovery_preserves_journal_if_old_service_cannot_start(self):
|
|
87
|
+
(self.root / 'node_modules').rename(self.root / 'previous-node_modules')
|
|
88
|
+
environment.JOURNAL.write_text('{}')
|
|
89
|
+
self.mocks[5].side_effect = RuntimeError('cannot restart')
|
|
90
|
+
with self.assertRaisesRegex(RuntimeError, 'cannot restart'):
|
|
91
|
+
environment.recover()
|
|
92
|
+
self.assertEqual(environment.version(), '0.75.0')
|
|
93
|
+
self.assertTrue(environment.JOURNAL.exists())
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ProcessTests(unittest.TestCase):
|
|
97
|
+
def test_timed_out_installation_kills_its_descendant_before_recovery(self):
|
|
98
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
99
|
+
pidfile = Path(directory) / 'child.pid'
|
|
100
|
+
code = "import subprocess,sys,time,pathlib; child=subprocess.Popen([sys.executable,'-c','import time; time.sleep(30)']); pathlib.Path(sys.argv[1]).write_text(str(child.pid)); time.sleep(30)"
|
|
101
|
+
child = None
|
|
102
|
+
try:
|
|
103
|
+
with self.assertRaises(subprocess.TimeoutExpired):
|
|
104
|
+
environment.run([sys.executable, '-c', code, str(pidfile)], timeout=.5)
|
|
105
|
+
child = int(pidfile.read_text())
|
|
106
|
+
state = Path('/proc') / str(child) / 'stat'
|
|
107
|
+
self.assertTrue(not state.exists() or state.read_text().split()[2] in ['Z', 'X'], 'installation child is still running after timeout')
|
|
108
|
+
finally:
|
|
109
|
+
if child:
|
|
110
|
+
try:
|
|
111
|
+
os.kill(child, signal.SIGKILL)
|
|
112
|
+
except ProcessLookupError:
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class StatusTests(unittest.TestCase):
|
|
117
|
+
def test_status_reports_recovery_when_interrupted_update_has_no_current_package(self):
|
|
118
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
119
|
+
journal = Path(directory) / 'update.json'
|
|
120
|
+
journal.write_text('{}')
|
|
121
|
+
with patch.object(environment, 'PACKAGE', Path(directory) / 'missing'), patch.object(environment, 'JOURNAL', journal), patch.object(environment, 'RUNTIMES', Path(directory) / 'runtimes'), patch.object(environment, 'free_lock', return_value=True), patch.object(environment.os, 'geteuid', return_value=0), patch.object(environment.sys, 'argv', ['helper', 'status']), patch('builtins.open', mock_open()), patch.object(environment.fcntl, 'flock'), patch('builtins.print') as output:
|
|
122
|
+
environment.main()
|
|
123
|
+
self.assertEqual(json.loads(output.call_args.args[0]), {'serviceVersion': None, 'serviceRunning': False, 'recoveryPending': True, 'runtimes': []})
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class HealthTests(unittest.TestCase):
|
|
127
|
+
def test_rejects_a_staged_service_without_host_management(self):
|
|
128
|
+
with patch.object(environment, 'free_lock', return_value=False), patch.object(environment, 'cli', return_value=json.dumps({'profiles': [], 'capabilities': ['attach-v1']})):
|
|
129
|
+
with self.assertRaisesRegex(RuntimeError, 'host management'):
|
|
130
|
+
environment.start_service()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class StopTests(unittest.TestCase):
|
|
134
|
+
def test_stop_refuses_to_change_container_while_a_private_shell_owns_a_lease(self):
|
|
135
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
136
|
+
with (Path(directory) / 'project.lease').open('w') as lease:
|
|
137
|
+
fcntl.flock(lease, fcntl.LOCK_EX)
|
|
138
|
+
with patch.object(environment, 'STATE', Path(directory), create=True), patch.object(environment, 'free_lock', return_value=True):
|
|
139
|
+
with self.assertRaisesRegex(RuntimeError, 'shell|direct connection'):
|
|
140
|
+
environment.stop()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class FirewallTests(unittest.TestCase):
|
|
144
|
+
def test_project_registration_allows_cloud_and_mcp_site(self):
|
|
145
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
146
|
+
path = Path(directory) / 'network.json'
|
|
147
|
+
with patch.object(environment, 'NETWORK', path), patch.object(environment, 'run') as execute:
|
|
148
|
+
environment.firewall('example.convex.cloud')
|
|
149
|
+
hosts = execute.call_args.kwargs['env']['DEVCONTAINER_EXTRA_ALLOWED_DOMAINS'].split(',')
|
|
150
|
+
self.assertIn('example.convex.cloud', hosts)
|
|
151
|
+
self.assertIn('example.convex.site', hosts)
|
|
152
|
+
self.assertIn('example.convex.site', json.loads(path.read_text()))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if __name__ == '__main__':
|
|
156
|
+
unittest.main()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/python3 -I
|
|
2
|
+
"""Administrator installation; never invoked by a project worker."""
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import pwd
|
|
8
|
+
import re
|
|
9
|
+
import shutil
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
parser = argparse.ArgumentParser()
|
|
15
|
+
parser.add_argument("--control-user", required=True)
|
|
16
|
+
parser.add_argument("--workspace", required=True)
|
|
17
|
+
parser.add_argument("--package-root", required=True)
|
|
18
|
+
parser.add_argument("--node", default="/usr/local/bin/node")
|
|
19
|
+
parser.add_argument("--state", default="/var/lib/convoy-projects")
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
if os.geteuid() != 0:
|
|
22
|
+
parser.error("Administrator installation requires root")
|
|
23
|
+
if not re.fullmatch(r"[a-z_][a-z0-9_-]*", args.control_user):
|
|
24
|
+
parser.error("Invalid control account")
|
|
25
|
+
account = pwd.getpwnam(args.control_user)
|
|
26
|
+
if account.pw_uid == 0:
|
|
27
|
+
parser.error("The control account must be unprivileged")
|
|
28
|
+
package = Path(args.package_root).resolve(strict=True)
|
|
29
|
+
cli = package / "dist/src/commands/project/worker.js"
|
|
30
|
+
if not cli.is_file():
|
|
31
|
+
parser.error("Install/build the Convoy CLI package first")
|
|
32
|
+
for root in [package, Path(args.node).resolve(strict=True)]:
|
|
33
|
+
for item in [root, *root.parents]:
|
|
34
|
+
info = item.stat()
|
|
35
|
+
if info.st_uid != 0 or info.st_mode & 0o022:
|
|
36
|
+
parser.error("CLI, Node and their parent directories must be root-owned without group/world writes")
|
|
37
|
+
workspace = Path(args.workspace).resolve(strict=True)
|
|
38
|
+
state = Path(args.state)
|
|
39
|
+
state.mkdir(mode=0o711, parents=True, exist_ok=True)
|
|
40
|
+
if state.is_symlink() or state.stat().st_uid != 0 or state.stat().st_mode & 0o022:
|
|
41
|
+
parser.error("State must be a root-owned directory without group/world writes")
|
|
42
|
+
launcher = Path("/usr/local/libexec/convoy-project-launcher")
|
|
43
|
+
launcher.parent.mkdir(mode=0o755, exist_ok=True)
|
|
44
|
+
shutil.copyfile(Path(__file__).with_name("launcher.py"), launcher)
|
|
45
|
+
launcher.chmod(0o755)
|
|
46
|
+
config_file = Path("/etc/convoy-projects.json")
|
|
47
|
+
config = {"control_uid": account.pw_uid, "workspace": str(workspace), "state": str(state.resolve()),
|
|
48
|
+
"package_root": str(package), "cli": str(cli), "node": str(Path(args.node).resolve()),
|
|
49
|
+
"installation_root": str(package.parents[2]) if package.parent.name == "@useconvoy" and package.parent.parent.name == "node_modules" else str(package),
|
|
50
|
+
"verified_runtimes": []}
|
|
51
|
+
if config_file.exists():
|
|
52
|
+
old = json.loads(config_file.read_text())
|
|
53
|
+
if any(old.get(key) != value for key, value in config.items() if key != "verified_runtimes"):
|
|
54
|
+
parser.error("An environment is already configured differently; perform an explicit administrator migration")
|
|
55
|
+
config["verified_runtimes"] = old.get("verified_runtimes", [])
|
|
56
|
+
config_file.write_text(json.dumps(config, indent=2) + "\n")
|
|
57
|
+
config_file.chmod(0o600)
|
|
58
|
+
sudoers = Path("/etc/sudoers.d/convoy-projects")
|
|
59
|
+
sudoers.write_text(f"{args.control_user} ALL=(root) NOPASSWD: {launcher}\n")
|
|
60
|
+
sudoers.chmod(0o440)
|
|
61
|
+
print("Project launcher installed. Complete the acceptance procedure before enabling runtime execution.")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
try:
|
|
66
|
+
main()
|
|
67
|
+
except (OSError, KeyError, ValueError):
|
|
68
|
+
print("Installation failed. Check the administrator paths and account.", file=sys.stderr)
|
|
69
|
+
sys.exit(1)
|