Skip to content

Commit

Permalink
Add a test ensuring correct mode of index dir
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jul 10, 2024
1 parent bc082b5 commit d01bac1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ def __init__(self, *args, **kwargs):
self.metadata = IndexMetadata(dirs=[])
self.prev_em_id = None

self._ensure_dirs()
self._load()

def _ensure_dirs(self):
if not os.path.exists(INDEX_SAVE_DIR):
os.makedirs(INDEX_SAVE_DIR)

self._load()

def _load(self):
"""Loads the vector store."""
if self.index is not None:
Expand Down
21 changes: 21 additions & 0 deletions packages/jupyter-ai/jupyter_ai/tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import os
import stat
from unittest import mock

from jupyter_ai.chat_handlers import learn


class MockLearnHandler(learn.LearnChatHandler):
def __init__(self):
pass


def test_learn_index_permissions(tmp_path):
test_dir = tmp_path / "test"
with mock.patch.object(learn, "INDEX_SAVE_DIR", new=test_dir):
handler = MockLearnHandler()
handler._ensure_dirs()
mode = os.stat(test_dir).st_mode
assert stat.filemode(mode) == "drwx------"


# TODO
# import json

Expand Down

0 comments on commit d01bac1

Please sign in to comment.