Files
magpie/internal/agentenv/agentenv_test.go
T
yetone f63549b5ca agentenv: an address variable is not a folder (AGY_LLM_GATEWAY_URL)
Every name in agentenv.Vars that isn't in NotPaths is taken for a
folder, and appdir passes over one that isn't an absolute path. So
AGY_LLM_GATEWAY_URL=http://... had magpie print "ignoring
AGY_LLM_GATEWAY_URL: not an absolute path" at every start. Found while
pointing a sandbox magpie at a sandbox Nowledge Mem through
NMEM_API_URL, which magpie dropped the same way.

TestAddressesAreNotPaths fails when a Vars name ending in _URL or _ADDR
is not in NotPaths.

Run (mote): go test -count=1 ./internal/agentenv ./internal/appdir ok.
Broken by hand: without the NotPaths entry, TestAddressesAreNotPaths is
red on AGY_LLM_GATEWAY_URL.
Not tried: a real Antigravity started with AGY_LLM_GATEWAY_URL set.
2026-11-19 15:44:35 +08:00

81 lines
2.4 KiB
Go

package agentenv
import (
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
)
// Every name in Vars is one magpie reads somewhere outside this package. A
// name it stopped reading, or one a sandbox invented, is a hole that every
// sandbox clearing this list believes is covered: internal/backup's cleared
// GEMINI_CLI_HOME and OPENCODE_CONFIG, which nothing reads, and not
// OPENCODE_CONFIG_DIR, which internal/agent does. This reads the sources
// rather than the agents' table, since the table is in internal/agent, which
// internal/sessions' tests cannot import; it looks for a quoted name, so a
// name only a comment mentions still counts, and a variable magpie reads
// through a name it builds at runtime would not.
func TestVarsAreRead(t *testing.T) {
found := make(map[string]bool, len(Vars))
err := filepath.WalkDir(filepath.Join("..", ".."), func(p string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
switch d.Name() {
case ".git", "dist", "node_modules", "agentenv":
return fs.SkipDir
}
return nil
}
if !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") {
return nil
}
b, err := os.ReadFile(p)
if err != nil {
return err
}
for _, v := range Vars {
if !found[v] && strings.Contains(string(b), `"`+v+`"`) {
found[v] = true
}
}
return nil
})
if err != nil {
t.Fatal(err)
}
for _, v := range Vars {
if !found[v] {
t.Errorf("%s is in Vars, but nothing outside this package reads it: magpie stopped reading it, or the name was never the one magpie reads", v)
}
}
}
// A name twice is a name a sandbox clears twice, which says the list was
// pasted together rather than kept.
func TestVarsAreApart(t *testing.T) {
seen := make(map[string]bool, len(Vars))
for _, v := range Vars {
if seen[v] {
t.Errorf("%s is in Vars twice", v)
}
seen[v] = true
}
}
// A variable that holds an address is in NotPaths. Every other one is
// taken for a folder, which magpie passes over when it isn't an absolute
// path: AGY_LLM_GATEWAY_URL=http://… had magpie print "ignoring
// AGY_LLM_GATEWAY_URL: not an absolute path" at every start, and
// appdir.Getenv read it as unset.
func TestAddressesAreNotPaths(t *testing.T) {
for _, v := range Vars {
if (strings.HasSuffix(v, "_URL") || strings.HasSuffix(v, "_ADDR")) && !NotPaths[v] {
t.Errorf("%s holds an address, but it isn't in NotPaths", v)
}
}
}