|
100 | 100 | results (f.context/all-contexts "readme" db* config) |
101 | 101 | file-paths (->> results (filter #(= "file" (:type %))) (map :path) set)] |
102 | 102 | (is (contains? file-paths readme))))))) |
| 103 | + |
| 104 | +(deftest relative-path-query-test |
| 105 | + (testing "./relative path lists entries in that directory (no glob)" |
| 106 | + (let [root (h/file-path "/fake/repo") |
| 107 | + rel (str root "/./src") |
| 108 | + entries [(str rel "/a.clj") (str rel "/pkg")] |
| 109 | + db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]})] |
| 110 | + (with-redefs [fs/glob (fn [& _] (throw (ex-info "glob should not be called for relative paths" {}))) |
| 111 | + fs/file (fn [& parts] (string/join "/" parts)) |
| 112 | + fs/exists? (fn [p] (= p rel)) |
| 113 | + fs/list-dir (fn [p] |
| 114 | + (is (= p rel)) |
| 115 | + entries) |
| 116 | + fs/parent (fn [_] (throw (ex-info "parent should not be used when path exists" {}))) |
| 117 | + fs/directory? (fn [p] (string/ends-with? (str p) "/pkg")) |
| 118 | + fs/canonicalize identity |
| 119 | + f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
| 120 | + f.mcp/all-resources (fn [_] [])] |
| 121 | + (let [result (f.context/all-contexts "./src" db* {})] |
| 122 | + ;; Root directory present |
| 123 | + (is (some #(= {:type "directory" :path root} %) result)) |
| 124 | + ;; Entries mapped from the relative listing |
| 125 | + (is (some #(= {:type "file" :path (str rel "/a.clj")} %) result)) |
| 126 | + (is (some #(= {:type "directory" :path (str rel "/pkg")} %) result)))))) |
| 127 | + |
| 128 | + (testing "./relative path falls back to parent directory when non-existent" |
| 129 | + (let [root (h/file-path "/fake/repo") |
| 130 | + rel (str root "/./missing/file") |
| 131 | + parent (str root "/./missing") |
| 132 | + entries [(str parent "/x.txt") (str parent "/subdir")] |
| 133 | + db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]})] |
| 134 | + (with-redefs [fs/glob (fn [& _] (throw (ex-info "glob should not be called for relative paths" {}))) |
| 135 | + fs/file (fn [& parts] (string/join "/" parts)) |
| 136 | + fs/exists? (fn [p] (= p "exists-nowhere")) ;; ensure rel does not exist |
| 137 | + fs/list-dir (fn [p] |
| 138 | + (is (= p parent)) |
| 139 | + entries) |
| 140 | + fs/parent (fn [p] |
| 141 | + (is (= p rel)) |
| 142 | + parent) |
| 143 | + fs/directory? (fn [p] (string/ends-with? (str p) "/subdir")) |
| 144 | + fs/canonicalize identity |
| 145 | + f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
| 146 | + f.mcp/all-resources (fn [_] [])] |
| 147 | + (let [result (f.context/all-contexts "./missing/file" db* {})] |
| 148 | + ;; Root directory present |
| 149 | + (is (some #(= {:type "directory" :path root} %) result)) |
| 150 | + ;; Entries mapped from the parent listing |
| 151 | + (is (some #(= {:type "file" :path (str parent "/x.txt")} %) result)) |
| 152 | + (is (some #(= {:type "directory" :path (str parent "/subdir")} %) result)))))) |
| 153 | + |
| 154 | + (testing "~ expands to home and lists entries" |
| 155 | + (let [root (h/file-path "/fake/repo") |
| 156 | + home "/home/tester" |
| 157 | + entries [(str home "/.bashrc") (str home "/projects")] |
| 158 | + db* (atom {:workspace-folders [{:uri (h/file-uri "file:///fake/repo")}]})] |
| 159 | + (with-redefs [fs/glob (fn [& _] (throw (ex-info "glob should not be called for ~ paths" {}))) |
| 160 | + fs/file (fn [& parts] (string/join "/" parts)) |
| 161 | + fs/expand-home (fn [p] |
| 162 | + (is (= p "~")) |
| 163 | + home) |
| 164 | + fs/exists? (fn [p] (= p home)) |
| 165 | + fs/list-dir (fn [p] |
| 166 | + (is (= p home)) |
| 167 | + entries) |
| 168 | + fs/directory? (fn [p] (string/ends-with? (str p) "/projects")) |
| 169 | + fs/canonicalize identity |
| 170 | + f.index/filter-allowed (fn [file-paths _root _config] file-paths) |
| 171 | + f.mcp/all-resources (fn [_] [])] |
| 172 | + (let [result (f.context/all-contexts "~" db* {})] |
| 173 | + ;; Root directory present |
| 174 | + (is (some #(= {:type "directory" :path root} %) result)) |
| 175 | + ;; Entries from home listing |
| 176 | + (is (some #(= {:type "file" :path (str home "/.bashrc")} %) result)) |
| 177 | + (is (some #(= {:type "directory" :path (str home "/projects")} %) result))))))) |
0 commit comments