|
| 1 | +package msgfmt |
| 2 | + |
| 3 | +import ( |
| 4 | + "path" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestIsAgentReadyForInitialPrompt(t *testing.T) { |
| 11 | + dir := "testdata/initialization" |
| 12 | + agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeCopilot, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeOpencode} |
| 13 | + for _, agentType := range agentTypes { |
| 14 | + t.Run(string(agentType), func(t *testing.T) { |
| 15 | + t.Run("ready", func(t *testing.T) { |
| 16 | + cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "ready")) |
| 17 | + if err != nil { |
| 18 | + t.Errorf("failed to read ready cases for agent type %s: %s", agentType, err) |
| 19 | + } |
| 20 | + if len(cases) == 0 { |
| 21 | + t.Errorf("no ready cases found for agent type %s", agentType) |
| 22 | + } |
| 23 | + for _, c := range cases { |
| 24 | + if c.IsDir() { |
| 25 | + continue |
| 26 | + } |
| 27 | + t.Run(c.Name(), func(t *testing.T) { |
| 28 | + msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "ready", c.Name())) |
| 29 | + assert.NoError(t, err) |
| 30 | + assert.True(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to be ready for message:\n%s", string(msg)) |
| 31 | + }) |
| 32 | + } |
| 33 | + }) |
| 34 | + |
| 35 | + t.Run("not_ready", func(t *testing.T) { |
| 36 | + cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "not_ready")) |
| 37 | + if err != nil { |
| 38 | + t.Errorf("failed to read not_ready cases for agent type %s: %s", agentType, err) |
| 39 | + } |
| 40 | + if len(cases) == 0 { |
| 41 | + t.Errorf("no not_ready cases found for agent type %s", agentType) |
| 42 | + } |
| 43 | + for _, c := range cases { |
| 44 | + if c.IsDir() { |
| 45 | + continue |
| 46 | + } |
| 47 | + t.Run(c.Name(), func(t *testing.T) { |
| 48 | + msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "not_ready", c.Name())) |
| 49 | + assert.NoError(t, err) |
| 50 | + assert.False(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to not be ready for message:\n%s", string(msg)) |
| 51 | + }) |
| 52 | + } |
| 53 | + }) |
| 54 | + }) |
| 55 | + } |
| 56 | +} |
0 commit comments