@useconvoy/cli 0.63.0 → 0.89.0
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.d.ts +1 -1
- package/dist/src/agent/app/thread-processor.js +46 -14
- package/dist/src/agent/app/thread-processor.js.map +1 -1
- package/dist/src/agent/app/worktree-op-processor.js +50 -5
- package/dist/src/agent/app/worktree-op-processor.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +6 -2
- 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 +2 -0
- package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/runner.js +132 -57
- package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/runtime.js +7 -0
- package/dist/src/agent/runtimes/claudeCode/runtime.js.map +1 -1
- package/dist/src/agent/runtimes/claudeCode/usage/errors.d.ts +3 -0
- package/dist/src/agent/runtimes/claudeCode/usage/errors.js +4 -0
- package/dist/src/agent/runtimes/claudeCode/usage/errors.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.d.ts +4 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.js +44 -0
- package/dist/src/agent/runtimes/claudeCode/usage/index.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.d.ts +7 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.js +84 -0
- package/dist/src/agent/runtimes/claudeCode/usage/parsers.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.d.ts +25 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.js +2 -0
- package/dist/src/agent/runtimes/claudeCode/usage/validators.js.map +1 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +4 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.js +115 -57
- 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/commands.d.ts +1 -1
- package/dist/src/agent/runtimes/codex/commands.js +1 -1
- package/dist/src/agent/runtimes/codex/commands.js.map +1 -1
- 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/runner.js +6 -0
- package/dist/src/agent/runtimes/codex/runner.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/codex/usage/index.d.ts +7 -0
- package/dist/src/agent/runtimes/codex/usage/index.js +63 -0
- package/dist/src/agent/runtimes/codex/usage/index.js.map +1 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.d.ts +6 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.js +58 -0
- package/dist/src/agent/runtimes/codex/usage/parsers.js.map +1 -0
- package/dist/src/agent/runtimes/codex/usage/validators.d.ts +16 -0
- package/dist/src/agent/runtimes/codex/usage/validators.js +2 -0
- package/dist/src/agent/runtimes/codex/usage/validators.js.map +1 -0
- package/dist/src/agent/runtimes/contracts.d.ts +10 -0
- package/dist/src/agent/runtimes/contracts.js +2 -0
- package/dist/src/agent/runtimes/contracts.js.map +1 -1
- package/dist/src/agent/runtimes/cursor/models.js +2 -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/tasks/attachments/transfer.js +5 -20
- package/dist/src/commands/tasks/attachments/transfer.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/convex/_generated/api.d.ts +2 -0
- 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 +19 -3
- package/dist/src/lib/git/checkpoint.js +58 -25
- package/dist/src/lib/git/checkpoint.js.map +1 -1
- package/dist/src/lib/git/exec.js +6 -0
- package/dist/src/lib/git/exec.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 +21 -0
- package/dist/src/lib/git/working-tree.js +90 -0
- package/dist/src/lib/git/working-tree.js.map +1 -0
- package/dist/src/lib/git/worktrees.d.ts +1 -1
- package/dist/src/lib/git/worktrees.js +4 -2
- package/dist/src/lib/git/worktrees.js.map +1 -1
- package/dist/src/lib/storage-upload.d.ts +10 -0
- package/dist/src/lib/storage-upload.js +21 -0
- package/dist/src/lib/storage-upload.js.map +1 -0
- package/dist/src/lib/thread-attachments.js +6 -27
- package/dist/src/lib/thread-attachments.js.map +1 -1
- 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 +5 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Convoy project environment
|
|
2
|
+
|
|
3
|
+
This template is for the OS-1958 implementation. Runtime and Docker/VM acceptance
|
|
4
|
+
are still pending. Execution starts disabled through `verified_runtimes: []`.
|
|
5
|
+
Do not use it for sensitive projects until the acceptance procedure passes.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Run `convoy devcontainer ~/Convoy --projects` on the host, then open `~/Convoy`
|
|
10
|
+
with Dev Containers. That folder is the parent mount, so adding another project
|
|
11
|
+
does not require rebuilding. The default `convoy devcontainer` template remains
|
|
12
|
+
the single-repository template.
|
|
13
|
+
|
|
14
|
+
The image needs the selected CLI version to be published. For testing unpublished
|
|
15
|
+
code, install a locally packed build under `/opt/convoy` as root and use the Linux
|
|
16
|
+
setup below. Do not point the privileged launcher at a mutable development checkout.
|
|
17
|
+
|
|
18
|
+
The state volume holds stable UID reservations and each project's private HOME.
|
|
19
|
+
The control volume holds local registrations. Preserve both volumes and the
|
|
20
|
+
workspace when recreating the container. Never reuse project UIDs for other OS
|
|
21
|
+
accounts or delete the identity registry while retaining project files.
|
|
22
|
+
|
|
23
|
+
The template requires Linux ownership enforcement and unprivileged user
|
|
24
|
+
namespaces. Docker Desktop mounts or a Docker seccomp policy can prevent these.
|
|
25
|
+
Registration fails in that case. Use Linux storage and an environment that
|
|
26
|
+
supports bubblewrap; do not work around it with a privileged container or by
|
|
27
|
+
disabling isolation. This template does not install a custom Docker seccomp policy.
|
|
28
|
+
|
|
29
|
+
## Linux VM setup
|
|
30
|
+
|
|
31
|
+
For the complete VM walkthrough, including Ubuntu AppArmor and Codex login,
|
|
32
|
+
see [Isolated projects on Linux](https://docs.convoy.build/docs/cli/isolated-projects).
|
|
33
|
+
|
|
34
|
+
Use a dedicated machine or account with Node 22, Python 3, bubblewrap, sudo, Git, util-linux
|
|
35
|
+
and the selected runtime CLIs. Install the Convoy package under a root-owned
|
|
36
|
+
prefix, for example `/opt/convoy`. Install runtime executables under `/usr/local`
|
|
37
|
+
with root ownership. Create a parent workspace owned by the control account,
|
|
38
|
+
without group/world write access.
|
|
39
|
+
|
|
40
|
+
Run the bundled installer as administrator:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
sudo python3 -I /opt/convoy/node_modules/@useconvoy/cli/dist/templates/project-isolation/install.py \
|
|
44
|
+
--control-user convoy --workspace /srv/convoy-workspaces \
|
|
45
|
+
--package-root /opt/convoy/node_modules/@useconvoy/cli --node /usr/local/bin/node
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The control user gets permission to invoke a restricted launcher. Agents cannot
|
|
49
|
+
invoke it. The launcher switches identity before starting bubblewrap, Git,
|
|
50
|
+
shells or the network-facing Convoy worker. It supplies no host environment,
|
|
51
|
+
runtime configuration, SSH agent, Docker socket or control credentials.
|
|
52
|
+
|
|
53
|
+
## Register and run
|
|
54
|
+
|
|
55
|
+
Create a Convoy API key restricted to exactly one project in the web app. Run
|
|
56
|
+
`convoy project add a` to enter the deployment, key and accessible project.
|
|
57
|
+
The command returns without starting a connection. Complete non-interactive use:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
convoy project add a --url https://example.convex.cloud \
|
|
61
|
+
--api-key "$PROJECT_A_KEY" --project "$PROJECT_A_ID" --profile-key a --non-interactive
|
|
62
|
+
convoy project list
|
|
63
|
+
convoy project shell a
|
|
64
|
+
# In the private shell: authenticate the runtime, then exit.
|
|
65
|
+
convoy connect --profile a
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Use another terminal for B. Ctrl+C stops the direct connection and its workers.
|
|
69
|
+
`convoy project remove b --yes` unregisters stopped B and keeps all files and
|
|
70
|
+
private state. Stop any connection or project shell before removal.
|
|
71
|
+
|
|
72
|
+
The last profile's removal disables that identity in the launcher. Removing
|
|
73
|
+
one of several aliases retains execution for the remaining profiles. Re-adding
|
|
74
|
+
the project re-enables its existing UID. Pending preparations appear in
|
|
75
|
+
`project list` with their path and allocated UID; an administrator can inspect
|
|
76
|
+
them before an explicit ownership migration. Retry the original registration
|
|
77
|
+
after repair. The audit and original clone source apply even if flags are
|
|
78
|
+
omitted on retry.
|
|
79
|
+
|
|
80
|
+
`convoy connect --profile a --name vm-a` preserves the connection name.
|
|
81
|
+
If a stale backend session conflicts, stop its owner or explicitly retry with
|
|
82
|
+
`--force`. Workers never prompt or take over automatically. Ctrl+C closes the
|
|
83
|
+
worker control pipe to release claims and disconnect, with a 30-second limit
|
|
84
|
+
before forced sandbox termination.
|
|
85
|
+
|
|
86
|
+
`--clone https://github.com/owner/repo.git` clones into a new folder without
|
|
87
|
+
inheriting host Git credentials. For private repositories, register an empty
|
|
88
|
+
folder, enter its project shell, authenticate Git there and clone into `.`.
|
|
89
|
+
`--reuse` accepts only a directory already owned by the allocated project UID/GID
|
|
90
|
+
with mode 0700 and project-owned files without hard links. It never changes
|
|
91
|
+
existing checkout ownership. Prefer a new clone; ownership migration is an
|
|
92
|
+
explicit administrator operation and should preserve a backup.
|
|
93
|
+
|
|
94
|
+
Profile keys remain local selectors. The existing `--project` connection flag
|
|
95
|
+
keeps its project-ID override meaning; use `--profile` for these registrations.
|
|
96
|
+
The plural `convoy projects list` still lists remote projects.
|
|
97
|
+
|
|
98
|
+
## Network and credentials
|
|
99
|
+
|
|
100
|
+
Strict mode is the container default. Set `CONVEX_DEPLOYMENT` for the backend,
|
|
101
|
+
or append self-hosted backend and clone domains to
|
|
102
|
+
`DEVCONTAINER_EXTRA_ALLOWED_DOMAINS`. After changing allowlists, run
|
|
103
|
+
`sudo /usr/local/bin/init-firewall.sh` with the updated variables in the
|
|
104
|
+
container. Include authentication endpoints needed by your selected runtime.
|
|
105
|
+
The direct VM workflow uses the VM's existing network policy.
|
|
106
|
+
|
|
107
|
+
Projects share the environment's network namespace. Do not expose unauthenticated
|
|
108
|
+
local services or VM instance-role credentials to that network. File isolation
|
|
109
|
+
does not protect a token served over TCP. Projects have separate authentication
|
|
110
|
+
files, but signing them into the same provider account does not create separately
|
|
111
|
+
scoped provider credentials.
|
|
112
|
+
|
|
113
|
+
## Acceptance procedure
|
|
114
|
+
|
|
115
|
+
Use a disposable environment with two test projects and non-sensitive credentials.
|
|
116
|
+
The administrator may enable candidate runtime names in
|
|
117
|
+
`/etc/convoy-projects.json` while testing. Supported names are `claude-code`,
|
|
118
|
+
`codex`, `cursor` and `opencode`. An empty list rejects all agent runtime launches.
|
|
119
|
+
Only retain names whose complete checks pass; both Codex transports need testing.
|
|
120
|
+
|
|
121
|
+
1. Register A and B and enter their shells. Record `id`, `/proc/self/status`,
|
|
122
|
+
workspace ownership and HOME. Check distinct UIDs, empty supplementary groups,
|
|
123
|
+
zero capabilities and `NoNewPrivs: 1`.
|
|
124
|
+
2. In A, write a marker, use symlinks toward B and the control HOME, and verify
|
|
125
|
+
reads/writes fail. Verify B's processes and control sockets are absent. Test
|
|
126
|
+
hard-linked input is rejected during reuse and a second A shell/connection
|
|
127
|
+
cannot acquire the lease.
|
|
128
|
+
3. Enable one candidate runtime in the disposable setup. Run real agents in A/B,
|
|
129
|
+
including shell commands, file edits, helpers, worktrees and a resumed thread.
|
|
130
|
+
Verify legitimate work succeeds and cross-project access still fails.
|
|
131
|
+
4. Cancel a run, close the terminal, kill the control process and kill the launcher
|
|
132
|
+
in separate runs. From the host, verify no project descendants remain.
|
|
133
|
+
5. Add C without rebuilding. Stop/remove B, verify its files remain and re-add it
|
|
134
|
+
with the same UID. Recreate the container preserving volumes and repeat.
|
|
135
|
+
6. Repeat on a configured Linux VM and record runtime/tool versions, mount type,
|
|
136
|
+
kernel, namespace restrictions and any exposed local network endpoints.
|
|
137
|
+
|
|
138
|
+
Current evidence is limited to automated policy and command tests. No runtime,
|
|
139
|
+
bind-mount or direct VM combination is certified by this change yet.
|
|
140
|
+
|
|
141
|
+
Malformed TOML stops config operations. Repair the file before retrying. CLI
|
|
142
|
+
mutations use `config.toml.lock`; after a crashed writer, verify no writer remains
|
|
143
|
+
before removing that lock directory. Project execution leases use kernel locks
|
|
144
|
+
and release when their owner exits.
|
|
145
|
+
|
|
146
|
+
## Browser automation
|
|
147
|
+
|
|
148
|
+
The image installs Playwright Chromium and OS dependencies before firewall startup.
|
|
149
|
+
CLI 0.66.0 adds `convoy browser smoke` and `convoy browser run script.mjs`.
|
|
150
|
+
Run them inside the project shell or agent, using `--session <name>` to retain
|
|
151
|
+
private login state. No browser debugging port or host browser profile is shared.
|
|
152
|
+
Chromium sandboxing defaults on; `--no-browser-sandbox` is an explicit choice
|
|
153
|
+
when the outer container/project boundary works but nested browser sandboxing
|
|
154
|
+
is unavailable. It does not change the firewall or outer isolation.
|
|
155
|
+
|
|
156
|
+
Existing containers need a rebuild or administrator library installation.
|
|
157
|
+
For the existing A/B VM, upgrade the root-owned CLI, install
|
|
158
|
+
Chromium with the bundled Playwright installer as administrator, and reinstall
|
|
159
|
+
the bundled project launcher with the same configuration. Registrations and
|
|
160
|
+
credentials remain in place. Full setup, agent examples and acceptance checks:
|
|
161
|
+
[Browser automation](https://docs.convoy.build/docs/cli/browser-automation).
|
|
162
|
+
|
|
163
|
+
## Keep registered projects running
|
|
164
|
+
|
|
165
|
+
After authenticating the runtimes and closing project shells, run these as the
|
|
166
|
+
control account inside the environment:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
convoy service start --background
|
|
170
|
+
convoy service status
|
|
171
|
+
convoy service logs --follow
|
|
172
|
+
convoy service stop
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Closing a log viewer or the starting terminal leaves background work running.
|
|
176
|
+
Explicit stop drains all workers and retains data. CLI 0.68.0 applies new
|
|
177
|
+
registrations without restarting siblings. Remove a live project with
|
|
178
|
+
`convoy project remove c --yes --interrupt`. For runtime login, pause C with
|
|
179
|
+
`convoy service pause c --interrupt`, enter/exit its project shell, then reconnect
|
|
180
|
+
using `convoy service reload --profile c --interrupt`. See the [persistent service guide](https://docs.convoy.build/docs/cli/project-service)
|
|
181
|
+
for A/B verification, retained logs and failure recovery.
|
|
182
|
+
|
|
183
|
+
## Managed Codex API keys
|
|
184
|
+
|
|
185
|
+
CLI 0.71.1 adds control-account key storage and project assignments. This image
|
|
186
|
+
includes the credential-capable launcher and Codex 0.156.1. Existing VM installs
|
|
187
|
+
must refresh the privileged launcher after installing the new CLI. Preserve
|
|
188
|
+
control/project-state volumes when rebuilding. See the
|
|
189
|
+
[provider-key guide](https://docs.convoy.build/docs/cli/provider-keys) for commands
|
|
190
|
+
and the VM/devcontainer acceptance sequence. Manual project shells keep native auth.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
### Create a project from the CLI
|
|
194
|
+
|
|
195
|
+
See the [project creation and recovery guide](https://docs.convoy.build/docs/cli/isolated-projects)
|
|
196
|
+
for creating or attaching projects, manual setup keys, and service commands.
|
|
197
|
+
|
|
198
|
+
## Managed host workflow
|
|
199
|
+
|
|
200
|
+
CLI 0.75.0 adds `convoy run --environment dev` and explicit `--environment` routing
|
|
201
|
+
for project, service, attachment and browser smoke commands. It builds this
|
|
202
|
+
bundled template through Docker with labeled Linux volumes, a custom seccomp
|
|
203
|
+
policy for nested bubblewrap, and a host-only root lifecycle helper. See
|
|
204
|
+
[Managed local environments](https://docs.convoy.build/docs/cli/managed-environments)
|
|
205
|
+
for setup, runtime verification, updates, recovery and acceptance commands.
|
|
206
|
+
The manual Dev Containers workflow above remains available.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Convoy projects",
|
|
3
|
+
"build": { "dockerfile": "Dockerfile", "args": { "CONVOY_VERSION": "0.89.0" } },
|
|
4
|
+
"remoteUser": "node",
|
|
5
|
+
"updateRemoteUserUID": false,
|
|
6
|
+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
|
|
7
|
+
"workspaceFolder": "/workspace",
|
|
8
|
+
"mounts": [
|
|
9
|
+
"source=convoy-project-state-${devcontainerId},target=/var/lib/convoy-projects,type=volume",
|
|
10
|
+
"source=convoy-control-${devcontainerId},target=/home/node/.config/convoy,type=volume"
|
|
11
|
+
],
|
|
12
|
+
"runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW"],
|
|
13
|
+
"containerEnv": {
|
|
14
|
+
"DEVCONTAINER_NETWORK_MODE": "${localEnv:DEVCONTAINER_NETWORK_MODE:strict}",
|
|
15
|
+
"CONVEX_DEPLOYMENT": "${localEnv:CONVEX_DEPLOYMENT}",
|
|
16
|
+
"DEVCONTAINER_EXTRA_ALLOWED_DOMAINS": "${localEnv:DEVCONTAINER_EXTRA_ALLOWED_DOMAINS}"
|
|
17
|
+
},
|
|
18
|
+
"postStartCommand": "sudo /usr/local/libexec/convoy-project-start",
|
|
19
|
+
"waitFor": "postStartCommand"
|
|
20
|
+
}
|
|
@@ -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()
|