The siblings of plugins #86 in the built-ins, for accounts not moved onto the plugins. ZCode (zcode_client.go): the Start Plan's environment section already took the agent's folder from its prompt, but fell back to the user's home when the prompt named none, said "Is a git repository: no" whatever the folder, and said magpie's $SHELL/%ComSpec% as the shell. zcodePlace now gives the folder and the git state: the agent's word, else this disk's (GitSaid/GitOnDisk). Each line is left out when unknown, and the Shell line is gone, as in plugin 0.1.15. Command Code (gateway/commandcode.go): a Go request's config said workingDir: home and isGitRepo: false always. It now says the agent's folder (workPlace) and its git state the same way. A request with no folder keeps the CLI's config in the home, as plugin 0.1.10 does. Run: TestZCodeEnvironmentSaysOnlyWhatIsKnown and TestCommandCodeGoSaysTheAgentsFolder (new), TestZCodeStartSentAsTheApp updated (its /work/proj isn't on this disk, so no git line, and no shell). Broken by hand: with git always "no" both ZCode tests fail; with the old commandcode.go 5 of the 6 cases fail. go test internal/gateway, internal/provider; gofmt -l; go vet darwin/linux/windows.
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// magpie-community/plugins#86: a Go request to /alpha/generate said the
|
|
// user's home as the working directory, outside a git repository, whatever
|
|
// folder the agent worked in. It says the agent's folder and repository,
|
|
// from the agent's words or this computer's disk; a request that names no
|
|
// folder keeps the CLI's config in the home.
|
|
func TestCommandCodeGoSaysTheAgentsFolder(t *testing.T) {
|
|
repo := t.TempDir()
|
|
if err := os.Mkdir(filepath.Join(repo, ".git"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
plain := t.TempDir()
|
|
home, _ := os.UserHomeDir()
|
|
ask := func(system string) gjson.Result {
|
|
t.Helper()
|
|
body, _ := json.Marshal(map[string]any{
|
|
"model": "m", "max_tokens": 16, "system": system,
|
|
"messages": []any{map[string]any{"role": "user", "content": "hi"}},
|
|
})
|
|
req, err := parse(provider.Anthropic, body)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return gjson.GetBytes(cmdRequest(req, "m"), "config")
|
|
}
|
|
for _, c := range []struct {
|
|
name, system, dir string
|
|
git bool
|
|
}{
|
|
{"Claude Code says it is a repository", "Primary working directory: /far/away\nIs a git repository: true\n", "/far/away", true},
|
|
{"Claude Code says it isn't", "Primary working directory: /far/away\nIs a git repository: false\n", "/far/away", false},
|
|
{"a repository on this disk", "<cwd>" + repo + "</cwd>", repo, true},
|
|
{"a folder on this disk outside one", "<cwd>" + plain + "</cwd>", plain, false},
|
|
{"a folder not here, nothing said", "<cwd>/far/away</cwd>", "/far/away", false},
|
|
{"no folder", "You are helpful.", home, false},
|
|
} {
|
|
got := ask(c.system)
|
|
if got.Get("workingDir").String() != c.dir || got.Get("isGitRepo").Bool() != c.git {
|
|
t.Errorf("%s: %s, want %s %v", c.name, got.Raw, c.dir, c.git)
|
|
}
|
|
}
|
|
}
|