|
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.test-helper :as h])) |
| 9 | + [eca.test-helper :as h] |
| 10 | + [matcher-combinators.test :refer [match?]])) |
| 11 | + |
| 12 | +(h/reset-components-before-test) |
10 | 13 |
|
11 | 14 | (deftest all-contexts-test |
12 | 15 | (testing "includes repoMap, root directories, files/dirs, and mcp resources" |
| 16 | + (h/reset-components!) |
13 | 17 | (let [root (h/file-path "/fake/repo") |
14 | 18 | ;; Fake filesystem entries under the root |
15 | 19 | fake-paths [(str root "/dir") |
16 | 20 | (str root "/foo.txt") |
17 | 21 | (str root "/dir/nested.txt") |
18 | | - (str root "/bar.txt")] |
19 | | - db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]})] |
20 | | - (with-redefs [fs/glob (fn [_root-filename pattern] |
| 22 | + (str root "/bar.txt")]] |
| 23 | + (swap! (h/db*) assoc :workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]) |
| 24 | + (with-redefs [f.context/all-files-from #'f.context/all-files-from* |
| 25 | + fs/glob (fn [_root-filename pattern] |
21 | 26 | ;; Very simple glob: filter by substring present in pattern ("**<q>**") |
22 | 27 | (let [q (string/replace pattern #"\*" "")] |
23 | 28 | (filter #(string/includes? (str %) q) fake-paths))) |
24 | 29 | fs/directory? (fn [p] (string/ends-with? (str p) "/dir")) |
25 | | - fs/canonicalize identity |
26 | 30 | f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
27 | 31 | f.mcp/all-resources (fn [_db] [{:uri "mcp://r1"}])] |
28 | | - (let [result (f.context/all-contexts nil db* {})] |
29 | | - ;; Starts with repoMap |
30 | | - (is (= "repoMap" (:type (first result)))) |
31 | | - ;; Contains root directory entries |
32 | | - (is (some #(= {:type "directory" :path root} %) result)) |
33 | | - ;; Contains file and directory entries from the fake paths |
34 | | - (is (some #(= {:type "directory" :path (str root "/dir")} %) result)) |
35 | | - (is (some #(= {:type "file" :path (str root "/foo.txt")} %) result)) |
36 | | - (is (some #(= {:type "file" :path (str root "/dir/nested.txt")} %) result)) |
37 | | - ;; MCP resources appended with proper type |
38 | | - (is (some #(= {:type "mcpResource" :uri "mcp://r1"} %) result)))))) |
| 32 | + (is (match? |
| 33 | + [{:type "repoMap"} |
| 34 | + {:type "cursor"} |
| 35 | + {:type "directory" :path root} |
| 36 | + {:type "directory" :path (str root "/dir")} |
| 37 | + {:type "file" :path (str root "/foo.txt")} |
| 38 | + {:type "file" :path (str root "/dir/nested.txt")} |
| 39 | + {:type "file" :path (str root "/bar.txt")} |
| 40 | + {:type "mcpResource" :uri "mcp://r1"}] |
| 41 | + (f.context/all-contexts nil (h/db*) (h/config))))))) |
39 | 42 |
|
40 | 43 | (testing "respects the query by limiting glob results" |
| 44 | + (h/reset-components!) |
41 | 45 | (let [root (h/file-path "/fake/repo") |
42 | 46 | fake-paths [(str root "/foo.txt") |
43 | | - (str root "/bar.txt")] |
44 | | - db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]})] |
45 | | - (with-redefs [fs/glob (fn [_root-filename pattern] |
| 47 | + (str root "/bar.txt")]] |
| 48 | + (swap! (h/db*) assoc :workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]) |
| 49 | + (with-redefs [f.context/all-files-from #'f.context/all-files-from* |
| 50 | + fs/glob (fn [_root-filename pattern] |
46 | 51 | (let [q (string/replace pattern #"\*" "")] |
47 | 52 | (filter #(string/includes? (str %) q) fake-paths))) |
48 | 53 | fs/directory? (constantly false) |
49 | 54 | fs/canonicalize identity |
50 | 55 | f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
51 | 56 | f.mcp/all-resources (fn [_db] [])] |
52 | | - (let [result (f.context/all-contexts "foo" db* {})] |
| 57 | + (let [result (f.context/all-contexts "foo" (h/db*) {})] |
53 | 58 | ;; Should include foo.txt but not bar.txt |
54 | 59 | (is (some #(= {:type "file" :path (str root "/foo.txt")} %) result)) |
55 | 60 | (is (not (some #(= {:type "file" :path (str root "/bar.txt")} %) result))))))) |
56 | 61 |
|
57 | 62 | (testing "aggregates entries across multiple workspace roots" |
| 63 | + (h/reset-components!) |
58 | 64 | (let [root1 (h/file-path "/fake/repo1") |
59 | | - root2 (h/file-path "/fake/repo2") |
60 | | - db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo1")} |
61 | | - {:uri (h/file-uri "file:///fake/repo2")}]})] |
62 | | - (with-redefs [fs/glob (fn [root-filename pattern] |
| 65 | + root2 (h/file-path "/fake/repo2")] |
| 66 | + (swap! (h/db*) assoc :workspace-folders [{:uri (h/file-uri "file:///fake/repo1")} |
| 67 | + {:uri (h/file-uri "file:///fake/repo2")}]) |
| 68 | + (with-redefs [f.context/all-files-from #'f.context/all-files-from* |
| 69 | + fs/glob (fn [root-filename pattern] |
63 | 70 | (let [q (string/replace pattern #"\*" "")] |
64 | 71 | (cond |
65 | 72 | (string/includes? (str root-filename) (h/file-path "/fake/repo1")) |
|
75 | 82 | fs/canonicalize identity |
76 | 83 | f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
77 | 84 | f.mcp/all-resources (fn [_db] [])] |
78 | | - (let [result (f.context/all-contexts nil db* {})] |
| 85 | + (let [result (f.context/all-contexts nil (h/db*) {})] |
79 | 86 | ;; Root directories present |
80 | 87 | (is (some #(= {:type "directory" :path root1} %) result)) |
81 | 88 | (is (some #(= {:type "directory" :path root2} %) result)) |
|
0 commit comments