|
7 | 7 | [eca.features.index :as f.index] |
8 | 8 | [eca.features.tools.mcp :as f.mcp] |
9 | 9 | [eca.llm-api :as llm-api] |
10 | | - [eca.shared :refer [multi-str]] |
| 10 | + [eca.shared :as shared :refer [multi-str]] |
11 | 11 | [eca.test-helper :as h] |
12 | 12 | [matcher-combinators.matchers :as m] |
13 | 13 | [matcher-combinators.test :refer [match?]])) |
|
338 | 338 | :content a-content}]) |
339 | 339 | (#'f.context/parse-agents-file a-file)))))) |
340 | 340 |
|
| 341 | +(deftest agents-file-contexts-test |
| 342 | + (testing "Flag disabled: only the workspace's own AGENTS.md plus global" |
| 343 | + (h/reset-components!) |
| 344 | + (let [ws "/a/b/c/d" |
| 345 | + ws-agents (str ws "/AGENTS.md") |
| 346 | + global-dir "/global" |
| 347 | + global-agents (str global-dir "/AGENTS.md") |
| 348 | + readable #{ws-agents global-agents}] |
| 349 | + (swap! (h/db*) assoc :workspace-folders [{:uri "file:///a/b/c/d"}]) |
| 350 | + (with-redefs [shared/uri->filename (constantly ws) |
| 351 | + shared/global-config-dir (constantly global-dir) |
| 352 | + fs/canonicalize identity |
| 353 | + fs/path (fn [& parts] (string/join "/" (map str parts))) |
| 354 | + fs/readable? (fn [p] (contains? readable (str p))) |
| 355 | + llm-api/refine-file-context (constantly "content")] |
| 356 | + (is (match? |
| 357 | + [{:type :agents-file :path ws-agents :content "content"} |
| 358 | + {:type :agents-file :path global-agents :content "content"}] |
| 359 | + (f.context/agents-file-contexts (h/db) {:includeParentAgentsFiles false})))))) |
| 360 | + |
| 361 | + (testing "Flag enabled: parents emitted outermost first, then workspace, then global" |
| 362 | + (h/reset-components!) |
| 363 | + (let [ws "/a/b/c/d" |
| 364 | + parent-ab-agents "/a/b/AGENTS.md" |
| 365 | + parent-abc-agents "/a/b/c/AGENTS.md" |
| 366 | + global-dir "/global" |
| 367 | + global-agents (str global-dir "/AGENTS.md") |
| 368 | + readable #{parent-ab-agents parent-abc-agents global-agents} |
| 369 | + parent-map {"/a/b/c/d" "/a/b/c" |
| 370 | + "/a/b/c" "/a/b" |
| 371 | + "/a/b" "/a" |
| 372 | + "/a" "/" |
| 373 | + "/" nil}] |
| 374 | + (swap! (h/db*) assoc :workspace-folders [{:uri "file:///a/b/c/d"}]) |
| 375 | + (with-redefs [shared/uri->filename (constantly ws) |
| 376 | + shared/global-config-dir (constantly global-dir) |
| 377 | + fs/canonicalize identity |
| 378 | + fs/parent (fn [p] (get parent-map (str p))) |
| 379 | + fs/path (fn [& parts] (string/join "/" (map str parts))) |
| 380 | + fs/readable? (fn [p] (contains? readable (str p))) |
| 381 | + llm-api/refine-file-context (constantly "content")] |
| 382 | + (is (match? |
| 383 | + [{:type :agents-file :path parent-ab-agents :content "content"} |
| 384 | + {:type :agents-file :path parent-abc-agents :content "content"} |
| 385 | + {:type :agents-file :path global-agents :content "content"}] |
| 386 | + (f.context/agents-file-contexts (h/db) {:includeParentAgentsFiles true})))))) |
| 387 | + |
| 388 | + (testing "Flag enabled but no parent has AGENTS.md: behaves like disabled" |
| 389 | + (h/reset-components!) |
| 390 | + (let [ws "/a/b/c/d" |
| 391 | + ws-agents (str ws "/AGENTS.md") |
| 392 | + global-dir "/global" |
| 393 | + global-agents (str global-dir "/AGENTS.md") |
| 394 | + readable #{ws-agents global-agents} |
| 395 | + parent-map {"/a/b/c/d" "/a/b/c" |
| 396 | + "/a/b/c" "/a/b" |
| 397 | + "/a/b" "/a" |
| 398 | + "/a" "/" |
| 399 | + "/" nil}] |
| 400 | + (swap! (h/db*) assoc :workspace-folders [{:uri "file:///a/b/c/d"}]) |
| 401 | + (with-redefs [shared/uri->filename (constantly ws) |
| 402 | + shared/global-config-dir (constantly global-dir) |
| 403 | + fs/canonicalize identity |
| 404 | + fs/parent (fn [p] (get parent-map (str p))) |
| 405 | + fs/path (fn [& parts] (string/join "/" (map str parts))) |
| 406 | + fs/readable? (fn [p] (contains? readable (str p))) |
| 407 | + llm-api/refine-file-context (constantly "content")] |
| 408 | + (is (match? |
| 409 | + [{:type :agents-file :path ws-agents :content "content"} |
| 410 | + {:type :agents-file :path global-agents :content "content"}] |
| 411 | + (f.context/agents-file-contexts (h/db) {:includeParentAgentsFiles true})))))) |
| 412 | + |
| 413 | + (testing "Two nested workspaces share ancestors via dedup" |
| 414 | + (h/reset-components!) |
| 415 | + (let [a-agents "/a/AGENTS.md" |
| 416 | + ab-agents "/a/b/AGENTS.md" |
| 417 | + abc-agents "/a/b/c/AGENTS.md" |
| 418 | + global-dir "/global" |
| 419 | + global-agents (str global-dir "/AGENTS.md") |
| 420 | + readable #{a-agents ab-agents abc-agents global-agents} |
| 421 | + parent-map {"/a/b/c/d" "/a/b/c" |
| 422 | + "/a/b/c" "/a/b" |
| 423 | + "/a/b" "/a" |
| 424 | + "/a" "/" |
| 425 | + "/" nil} |
| 426 | + uri->filename-map {"file:///a/b" "/a/b" |
| 427 | + "file:///a/b/c/d" "/a/b/c/d"}] |
| 428 | + (swap! (h/db*) assoc :workspace-folders [{:uri "file:///a/b"} |
| 429 | + {:uri "file:///a/b/c/d"}]) |
| 430 | + (with-redefs [shared/uri->filename (fn [u] (get uri->filename-map u)) |
| 431 | + shared/global-config-dir (constantly global-dir) |
| 432 | + fs/canonicalize identity |
| 433 | + fs/parent (fn [p] (get parent-map (str p))) |
| 434 | + fs/path (fn [& parts] (string/join "/" (map str parts))) |
| 435 | + fs/readable? (fn [p] (contains? readable (str p))) |
| 436 | + llm-api/refine-file-context (constantly "content")] |
| 437 | + (is (match? |
| 438 | + [{:type :agents-file :path a-agents} |
| 439 | + {:type :agents-file :path ab-agents} |
| 440 | + {:type :agents-file :path abc-agents} |
| 441 | + {:type :agents-file :path global-agents}] |
| 442 | + (f.context/agents-file-contexts (h/db) {:includeParentAgentsFiles true})))))) |
| 443 | + |
| 444 | + (testing "Workspace at filesystem root: no parent walk" |
| 445 | + (h/reset-components!) |
| 446 | + (let [ws "/" |
| 447 | + ws-agents "//AGENTS.md" |
| 448 | + global-dir "/global" |
| 449 | + global-agents (str global-dir "/AGENTS.md") |
| 450 | + readable #{ws-agents global-agents} |
| 451 | + parent-map {"/" nil}] |
| 452 | + (swap! (h/db*) assoc :workspace-folders [{:uri "file:///"}]) |
| 453 | + (with-redefs [shared/uri->filename (constantly ws) |
| 454 | + shared/global-config-dir (constantly global-dir) |
| 455 | + fs/canonicalize identity |
| 456 | + fs/parent (fn [p] (get parent-map (str p))) |
| 457 | + fs/path (fn [& parts] (string/join "/" (map str parts))) |
| 458 | + fs/readable? (fn [p] (contains? readable (str p))) |
| 459 | + llm-api/refine-file-context (constantly "content")] |
| 460 | + (is (match? |
| 461 | + [{:type :agents-file :path ws-agents} |
| 462 | + {:type :agents-file :path global-agents}] |
| 463 | + (f.context/agents-file-contexts (h/db) {:includeParentAgentsFiles true}))))))) |
| 464 | + |
341 | 465 | (deftest contexts-str-from-prompt-test |
342 | 466 | (testing "not context mention" |
343 | 467 | (is (match? |
|
0 commit comments