|
| 1 | +package engine |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/shrug-labs/aipack/internal/domain" |
| 8 | +) |
| 9 | + |
| 10 | +func TestStripFrontmatterKeys_Agent_RemovesHarness(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + fm := domain.AgentFrontmatter{ |
| 13 | + Name: "explorer", |
| 14 | + Description: "Fast exploration", |
| 15 | + Tools: []string{"Read", "Grep"}, |
| 16 | + Harness: map[string]map[string]any{ |
| 17 | + "codex": {"model": "o3"}, |
| 18 | + }, |
| 19 | + } |
| 20 | + out, err := StripFrontmatterKeys(fm, "harness") |
| 21 | + if err != nil { |
| 22 | + t.Fatal(err) |
| 23 | + } |
| 24 | + s := string(out) |
| 25 | + if strings.Contains(s, "harness") { |
| 26 | + t.Fatalf("should strip harness key, got:\n%s", s) |
| 27 | + } |
| 28 | + if !strings.Contains(s, "explorer") { |
| 29 | + t.Fatal("should preserve name") |
| 30 | + } |
| 31 | + if !strings.Contains(s, "Read") { |
| 32 | + t.Fatal("should preserve tools") |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func TestStripFrontmatterKeys_Rule_RemovesPaths(t *testing.T) { |
| 37 | + t.Parallel() |
| 38 | + fm := domain.RuleFrontmatter{ |
| 39 | + Name: "my-rule", |
| 40 | + Description: "Does things", |
| 41 | + Paths: []string{"src/**/*.go"}, |
| 42 | + } |
| 43 | + out, err := StripFrontmatterKeys(fm, "paths") |
| 44 | + if err != nil { |
| 45 | + t.Fatal(err) |
| 46 | + } |
| 47 | + s := string(out) |
| 48 | + if strings.Contains(s, "paths") { |
| 49 | + t.Fatalf("should strip paths key, got:\n%s", s) |
| 50 | + } |
| 51 | + if !strings.Contains(s, "my-rule") { |
| 52 | + t.Fatal("should preserve name") |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +func TestStripFrontmatterKeys_NoKeysToStrip(t *testing.T) { |
| 57 | + t.Parallel() |
| 58 | + fm := domain.AgentFrontmatter{ |
| 59 | + Name: "simple", |
| 60 | + Description: "No harness-specific fields", |
| 61 | + } |
| 62 | + out, err := StripFrontmatterKeys(fm, "harness") |
| 63 | + if err != nil { |
| 64 | + t.Fatal(err) |
| 65 | + } |
| 66 | + if !strings.Contains(string(out), "simple") { |
| 67 | + t.Fatal("should preserve content when nothing to strip") |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +func TestStripFrontmatterKeys_MultipleKeys(t *testing.T) { |
| 72 | + t.Parallel() |
| 73 | + fm := domain.AgentFrontmatter{ |
| 74 | + Name: "test", |
| 75 | + Description: "test agent", |
| 76 | + Tools: []string{"Read"}, |
| 77 | + Harness: map[string]map[string]any{ |
| 78 | + "codex": {"model": "o3"}, |
| 79 | + }, |
| 80 | + } |
| 81 | + out, err := StripFrontmatterKeys(fm, "harness", "tools") |
| 82 | + if err != nil { |
| 83 | + t.Fatal(err) |
| 84 | + } |
| 85 | + s := string(out) |
| 86 | + if strings.Contains(s, "harness") { |
| 87 | + t.Fatal("should strip harness") |
| 88 | + } |
| 89 | + if strings.Contains(s, "tools") { |
| 90 | + t.Fatal("should strip tools") |
| 91 | + } |
| 92 | + if !strings.Contains(s, "test") { |
| 93 | + t.Fatal("should preserve name") |
| 94 | + } |
| 95 | +} |
0 commit comments