|
6 | 6 | [eca.features.context :as f.context] |
7 | 7 | [eca.features.index :as f.index] |
8 | 8 | [eca.features.tools.mcp :as f.mcp] |
| 9 | + [eca.llm-api :as llm-api] |
| 10 | + [eca.shared :refer [multi-str]] |
9 | 11 | [eca.test-helper :as h] |
10 | | - [matcher-combinators.test :refer [match?]])) |
| 12 | + [matcher-combinators.test :refer [match?]] |
| 13 | + [matcher-combinators.matchers :as m])) |
11 | 14 |
|
12 | 15 | (h/reset-components-before-test) |
13 | 16 |
|
|
182 | 185 | ;; Entries from home listing |
183 | 186 | (is (some #(= {:type "file" :path (str home "/.bashrc")} %) result)) |
184 | 187 | (is (some #(= {:type "directory" :path (str home "/projects")} %) result))))))) |
| 188 | + |
| 189 | +(deftest parse-agents-file-test |
| 190 | + (testing "simple agents file with no path inclusion" |
| 191 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 192 | + a-content (multi-str |
| 193 | + "- do foo")] |
| 194 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 195 | + (condp = p |
| 196 | + a-file a-content))] |
| 197 | + (is (match? |
| 198 | + (m/in-any-order |
| 199 | + [{:type :agents-file |
| 200 | + :path a-file |
| 201 | + :content a-content}]) |
| 202 | + (#'f.context/parse-agents-file a-file)))))) |
| 203 | + (testing "Single relative path inclusion" |
| 204 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 205 | + a-content (multi-str |
| 206 | + "- do foo" |
| 207 | + "- follow @b.md") |
| 208 | + b-file (h/file-path "/fake/b.md") |
| 209 | + b-content (multi-str |
| 210 | + "- do bar")] |
| 211 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 212 | + (condp = p |
| 213 | + a-file a-content |
| 214 | + b-file b-content))] |
| 215 | + (is (match? |
| 216 | + (m/in-any-order |
| 217 | + [{:type :agents-file |
| 218 | + :path a-file |
| 219 | + :content a-content} |
| 220 | + {:type :agents-file |
| 221 | + :path b-file |
| 222 | + :content b-content}]) |
| 223 | + (#'f.context/parse-agents-file a-file)))))) |
| 224 | + (testing "Single absolute path inclusion" |
| 225 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 226 | + a-content (multi-str |
| 227 | + "- do foo" |
| 228 | + "@/fake/src/b.md is where the nice things live") |
| 229 | + b-file (h/file-path "/fake/src/b.md") |
| 230 | + b-content (multi-str |
| 231 | + "- do bar")] |
| 232 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 233 | + (condp = p |
| 234 | + a-file a-content |
| 235 | + b-file b-content))] |
| 236 | + (is (match? |
| 237 | + (m/in-any-order |
| 238 | + [{:type :agents-file |
| 239 | + :path a-file |
| 240 | + :content a-content} |
| 241 | + {:type :agents-file |
| 242 | + :path b-file |
| 243 | + :content b-content}]) |
| 244 | + (#'f.context/parse-agents-file a-file)))))) |
| 245 | + (testing "Multiple path inclusions with different extensions" |
| 246 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 247 | + a-content (multi-str |
| 248 | + "- do foo" |
| 249 | + "- check @./src/b.md for b things" |
| 250 | + "- also follow @../c.txt") |
| 251 | + b-file (h/file-path "/fake/src/b.md") |
| 252 | + b-content (multi-str |
| 253 | + "- do bar") |
| 254 | + c-file (h/file-path "/c.txt") |
| 255 | + c-content (multi-str |
| 256 | + "- do bazzz")] |
| 257 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 258 | + (condp = p |
| 259 | + a-file a-content |
| 260 | + b-file b-content |
| 261 | + c-file c-content))] |
| 262 | + (is (match? |
| 263 | + (m/in-any-order |
| 264 | + [{:type :agents-file |
| 265 | + :path a-file |
| 266 | + :content a-content} |
| 267 | + {:type :agents-file |
| 268 | + :path b-file |
| 269 | + :content b-content} |
| 270 | + {:type :agents-file |
| 271 | + :path c-file |
| 272 | + :content c-content}]) |
| 273 | + (#'f.context/parse-agents-file a-file)))))) |
| 274 | + (testing "Recursive path inclusions" |
| 275 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 276 | + a-content (multi-str |
| 277 | + "- do foo" |
| 278 | + "- check @b.md for b things") |
| 279 | + b-file (h/file-path "/fake/b.md") |
| 280 | + b-content (multi-str |
| 281 | + "- check @../c.md") |
| 282 | + c-file (h/file-path "/c.md") |
| 283 | + c-content (multi-str |
| 284 | + "- do bazzz")] |
| 285 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 286 | + (condp = p |
| 287 | + a-file a-content |
| 288 | + b-file b-content |
| 289 | + c-file c-content))] |
| 290 | + (is (match? |
| 291 | + (m/in-any-order |
| 292 | + [{:type :agents-file |
| 293 | + :path a-file |
| 294 | + :content a-content} |
| 295 | + {:type :agents-file |
| 296 | + :path b-file |
| 297 | + :content b-content} |
| 298 | + {:type :agents-file |
| 299 | + :path c-file |
| 300 | + :content c-content}]) |
| 301 | + (#'f.context/parse-agents-file a-file)))))) |
| 302 | + (testing "Multiple mentions to same file include it once" |
| 303 | + (let [a-file (h/file-path "/fake/AGENTS.md") |
| 304 | + a-content (multi-str |
| 305 | + "- do foo" |
| 306 | + "- check @b.md for b things" |
| 307 | + "- make sure you check @b.md for sure") |
| 308 | + b-file (h/file-path "/fake/b.md") |
| 309 | + b-content (multi-str |
| 310 | + "- yeah")] |
| 311 | + (with-redefs [llm-api/refine-file-context (fn [p _l] |
| 312 | + (condp = p |
| 313 | + a-file a-content |
| 314 | + b-file b-content))] |
| 315 | + (is (match? |
| 316 | + (m/in-any-order |
| 317 | + [{:type :agents-file |
| 318 | + :path a-file |
| 319 | + :content a-content} |
| 320 | + {:type :agents-file |
| 321 | + :path b-file |
| 322 | + :content b-content}]) |
| 323 | + (#'f.context/parse-agents-file a-file))))))) |
0 commit comments