Skip to content

Commit a6fa657

Browse files
committed
Fix tests
1 parent 527a5c3 commit a6fa657

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

src/eca/features/context.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
(map :uri)
127127
(map shared/uri->filename)
128128
(mapcat #(contexts-for % query config))
129-
(take 200) ;; for performance, user can always make query specific for better results.
129+
(take 100) ;; for performance, user can always make query specific for better results.
130130
(map file->context))
131131
(:workspace-folders @db*)))
132132
root-dirs (mapv (fn [{:keys [uri]}] {:type "directory"

test/eca/features/context_test.clj

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,67 @@
66
[eca.features.context :as f.context]
77
[eca.features.index :as f.index]
88
[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)
1013

1114
(deftest all-contexts-test
1215
(testing "includes repoMap, root directories, files/dirs, and mcp resources"
16+
(h/reset-components!)
1317
(let [root (h/file-path "/fake/repo")
1418
;; Fake filesystem entries under the root
1519
fake-paths [(str root "/dir")
1620
(str root "/foo.txt")
1721
(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]
2126
;; Very simple glob: filter by substring present in pattern ("**<q>**")
2227
(let [q (string/replace pattern #"\*" "")]
2328
(filter #(string/includes? (str %) q) fake-paths)))
2429
fs/directory? (fn [p] (string/ends-with? (str p) "/dir"))
25-
fs/canonicalize identity
2630
f.index/filter-allowed (fn [file-paths _root _config] file-paths)
2731
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)))))))
3942

4043
(testing "respects the query by limiting glob results"
44+
(h/reset-components!)
4145
(let [root (h/file-path "/fake/repo")
4246
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]
4651
(let [q (string/replace pattern #"\*" "")]
4752
(filter #(string/includes? (str %) q) fake-paths)))
4853
fs/directory? (constantly false)
4954
fs/canonicalize identity
5055
f.index/filter-allowed (fn [file-paths _root _config] file-paths)
5156
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*) {})]
5358
;; Should include foo.txt but not bar.txt
5459
(is (some #(= {:type "file" :path (str root "/foo.txt")} %) result))
5560
(is (not (some #(= {:type "file" :path (str root "/bar.txt")} %) result)))))))
5661

5762
(testing "aggregates entries across multiple workspace roots"
63+
(h/reset-components!)
5864
(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]
6370
(let [q (string/replace pattern #"\*" "")]
6471
(cond
6572
(string/includes? (str root-filename) (h/file-path "/fake/repo1"))
@@ -75,7 +82,7 @@
7582
fs/canonicalize identity
7683
f.index/filter-allowed (fn [file-paths _root _config] file-paths)
7784
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*) {})]
7986
;; Root directories present
8087
(is (some #(= {:type "directory" :path root1} %) result))
8188
(is (some #(= {:type "directory" :path root2} %) result))

0 commit comments

Comments
 (0)