|
| 1 | +package internal |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestFilterRegistry_EmptyRegistry(t *testing.T) { |
| 8 | + registry := Registry{Docs: []RegistryDoc{}, Skills: []RegistrySkill{}} |
| 9 | + session := SessionState{} |
| 10 | + |
| 11 | + got := filterRegistry(registry, session) |
| 12 | + |
| 13 | + if len(got.Docs) != 0 { |
| 14 | + t.Errorf("expected 0 docs, got %d", len(got.Docs)) |
| 15 | + } |
| 16 | + if len(got.Skills) != 0 { |
| 17 | + t.Errorf("expected 0 skills, got %d", len(got.Skills)) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func TestFilterRegistry_ExcludesDocsInSession(t *testing.T) { |
| 22 | + registry := Registry{ |
| 23 | + Docs: []RegistryDoc{ |
| 24 | + {Path: "docs/a.md", Summary: "doc a"}, |
| 25 | + {Path: "docs/b.md", Summary: "doc b"}, |
| 26 | + }, |
| 27 | + Skills: []RegistrySkill{}, |
| 28 | + } |
| 29 | + session := SessionState{ |
| 30 | + DocsRead: []string{"docs/a.md"}, |
| 31 | + } |
| 32 | + |
| 33 | + got := filterRegistry(registry, session) |
| 34 | + |
| 35 | + if len(got.Docs) != 1 { |
| 36 | + t.Fatalf("expected 1 doc, got %d", len(got.Docs)) |
| 37 | + } |
| 38 | + if got.Docs[0].Path != "docs/b.md" { |
| 39 | + t.Errorf("expected docs/b.md, got %s", got.Docs[0].Path) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestFilterRegistry_ExcludesSkillsInSession(t *testing.T) { |
| 44 | + registry := Registry{ |
| 45 | + Docs: []RegistryDoc{}, |
| 46 | + Skills: []RegistrySkill{{Name: "deploy", Description: "deploy skill"}, {Name: "test", Description: "test skill"}}, |
| 47 | + } |
| 48 | + session := SessionState{ |
| 49 | + SkillsUsed: []string{"deploy"}, |
| 50 | + } |
| 51 | + |
| 52 | + got := filterRegistry(registry, session) |
| 53 | + |
| 54 | + if len(got.Skills) != 1 { |
| 55 | + t.Fatalf("expected 1 skill, got %d", len(got.Skills)) |
| 56 | + } |
| 57 | + if got.Skills[0].Name != "test" { |
| 58 | + t.Errorf("expected test skill, got %s", got.Skills[0].Name) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +func TestFilterRegistry_KeepsItemsNotInSession(t *testing.T) { |
| 63 | + registry := Registry{ |
| 64 | + Docs: []RegistryDoc{{Path: "docs/a.md", Summary: "doc a"}}, |
| 65 | + Skills: []RegistrySkill{{Name: "build", Description: "build skill"}}, |
| 66 | + } |
| 67 | + session := SessionState{ |
| 68 | + DocsRead: []string{"docs/other.md"}, |
| 69 | + SkillsUsed: []string{"other-skill"}, |
| 70 | + } |
| 71 | + |
| 72 | + got := filterRegistry(registry, session) |
| 73 | + |
| 74 | + if len(got.Docs) != 1 { |
| 75 | + t.Errorf("expected 1 doc kept, got %d", len(got.Docs)) |
| 76 | + } |
| 77 | + if len(got.Skills) != 1 { |
| 78 | + t.Errorf("expected 1 skill kept, got %d", len(got.Skills)) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +func TestFilterRegistry_MixedExcludeAndKeep(t *testing.T) { |
| 83 | + registry := Registry{ |
| 84 | + Docs: []RegistryDoc{ |
| 85 | + {Path: "docs/keep.md", Summary: "keep"}, |
| 86 | + {Path: "docs/drop.md", Summary: "drop"}, |
| 87 | + {Path: "docs/also-keep.md", Summary: "also keep"}, |
| 88 | + }, |
| 89 | + Skills: []RegistrySkill{ |
| 90 | + {Name: "keep-skill", Description: "kept"}, |
| 91 | + {Name: "drop-skill", Description: "dropped"}, |
| 92 | + }, |
| 93 | + } |
| 94 | + session := SessionState{ |
| 95 | + DocsRead: []string{"docs/drop.md"}, |
| 96 | + SkillsUsed: []string{"drop-skill"}, |
| 97 | + } |
| 98 | + |
| 99 | + got := filterRegistry(registry, session) |
| 100 | + |
| 101 | + if len(got.Docs) != 2 { |
| 102 | + t.Fatalf("expected 2 docs, got %d", len(got.Docs)) |
| 103 | + } |
| 104 | + if got.Docs[0].Path != "docs/keep.md" || got.Docs[1].Path != "docs/also-keep.md" { |
| 105 | + t.Errorf("unexpected docs: %v, %v", got.Docs[0].Path, got.Docs[1].Path) |
| 106 | + } |
| 107 | + if len(got.Skills) != 1 { |
| 108 | + t.Fatalf("expected 1 skill, got %d", len(got.Skills)) |
| 109 | + } |
| 110 | + if got.Skills[0].Name != "keep-skill" { |
| 111 | + t.Errorf("expected keep-skill, got %s", got.Skills[0].Name) |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +func TestRoute_EmptyRegistryReturnsSkipReason(t *testing.T) { |
| 116 | + input := RouteInput{ |
| 117 | + Messages: []Message{{Type: "user", Text: "hello"}}, |
| 118 | + Registry: Registry{Docs: []RegistryDoc{}, Skills: []RegistrySkill{}}, |
| 119 | + Session: SessionState{}, |
| 120 | + } |
| 121 | + |
| 122 | + result, _, _, _, skipReason, err := Route(input, DefaultConfig()) |
| 123 | + |
| 124 | + if err != nil { |
| 125 | + t.Fatalf("unexpected error: %v", err) |
| 126 | + } |
| 127 | + if skipReason != "no docs or skills in registry" { |
| 128 | + t.Errorf("expected skip reason 'no docs or skills in registry', got %q", skipReason) |
| 129 | + } |
| 130 | + if len(result.Docs) != 0 || len(result.Skills) != 0 { |
| 131 | + t.Errorf("expected empty result, got docs=%v skills=%v", result.Docs, result.Skills) |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +func TestRoute_AllItemsAlreadyInjectedReturnsSkipReason(t *testing.T) { |
| 136 | + input := RouteInput{ |
| 137 | + Messages: []Message{{Type: "user", Text: "hello"}}, |
| 138 | + Registry: Registry{ |
| 139 | + Docs: []RegistryDoc{{Path: "docs/a.md", Summary: "a"}}, |
| 140 | + Skills: []RegistrySkill{{Name: "build", Description: "build"}}, |
| 141 | + }, |
| 142 | + Session: SessionState{ |
| 143 | + DocsRead: []string{"docs/a.md"}, |
| 144 | + SkillsUsed: []string{"build"}, |
| 145 | + }, |
| 146 | + } |
| 147 | + |
| 148 | + result, _, _, _, skipReason, err := Route(input, DefaultConfig()) |
| 149 | + |
| 150 | + if err != nil { |
| 151 | + t.Fatalf("unexpected error: %v", err) |
| 152 | + } |
| 153 | + if skipReason != "all 2 item(s) already injected this session" { |
| 154 | + t.Errorf("expected skip reason about 2 items, got %q", skipReason) |
| 155 | + } |
| 156 | + if len(result.Docs) != 0 || len(result.Skills) != 0 { |
| 157 | + t.Errorf("expected empty result, got docs=%v skills=%v", result.Docs, result.Skills) |
| 158 | + } |
| 159 | +} |
0 commit comments