|
| 1 | +package agent |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/minicodemonkey/chief/internal/loop" |
| 8 | +) |
| 9 | + |
| 10 | +func TestOpenCodeProvider_Name(t *testing.T) { |
| 11 | + p := NewOpenCodeProvider("") |
| 12 | + if p.Name() != "OpenCode" { |
| 13 | + t.Errorf("Name() = %q, want OpenCode", p.Name()) |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +func TestOpenCodeProvider_CLIPath(t *testing.T) { |
| 18 | + p := NewOpenCodeProvider("") |
| 19 | + if p.CLIPath() != "opencode" { |
| 20 | + t.Errorf("CLIPath() empty arg = %q, want opencode", p.CLIPath()) |
| 21 | + } |
| 22 | + p2 := NewOpenCodeProvider("/usr/local/bin/opencode") |
| 23 | + if p2.CLIPath() != "/usr/local/bin/opencode" { |
| 24 | + t.Errorf("CLIPath() custom = %q, want /usr/local/bin/opencode", p2.CLIPath()) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +func TestOpenCodeProvider_LogFileName(t *testing.T) { |
| 29 | + p := NewOpenCodeProvider("") |
| 30 | + if p.LogFileName() != "opencode.log" { |
| 31 | + t.Errorf("LogFileName() = %q, want opencode.log", p.LogFileName()) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestOpenCodeProvider_LoopCommand(t *testing.T) { |
| 36 | + ctx := context.Background() |
| 37 | + p := NewOpenCodeProvider("/bin/opencode") |
| 38 | + cmd := p.LoopCommand(ctx, "hello world", "/work/dir") |
| 39 | + |
| 40 | + if cmd.Path != "/bin/opencode" { |
| 41 | + t.Errorf("LoopCommand Path = %q, want /bin/opencode", cmd.Path) |
| 42 | + } |
| 43 | + wantArgs := []string{"/bin/opencode", "run", "--format", "json", "hello world"} |
| 44 | + if len(cmd.Args) != len(wantArgs) { |
| 45 | + t.Fatalf("LoopCommand Args len = %d, want %d: %v", len(cmd.Args), len(wantArgs), cmd.Args) |
| 46 | + } |
| 47 | + for i, w := range wantArgs { |
| 48 | + if cmd.Args[i] != w { |
| 49 | + t.Errorf("LoopCommand Args[%d] = %q, want %q", i, cmd.Args[i], w) |
| 50 | + } |
| 51 | + } |
| 52 | + if cmd.Dir != "/work/dir" { |
| 53 | + t.Errorf("LoopCommand Dir = %q, want /work/dir", cmd.Dir) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +func TestOpenCodeProvider_ConvertCommand(t *testing.T) { |
| 58 | + p := NewOpenCodeProvider("opencode") |
| 59 | + cmd, mode, outPath, err := p.ConvertCommand("/prd/dir", "convert prompt") |
| 60 | + if err != nil { |
| 61 | + t.Fatalf("ConvertCommand unexpected error: %v", err) |
| 62 | + } |
| 63 | + if mode != loop.OutputStdout { |
| 64 | + t.Errorf("ConvertCommand mode = %v, want OutputStdout", mode) |
| 65 | + } |
| 66 | + if outPath != "" { |
| 67 | + t.Errorf("ConvertCommand outPath = %q, want empty string", outPath) |
| 68 | + } |
| 69 | + if cmd.Path != "opencode" { |
| 70 | + t.Errorf("ConvertCommand Path = %q, want opencode", cmd.Path) |
| 71 | + } |
| 72 | + if cmd.Dir != "/prd/dir" { |
| 73 | + t.Errorf("ConvertCommand Dir = %q, want /prd/dir", cmd.Dir) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestOpenCodeProvider_FixJSONCommand(t *testing.T) { |
| 78 | + p := NewOpenCodeProvider("opencode") |
| 79 | + cmd, mode, outPath, err := p.FixJSONCommand("fix prompt") |
| 80 | + if err != nil { |
| 81 | + t.Fatalf("FixJSONCommand unexpected error: %v", err) |
| 82 | + } |
| 83 | + if mode != loop.OutputStdout { |
| 84 | + t.Errorf("FixJSONCommand mode = %v, want OutputStdout", mode) |
| 85 | + } |
| 86 | + if outPath != "" { |
| 87 | + t.Errorf("FixJSONCommand outPath = %q, want empty string", outPath) |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func TestOpenCodeProvider_InteractiveCommand(t *testing.T) { |
| 92 | + p := NewOpenCodeProvider("opencode") |
| 93 | + cmd := p.InteractiveCommand("/work", "my prompt") |
| 94 | + if cmd.Dir != "/work" { |
| 95 | + t.Errorf("InteractiveCommand Dir = %q, want /work", cmd.Dir) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +func TestOpenCodeProvider_ParseLine(t *testing.T) { |
| 100 | + p := NewOpenCodeProvider("") |
| 101 | + e := p.ParseLine(`{"type":"step_start","timestamp":1234567890,"sessionID":"ses_test123"}`) |
| 102 | + if e == nil { |
| 103 | + t.Fatal("ParseLine(step_start) returned nil") |
| 104 | + } |
| 105 | + if e.Type != loop.EventIterationStart { |
| 106 | + t.Errorf("ParseLine(step_start) Type = %v, want EventIterationStart", e.Type) |
| 107 | + } |
| 108 | +} |
0 commit comments