|
1 | 1 | package codingcontext |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
| 5 | + "log/slog" |
| 6 | + "os" |
4 | 7 | "testing" |
5 | 8 |
|
6 | 9 | "github.com/kitproj/coding-context-cli/pkg/codingcontext/markdown" |
7 | 10 | "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" |
8 | 11 | ) |
9 | 12 |
|
| 13 | +func TestResult_Prompt(t *testing.T) { |
| 14 | + tests := []struct { |
| 15 | + name string |
| 16 | + setup func(t *testing.T, dir string) |
| 17 | + taskName string |
| 18 | + want string |
| 19 | + }{ |
| 20 | + { |
| 21 | + name: "task only without rules", |
| 22 | + setup: func(t *testing.T, dir string) { |
| 23 | + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") |
| 24 | + }, |
| 25 | + taskName: "test-task", |
| 26 | + want: "Task content\n", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "single rule and task", |
| 30 | + setup: func(t *testing.T, dir string) { |
| 31 | + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") |
| 32 | + createRule(t, dir, ".agents/rules/rule1.md", "", "Rule 1 content\n") |
| 33 | + }, |
| 34 | + taskName: "test-task", |
| 35 | + want: "Rule 1 content\n\nTask content\n", |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "multiple rules and task", |
| 39 | + setup: func(t *testing.T, dir string) { |
| 40 | + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") |
| 41 | + createRule(t, dir, ".agents/rules/rule1.md", "", "Rule 1 content\n") |
| 42 | + createRule(t, dir, ".agents/rules/rule2.md", "", "Rule 2 content\n") |
| 43 | + }, |
| 44 | + taskName: "test-task", |
| 45 | + want: "Rule 1 content\n\nRule 2 content\n\nTask content\n", |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + for _, tt := range tests { |
| 50 | + t.Run(tt.name, func(t *testing.T) { |
| 51 | + tmpDir := t.TempDir() |
| 52 | + tt.setup(t, tmpDir) |
| 53 | + |
| 54 | + ctx := New( |
| 55 | + WithSearchPaths("file://"+tmpDir), |
| 56 | + WithLogger(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError}))), |
| 57 | + ) |
| 58 | + |
| 59 | + result, err := ctx.Run(context.Background(), tt.taskName) |
| 60 | + if err != nil { |
| 61 | + t.Fatalf("Run() error = %v", err) |
| 62 | + } |
| 63 | + |
| 64 | + if result.Prompt != tt.want { |
| 65 | + t.Errorf("Result.Prompt = %q, want %q", result.Prompt, tt.want) |
| 66 | + } |
| 67 | + }) |
| 68 | + } |
| 69 | +} |
| 70 | + |
10 | 71 | func TestResult_MCPServers(t *testing.T) { |
11 | 72 | tests := []struct { |
12 | 73 | name string |
|
0 commit comments