mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
opencode gets the rule pi got: an entry of its auth.json that devvm
neither binds nor passes reaches the VM's copy with only the fields
that name its account, with the login_withheld warning, which says to
list the provider under opencode in config.toml's [pass-keys]. A listed
provider's api entry goes whole, metadata included (login_passed), and
opencode 2's import brings every API key the copy holds into its
database. A bound API key's entry is {type, key: placeholder} alone, its
metadata kept on the host. pi's allowlist becomes withheldEntry and
withheldKeep, which both agents share; login_oauth_withheld goes.
A user with a local server's key in opencode sees it withheld after
upgrading, and the launch warning names the provider.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
54 lines
1.9 KiB
Go
54 lines
1.9 KiB
Go
package settings
|
|
|
|
import (
|
|
"errors"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/devvmhq/devvm/internal/state"
|
|
)
|
|
|
|
// config.toml's [pass-keys]: opencode's and pi's lists of providers, each
|
|
// agent's own, none without it, and none for an agent it has no key for; a
|
|
// name that isn't a provider's ID, a repeat or an agent devvm has no key
|
|
// for (Codex) is refused, naming its line.
|
|
func TestPassKeys(t *testing.T) {
|
|
d := testDirs(t)
|
|
for _, c := range []struct {
|
|
config string
|
|
pi, opencode []string
|
|
}{
|
|
{"", nil, nil},
|
|
{"[pass-keys]\n", nil, nil},
|
|
{"[pass-keys]\npi = []\n", []string{}, nil},
|
|
{"[pass-keys]\npi = [\"ollama\", \"lm-studio\"]\n", []string{"ollama", "lm-studio"}, nil},
|
|
{"[pass-keys]\nopencode = [\"ollama\"]\n", nil, []string{"ollama"}},
|
|
{"[pass-keys]\nopencode = [\"llama.cpp\"]\npi = [\"ollama\"]\n", []string{"ollama"}, []string{"llama.cpp"}},
|
|
} {
|
|
write(t, d.ConfigFile(), c.config)
|
|
for agent, want := range map[string][]string{"pi": c.pi, "opencode": c.opencode} {
|
|
if got, err := PassKeys(d, agent); err != nil || !slices.Equal(got, want) || (got == nil) != (want == nil) {
|
|
t.Errorf("%q for %s: %q, %v; want %q", c.config, agent, got, err, want)
|
|
}
|
|
}
|
|
if got, err := PassKeys(d, "codex"); err != nil || got != nil {
|
|
t.Errorf("%q for codex: %q, %v", c.config, got, err)
|
|
}
|
|
}
|
|
for config, line := range map[string]int{
|
|
"[pass-keys]\npi = [\"Ollama\"]\n": 2,
|
|
"[pass-keys]\npi = [\"a\", \"a\"]\n": 2,
|
|
"[pass-keys]\npi = \"ollama\"\n": 2,
|
|
"[pass-keys]\nopencode = [\"Not One\"]\n": 2,
|
|
"# x\n[pass-keys]\ncodex = [\"ollama\"]\n": 3,
|
|
"[pass-keys]\npi = []\nnone = [\"ollama\"]\n": 3,
|
|
"[pass-keys]\nopencode = []\nclaude = [\"x\"]\n": 3,
|
|
} {
|
|
write(t, d.ConfigFile(), config)
|
|
_, err := PassKeys(d, "pi")
|
|
if c, ok := errors.AsType[*state.CorruptError](err); !ok || c.Line != line {
|
|
t.Errorf("%q: %v, want line %d", config, err, line)
|
|
}
|
|
}
|
|
}
|