package fakeclaude import ( "reflect" "testing" ) // The Assistant's tool words: look with or without a query, describe an // operation, use one with a JSON input, and read an attached file. func TestAssistantToolWords(t *testing.T) { for _, c := range []struct { name, arg string want map[string]any }{ {"look", "", map[string]any{}}, {"look", "notes", map[string]any{"query": "notes"}}, {"describe", "team_request", map[string]any{"operation": "team_request"}}, {"use", `team_request|{"words":"fix it"}`, map[string]any{"operation": "team_request", "input": map[string]any{"words": "fix it"}}}, {"use", "base_people", map[string]any{"operation": "base_people", "input": map[string]any{}}}, {"read_attachment", "/workspace/attachments/at_abcdefgh/notes.md", map[string]any{"path": "/workspace/attachments/at_abcdefgh/notes.md"}}, } { if got := ToolInput(c.name, c.arg); !reflect.DeepEqual(got, c.want) { t.Errorf("%s:%s = %v, want %v", c.name, c.arg, got, c.want) } } } // A job's news steers the fake Assistant by what it says: a question is // answered with team_reply, a stop with nudges left is nudged with the // person's quoted words (and the rot13 context in them, decoded), a stop // it cannot get past is "It stopped.", and other news is left alone. func TestAssistantJobNews(t *testing.T) { head := "[News about one of the person's jobs, from the system.]\nJob \"Fixing \\\"it\\\"\" (request h_abc123).\n" words := "The person asked for it in these words: \"Do it nudge:gbby:ernq_gnfx:$gnfx gbby:fgneg_gnfx:$gnfx|Tb.\"\n" for _, c := range []struct { name, prompt, steer, reply string ok bool }{ {"options", head + words + "The work on it has a question: \"Which page?\"\nThe answer must be one of: \"Sign \\\"in\\\"\", \"Home\"\n", `tool:use:team_reply|{"answer":"Sign \"in\"","request":"h_abc123"}`, "", true}, {"free", head + words + "The work on it has a question: \"Which words? answer: Sign in now\"\n", `tool:use:team_reply|{"answer":"Sign in now","request":"h_abc123"}`, "", true}, {"no work", head + words + "It stopped before any work started. Push it through. Nudges left: 2. Say nothing.\n", `tool:use:team_nudge|{"context":"tool:read_task:\u0024task\ntool:start_task:\u0024task|Go.","request":"h_abc123","words":"Do it nudge:gbby:ernq_gnfx:\u0024gnfx gbby:fgneg_gnfx:\u0024gnfx|Tb."}`, "", true}, {"failed", head + "The person asked for it in these words: \"Fix it\"\nA step of it failed and can be tried again. Nudges left: 1.\n", `tool:use:team_nudge|{"request":"h_abc123","words":"Fix it"}`, "", true}, {"spent", head + words + "It stopped before any work started. Nudges left: 0.\n", "", "", false}, {"no nudges", head + words + "It stopped again and no nudges are left.\n", "", "It stopped.", true}, {"person", head + words + "It stopped, and only the person can move it on: it needs access.\n", "", "It stopped.", true}, {"ready", head + words + "It is ready for the person to try.\n", "", "", false}, {"not news", "Newest message:\nThe work on it has a question: \"x\"", "", "", false}, } { steer, reply, ok := news(c.prompt) if steer != c.steer || reply != c.reply || ok != c.ok { t.Errorf("%s: news = %q, %q, %v; want %q, %q, %v", c.name, steer, reply, ok, c.steer, c.reply, c.ok) } // What the fake then calls is the operation with that input. if m := toolWord.FindStringSubmatch(steer); steer != "" && (m == nil || m[1] != "use" || ToolInput(m[1], m[2])["input"] == nil) { t.Errorf("%s: steer %q is no use word", c.name, steer) } } }