cognee 0.2.3.dev1__py3-none-any.whl → 0.3.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. cognee/__init__.py +1 -0
  2. cognee/__main__.py +4 -0
  3. cognee/api/client.py +28 -3
  4. cognee/api/health.py +10 -13
  5. cognee/api/v1/add/add.py +20 -6
  6. cognee/api/v1/add/routers/get_add_router.py +12 -37
  7. cognee/api/v1/cloud/routers/__init__.py +1 -0
  8. cognee/api/v1/cloud/routers/get_checks_router.py +23 -0
  9. cognee/api/v1/cognify/code_graph_pipeline.py +14 -3
  10. cognee/api/v1/cognify/cognify.py +67 -105
  11. cognee/api/v1/cognify/routers/get_cognify_router.py +11 -3
  12. cognee/api/v1/datasets/routers/get_datasets_router.py +16 -5
  13. cognee/api/v1/memify/routers/__init__.py +1 -0
  14. cognee/api/v1/memify/routers/get_memify_router.py +100 -0
  15. cognee/api/v1/notebooks/routers/__init__.py +1 -0
  16. cognee/api/v1/notebooks/routers/get_notebooks_router.py +96 -0
  17. cognee/api/v1/responses/default_tools.py +4 -0
  18. cognee/api/v1/responses/dispatch_function.py +6 -1
  19. cognee/api/v1/responses/models.py +1 -1
  20. cognee/api/v1/search/routers/get_search_router.py +20 -1
  21. cognee/api/v1/search/search.py +17 -4
  22. cognee/api/v1/sync/__init__.py +17 -0
  23. cognee/api/v1/sync/routers/__init__.py +3 -0
  24. cognee/api/v1/sync/routers/get_sync_router.py +241 -0
  25. cognee/api/v1/sync/sync.py +877 -0
  26. cognee/api/v1/users/routers/get_auth_router.py +13 -1
  27. cognee/base_config.py +10 -1
  28. cognee/cli/__init__.py +10 -0
  29. cognee/cli/_cognee.py +180 -0
  30. cognee/cli/commands/__init__.py +1 -0
  31. cognee/cli/commands/add_command.py +80 -0
  32. cognee/cli/commands/cognify_command.py +128 -0
  33. cognee/cli/commands/config_command.py +225 -0
  34. cognee/cli/commands/delete_command.py +80 -0
  35. cognee/cli/commands/search_command.py +149 -0
  36. cognee/cli/config.py +33 -0
  37. cognee/cli/debug.py +21 -0
  38. cognee/cli/echo.py +45 -0
  39. cognee/cli/exceptions.py +23 -0
  40. cognee/cli/minimal_cli.py +97 -0
  41. cognee/cli/reference.py +26 -0
  42. cognee/cli/suppress_logging.py +12 -0
  43. cognee/eval_framework/corpus_builder/corpus_builder_executor.py +2 -2
  44. cognee/eval_framework/eval_config.py +1 -1
  45. cognee/infrastructure/databases/graph/config.py +10 -4
  46. cognee/infrastructure/databases/graph/get_graph_engine.py +4 -9
  47. cognee/infrastructure/databases/graph/kuzu/adapter.py +199 -2
  48. cognee/infrastructure/databases/graph/neo4j_driver/adapter.py +138 -0
  49. cognee/infrastructure/databases/relational/__init__.py +2 -0
  50. cognee/infrastructure/databases/relational/get_async_session.py +15 -0
  51. cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +6 -1
  52. cognee/infrastructure/databases/relational/with_async_session.py +25 -0
  53. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +1 -1
  54. cognee/infrastructure/databases/vector/config.py +13 -6
  55. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +6 -4
  56. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +16 -7
  57. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +5 -5
  58. cognee/infrastructure/databases/vector/embeddings/config.py +2 -2
  59. cognee/infrastructure/databases/vector/embeddings/embedding_rate_limiter.py +2 -6
  60. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +10 -7
  61. cognee/infrastructure/files/storage/LocalFileStorage.py +9 -0
  62. cognee/infrastructure/files/storage/S3FileStorage.py +5 -0
  63. cognee/infrastructure/files/storage/StorageManager.py +7 -1
  64. cognee/infrastructure/files/storage/storage.py +16 -0
  65. cognee/infrastructure/files/utils/get_data_file_path.py +14 -9
  66. cognee/infrastructure/files/utils/get_file_metadata.py +2 -1
  67. cognee/infrastructure/llm/LLMGateway.py +32 -5
  68. cognee/infrastructure/llm/config.py +6 -4
  69. cognee/infrastructure/llm/prompts/extract_query_time.txt +15 -0
  70. cognee/infrastructure/llm/prompts/generate_event_entity_prompt.txt +25 -0
  71. cognee/infrastructure/llm/prompts/generate_event_graph_prompt.txt +30 -0
  72. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +16 -5
  73. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/__init__.py +2 -0
  74. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/extract_event_entities.py +44 -0
  75. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/__init__.py +1 -0
  76. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_content_graph.py +19 -15
  77. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/extraction/knowledge_graph/extract_event_graph.py +46 -0
  78. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +3 -3
  79. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +3 -3
  80. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +2 -2
  81. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +14 -8
  82. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/ollama/adapter.py +6 -4
  83. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +28 -4
  84. cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +2 -2
  85. cognee/infrastructure/llm/tokenizer/HuggingFace/adapter.py +3 -3
  86. cognee/infrastructure/llm/tokenizer/Mistral/adapter.py +3 -3
  87. cognee/infrastructure/llm/tokenizer/TikToken/adapter.py +6 -6
  88. cognee/infrastructure/llm/utils.py +7 -7
  89. cognee/infrastructure/utils/run_sync.py +8 -1
  90. cognee/modules/chunking/models/DocumentChunk.py +4 -3
  91. cognee/modules/cloud/exceptions/CloudApiKeyMissingError.py +15 -0
  92. cognee/modules/cloud/exceptions/CloudConnectionError.py +15 -0
  93. cognee/modules/cloud/exceptions/__init__.py +2 -0
  94. cognee/modules/cloud/operations/__init__.py +1 -0
  95. cognee/modules/cloud/operations/check_api_key.py +25 -0
  96. cognee/modules/data/deletion/prune_system.py +1 -1
  97. cognee/modules/data/methods/__init__.py +2 -0
  98. cognee/modules/data/methods/check_dataset_name.py +1 -1
  99. cognee/modules/data/methods/create_authorized_dataset.py +19 -0
  100. cognee/modules/data/methods/get_authorized_dataset.py +11 -5
  101. cognee/modules/data/methods/get_authorized_dataset_by_name.py +16 -0
  102. cognee/modules/data/methods/get_dataset_data.py +1 -1
  103. cognee/modules/data/methods/load_or_create_datasets.py +2 -20
  104. cognee/modules/engine/models/Event.py +16 -0
  105. cognee/modules/engine/models/Interval.py +8 -0
  106. cognee/modules/engine/models/Timestamp.py +13 -0
  107. cognee/modules/engine/models/__init__.py +3 -0
  108. cognee/modules/engine/utils/__init__.py +2 -0
  109. cognee/modules/engine/utils/generate_event_datapoint.py +46 -0
  110. cognee/modules/engine/utils/generate_timestamp_datapoint.py +51 -0
  111. cognee/modules/graph/cognee_graph/CogneeGraph.py +2 -2
  112. cognee/modules/graph/methods/get_formatted_graph_data.py +3 -2
  113. cognee/modules/graph/utils/__init__.py +1 -0
  114. cognee/modules/graph/utils/resolve_edges_to_text.py +71 -0
  115. cognee/modules/memify/__init__.py +1 -0
  116. cognee/modules/memify/memify.py +118 -0
  117. cognee/modules/notebooks/methods/__init__.py +5 -0
  118. cognee/modules/notebooks/methods/create_notebook.py +26 -0
  119. cognee/modules/notebooks/methods/delete_notebook.py +13 -0
  120. cognee/modules/notebooks/methods/get_notebook.py +21 -0
  121. cognee/modules/notebooks/methods/get_notebooks.py +18 -0
  122. cognee/modules/notebooks/methods/update_notebook.py +17 -0
  123. cognee/modules/notebooks/models/Notebook.py +53 -0
  124. cognee/modules/notebooks/models/__init__.py +1 -0
  125. cognee/modules/notebooks/operations/__init__.py +1 -0
  126. cognee/modules/notebooks/operations/run_in_local_sandbox.py +55 -0
  127. cognee/modules/pipelines/__init__.py +1 -1
  128. cognee/modules/pipelines/exceptions/tasks.py +18 -0
  129. cognee/modules/pipelines/layers/__init__.py +1 -0
  130. cognee/modules/pipelines/layers/check_pipeline_run_qualification.py +59 -0
  131. cognee/modules/pipelines/layers/pipeline_execution_mode.py +127 -0
  132. cognee/modules/pipelines/layers/reset_dataset_pipeline_run_status.py +28 -0
  133. cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +34 -0
  134. cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +55 -0
  135. cognee/modules/pipelines/layers/setup_and_check_environment.py +41 -0
  136. cognee/modules/pipelines/layers/validate_pipeline_tasks.py +20 -0
  137. cognee/modules/pipelines/methods/__init__.py +2 -0
  138. cognee/modules/pipelines/methods/get_pipeline_runs_by_dataset.py +34 -0
  139. cognee/modules/pipelines/methods/reset_pipeline_run_status.py +16 -0
  140. cognee/modules/pipelines/operations/__init__.py +0 -1
  141. cognee/modules/pipelines/operations/log_pipeline_run_initiated.py +1 -1
  142. cognee/modules/pipelines/operations/pipeline.py +24 -138
  143. cognee/modules/pipelines/operations/run_tasks.py +17 -41
  144. cognee/modules/retrieval/base_feedback.py +11 -0
  145. cognee/modules/retrieval/base_graph_retriever.py +18 -0
  146. cognee/modules/retrieval/base_retriever.py +1 -1
  147. cognee/modules/retrieval/code_retriever.py +8 -0
  148. cognee/modules/retrieval/coding_rules_retriever.py +31 -0
  149. cognee/modules/retrieval/completion_retriever.py +9 -3
  150. cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -0
  151. cognee/modules/retrieval/cypher_search_retriever.py +1 -9
  152. cognee/modules/retrieval/graph_completion_context_extension_retriever.py +29 -13
  153. cognee/modules/retrieval/graph_completion_cot_retriever.py +30 -13
  154. cognee/modules/retrieval/graph_completion_retriever.py +107 -56
  155. cognee/modules/retrieval/graph_summary_completion_retriever.py +5 -1
  156. cognee/modules/retrieval/insights_retriever.py +14 -3
  157. cognee/modules/retrieval/natural_language_retriever.py +0 -4
  158. cognee/modules/retrieval/summaries_retriever.py +1 -1
  159. cognee/modules/retrieval/temporal_retriever.py +152 -0
  160. cognee/modules/retrieval/user_qa_feedback.py +83 -0
  161. cognee/modules/retrieval/utils/brute_force_triplet_search.py +7 -32
  162. cognee/modules/retrieval/utils/completion.py +10 -3
  163. cognee/modules/retrieval/utils/extract_uuid_from_node.py +18 -0
  164. cognee/modules/retrieval/utils/models.py +40 -0
  165. cognee/modules/search/methods/get_search_type_tools.py +168 -0
  166. cognee/modules/search/methods/no_access_control_search.py +47 -0
  167. cognee/modules/search/methods/search.py +239 -118
  168. cognee/modules/search/types/SearchResult.py +21 -0
  169. cognee/modules/search/types/SearchType.py +3 -0
  170. cognee/modules/search/types/__init__.py +1 -0
  171. cognee/modules/search/utils/__init__.py +2 -0
  172. cognee/modules/search/utils/prepare_search_result.py +41 -0
  173. cognee/modules/search/utils/transform_context_to_graph.py +38 -0
  174. cognee/modules/settings/get_settings.py +2 -2
  175. cognee/modules/sync/__init__.py +1 -0
  176. cognee/modules/sync/methods/__init__.py +23 -0
  177. cognee/modules/sync/methods/create_sync_operation.py +53 -0
  178. cognee/modules/sync/methods/get_sync_operation.py +107 -0
  179. cognee/modules/sync/methods/update_sync_operation.py +248 -0
  180. cognee/modules/sync/models/SyncOperation.py +142 -0
  181. cognee/modules/sync/models/__init__.py +3 -0
  182. cognee/modules/users/__init__.py +0 -1
  183. cognee/modules/users/methods/__init__.py +4 -1
  184. cognee/modules/users/methods/create_user.py +26 -1
  185. cognee/modules/users/methods/get_authenticated_user.py +36 -42
  186. cognee/modules/users/methods/get_default_user.py +3 -1
  187. cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +2 -1
  188. cognee/root_dir.py +19 -0
  189. cognee/shared/CodeGraphEntities.py +1 -0
  190. cognee/shared/logging_utils.py +143 -32
  191. cognee/shared/utils.py +0 -1
  192. cognee/tasks/codingagents/coding_rule_associations.py +127 -0
  193. cognee/tasks/graph/extract_graph_from_data.py +6 -2
  194. cognee/tasks/ingestion/save_data_item_to_storage.py +23 -0
  195. cognee/tasks/memify/__init__.py +2 -0
  196. cognee/tasks/memify/extract_subgraph.py +7 -0
  197. cognee/tasks/memify/extract_subgraph_chunks.py +11 -0
  198. cognee/tasks/repo_processor/get_local_dependencies.py +2 -0
  199. cognee/tasks/repo_processor/get_repo_file_dependencies.py +144 -47
  200. cognee/tasks/storage/add_data_points.py +33 -3
  201. cognee/tasks/temporal_graph/__init__.py +1 -0
  202. cognee/tasks/temporal_graph/add_entities_to_event.py +85 -0
  203. cognee/tasks/temporal_graph/enrich_events.py +34 -0
  204. cognee/tasks/temporal_graph/extract_events_and_entities.py +32 -0
  205. cognee/tasks/temporal_graph/extract_knowledge_graph_from_events.py +41 -0
  206. cognee/tasks/temporal_graph/models.py +49 -0
  207. cognee/tests/integration/cli/__init__.py +3 -0
  208. cognee/tests/integration/cli/test_cli_integration.py +331 -0
  209. cognee/tests/integration/documents/PdfDocument_test.py +2 -2
  210. cognee/tests/integration/documents/TextDocument_test.py +2 -4
  211. cognee/tests/integration/documents/UnstructuredDocument_test.py +5 -8
  212. cognee/tests/{test_deletion.py → test_delete_hard.py} +0 -37
  213. cognee/tests/test_delete_soft.py +85 -0
  214. cognee/tests/test_kuzu.py +2 -2
  215. cognee/tests/test_neo4j.py +2 -2
  216. cognee/tests/test_permissions.py +3 -3
  217. cognee/tests/test_relational_db_migration.py +7 -5
  218. cognee/tests/test_search_db.py +136 -23
  219. cognee/tests/test_temporal_graph.py +167 -0
  220. cognee/tests/unit/api/__init__.py +1 -0
  221. cognee/tests/unit/api/test_conditional_authentication_endpoints.py +246 -0
  222. cognee/tests/unit/cli/__init__.py +3 -0
  223. cognee/tests/unit/cli/test_cli_commands.py +483 -0
  224. cognee/tests/unit/cli/test_cli_edge_cases.py +625 -0
  225. cognee/tests/unit/cli/test_cli_main.py +173 -0
  226. cognee/tests/unit/cli/test_cli_runner.py +62 -0
  227. cognee/tests/unit/cli/test_cli_utils.py +127 -0
  228. cognee/tests/unit/modules/retrieval/chunks_retriever_test.py +18 -2
  229. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +12 -15
  230. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +10 -15
  231. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +4 -3
  232. cognee/tests/unit/modules/retrieval/insights_retriever_test.py +4 -2
  233. cognee/tests/unit/modules/retrieval/rag_completion_retriever_test.py +18 -2
  234. cognee/tests/unit/modules/retrieval/temporal_retriever_test.py +225 -0
  235. cognee/tests/unit/modules/users/__init__.py +1 -0
  236. cognee/tests/unit/modules/users/test_conditional_authentication.py +277 -0
  237. cognee/tests/unit/processing/utils/utils_test.py +20 -1
  238. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/METADATA +13 -9
  239. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/RECORD +245 -135
  240. cognee-0.3.0.dev0.dist-info/entry_points.txt +2 -0
  241. cognee/infrastructure/databases/graph/networkx/adapter.py +0 -1017
  242. cognee/infrastructure/pipeline/models/Operation.py +0 -60
  243. cognee/notebooks/github_analysis_step_by_step.ipynb +0 -37
  244. cognee/tests/tasks/descriptive_metrics/networkx_metrics_test.py +0 -7
  245. cognee/tests/unit/modules/search/search_methods_test.py +0 -223
  246. /cognee/{infrastructure/databases/graph/networkx → api/v1/memify}/__init__.py +0 -0
  247. /cognee/{infrastructure/pipeline/models → tasks/codingagents}/__init__.py +0 -0
  248. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/WHEEL +0 -0
  249. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/LICENSE +0 -0
  250. {cognee-0.2.3.dev1.dist-info → cognee-0.3.0.dev0.dist-info}/licenses/NOTICE.md +0 -0
@@ -0,0 +1,483 @@
1
+ """
2
+ Tests for individual CLI commands with proper mocking and coroutine handling.
3
+ """
4
+
5
+ import pytest
6
+ import sys
7
+ import argparse
8
+ import asyncio
9
+ from unittest.mock import patch, MagicMock, AsyncMock, ANY
10
+ from cognee.cli.commands.add_command import AddCommand
11
+ from cognee.cli.commands.search_command import SearchCommand
12
+ from cognee.cli.commands.cognify_command import CognifyCommand
13
+ from cognee.cli.commands.delete_command import DeleteCommand
14
+ from cognee.cli.commands.config_command import ConfigCommand
15
+ from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
16
+
17
+
18
+ # Mock asyncio.run to properly handle coroutines
19
+ def _mock_run(coro):
20
+ # Create an event loop and run the coroutine
21
+ loop = asyncio.new_event_loop()
22
+ try:
23
+ return loop.run_until_complete(coro)
24
+ finally:
25
+ loop.close()
26
+
27
+
28
+ class TestAddCommand:
29
+ """Test the AddCommand class"""
30
+
31
+ def test_command_properties(self):
32
+ """Test basic command properties"""
33
+ command = AddCommand()
34
+ assert command.command_string == "add"
35
+ assert "Add data" in command.help_string
36
+ assert command.docs_url is not None
37
+
38
+ def test_configure_parser(self):
39
+ """Test parser configuration"""
40
+ command = AddCommand()
41
+ parser = argparse.ArgumentParser()
42
+
43
+ command.configure_parser(parser)
44
+
45
+ # Check that required arguments are added
46
+ actions = {action.dest: action for action in parser._actions}
47
+ assert "data" in actions
48
+ assert "dataset_name" in actions
49
+
50
+ # Check data argument accepts multiple values
51
+ assert actions["data"].nargs == "+"
52
+
53
+ @patch("cognee.cli.commands.add_command.asyncio.run", side_effect=_mock_run)
54
+ def test_execute_single_item(self, mock_asyncio_run):
55
+ """Test execute with single data item"""
56
+ # Mock the cognee module
57
+ mock_cognee = MagicMock()
58
+ mock_cognee.add = AsyncMock()
59
+
60
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
61
+ command = AddCommand()
62
+ args = argparse.Namespace(data=["test.txt"], dataset_name="test_dataset")
63
+ command.execute(args)
64
+
65
+ mock_asyncio_run.assert_called_once()
66
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
67
+ mock_cognee.add.assert_awaited_once_with(data="test.txt", dataset_name="test_dataset")
68
+
69
+ @patch("cognee.cli.commands.add_command.asyncio.run", side_effect=_mock_run)
70
+ def test_execute_multiple_items(self, mock_asyncio_run):
71
+ """Test execute with multiple data items"""
72
+ # Mock the cognee module
73
+ mock_cognee = MagicMock()
74
+ mock_cognee.add = AsyncMock()
75
+
76
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
77
+ command = AddCommand()
78
+ args = argparse.Namespace(data=["test1.txt", "test2.txt"], dataset_name="test_dataset")
79
+ command.execute(args)
80
+
81
+ mock_asyncio_run.assert_called_once()
82
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
83
+ mock_cognee.add.assert_awaited_once_with(
84
+ data=["test1.txt", "test2.txt"], dataset_name="test_dataset"
85
+ )
86
+
87
+ @patch("cognee.cli.commands.add_command.asyncio.run")
88
+ def test_execute_with_exception(self, mock_asyncio_run):
89
+ """Test execute handles exceptions properly"""
90
+ command = AddCommand()
91
+ args = argparse.Namespace(data=["test.txt"], dataset_name="test_dataset")
92
+
93
+ mock_asyncio_run.side_effect = Exception("Test error")
94
+
95
+ with pytest.raises(CliCommandException):
96
+ command.execute(args)
97
+
98
+
99
+ class TestSearchCommand:
100
+ """Test the SearchCommand class"""
101
+
102
+ def test_command_properties(self):
103
+ """Test basic command properties"""
104
+ command = SearchCommand()
105
+ assert command.command_string == "search"
106
+ assert "Search and query" in command.help_string
107
+ assert command.docs_url is not None
108
+
109
+ def test_configure_parser(self):
110
+ """Test parser configuration"""
111
+ command = SearchCommand()
112
+ parser = argparse.ArgumentParser()
113
+
114
+ command.configure_parser(parser)
115
+
116
+ # Check that required arguments are added
117
+ actions = {action.dest: action for action in parser._actions}
118
+ assert "query_text" in actions
119
+ assert "query_type" in actions
120
+ assert "datasets" in actions
121
+ assert "top_k" in actions
122
+ assert "output_format" in actions
123
+
124
+ # Check default values
125
+ assert actions["query_type"].default == "GRAPH_COMPLETION"
126
+ assert actions["top_k"].default == 10
127
+ assert actions["output_format"].default == "pretty"
128
+
129
+ @patch("cognee.cli.commands.search_command.asyncio.run", side_effect=_mock_run)
130
+ def test_execute_basic_search(self, mock_asyncio_run):
131
+ """Test execute with basic search"""
132
+ # Mock the cognee module and SearchType
133
+ mock_cognee = MagicMock()
134
+ mock_cognee.search = AsyncMock(return_value=["result1", "result2"])
135
+ mock_search_type = MagicMock()
136
+ mock_search_type.__getitem__.return_value = "GRAPH_COMPLETION"
137
+
138
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
139
+ command = SearchCommand()
140
+ args = argparse.Namespace(
141
+ query_text="test query",
142
+ query_type="GRAPH_COMPLETION",
143
+ datasets=None,
144
+ top_k=10,
145
+ system_prompt=None,
146
+ output_format="pretty",
147
+ )
148
+ command.execute(args)
149
+
150
+ mock_asyncio_run.assert_called_once()
151
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
152
+ mock_cognee.search.assert_awaited_once_with(
153
+ query_text="test query",
154
+ query_type=ANY,
155
+ datasets=None,
156
+ top_k=10,
157
+ system_prompt_path="answer_simple_question.txt",
158
+ )
159
+ # verify the enum’s name separately
160
+ called_enum = mock_cognee.search.await_args.kwargs["query_type"]
161
+ assert called_enum.name == "GRAPH_COMPLETION"
162
+
163
+ @patch("cognee.cli.commands.search_command.asyncio.run")
164
+ def test_execute_with_exception(self, mock_asyncio_run):
165
+ """Test execute handles exceptions properly"""
166
+ command = SearchCommand()
167
+ args = argparse.Namespace(
168
+ query_text="test query",
169
+ query_type="GRAPH_COMPLETION",
170
+ datasets=None,
171
+ top_k=10,
172
+ system_prompt=None,
173
+ output_format="pretty",
174
+ )
175
+
176
+ mock_asyncio_run.side_effect = Exception("Search error")
177
+
178
+ with pytest.raises(CliCommandException):
179
+ command.execute(args)
180
+
181
+
182
+ class TestCognifyCommand:
183
+ """Test the CognifyCommand class"""
184
+
185
+ def test_command_properties(self):
186
+ """Test basic command properties"""
187
+ command = CognifyCommand()
188
+ assert command.command_string == "cognify"
189
+ assert "Transform ingested data" in command.help_string
190
+ assert command.docs_url is not None
191
+
192
+ def test_configure_parser(self):
193
+ """Test parser configuration"""
194
+ command = CognifyCommand()
195
+ parser = argparse.ArgumentParser()
196
+
197
+ command.configure_parser(parser)
198
+
199
+ # Check that arguments are added
200
+ actions = {action.dest: action for action in parser._actions}
201
+ assert "datasets" in actions
202
+ assert "chunk_size" in actions
203
+ assert "ontology_file" in actions
204
+ assert "chunker" in actions
205
+ assert "background" in actions
206
+ assert "verbose" in actions
207
+
208
+ # Check default values
209
+ assert actions["chunker"].default == "TextChunker"
210
+
211
+ @patch("cognee.cli.commands.cognify_command.asyncio.run", side_effect=_mock_run)
212
+ def test_execute_basic_cognify(self, mock_asyncio_run):
213
+ """Test execute with basic cognify"""
214
+ # Mock the cognee module
215
+ mock_cognee = MagicMock()
216
+ mock_cognee.cognify = AsyncMock(return_value="success")
217
+
218
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
219
+ command = CognifyCommand()
220
+ args = argparse.Namespace(
221
+ datasets=None,
222
+ chunk_size=None,
223
+ ontology_file=None,
224
+ chunker="TextChunker",
225
+ background=False,
226
+ verbose=False,
227
+ )
228
+ command.execute(args)
229
+
230
+ mock_asyncio_run.assert_called_once()
231
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
232
+ from cognee.modules.chunking.TextChunker import TextChunker
233
+
234
+ mock_cognee.cognify.assert_awaited_once_with(
235
+ datasets=None,
236
+ chunk_size=None,
237
+ ontology_file_path=None,
238
+ chunker=TextChunker,
239
+ run_in_background=False,
240
+ )
241
+
242
+ @patch("cognee.cli.commands.cognify_command.asyncio.run")
243
+ def test_execute_with_exception(self, mock_asyncio_run):
244
+ """Test execute handles exceptions properly"""
245
+ command = CognifyCommand()
246
+ args = argparse.Namespace(
247
+ datasets=None,
248
+ chunk_size=None,
249
+ ontology_file=None,
250
+ chunker="TextChunker",
251
+ background=False,
252
+ verbose=False,
253
+ )
254
+
255
+ mock_asyncio_run.side_effect = Exception("Cognify error")
256
+
257
+ with pytest.raises(CliCommandException):
258
+ command.execute(args)
259
+
260
+
261
+ class TestDeleteCommand:
262
+ """Test the DeleteCommand class"""
263
+
264
+ def test_command_properties(self):
265
+ """Test basic command properties"""
266
+ command = DeleteCommand()
267
+ assert command.command_string == "delete"
268
+ assert "Delete data" in command.help_string
269
+ assert command.docs_url is not None
270
+
271
+ def test_configure_parser(self):
272
+ """Test parser configuration"""
273
+ command = DeleteCommand()
274
+ parser = argparse.ArgumentParser()
275
+
276
+ command.configure_parser(parser)
277
+
278
+ # Check that arguments are added
279
+ actions = {action.dest: action for action in parser._actions}
280
+ assert "dataset_name" in actions
281
+ assert "user_id" in actions
282
+ assert "all" in actions
283
+ assert "force" in actions
284
+
285
+ @patch("cognee.cli.commands.delete_command.fmt.confirm")
286
+ @patch("cognee.cli.commands.delete_command.asyncio.run", side_effect=_mock_run)
287
+ def test_execute_delete_dataset_with_confirmation(self, mock_asyncio_run, mock_confirm):
288
+ """Test execute delete dataset with user confirmation"""
289
+ # Mock the cognee module
290
+ mock_cognee = MagicMock()
291
+ mock_cognee.delete = AsyncMock()
292
+
293
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
294
+ command = DeleteCommand()
295
+ args = argparse.Namespace(
296
+ dataset_name="test_dataset", user_id=None, all=False, force=False
297
+ )
298
+
299
+ mock_confirm.return_value = True
300
+
301
+ command.execute(args)
302
+
303
+ mock_confirm.assert_called_once_with(f"Delete dataset '{args.dataset_name}'?")
304
+ mock_asyncio_run.assert_called_once()
305
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
306
+ mock_cognee.delete.assert_awaited_once_with(dataset_name="test_dataset", user_id=None)
307
+
308
+ @patch("cognee.cli.commands.delete_command.fmt.confirm")
309
+ def test_execute_delete_cancelled(self, mock_confirm):
310
+ """Test execute when user cancels deletion"""
311
+ command = DeleteCommand()
312
+ args = argparse.Namespace(dataset_name="test_dataset", user_id=None, all=False, force=False)
313
+
314
+ mock_confirm.return_value = False
315
+
316
+ # Should not raise exception, just return
317
+ command.execute(args)
318
+
319
+ mock_confirm.assert_called_once_with(f"Delete dataset '{args.dataset_name}'?")
320
+
321
+ @patch("cognee.cli.commands.delete_command.asyncio.run", side_effect=_mock_run)
322
+ def test_execute_delete_forced(self, mock_asyncio_run):
323
+ """Test execute delete with force flag"""
324
+ # Mock the cognee module
325
+ mock_cognee = MagicMock()
326
+ mock_cognee.delete = AsyncMock()
327
+
328
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
329
+ command = DeleteCommand()
330
+ args = argparse.Namespace(
331
+ dataset_name="test_dataset", user_id=None, all=False, force=True
332
+ )
333
+
334
+ command.execute(args)
335
+
336
+ mock_asyncio_run.assert_called_once()
337
+ assert asyncio.iscoroutine(mock_asyncio_run.call_args[0][0])
338
+ mock_cognee.delete.assert_awaited_once_with(dataset_name="test_dataset", user_id=None)
339
+
340
+ def test_execute_no_delete_target(self):
341
+ """Test execute when no delete target is specified"""
342
+ command = DeleteCommand()
343
+ args = argparse.Namespace(dataset_name=None, user_id=None, all=False, force=False)
344
+
345
+ # Should not raise exception, just return with error message
346
+ command.execute(args)
347
+
348
+ @patch("cognee.cli.commands.delete_command.asyncio.run")
349
+ def test_execute_with_exception(self, mock_asyncio_run):
350
+ """Test execute handles exceptions properly"""
351
+ command = DeleteCommand()
352
+ args = argparse.Namespace(dataset_name="test_dataset", user_id=None, all=False, force=True)
353
+
354
+ mock_asyncio_run.side_effect = Exception("Delete error")
355
+
356
+ with pytest.raises(CliCommandException):
357
+ command.execute(args)
358
+
359
+
360
+ class TestConfigCommand:
361
+ """Test the ConfigCommand class"""
362
+
363
+ def test_command_properties(self):
364
+ """Test basic command properties"""
365
+ command = ConfigCommand()
366
+ assert command.command_string == "config"
367
+ assert "Manage cognee configuration" in command.help_string
368
+ assert command.docs_url is not None
369
+
370
+ def test_configure_parser(self):
371
+ """Test parser configuration"""
372
+ command = ConfigCommand()
373
+ parser = argparse.ArgumentParser()
374
+
375
+ command.configure_parser(parser)
376
+
377
+ # Check that subparsers are created
378
+ subparsers_actions = [
379
+ action for action in parser._actions if isinstance(action, argparse._SubParsersAction)
380
+ ]
381
+ assert len(subparsers_actions) == 1
382
+
383
+ subparsers = subparsers_actions[0]
384
+ assert "get" in subparsers.choices
385
+ assert "set" in subparsers.choices
386
+ assert "list" in subparsers.choices
387
+ assert "unset" in subparsers.choices
388
+ assert "reset" in subparsers.choices
389
+
390
+ def test_execute_no_action(self):
391
+ """Test execute when no config action is provided"""
392
+ command = ConfigCommand()
393
+ args = argparse.Namespace()
394
+
395
+ # Should not raise exception, just return with error message
396
+ command.execute(args)
397
+
398
+ @patch("builtins.__import__")
399
+ def test_execute_get_action(self, mock_import):
400
+ """Test execute get action"""
401
+ # Mock the cognee module
402
+ mock_cognee = MagicMock()
403
+ mock_cognee.config.get = MagicMock(return_value="openai")
404
+ mock_import.return_value = mock_cognee
405
+
406
+ command = ConfigCommand()
407
+ args = argparse.Namespace(config_action="get", key="llm_provider")
408
+
409
+ command.execute(args)
410
+
411
+ @patch("builtins.__import__")
412
+ def test_execute_set_action(self, mock_import):
413
+ """Test execute set action"""
414
+ # Mock the cognee module
415
+ mock_cognee = MagicMock()
416
+ mock_cognee.config.set = MagicMock()
417
+ mock_import.return_value = mock_cognee
418
+
419
+ command = ConfigCommand()
420
+ args = argparse.Namespace(config_action="set", key="llm_provider", value="anthropic")
421
+
422
+ command.execute(args)
423
+
424
+ @patch("builtins.__import__")
425
+ def test_execute_set_action_json_value(self, mock_import):
426
+ """Test execute set action with JSON value"""
427
+ # Mock the cognee module
428
+ mock_cognee = MagicMock()
429
+ mock_cognee.config.set = MagicMock()
430
+ mock_import.return_value = mock_cognee
431
+
432
+ command = ConfigCommand()
433
+ args = argparse.Namespace(config_action="set", key="chunk_size", value="1024")
434
+
435
+ command.execute(args)
436
+
437
+ def test_execute_list_action(self):
438
+ """Test execute list action"""
439
+ command = ConfigCommand()
440
+ args = argparse.Namespace(config_action="list")
441
+
442
+ # Should not raise exception
443
+ command.execute(args)
444
+
445
+ @patch("cognee.cli.commands.config_command.fmt.confirm")
446
+ def test_execute_unset_action(self, mock_confirm):
447
+ """Test execute unset action"""
448
+ # Mock the cognee module
449
+ mock_cognee = MagicMock()
450
+ mock_cognee.config.set_llm_provider = MagicMock()
451
+
452
+ with patch.dict(sys.modules, {"cognee": mock_cognee}):
453
+ command = ConfigCommand()
454
+ args = argparse.Namespace(config_action="unset", key="llm_provider", force=False)
455
+
456
+ mock_confirm.return_value = True
457
+
458
+ command.execute(args)
459
+
460
+ mock_confirm.assert_called_once()
461
+
462
+ @patch("cognee.cli.commands.config_command.fmt.confirm")
463
+ def test_execute_reset_action(self, mock_confirm):
464
+ """Test execute reset action"""
465
+ command = ConfigCommand()
466
+ args = argparse.Namespace(config_action="reset", force=False)
467
+
468
+ mock_confirm.return_value = True
469
+
470
+ # Should not raise exception
471
+ command.execute(args)
472
+
473
+ mock_confirm.assert_called_once()
474
+
475
+ def test_execute_with_exception(self):
476
+ """Test execute handles exceptions properly"""
477
+ # Test with an invalid action that will cause an exception in the main execute method
478
+ command = ConfigCommand()
479
+ args = argparse.Namespace(config_action="invalid_action")
480
+
481
+ # This should not raise CliCommandException, just handle it gracefully
482
+ # The config command handles unknown actions by showing an error message
483
+ command.execute(args)