Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/herdr/herdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func (c *Client) NewTab(ctx context.Context, workspace, label, cwd string, env m
ID string `json:"pane_id"`
} `json:"root_pane"`
}
if env == nil {
env = map[string]string{} // herdr rejects "env": null
}
err = c.call(ctx, "tab.create", map[string]any{
"workspace_id": workspace, "label": label, "cwd": cwd, "env": env,
}, &res)
Expand All @@ -258,6 +261,9 @@ func (c *Client) NewTab(ctx context.Context, workspace, label, cwd string, env m
// StartAgent launches the kind's executable with args in pane, which must be
// at its shell prompt, and waits until it takes input.
func (c *Client) StartAgent(ctx context.Context, name, kind, pane string, args []string) error {
if args == nil {
args = []string{} // herdr rejects "args": null
}
return c.call(ctx, "agent.start", map[string]any{
"name": name, "kind": kind, "pane_id": pane, "args": args,
}, nil)
Expand Down
36 changes: 36 additions & 0 deletions internal/herdr/herdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ func TestAgents(t *testing.T) {
}
}

func TestStartAgentWithoutArgs(t *testing.T) {
c := fakeServer(t, func(method string, p json.RawMessage) []string {
var params struct {
Args []string `json:"args"`
}
_ = json.Unmarshal(p, &params)
if method != "agent.start" || params.Args == nil {
return []string{`{"id":"x","error":{"code":"invalid_request","message":"invalid type: null, expected a sequence"}}`}
}
return []string{`{"id":"x","result":{"type":"agent_started"}}`}
})
if err := c.StartAgent(context.Background(), "jira-prot-1", "claude", "w1:p1", nil); err != nil {
t.Fatal(err)
}
}

func TestNewTabWithoutEnv(t *testing.T) {
c := fakeServer(t, func(method string, p json.RawMessage) []string {
var params struct {
Env map[string]string `json:"env"`
}
_ = json.Unmarshal(p, &params)
if method != "tab.create" || params.Env == nil {
return []string{`{"id":"x","error":{"code":"invalid_request","message":"invalid type: null, expected a map"}}`}
}
return []string{`{"id":"x","result":{"type":"tab_created","tab":{"tab_id":"w1:t2"},"root_pane":{"pane_id":"w1:p2"}}}`}
})
tab, pane, err := c.NewTab(context.Background(), "w1", "PROT-1", "/src/a", nil)
if err != nil {
t.Fatal(err)
}
if tab != "w1:t2" || pane != "w1:p2" {
t.Fatalf("tab, pane = %q, %q", tab, pane)
}
}

func TestPromptError(t *testing.T) {
c := fakeServer(t, func(string, json.RawMessage) []string {
return []string{`{"id":"x","error":{"code":"agent_blocked","message":"agent is blocked"}}`}
Expand Down
5 changes: 3 additions & 2 deletions internal/web/api_agents_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestStartStreamsSteps(t *testing.T) {
f.mu.Unlock()
// herdr refuses an argument with a newline: the prompt is pasted once
// the agent runs, {key} filled in.
if args != nil || text != "line one\nline two DEMO-5" {
if a, _ := args.([]any); len(a) != 0 || text != "line one\nline two DEMO-5" {
t.Errorf("args = %#v, prompt %q", args, text)
}
if create["branch"] != "issue/DEMO-5-new" {
Expand Down Expand Up @@ -224,7 +224,8 @@ func TestStartAnotherInPath(t *testing.T) {
f.mu.Lock()
tab, start := f.params["tab.create"], f.params["agent.start"]
f.mu.Unlock()
if tab["workspace_id"] != "w6" || tab["cwd"] != "/w/demo-5-b" || tab["label"] != "DEMO-5" || start["pane_id"] != "p3" || start["args"] != nil {
args, _ := start["args"].([]any)
if tab["workspace_id"] != "w6" || tab["cwd"] != "/w/demo-5-b" || tab["label"] != "DEMO-5" || start["pane_id"] != "p3" || len(args) != 0 {
t.Errorf("tab.create %v agent.start %v", tab, start)
}
if d, _ := res["Did"].([]any); len(d) != 0 || f.called("user.assign") {
Expand Down
2 changes: 1 addition & 1 deletion internal/web/api_agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func TestStartWorkSequence(t *testing.T) {
if !strings.Contains(order, "worktree.open,worktree.create,tab.rename,agent.start,agent.prompt") {
t.Errorf("calls = %s", order)
}
if start["args"] != nil || start["pane_id"] != "p2" || start["kind"] != "claude" || prompt["text"] != "Do DEMO-5 now" || prompt["target"] != "p2" {
if a, _ := start["args"].([]any); len(a) != 0 || start["pane_id"] != "p2" || start["kind"] != "claude" || prompt["text"] != "Do DEMO-5 now" || prompt["target"] != "p2" {
t.Errorf("agent.start = %v", start)
}
if fmt.Sprint(rename["label"]) != "DEMO-5" {
Expand Down
Loading