* agent: AtomCode is wired like its own CodingPlan sign-in — one provider account, one model table per catalog model
AtomCode (atomgit.com/atomgit_atomcode/atomcode, AtomGit's open Rust terminal agent) keeps its settings in ~/.atomcode/config.toml ($ATOMCODE_HOME). Its account schema, what its own CodingPlan sign-in writes, is one [provider_accounts."magpie"] table at the gateway's /v1 (protocol openai, gateway.TokenFor("atomcode") as the key, so a request is its agent's even when the UA is overridden) and one [models."magpie/<provider>/<model>"] table per catalog model: the model string goes to the gateway as it is to resolve, with the model's context window (AtomCode compacts as it nears it; a 128000 one is told when the model's isn't known, and an output above the told window is cut to it), its output limit, vision and reasoning_effort_levels; reasoning_effort rides on the table once the user picks one. Picking a model points default_provider and default_model at it — default_model wins when both are set, as atomcode reads it — and stashes the defaults the user had; stepping out puts them back. The picker offers the user's own model tables and the catalog via magpie; the Library gives AtomCode its ATOMCODE.md, its mcp.json (omp's shape) and skills/; its UA is atomcode/<version>.
Found against a real atomcode 5.2.1: the documented legacy [providers.*] tables work, but its own sign-in writes the account schema, so magpie writes that; reasoning_effort, max_tokens and supports_vision were verified to reach the request from the model table, and default_model to win over default_provider. Verified end to end on a real install: atomcode --provider "magpie/…" answered through the gateway, and the Agents page shows the tile, its picker and the Usage attribution. TestAtomcodeWiring, TestAtomcodeRestoresOwnDefaults and TestAtomcodeSync fail on the old code; TestDriftUnwiredEveryAgent and TestUnsetAgentsReadEmpty cover it from All(). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./internal/agent ./internal/library ./internal/agentenv pass; the plugin-host and timing failures of the full ./... run fail on main without this change too.
* tweak
* agent: AtomCode's config is matched by its own spellings, and Sync keeps the effort — AtomCode rewrites its config through serde on every /model and /cd, and that writes the account header bare ([provider_accounts.magpie]) where magpie wrote it quoted, so after the first rewrite Check read the wiring as gone, Sync and every pick appended a second account table (edited TOML is invalid: table magpie already exists) and clearing left the unquoted table and its api_key behind. The account is now matched by exact name in its three spellings (quoted, bare, literal — magpie-2 stays out) and the model tables by their decoded keys (kimiModelKey, replacing atomcodeModelName), through a new SetTOMLTablesMatching that takes exact names beside prefixes; SetTOMLTables delegates with none, unchanged. Sync carries each magpie model table's reasoning_effort over when rewriting — it ran at every gateway start and catalog change and dropped both an effort picked in magpie and one picked with AtomCode's /effort, and picking another model cleared every table's. The effort Set validates against the levels AtomCode knows (low, medium, high, xhigh, max — its clamp_effort_to_levels drops none, minimal and ultra), a model without levels offers none now, and the low/medium/high fallback is gone with it. supports_vision is written explicitly false, where AtomCode otherwise guesses from the model name. The user's legacy [providers.*] entries join the picker, a stashed default_model naming one comes back on Disconnect, and picking one sets default_provider and takes default_model out, as the legacy shape reads. site docs (en, zh, ja) list AtomCode. TestAtomcodeSync rewrites the config into the bare and single-quoted spellings before Sync and again before clearing and fails on the old code (drift reported, effort dropped, unquoted table left behind); TestAtomcodeLegacyProvidersArePickableAndRestored and TestAtomcodeEffortLevelsMatchAgentSupport are new. Reported by yetone on #736. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./internal/agent ./internal/edit pass.
* agent: TestAtomcodeWiring picks an effort through the field too — the write side of the validation the last commit added (a level AtomCode knows lands as reasoning_effort on the model table, one it does not know is refused) had no coverage left: the test only read back what AtomCode's own /effort had written. provider.SetModelEfforts gives fake/m1 levels to offer.
* agent: Disconnect puts AtomCode's default_provider back only where AtomCode still has it — the restore checked the stash's value was not magpie's but not that the table it names was still there, so a table the user had deleted in between came back as a dangling default (the account schema's default_provider names a model table, the legacy shape a [providers.*] one; own answers for both). The default_model branch checked already. TestAtomcodeRestoresOwnDefaults deletes the stashed provider's model table before clearing and fails on the old code.
* agent: AtomCode joins the CLI updates — npm @atomgit.com/atomcode, the brew cask atomcode, and the curl script's ~/.local/bin/atomcode updating itself with atomcode upgrade, so the Agents page shows its version and a newer one as the other agents' do (#736). TestHowInstalled covers the npm prefix, the cask and the self-updating installer.
* agent: AtomCode's self-updater waits for its install paths to be confirmed — the branch recognized a binary under ~/.local/bin as `atomcode upgrade`, on a docs page, while the README shows another path and the command has not been driven outside the help text; the reviewer asked for it removed until the standalone command and the script's real default are settled. npm and the brew cask stay, with their tests; a comment marks what is pending.
---------
Co-authored-by: googya <118465+googya@users.noreply.github.com>
273 lines
9.1 KiB
Go
273 lines
9.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
func atomcodeSaveFake(t *testing.T) {
|
|
t.Helper()
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// Picking a model for AtomCode writes the account "magpie" and one model
|
|
// table per catalog model — as its own CodingPlan sign-in writes them — and
|
|
// points both defaults at the picked one; the table's model is the catalog
|
|
// reference the gateway resolves.
|
|
func TestAtomcodeWiring(t *testing.T) {
|
|
home := t.TempDir()
|
|
atomcodeSaveFake(t)
|
|
a := atomcode(home)
|
|
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(home, ".atomcode", "config.toml")
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg := string(b)
|
|
for _, want := range []string{
|
|
`default_provider = "magpie/fake/m1"`,
|
|
`default_model = "magpie/fake/m1"`,
|
|
`[provider_accounts."magpie"]`,
|
|
`base_url = "` + gatewayV1() + `"`,
|
|
`api_key = "` + gateway.TokenFor("atomcode") + `"`,
|
|
`[models."magpie/fake/m1"]`,
|
|
`account = "magpie"`,
|
|
`model = "fake/m1"`,
|
|
`context_window = 128000`,
|
|
} {
|
|
if !strings.Contains(cfg, want) {
|
|
t.Errorf("want %s in:\n%s", want, cfg)
|
|
}
|
|
}
|
|
if v := a.Field("model").Get(); v != "magpie/fake/m1" {
|
|
t.Fatalf("model reads %q", v)
|
|
}
|
|
if d := a.Drift(); d != nil {
|
|
t.Fatalf("drift right after a set: %+v\n%s", d, cfg)
|
|
}
|
|
// an effort picked in magpie is written to the model table, and one
|
|
// AtomCode does not know is turned away
|
|
if err := provider.SetModelEfforts("fake/m1", []string{"low", "medium", "high"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("effort", "high"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tbl, _ := edit.GetTOMLTable(path, atomcodeTable("magpie/fake/m1")); tbl["reasoning_effort"] != "high" {
|
|
t.Fatalf("reasoning_effort: %v", tbl)
|
|
}
|
|
if err := a.Apply("effort", "ultra"); err == nil {
|
|
t.Fatal("an effort AtomCode does not know was accepted")
|
|
}
|
|
// an AtomCode-owned effort is kept with the model table
|
|
if err := edit.SetTOMLKey(path, atomcodeTable("magpie/fake/m1"), "reasoning_effort", "high"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v := a.Field("effort").Get(); v != "high" {
|
|
t.Fatalf("effort reads %q", v)
|
|
}
|
|
if err := a.Apply("effort", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v := a.Field("effort").Get(); v != "" {
|
|
t.Fatalf("effort reads %q after clearing", v)
|
|
}
|
|
}
|
|
|
|
// Clearing AtomCode's model takes magpie's account and model tables out and
|
|
// puts the defaults the user had back — the shape its own sign-in writes.
|
|
func TestAtomcodeRestoresOwnDefaults(t *testing.T) {
|
|
home := t.TempDir()
|
|
atomcodeSaveFake(t)
|
|
path := filepath.Join(home, ".atomcode", "config.toml")
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(`default_provider = "AtomGit-qwen3.8-27b"
|
|
default_model = "AtomGit-glm5.3-flash"
|
|
|
|
[provider_accounts.AtomGit]
|
|
provider = "openai"
|
|
base_url = "https://llm-api.atomgit.com/v1"
|
|
|
|
[models."AtomGit-qwen3.8-27b"]
|
|
account = "AtomGit"
|
|
model = "qwen3.8-27b"
|
|
context_window = 262144
|
|
|
|
[models."AtomGit-glm5.3-flash"]
|
|
account = "AtomGit"
|
|
model = "glm5.3-flash"
|
|
context_window = 512000
|
|
`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := atomcode(home)
|
|
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg, _ := os.ReadFile(path)
|
|
for _, want := range []string{`[provider_accounts.AtomGit]`, `[models."AtomGit-glm5.3-flash"]`, `[models."magpie/fake/m1"]`} {
|
|
if !strings.Contains(string(cfg), want) {
|
|
t.Fatalf("want %s kept or written in:\n%s", want, cfg)
|
|
}
|
|
}
|
|
if err := edit.DelTOMLTable(path, `models."AtomGit-qwen3.8-27b"`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("model", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg, _ = os.ReadFile(path)
|
|
if !strings.Contains(string(cfg), `default_model = "AtomGit-glm5.3-flash"`) {
|
|
t.Fatalf("the user's own defaults did not come back:\n%s", cfg)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_provider"); v != "" {
|
|
t.Fatalf("deleted provider table was restored as default_provider: %q\n%s", v, cfg)
|
|
}
|
|
if ts, _ := edit.TOMLTables(path); strings.Contains(strings.Join(ts, "\n"), atomcodeAccount) {
|
|
t.Fatalf("magpie's tables stayed:\n%s", cfg)
|
|
}
|
|
if v := a.Field("model").Get(); v != "AtomGit-glm5.3-flash" {
|
|
t.Fatalf("model reads %q, want the user's own default_model", v)
|
|
}
|
|
// a second clear, nothing of magpie's in use, takes both defaults out
|
|
if err := a.Apply("model", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_model"); v != "" {
|
|
t.Fatalf("default_model is %q", v)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_provider"); v != "" {
|
|
t.Fatalf("default_provider is %q", v)
|
|
}
|
|
}
|
|
|
|
// The catalog as it is now reaches AtomCode's config when Sync runs, and a
|
|
// file magpie wrote nothing into stays as it is.
|
|
func TestAtomcodeSync(t *testing.T) {
|
|
home := t.TempDir()
|
|
atomcodeSaveFake(t)
|
|
a := atomcode(home)
|
|
path := filepath.Join(home, ".atomcode", "config.toml")
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(path); err == nil {
|
|
t.Fatal("Sync wrote a config where magpie had nothing")
|
|
}
|
|
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := edit.SetTOMLKey(path, atomcodeTable("magpie/fake/m1"), "reasoning_effort", "high"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, _ := os.ReadFile(path)
|
|
config := strings.ReplaceAll(string(b), `[provider_accounts."magpie"]`, `[provider_accounts.magpie]`)
|
|
config = strings.ReplaceAll(config, `[models."magpie/fake/m1"]`, `[models.'magpie/fake/m1']`)
|
|
if err := os.WriteFile(path, []byte(config), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if d := a.Drift(); d != nil {
|
|
t.Fatalf("valid unquoted account/single-quoted model reported drift: %+v", d)
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2", "m3"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg, _ := os.ReadFile(path)
|
|
if !strings.Contains(string(cfg), `[models."magpie/fake/m3"]`) {
|
|
t.Fatalf("the new model did not reach the config:\n%s", cfg)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_model"); v != "magpie/fake/m1" {
|
|
t.Fatalf("Sync moved the default: %q", v)
|
|
}
|
|
if !strings.Contains(string(cfg), `reasoning_effort = "high"`) {
|
|
t.Fatalf("Sync dropped the selected effort:\n%s", cfg)
|
|
}
|
|
if strings.Count(string(cfg), "[provider_accounts.magpie]") != 0 || strings.Count(string(cfg), `[provider_accounts."magpie"]`) != 1 {
|
|
t.Fatalf("Sync did not canonicalize the exact magpie account:\n%s", cfg)
|
|
}
|
|
config = strings.ReplaceAll(string(cfg), `[provider_accounts."magpie"]`, `[provider_accounts.magpie]`)
|
|
config = strings.ReplaceAll(config, `[models."magpie/fake/m1"]`, `[models.'magpie/fake/m1']`)
|
|
if err := os.WriteFile(path, []byte(config), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("model", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg, _ = os.ReadFile(path)
|
|
if strings.Contains(string(cfg), "[provider_accounts.magpie]") || strings.Contains(string(cfg), gateway.TokenFor("atomcode")) {
|
|
t.Fatalf("clearing left the unquoted magpie account or key behind:\n%s", cfg)
|
|
}
|
|
}
|
|
|
|
func TestAtomcodeLegacyProvidersArePickableAndRestored(t *testing.T) {
|
|
home := t.TempDir()
|
|
path := filepath.Join(home, ".atomcode", "config.toml")
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(`default_provider = "legacy"
|
|
default_model = "legacy"
|
|
|
|
[providers.legacy]
|
|
type = "openai"
|
|
model = "legacy-model"
|
|
base_url = "https://example.com/v1"
|
|
`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
atomcodeSaveFake(t)
|
|
a := atomcode(home)
|
|
if !slices.ContainsFunc(a.Field("model").Options(a.Values()), func(o Option) bool { return o.Value == "legacy" }) {
|
|
t.Fatal("legacy provider missing from model picker")
|
|
}
|
|
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("model", ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_model"); v != "legacy" {
|
|
t.Fatalf("legacy default_model not restored: %q", v)
|
|
}
|
|
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("model", "legacy"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_provider"); v != "legacy" {
|
|
t.Fatalf("legacy provider was not selected: %q", v)
|
|
}
|
|
if v, _ := edit.GetTOMLTop(path, "default_model"); v != "" {
|
|
t.Fatalf("legacy selection left a default_model override: %q", v)
|
|
}
|
|
}
|
|
|
|
func TestAtomcodeEffortLevelsMatchAgentSupport(t *testing.T) {
|
|
got := atomcodeSupportedEfforts([]string{"none", "minimal", "low", "medium", "high", "xhigh", "ultra", "max"})
|
|
want := []string{"low", "medium", "high", "xhigh", "max"}
|
|
if !slices.Equal(got, want) {
|
|
t.Fatalf("supported effort levels = %v, want %v", got, want)
|
|
}
|
|
if got := atomcodeSupportedEfforts(nil); len(got) != 0 {
|
|
t.Fatalf("non-reasoning model has effort options: %v", got)
|
|
}
|
|
}
|