mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
A VM's state is vms/<hash>/vm.json: core fields (version, id, name, alias, image, chain, from, dir, folder, backend, backend_at, created) and one section per package, each a json.RawMessage its owner decodes into its own type (state.Section, state.SetSection), what was asked for at its top level and what devvm made under "made": net (netpolicy), git (gitprotect), ports (the new internal/ports), agent (sshagent), tools (tools), secrets (secrets), and size, clone, devcontainer, desktop and links (vm, internal/vm/state.go). - state.VM.Update takes vms/<hash>/lock (platform.LockFile), reads the file again, applies a change and writes it once; a failed change, or write, writes nothing. VM.Set and its calls are gone; read-modify-write of lists (links, publish, secrets, tools, size, ports) happens inside Update. VM.Claim also holds run/claims.lock, after the VM's own; VM.Create writes a new VM's whole record once, its alias chosen (sshconfig.ChooseAlias) under the claims lock. Reads take no lock. - created replaces "net unset" as unfinished (VM.Finished). - internal/ports: the ports section (forward, host.ssh/proxy/desktop), ports.Used (was netpolicy.UsedPorts), and one Allocator for ssh, proxy and desktop ports under the claims lock (desktop allocated without one before; run/ports.lock and netpolicy's own ports key are gone). - gitprotect: mode recorded before the backend makes the VM (NewMode; clone for --clone, which ls and git-protect share as gitprotect.Mode); made.git_id (platform.FolderID), one git_dirs list for modules and embedded git dirs, delegations, protected; Unlock takes the union of recorded and current git dirs. - links' entries, git dirs, tools and devcontainer commands are JSON lists, not strings in values; the key=value parser is gone. - vm.checkState reads every section of the folder's VM as it's found. - registry.For drops its unused Dirs. - Tests: TestVMRoundTrip, TestVMOtherName, TestVMID, TestVMUpdate, TestVMUpdateTogether (two writers on one VM and on crossed VMs), TestVMClaim, TestVMFailures, TestVMCorrupt, TestChooseAliasTogether, TestUsed, TestSSH, TestChooseTogether, TestUnlockRecorded, TestCheckState, TestChangesTogether, TestChangesAtOnce; testscript's vm_state, json_set with dotted and := keys; e2e's vm_state/vm_set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
103 lines
3.8 KiB
Plaintext
103 lines
3.8 KiB
Plaintext
# devvm host and devvm code: the folder's VM launched as devvm does without
|
|
# its shell (checked, started, self-checked, set up, in devvm's ssh
|
|
# config), then its host name shown, or its folder opened in VS Code (a
|
|
# stub code) with the SSH agent devvm started with. The Include line is
|
|
# offered for the sandbox's own ~/.ssh/config only.
|
|
|
|
# No VM.
|
|
project web
|
|
! exec devvm host
|
|
stderr '^devvm: no_vm dir=\S*/web$'
|
|
! exec devvm code
|
|
stderr '^devvm: no_vm dir=\S*/web$'
|
|
! exec devvm host now
|
|
stderr '^devvm: args_none command=devvm host given=now$'
|
|
! exec devvm code .
|
|
stderr '^devvm: args_none command=devvm code given=\.$'
|
|
|
|
# A stopped VM: started and set up, no shell. Without a terminal, the
|
|
# Include line is shown, not added.
|
|
exec devvm --no-network-policy --no-git-protect
|
|
vm_name WEB web
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm host
|
|
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
|
|
stdout '^ssh_include_needed line=Include /\S*/data/devvm/ssh_config$'
|
|
stderr '^devvm: ssh_include_yourself$'
|
|
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
|
|
stub_calls
|
|
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
|
|
stdout 'tar -xf'
|
|
! stdout 'limactl shell --workdir /\S*/web devvm-web'
|
|
catg $DATA/ssh_config
|
|
stdout '^Host devvm-web devvm-web-[0-9a-f]{14}$'
|
|
! exists $HOME/.ssh
|
|
|
|
# With the line there: nothing asked. A size its state asks for waits for
|
|
# the running VM's next start, as on a launch.
|
|
exec sh -c 'mkdir -p "$HOME/.ssh" && echo "Include $DATA/ssh_config" > "$HOME/.ssh/config"'
|
|
# ssh by the folder's name reads devvm's ssh config in its data folder
|
|
# through that line: the real ssh resolves the name, connecting to nothing.
|
|
[exec:/usr/bin/ssh] exec /usr/bin/ssh -F $HOME/.ssh/config -G devvm-web
|
|
[exec:/usr/bin/ssh] stdout '^hostname 127\.0\.0\.1$'
|
|
[exec:/usr/bin/ssh] stdout '^userknownhostsfile \S*/data/devvm/known_hosts$'
|
|
[exec:/usr/bin/ssh] stdout '^hostkeyalias devvm-web-[0-9a-f]{14}$'
|
|
json_set $WEB_dir/vm.json size.cpus=6
|
|
stub_reset
|
|
exec devvm host
|
|
! stdout 'starting|ssh_include'
|
|
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
|
|
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
|
|
stub_calls
|
|
! stdout 'limactl (start|edit)'
|
|
|
|
# devvm code: the folder in VS Code over Remote-SSH, with the SSH agent
|
|
# devvm started with, though this VM's own connections carry none.
|
|
env SSH_AUTH_SOCK=$WORK/user-agent.sock
|
|
stub_reset
|
|
exec devvm code
|
|
stub_calls
|
|
stdout '^code --remote ssh-remote\+devvm-web /\S*/web$'
|
|
exec sh -c 'cat "$STUB_DIR/code-agent"'
|
|
stdout '^\S*/user-agent\.sock$'
|
|
env SSH_AUTH_SOCK=
|
|
|
|
# Two folders named web: the VM by its full name.
|
|
mkdir $WORK/other/web
|
|
cd $WORK/other/web
|
|
exec devvm --no-network-policy --no-git-protect
|
|
stub_reset
|
|
exec devvm code
|
|
stub_calls
|
|
stdout '^code --remote ssh-remote\+devvm-web-[0-9a-f]{14} /\S*/other/web$'
|
|
|
|
# No code command on PATH: said, with the host to connect to.
|
|
exec sh -c 'mkdir "$WORK/nocode" && for f in "$(dirname "$DEVVM_HOST_MISE")"/*; do [ "${f##*/}" = code ] || ln -s "$f" "$WORK/nocode/"; done'
|
|
env SAVED_PATH=$PATH
|
|
env PATH=$DEVVM_BIN:$WORK/nocode:/usr/bin:/bin:/usr/sbin:/sbin
|
|
stub_reset
|
|
! exec devvm code
|
|
stderr '^devvm: no_code_command host=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout '^code '
|
|
env PATH=$SAVED_PATH
|
|
|
|
# Network policy: a VM devvm started confined that still reaches the
|
|
# internet directly is stopped, as on a launch; no host name. (Its
|
|
# hostagent here: the test's runner, which runs on, in place of the
|
|
# stub's.)
|
|
project leak
|
|
exec devvm --network-policy --no-git-protect
|
|
vm_name LEAK leak
|
|
exec sh -c 'echo $PPID > "$LIMA_HOME/$LEAK/ha.pid"; echo "$PPID 1" > "$LEAK_dir/run/started"'
|
|
stub_reset
|
|
exec sh -c ': > "$STUB_DIR/net-direct"'
|
|
! exec devvm host
|
|
stderr '^devvm: net_direct_route vm=devvm-leak-[0-9a-f]{14}$'
|
|
! stdout ssh_host_info
|
|
stub_calls
|
|
stdout '^limactl stop devvm-leak-[0-9a-f]{14}$'
|
|
! stdout 'tar -xf'
|
|
rm $STUB_DIR/net-direct
|