188 lines
4.6 KiB
Go
188 lines
4.6 KiB
Go
package adapters
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
)
|
|
|
|
func TestCLIConfFromStruct_ProfileRuntimeOptions(t *testing.T) {
|
|
st, err := structpb.NewStruct(map[string]any{
|
|
"profiles": map[string]any{
|
|
"claude": map[string]any{
|
|
"command": "claude",
|
|
"args": []any{"-p"},
|
|
"env": []any{},
|
|
"persistent": false,
|
|
"terminal": false,
|
|
"output_format": "claude-json",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("structpb: %v", err)
|
|
}
|
|
|
|
cfg := cliConfFromStruct(st)
|
|
|
|
prof, ok := cfg.Profiles["claude"]
|
|
if !ok {
|
|
t.Fatal("expected claude profile")
|
|
}
|
|
if prof.Command != "claude" {
|
|
t.Fatalf("command: got %q", prof.Command)
|
|
}
|
|
if len(prof.Args) != 1 || prof.Args[0] != "-p" {
|
|
t.Fatalf("args: got %#v", prof.Args)
|
|
}
|
|
if prof.OutputFormat != "claude-json" {
|
|
t.Fatalf("output_format: got %q", prof.OutputFormat)
|
|
}
|
|
}
|
|
|
|
func TestCLIConfFromStruct_ClaudeHeadlessBypassProfile(t *testing.T) {
|
|
st, err := structpb.NewStruct(map[string]any{
|
|
"profiles": map[string]any{
|
|
"claude": map[string]any{
|
|
"command": "claude",
|
|
"args": []any{"-p", "--dangerously-skip-permissions"},
|
|
"env": []any{},
|
|
"persistent": false,
|
|
"terminal": false,
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("structpb: %v", err)
|
|
}
|
|
|
|
cfg := cliConfFromStruct(st)
|
|
|
|
prof, ok := cfg.Profiles["claude"]
|
|
if !ok {
|
|
t.Fatal("expected claude profile")
|
|
}
|
|
if prof.Command != "claude" {
|
|
t.Fatalf("command: got %q", prof.Command)
|
|
}
|
|
if len(prof.Args) != 2 || prof.Args[0] != "-p" || prof.Args[1] != "--dangerously-skip-permissions" {
|
|
t.Fatalf("args: got %#v", prof.Args)
|
|
}
|
|
if prof.Persistent {
|
|
t.Fatal("expected persistent=false")
|
|
}
|
|
if prof.Terminal {
|
|
t.Fatal("expected terminal=false")
|
|
}
|
|
}
|
|
|
|
func TestCLIConfFromStruct_GeminiHeadlessYoloProfile(t *testing.T) {
|
|
st, err := structpb.NewStruct(map[string]any{
|
|
"profiles": map[string]any{
|
|
"gemini": map[string]any{
|
|
"command": "gemini",
|
|
"args": []any{"-p", "--approval-mode", "yolo"},
|
|
"env": []any{},
|
|
"persistent": false,
|
|
"terminal": false,
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("structpb: %v", err)
|
|
}
|
|
|
|
cfg := cliConfFromStruct(st)
|
|
|
|
prof, ok := cfg.Profiles["gemini"]
|
|
if !ok {
|
|
t.Fatal("expected gemini profile")
|
|
}
|
|
if prof.Command != "gemini" {
|
|
t.Fatalf("command: got %q", prof.Command)
|
|
}
|
|
if len(prof.Args) != 3 || prof.Args[0] != "-p" || prof.Args[1] != "--approval-mode" || prof.Args[2] != "yolo" {
|
|
t.Fatalf("args: got %#v", prof.Args)
|
|
}
|
|
if prof.Persistent {
|
|
t.Fatal("expected persistent=false")
|
|
}
|
|
if prof.Terminal {
|
|
t.Fatal("expected terminal=false")
|
|
}
|
|
}
|
|
|
|
func TestCLIConfFromStruct_ClineConfigProfile(t *testing.T) {
|
|
st, err := structpb.NewStruct(map[string]any{
|
|
"profiles": map[string]any{
|
|
"cline-dgx": map[string]any{
|
|
"command": "/config/.npm-global/bin/cline",
|
|
"args": []any{"-y", "--json", "--config", "/config/.cline/profiles/ollama-dgx"},
|
|
"env": []any{},
|
|
"persistent": false,
|
|
"terminal": false,
|
|
"output_format": "cline-json",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("structpb: %v", err)
|
|
}
|
|
|
|
cfg := cliConfFromStruct(st)
|
|
|
|
prof, ok := cfg.Profiles["cline-dgx"]
|
|
if !ok {
|
|
t.Fatal("expected cline-dgx profile")
|
|
}
|
|
if prof.Command != "/config/.npm-global/bin/cline" {
|
|
t.Fatalf("command: got %q", prof.Command)
|
|
}
|
|
if len(prof.Args) != 4 || prof.Args[0] != "-y" || prof.Args[1] != "--json" || prof.Args[2] != "--config" || prof.Args[3] != "/config/.cline/profiles/ollama-dgx" {
|
|
t.Fatalf("args: got %#v", prof.Args)
|
|
}
|
|
if prof.OutputFormat != "cline-json" {
|
|
t.Fatalf("output_format: got %q", prof.OutputFormat)
|
|
}
|
|
}
|
|
|
|
func TestCLIConfFromStruct_ProfileCompletionMarker(t *testing.T) {
|
|
st, err := structpb.NewStruct(map[string]any{
|
|
"profiles": map[string]any{
|
|
"codex": map[string]any{
|
|
"command": "codex",
|
|
"args": []any{},
|
|
"env": []any{},
|
|
"persistent": true,
|
|
"terminal": false,
|
|
"completion_marker": map[string]any{
|
|
"line": "[[DONE]]",
|
|
"regex": `^\[\[DONE\]\]$`,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("structpb: %v", err)
|
|
}
|
|
|
|
cfg := cliConfFromStruct(st)
|
|
|
|
prof, ok := cfg.Profiles["codex"]
|
|
if !ok {
|
|
t.Fatal("expected codex profile")
|
|
}
|
|
if prof.CompletionMarker.Line != "[[DONE]]" {
|
|
t.Fatalf("completion_marker.line: got %q", prof.CompletionMarker.Line)
|
|
}
|
|
if prof.CompletionMarker.Regex != `^\[\[DONE\]\]$` {
|
|
t.Fatalf("completion_marker.regex: got %q", prof.CompletionMarker.Regex)
|
|
}
|
|
}
|
|
|
|
func TestCLIConfFromStruct_NilSettings(t *testing.T) {
|
|
cfg := cliConfFromStruct(nil)
|
|
if cfg.Enabled {
|
|
t.Fatal("expected enabled=false for nil settings")
|
|
}
|
|
}
|