|
378 | 378 | ((get-in f.tools.filesystem/definitions ["eca_move_file" :handler]) |
379 | 379 | {"source" (h/file-path "/foo/bar/some_file.clj") |
380 | 380 | "destination" (h/file-path "/foo/bar/other_file.clj")} |
381 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}}))))) |
| 381 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))))) |
382 | 382 |
|
383 | | - (deftest preview-file-change-test |
384 | | - (testing "Preview does not modify files" |
385 | | - (let [spit-called* (atom false) |
386 | | - original-file-content "line1\nline2\nline3"] |
387 | | - (is (match? |
388 | | - {:error false |
389 | | - :contents [{:type :text |
390 | | - :text (format "Change simulation completed for %s. Original file unchanged - preview only." (h/file-path "/foo/bar/my-file.txt"))}]} |
391 | | - (with-redefs [fs/exists? (constantly true) |
392 | | - fs/readable? (constantly true) |
393 | | - f.tools.filesystem/allowed-path? (constantly true) |
394 | | - slurp (constantly original-file-content) |
395 | | - spit (fn [& _] (reset! spit-called* true))] |
396 | | - ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
397 | | - {"path" (h/file-path "/foo/bar/my-file.txt") |
398 | | - "original_content" "line2" |
399 | | - "new_content" "modified line2"} |
400 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
| 383 | +(deftest preview-file-change-test |
| 384 | + (testing "Preview does not modify files" |
| 385 | + (let [spit-called* (atom false) |
| 386 | + original-file-content "line1\nline2\nline3"] |
| 387 | + (is (match? |
| 388 | + {:error false |
| 389 | + :contents [{:type :text |
| 390 | + :text (format "Change simulation completed for %s. Original file unchanged - preview only." (h/file-path "/foo/bar/my-file.txt"))}]} |
| 391 | + (with-redefs [fs/exists? (constantly true) |
| 392 | + fs/readable? (constantly true) |
| 393 | + f.tools.filesystem/allowed-path? (constantly true) |
| 394 | + slurp (constantly original-file-content) |
| 395 | + spit (fn [& _] (reset! spit-called* true))] |
| 396 | + ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
| 397 | + {"path" (h/file-path "/foo/bar/my-file.txt") |
| 398 | + "original_content" "line2" |
| 399 | + "new_content" "modified line2"} |
| 400 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
401 | 401 | ;; Verify that spit was never called (no file modification) |
402 | | - (is (false? @spit-called*)))) |
| 402 | + (is (false? @spit-called*)))) |
403 | 403 |
|
404 | | - (testing "Preview handles content not found" |
405 | | - (let [spit-called* (atom false)] |
406 | | - (is (match? |
407 | | - {:error true |
408 | | - :contents [{:type :text |
409 | | - :text (format "Original content not found in %s" (h/file-path "/foo/bar/my-file.txt"))}]} |
410 | | - (with-redefs [fs/exists? (constantly true) |
411 | | - fs/readable? (constantly true) |
412 | | - f.tools.filesystem/allowed-path? (constantly true) |
413 | | - slurp (constantly "line1\nline2\nline3") |
414 | | - spit (fn [& _] (reset! spit-called* true))] |
415 | | - ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
416 | | - {"path" (h/file-path "/foo/bar/my-file.txt") |
417 | | - "original_content" "notfound" |
418 | | - "new_content" "new"} |
419 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
| 404 | + (testing "Preview handles content not found" |
| 405 | + (let [spit-called* (atom false)] |
| 406 | + (is (match? |
| 407 | + {:error true |
| 408 | + :contents [{:type :text |
| 409 | + :text (format "Original content not found in %s" (h/file-path "/foo/bar/my-file.txt"))}]} |
| 410 | + (with-redefs [fs/exists? (constantly true) |
| 411 | + fs/readable? (constantly true) |
| 412 | + f.tools.filesystem/allowed-path? (constantly true) |
| 413 | + slurp (constantly "line1\nline2\nline3") |
| 414 | + spit (fn [& _] (reset! spit-called* true))] |
| 415 | + ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
| 416 | + {"path" (h/file-path "/foo/bar/my-file.txt") |
| 417 | + "original_content" "notfound" |
| 418 | + "new_content" "new"} |
| 419 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
420 | 420 | ;; Verify that spit was never called even for error case |
421 | | - (is (false? @spit-called*)))) |
| 421 | + (is (false? @spit-called*)))) |
422 | 422 |
|
423 | | - (testing "Preview succeeds for new file creation (empty original content)" |
424 | | - (let [spit-called* (atom false)] |
425 | | - (is (match? |
426 | | - {:error false |
427 | | - :contents [{:type :text |
428 | | - :text (format "New file creation simulation completed for %s. File will be created - preview only." (h/file-path "/foo/bar/new-file.txt"))}]} |
429 | | - (with-redefs [fs/exists? (constantly false) ; File doesn't exist |
430 | | - f.tools.filesystem/allowed-path? (constantly true) |
431 | | - spit (fn [& _] (reset! spit-called* true))] |
432 | | - ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
433 | | - {"path" (h/file-path "/foo/bar/new-file.txt") |
434 | | - "original_content" "" ; Empty for new file |
435 | | - "new_content" "New file content"} |
436 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
| 423 | + (testing "Preview succeeds for new file creation (empty original content)" |
| 424 | + (let [spit-called* (atom false)] |
| 425 | + (is (match? |
| 426 | + {:error false |
| 427 | + :contents [{:type :text |
| 428 | + :text (format "New file creation simulation completed for %s. File will be created - preview only." (h/file-path "/foo/bar/new-file.txt"))}]} |
| 429 | + (with-redefs [fs/exists? (constantly false) ; File doesn't exist |
| 430 | + f.tools.filesystem/allowed-path? (constantly true) |
| 431 | + spit (fn [& _] (reset! spit-called* true))] |
| 432 | + ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
| 433 | + {"path" (h/file-path "/foo/bar/new-file.txt") |
| 434 | + "original_content" "" ; Empty for new file |
| 435 | + "new_content" "New file content"} |
| 436 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
437 | 437 | ;; Verify that spit was never called (no file modification) |
438 | | - (is (false? @spit-called*)))) |
| 438 | + (is (false? @spit-called*)))) |
439 | 439 |
|
440 | | - (testing "Preview fails when trying to find content in non-existent file" |
441 | | - (let [spit-called* (atom false)] |
442 | | - (is (match? |
443 | | - {:error true |
444 | | - :contents [{:type :text |
445 | | - :text (format "Preview error for %s: For new files, original_content must be empty string (\"\"). Use markdown blocks during exploration, then eca_preview_file_change for final implementation only." (h/file-path "/foo/bar/missing-file.txt"))}]} |
446 | | - (with-redefs [fs/exists? (constantly false) ; File doesn't exist |
447 | | - f.tools.filesystem/allowed-path? (constantly true) |
448 | | - spit (fn [& _] (reset! spit-called* true))] |
449 | | - ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
450 | | - {"path" (h/file-path "/foo/bar/missing-file.txt") |
451 | | - "original_content" "some content" ; Non-empty for non-existent file |
452 | | - "new_content" "replacement content"} |
453 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
| 440 | + (testing "Preview fails when trying to find content in non-existent file" |
| 441 | + (let [spit-called* (atom false)] |
| 442 | + (is (match? |
| 443 | + {:error true |
| 444 | + :contents [{:type :text |
| 445 | + :text (format "Preview error for %s: For new files, original_content must be empty string (\"\"). Use markdown blocks during exploration, then eca_preview_file_change for final implementation only." (h/file-path "/foo/bar/missing-file.txt"))}]} |
| 446 | + (with-redefs [fs/exists? (constantly false) ; File doesn't exist |
| 447 | + f.tools.filesystem/allowed-path? (constantly true) |
| 448 | + spit (fn [& _] (reset! spit-called* true))] |
| 449 | + ((get-in f.tools.filesystem/definitions ["eca_preview_file_change" :handler]) |
| 450 | + {"path" (h/file-path "/foo/bar/missing-file.txt") |
| 451 | + "original_content" "some content" ; Non-empty for non-existent file |
| 452 | + "new_content" "replacement content"} |
| 453 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar") :name "foo"}]}})))) |
454 | 454 | ;; Verify that spit was never called |
455 | | - (is (false? @spit-called*)))))) |
| 455 | + (is (false? @spit-called*))))) |
0 commit comments