mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
opencode 2 keeps its background service's settings in ~/.config/opencode/service.json, or service-<channel>.json on another channel (opencode v2.4.1's service-config.ts): the service's password, which the service makes when the file has none, and with remote access on, the secret route its address is served on and remoteAccepted. devvm agent import, and devvm agent save, copied every file of opencode's folder into the store, so every VM with opencode got a copy at each launch, with devvm-redacted in place of the password and the route as it was: each such VM's service took the known password devvm-redacted. The agents' registry gets FolderOwn, the names of a WholeFolder agent's entries that are each machine's own; MachineOwn covers them, so agentFiles, agentDirs, agentLinks and listedPath leave them out: the import never copies them, no VM gets them from a store that holds them, and the save's script never sends the VM's own (which would have made the save fail). cleanStore (cleanSeeds, which now also runs cleanFolderOwn through the shared cleanOwn) takes them out of the store at a start, warning once (agent_store_own_cleaned, agent_store_own_clean_failed). The setup gets machine-own (agents.MachineOwnFiles) and DEVVM_REDACTED (agentlogin.RedactMark, exported, and now the one source of the placeholder in agentlogin's copies), and sync.sh's clean_machine_own takes out each regular file of those names that holds the placeholder, failing the setup with the cause when it can't, so the VM's opencode makes its own password; opencode service get password shows it. Tests that failed first: TestSeeds' MachineOwn cases, TestOpencodeServiceNotImported, TestOpencodeServiceNotStaged, TestOpencodeServiceNotSaved, TestCleanStoreOpencodeService and TestSyncCleansMachineOwn. e2e's network section plants the store's service.json and checks the start takes it out, no VM gets its password or route, two VMs' passwords differ, and a launch takes out devvm's old copy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
92 lines
3.7 KiB
Go
92 lines
3.7 KiB
Go
//go:build e2e
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// This machine's opencode service password and remote route, planted in
|
|
// the agent store's service.json as an earlier devvm agent import left it,
|
|
// which no VM may get.
|
|
const (
|
|
opencodeHostPassword = "e2e-host-opencode-service-password" //nolint:gosec // a test's fake password, planted to be found missing
|
|
opencodeHostRoute = "e2ehostroute0001"
|
|
)
|
|
|
|
// plantOpencodeService writes opencode's service.json into the sandbox's
|
|
// agent store, as opencode 2.4.1 writes it on this machine with remote
|
|
// access on, and returns its path, and the error of writing it.
|
|
func plantOpencodeService(s *S) (string, error) {
|
|
p := filepath.Join(filepath.Dir(s.Paths.Layers), "agents", "opencode", ".config", "opencode", "service.json")
|
|
data := `{"password": "` + opencodeHostPassword + `", "remote": {"route": "` + opencodeHostRoute + `"}, "remoteAccepted": true}`
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o700); err != nil {
|
|
return p, err
|
|
}
|
|
return p, os.WriteFile(p, []byte(data), 0o600)
|
|
}
|
|
|
|
// netOpencodeService: the start of vm, an opencode VM in the folder oc,
|
|
// takes the store's opencode service settings (stored) out, saying so in
|
|
// its launch's output (lr); no VM gets this machine's password or route;
|
|
// each VM's opencode makes a service password of its own; and a launch's
|
|
// setup takes out the copy with devvm-redacted that an earlier devvm gave
|
|
// the VM. planted is the error of planting stored.
|
|
func netOpencodeService(n *netRun, oc, vm, stored string, planted error, lr Res) {
|
|
s := n.s
|
|
s.Check("an opencode VM's start takes this machine's opencode service settings out of the agent store, and says so", func() error {
|
|
if planted != nil {
|
|
return failed("planting "+stored, planted)
|
|
}
|
|
if _, err := os.Lstat(stored); !errors.Is(err, os.ErrNotExist) {
|
|
return failed("the store still has "+stored, err)
|
|
}
|
|
if !strings.Contains(lr.Out, "agent_store_own_cleaned") {
|
|
return errors.New("no warning names it:\n" + lr.Out)
|
|
}
|
|
return nil
|
|
})
|
|
s.Check("no VM gets this machine's opencode service password or remote route", func() error {
|
|
for _, v := range []string{vm, n.vm} {
|
|
has, err := vmHas(s, v, false, "cat ~/.config/opencode/service*.json 2>/dev/null; true", opencodeHostPassword, opencodeHostRoute)
|
|
if v == "" || err != nil || has {
|
|
return failed("VM "+v+"'s opencode service settings hold this machine's", err)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
own := "opencode service get password"
|
|
s.Check("each VM's opencode service has a password of its own", func() error {
|
|
a, b := vmOut(s, vm, own), vmOut(s, n.vm, own)
|
|
for _, p := range []string{a, b} {
|
|
if p == "" || strings.ContainsAny(p, " \n") || p == "devvm-redacted" || p == opencodeHostPassword {
|
|
return fmt.Errorf("a VM's password is %q", p)
|
|
}
|
|
}
|
|
if a == b {
|
|
return errors.New("two VMs have the same opencode service password")
|
|
}
|
|
return nil
|
|
})
|
|
s.Check("a launch takes out the copy with devvm-redacted that an earlier devvm gave the VM, so its opencode makes its own", func() error {
|
|
old := `{"password": "devvm-redacted", "remote": {"route": "` + opencodeHostRoute + `"}}`
|
|
if vm == "" || inVM(s, vm, "printf '%s' '"+old+"' > ~/.config/opencode/service.json") != nil {
|
|
return errors.New("planting devvm's old copy in the VM failed")
|
|
}
|
|
if _, _, err := launchWith(s, oc, n.home()); err != nil {
|
|
return err
|
|
}
|
|
if has, err := vmHas(s, vm, false, "cat ~/.config/opencode/service.json 2>/dev/null; true", "devvm-redacted", opencodeHostRoute); err != nil || has {
|
|
return failed("the old copy is still in the VM", err)
|
|
}
|
|
if p := vmOut(s, vm, own); p == "" || p == "devvm-redacted" {
|
|
return fmt.Errorf("the VM's password is %q", p)
|
|
}
|
|
return nil
|
|
})
|
|
}
|