47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWrapperExtensionsReadsBackWhatWasWritten(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
id := "agent-1"
|
|
chosen := []extensionItem{
|
|
{name: "ask-user-question", path: "/x/ask-user-question/index.ts"},
|
|
{name: "web-fetch", path: "/x/web-fetch.ts"},
|
|
}
|
|
fc := &fakeClient{}
|
|
p := &agentPicker{client: fc}
|
|
if err := writeWrapper(p, id, chosen); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := wrapperExtensions(id)
|
|
if !got["ask-user-question"] || !got["web-fetch"] {
|
|
t.Fatalf("read back %v, want both", got)
|
|
}
|
|
if err := writeWrapper(p, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(home, ".local", "share", "paperclip-harness", "wrappers", id+".sh")); !os.IsNotExist(err) {
|
|
t.Fatalf("wrapper should be removed when nothing is chosen")
|
|
}
|
|
if fc.lastCommand != "pi" {
|
|
t.Fatalf("command should go back to pi, got %q", fc.lastCommand)
|
|
}
|
|
}
|
|
|
|
type fakeClient struct{ lastCommand string }
|
|
|
|
func (f *fakeClient) AgentRaw(string) (map[string]any, error) {
|
|
return map[string]any{"adapterConfig": map[string]any{}}, nil
|
|
}
|
|
func (f *fakeClient) UpdateAgent(_ string, body map[string]any) error {
|
|
cfg, _ := body["adapterConfig"].(map[string]any)
|
|
f.lastCommand, _ = cfg["command"].(string)
|
|
return nil
|
|
}
|