@@ -675,6 +675,36 @@ everything is cleaned up afterward."
675675 (ai-code-context-action '(4 ))
676676 (should completing-read-called))))
677677
678+ (ert-deftest ai-code-test-add-context-allows-non-git-file-for-existing-repo-context ()
679+ " Test `ai-code-add-context' can add a non-git file to an existing repo context."
680+ (let ((ai-code--repo-context-info (make-hash-table :test #'equal ))
681+ (repo-root " /tmp/existing-repo/" )
682+ (new-file (make-temp-file " ai-code-context-" )))
683+ (unwind-protect
684+ (with-temp-buffer
685+ (setq buffer-file-name new-file)
686+ (puthash repo-root
687+ '(" /tmp/existing-repo/lib/existing-context.el" )
688+ ai-code--repo-context-info)
689+ (cl-letf (((symbol-function 'ai-code--git-root )
690+ (lambda (&optional _dir ) nil ))
691+ ((symbol-function 'walk-windows )
692+ (lambda (&rest _args ) nil ))
693+ ((symbol-function 'completing-read )
694+ (lambda (_prompt collection &rest _args )
695+ (should (equal collection (list repo-root)))
696+ repo-root))
697+ ((symbol-function 'derived-mode-p )
698+ (lambda (&rest _args ) nil ))
699+ ((symbol-function 'message )
700+ (lambda (&rest _args ) nil )))
701+ (ai-code-add-context)
702+ (should (equal (gethash repo-root ai-code--repo-context-info)
703+ (list new-file
704+ " /tmp/existing-repo/lib/existing-context.el" )))))
705+ (when (file-exists-p new-file)
706+ (delete-file new-file)))))
707+
678708(ert-deftest ai-code-test-build-or-test-project-dispatches-test-project ()
679709 " Test selecting \" Test project\" dispatches to `ai-code-test-project' ."
680710 (let ((test-project-called nil )
0 commit comments