| 1 | package thin |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // A Claude step's shell worked when one of its Bash calls came back |
| 6 | // without an error; it had none when it ran Bash and every call failed |
| 7 | // (refused, or the sandbox could not start). A step that never ran Bash |
| 8 | // had a shell it did not use. |
| 9 | func TestShellUse(t *testing.T) { |
| 10 | bash := func(id string) []byte { |
| 11 | return []byte(`{"type":"assistant","session_id":"s","message":{"content":[{"type":"tool_use","id":"` + id + `","name":"Bash","input":{"command":"go test ./..."}}]}}`) |
| 12 | } |
| 13 | read := []byte(`{"type":"assistant","session_id":"s","message":{"content":[{"type":"tool_use","id":"r1","name":"Read","input":{"file_path":"/workspace/a"}}]}}`) |
| 14 | result := func(id string, failed bool) []byte { |
| 15 | e := "false" |
| 16 | if failed { |
| 17 | e = "true" |
| 18 | } |
| 19 | return []byte(`{"type":"user","session_id":"s","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"` + id + `","content":"x","is_error":` + e + `}]}}`) |
| 20 | } |
| 21 | for name, c := range map[string]struct { |
| 22 | frames [][]byte |
| 23 | none bool |
| 24 | }{ |
| 25 | "never ran": {[][]byte{read, result("r1", true)}, false}, |
| 26 | "all refused": {[][]byte{bash("b1"), result("b1", true), bash("b2"), result("b2", true), read, result("r1", false)}, true}, |
| 27 | "one worked": {[][]byte{bash("b1"), result("b1", true), bash("b2"), result("b2", false)}, false}, |
| 28 | "no result yet": {[][]byte{bash("b1")}, true}, |
| 29 | "another's error": {[][]byte{bash("b1"), result("b1", false), result("zz", true)}, false}, |
| 30 | } { |
| 31 | var s shellUse |
| 32 | for _, f := range c.frames { |
| 33 | s.frame(f) |
| 34 | } |
| 35 | if s.none() != c.none { |
| 36 | t.Errorf("%s: none %v, want %v (%+v)", name, s.none(), c.none, s) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |