codemie-test-harness 0.1.145__py3-none-any.whl → 0.1.147__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.

Potentially problematic release.


This version of codemie-test-harness might be problematic. Click here for more details.

@@ -33,6 +33,7 @@ from codemie_test_harness.tests.utils.aws_parameters_store import CredentialsUti
33
33
  from codemie_test_harness.tests.utils.base_utils import get_random_name, wait_for_entity
34
34
  from codemie_test_harness.tests.utils.client_factory import get_client
35
35
  from codemie_test_harness.tests.utils.constants import TESTS_PATH
36
+ from codemie_test_harness.tests.utils.conversation_utils import ConversationUtils
36
37
  from codemie_test_harness.tests.utils.datasource_utils import DataSourceUtils
37
38
  from codemie_test_harness.tests.utils.gitbud_utils import GitBudUtils
38
39
  from codemie_test_harness.tests.utils.integration_utils import IntegrationUtils
@@ -63,13 +64,15 @@ def pytest_configure(config):
63
64
  """
64
65
  from codemie_test_harness.cli.runner import resolve_tests_path_and_root
65
66
  from codemie_test_harness.tests.utils.aws_parameters_store import AwsParameterStore
67
+ from codemie_test_harness.tests.utils.env_utils import EnvManager
66
68
 
67
69
  # Resolve the root directory and .env file path
68
70
  _, root_dir = resolve_tests_path_and_root()
69
71
  env_file_path = Path(root_dir) / ".env"
70
72
 
71
73
  # Load initial .env file
72
- load_dotenv(env_file_path)
74
+ if env_file_path.exists():
75
+ load_dotenv(env_file_path)
73
76
 
74
77
  # Check if AWS credentials are available for parameter store
75
78
  if os.getenv("AWS_ACCESS_KEY") and os.getenv("AWS_SECRET_KEY"):
@@ -84,12 +87,10 @@ def pytest_configure(config):
84
87
  f"/codemie/autotests/dotenv/{os.getenv('ENV')}"
85
88
  )
86
89
 
87
- # Write the AWS parameters to .env file
88
- with open(env_file_path, "w") as file:
89
- file.write(dotenv)
90
-
91
- # Reload .env file with AWS parameters
92
- load_dotenv(env_file_path)
90
+ # Safely update .env file with new content
91
+ EnvManager.update_env_file_safely(
92
+ env_file_path=env_file_path, new_content=dotenv, clear_old_vars=True
93
+ )
93
94
 
94
95
 
95
96
  def pytest_unconfigure(config):
@@ -232,6 +233,11 @@ def llm_utils(client):
232
233
  return LLMUtils(client)
233
234
 
234
235
 
236
+ @pytest.fixture(scope="session")
237
+ def conversation_utils(client):
238
+ return ConversationUtils(client)
239
+
240
+
235
241
  @pytest.fixture(scope="function")
236
242
  def git_integration(integration_utils):
237
243
  integration = integration_utils.create_integration(
@@ -465,7 +471,7 @@ def kb_context():
465
471
 
466
472
 
467
473
  @pytest.fixture(scope="function")
468
- def assistant(default_llm, assistant_utils):
474
+ def assistant(default_llm, assistant_utils, conversation_utils):
469
475
  """Create assistant"""
470
476
  created_assistant = None
471
477
 
@@ -511,6 +517,11 @@ def assistant(default_llm, assistant_utils):
511
517
  yield _create_assistant
512
518
  if created_assistant:
513
519
  assistant_utils.delete_assistant(created_assistant)
520
+ conversations = conversation_utils.get_conversation_by_assistant_id(
521
+ created_assistant["id"]
522
+ )
523
+ for conversation in conversations:
524
+ conversation_utils.delete_conversation(conversation.id)
514
525
 
515
526
 
516
527
  @pytest.fixture(scope="function")
@@ -860,6 +871,10 @@ def pytest_sessionfinish(session):
860
871
  if prefix in assistant.name:
861
872
  client.assistants.delete(assistant_id=assistant.id)
862
873
  sleep(clean_up_timeout)
874
+ conversations = client.conversations.list_by_assistant_id(assistant.id)
875
+ for conversation in conversations:
876
+ client.conversations.delete(conversation.id)
877
+ sleep(clean_up_timeout)
863
878
  workflows = client.workflows.list(
864
879
  filters={"name": autotest_entity_prefix}, per_page=200
865
880
  )
File without changes
@@ -0,0 +1,123 @@
1
+ import pytest
2
+ from codemie_sdk.models.conversation import Conversation, ConversationDetails
3
+ from hamcrest import (
4
+ assert_that,
5
+ has_length,
6
+ instance_of,
7
+ all_of,
8
+ has_property,
9
+ greater_than_or_equal_to,
10
+ has_item,
11
+ equal_to,
12
+ has_entry,
13
+ )
14
+
15
+ from codemie_test_harness.tests.utils.base_utils import get_random_name
16
+
17
+
18
+ @pytest.mark.regression
19
+ def test_list_conversations(assistant, assistant_utils, conversation_utils):
20
+ assistant = assistant()
21
+ assistant_utils.ask_assistant(assistant, f"prompt {get_random_name()}")
22
+
23
+ conversations = conversation_utils.list_conversations()
24
+
25
+ assert_that(conversations, instance_of(list))
26
+ assert_that(conversations, has_length(greater_than_or_equal_to(1)))
27
+
28
+ conversation = conversations[0]
29
+ assert_that(
30
+ conversation,
31
+ all_of(
32
+ instance_of(Conversation),
33
+ has_property("id"),
34
+ has_property("name"),
35
+ has_property("folder"),
36
+ has_property("pinned"),
37
+ has_property("date"),
38
+ has_property("assistant_ids", instance_of(list)),
39
+ has_property("initial_assistant_id"),
40
+ ),
41
+ )
42
+
43
+
44
+ @pytest.mark.regression
45
+ def test_get_specific_conversation(assistant, assistant_utils, conversation_utils):
46
+ prompt = f"prompt {get_random_name()}"
47
+ assistant = assistant()
48
+
49
+ assistant_utils.ask_assistant(assistant, prompt)
50
+
51
+ conversations = conversation_utils.list_conversations()
52
+
53
+ first_conversation = conversations[0]
54
+ conversation = conversation_utils.get_conversation_by_id(first_conversation.id)
55
+ assert_that(
56
+ conversation,
57
+ all_of(
58
+ instance_of(ConversationDetails),
59
+ has_property("id", first_conversation.id),
60
+ has_property("conversation_name", prompt),
61
+ has_property("initial_assistant_id", assistant.id),
62
+ ),
63
+ )
64
+
65
+
66
+ @pytest.mark.regression
67
+ def test_get_conversation_by_assistant_id(
68
+ assistant, assistant_utils, conversation_utils
69
+ ):
70
+ prompt = f"prompt {get_random_name()}"
71
+ assistant = assistant()
72
+
73
+ assistant_utils.ask_assistant(assistant, prompt)
74
+ conversation = conversation_utils.get_conversation_by_assistant_id(assistant.id)
75
+ assert_that(
76
+ conversation[0],
77
+ all_of(
78
+ instance_of(Conversation),
79
+ has_property("id", conversation[0].id),
80
+ has_property("name", prompt),
81
+ has_property("assistant_ids", has_item(assistant.id)),
82
+ has_property("initial_assistant_id", assistant.id),
83
+ ),
84
+ )
85
+
86
+
87
+ @pytest.mark.regression
88
+ def test_delete_conversation(assistant, assistant_utils, conversation_utils):
89
+ prompt = f"prompt {get_random_name()}"
90
+ assistant = assistant()
91
+
92
+ assistant_utils.ask_assistant(assistant, prompt)
93
+ conversation = conversation_utils.get_conversation_by_assistant_id(assistant.id)
94
+
95
+ delete_response = conversation_utils.delete_conversation(conversation[0].id)
96
+ assert_that(
97
+ delete_response["message"],
98
+ equal_to("Specified conversation removed"),
99
+ "Conversation delete response is not as expected.",
100
+ )
101
+
102
+
103
+ @pytest.mark.regression
104
+ def test_get_non_existent_conversation(assistant, assistant_utils, conversation_utils):
105
+ invalid_id = get_random_name()
106
+ with pytest.raises(Exception) as exc_info:
107
+ conversation_utils.get_conversation_by_id(invalid_id)
108
+
109
+ error_response = exc_info.value.response.json()
110
+ assert_that(
111
+ error_response["error"],
112
+ all_of(
113
+ has_entry("message", "Conversation not found"),
114
+ has_entry(
115
+ "details",
116
+ f"The conversation with ID [{invalid_id}] could not be found in the system.",
117
+ ),
118
+ has_entry(
119
+ "help",
120
+ "Please verify the conversation ID and try again. If you believe this is an error, contact support.",
121
+ ),
122
+ ),
123
+ )
@@ -0,0 +1,17 @@
1
+ import requests
2
+
3
+ from codemie_test_harness.tests.utils.base_utils import BaseUtils
4
+
5
+
6
+ class ConversationUtils(BaseUtils):
7
+ def list_conversations(self):
8
+ return self.client.conversations.list()
9
+
10
+ def get_conversation_by_assistant_id(self, assistant_id: str):
11
+ return self.client.conversations.list_by_assistant_id(assistant_id)
12
+
13
+ def get_conversation_by_id(self, conversation_id: str) -> requests.Response:
14
+ return self.client.conversations.get_conversation(conversation_id)
15
+
16
+ def delete_conversation(self, conversation_id: str) -> requests.Response:
17
+ return self.client.conversations.delete(conversation_id)
@@ -0,0 +1,125 @@
1
+ """
2
+ Utility functions for managing environment variables and dotenv files with caching prevention.
3
+ """
4
+
5
+ import os
6
+ import time
7
+ from pathlib import Path
8
+ from dotenv import load_dotenv
9
+
10
+
11
+ class EnvManager:
12
+ """
13
+ Manages environment variables with proper caching prevention.
14
+ """
15
+
16
+ @staticmethod
17
+ def clear_env_vars_from_file(env_file_path: Path) -> None:
18
+ """
19
+ Clear environment variables that exist in the specified .env file from os.environ.
20
+
21
+ Args:
22
+ env_file_path: Path to the .env file
23
+ """
24
+ if not env_file_path.exists():
25
+ return
26
+
27
+ with open(env_file_path, "r") as f:
28
+ content = f.read()
29
+
30
+ for line in content.splitlines():
31
+ line = line.strip()
32
+ if line and "=" in line and not line.startswith("#"):
33
+ key = line.split("=", 1)[0].strip()
34
+ os.environ.pop(key, None)
35
+
36
+ @staticmethod
37
+ def write_env_file_safely(env_file_path: Path, content: str) -> None:
38
+ """
39
+ Write content to .env file with proper flushing and sync.
40
+
41
+ Args:
42
+ env_file_path: Path to the .env file
43
+ content: Content to write
44
+ """
45
+ # Ensure parent directory exists
46
+ env_file_path.parent.mkdir(parents=True, exist_ok=True)
47
+
48
+ # Write with proper flushing
49
+ with open(env_file_path, "w", encoding="utf-8") as file:
50
+ file.write(content)
51
+ file.flush()
52
+ os.fsync(file.fileno())
53
+
54
+ @staticmethod
55
+ def load_env_with_retry(
56
+ env_file_path: Path,
57
+ max_retries: int = 3,
58
+ retry_delay: float = 0.1,
59
+ override: bool = True,
60
+ ) -> bool:
61
+ """
62
+ Load .env file with retry mechanism to handle caching issues.
63
+
64
+ Args:
65
+ env_file_path: Path to the .env file
66
+ max_retries: Maximum number of retry attempts
67
+ retry_delay: Delay between retries in seconds
68
+ override: Whether to override existing environment variables
69
+
70
+ Returns:
71
+ bool: True if successfully loaded, False otherwise
72
+ """
73
+ for attempt in range(max_retries):
74
+ try:
75
+ # Small delay to ensure file system consistency
76
+ if attempt > 0:
77
+ time.sleep(retry_delay)
78
+
79
+ # Verify file exists and is readable
80
+ if not env_file_path.exists():
81
+ raise FileNotFoundError(f".env file not found: {env_file_path}")
82
+
83
+ # Read file content to verify it's accessible
84
+ with open(env_file_path, "r") as f:
85
+ content = f.read()
86
+
87
+ if not content.strip():
88
+ raise ValueError("Empty .env file")
89
+
90
+ # Load environment variables
91
+ success = load_dotenv(env_file_path, override=override)
92
+
93
+ if success:
94
+ return True
95
+
96
+ except Exception as e:
97
+ if attempt == max_retries - 1:
98
+ raise Exception(
99
+ f"Failed to load .env file after {max_retries} attempts: {e}"
100
+ )
101
+ continue
102
+
103
+ return False
104
+
105
+ @staticmethod
106
+ def update_env_file_safely(
107
+ env_file_path: Path, new_content: str, clear_old_vars: bool = True
108
+ ) -> None:
109
+ """
110
+ Safely update .env file with new content, handling caching issues.
111
+
112
+ Args:
113
+ env_file_path: Path to the .env file
114
+ new_content: New content to write
115
+ clear_old_vars: Whether to clear old environment variables
116
+ """
117
+ # Clear old environment variables if requested
118
+ if clear_old_vars:
119
+ EnvManager.clear_env_vars_from_file(env_file_path)
120
+
121
+ # Write new content safely
122
+ EnvManager.write_env_file_safely(env_file_path, new_content)
123
+
124
+ # Load new environment variables with retry
125
+ EnvManager.load_env_with_retry(env_file_path, override=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: codemie-test-harness
3
- Version: 0.1.145
3
+ Version: 0.1.147
4
4
  Summary: Autotest for CodeMie backend and UI
5
5
  Author: Anton Yeromin
6
6
  Author-email: anton_yeromin@epam.com
@@ -13,7 +13,7 @@ Requires-Dist: aws-assume-role-lib (>=2.10.0,<3.0.0)
13
13
  Requires-Dist: boto3 (>=1.39.8,<2.0.0)
14
14
  Requires-Dist: click (>=8.1.7,<9.0.0)
15
15
  Requires-Dist: codemie-plugins (>=0.1.123,<0.2.0)
16
- Requires-Dist: codemie-sdk-python (==0.1.145)
16
+ Requires-Dist: codemie-sdk-python (==0.1.147)
17
17
  Requires-Dist: pytest (>=8.4.1,<9.0.0)
18
18
  Requires-Dist: pytest-playwright (>=0.7.0,<0.8.0)
19
19
  Requires-Dist: pytest-reportportal (>=5.5.2,<6.0.0)
@@ -55,7 +55,9 @@ codemie_test_harness/tests/assistant/tools/servicenow/__init__.py,sha256=47DEQpj
55
55
  codemie_test_harness/tests/assistant/tools/servicenow/test_servicenow_tools.py,sha256=JV_n6COaCsd0_rxQBJvvLZfPdo8BsCbG8Ti-UpzFvfQ,644
56
56
  codemie_test_harness/tests/assistant/tools/vcs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  codemie_test_harness/tests/assistant/tools/vcs/test_assistant_with_vcs_tools.py,sha256=5-QybLWmYSqHG4Sqr-IN-vNcStV4skSwCJQN44Nfats,922
58
- codemie_test_harness/tests/conftest.py,sha256=qzKtJdd7j0I6jBiIOCnz1uF0-Qm0wLWkSwXK_Rg3adI,27869
58
+ codemie_test_harness/tests/conftest.py,sha256=QPqNG47RE7tqzqMW21VMlEeijY2q9PYQNwbTauDkTmY,28638
59
+ codemie_test_harness/tests/conversations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
+ codemie_test_harness/tests/conversations/test_conversations_endpoints.py,sha256=SQraRVrjjE4mYTs4EuGzMrO96DuOuKTiYQ4ZRBhHx70,3913
59
61
  codemie_test_harness/tests/e2e/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
62
  codemie_test_harness/tests/e2e/test_e2e.py,sha256=RUvSu_uNInU1OFfkNft3-Cmd0KZV7JdHqCxSK2ZWXHw,6257
61
63
  codemie_test_harness/tests/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -213,7 +215,9 @@ codemie_test_harness/tests/utils/aws_parameters_store.py,sha256=uwhvrk4qYYWLILS0
213
215
  codemie_test_harness/tests/utils/base_utils.py,sha256=tfishCUxO3iEuasWOifoF9_fXspm4uIHS26Ryqu-NxA,5998
214
216
  codemie_test_harness/tests/utils/client_factory.py,sha256=Yyg2iXe7g7fIfIUbOH8z_8qgVo_lB-nYLOfCV5ONXFw,641
215
217
  codemie_test_harness/tests/utils/constants.py,sha256=lb6mgLjt0GM85Khs18rL1jnE9ILx8L811ykNhpF6IDA,1111
218
+ codemie_test_harness/tests/utils/conversation_utils.py,sha256=SWj6TBWOQoX5Yh6Wk63yHQFveRXgK1mpLb3PUKAa57A,648
216
219
  codemie_test_harness/tests/utils/datasource_utils.py,sha256=-_HZfW_UufSUVkSUCVq4jMlq9MCcKtMhzD6iBtadzmk,12502
220
+ codemie_test_harness/tests/utils/env_utils.py,sha256=9tyVgxKfYqdtSoo9dRTScOZWjAUm82_65JjaKggcwCg,3999
217
221
  codemie_test_harness/tests/utils/file_utils.py,sha256=hY-kwnyzvtd1BQif8r5NhvRTGfpKLmQKyRsq1Tuflhg,585
218
222
  codemie_test_harness/tests/utils/gitbud_utils.py,sha256=UJ3RbhPSjHQSdos6S6zTR9iZULrBDJXoXq9cbjFH7bo,7829
219
223
  codemie_test_harness/tests/utils/http_utils.py,sha256=wjhttibzzNhleKzWgWC01Q0Y5sV9scu-Ski-qgJPd-Q,4179
@@ -323,7 +327,7 @@ codemie_test_harness/tests/workflow/virtual_assistant_tools/servicenow/__init__.
323
327
  codemie_test_harness/tests/workflow/virtual_assistant_tools/servicenow/test_workflow_with_servicenow_tools.py,sha256=Cxe5Yuy9JE_IEsnQOThpVIZQqpfLuHfDkF6JwLngDc8,890
324
328
  codemie_test_harness/tests/workflow/virtual_assistant_tools/vcs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
325
329
  codemie_test_harness/tests/workflow/virtual_assistant_tools/vcs/test_workflow_with_vcs_tools.py,sha256=tm0NvUf_UtzLPTYJWykYpsNoxoVs-Eh80guDmRwImwg,1106
326
- codemie_test_harness-0.1.145.dist-info/METADATA,sha256=51dlZOgpU6_HjYSp6gV5MiLCqZ-5ZoxhwBUgTL3Bgfg,8998
327
- codemie_test_harness-0.1.145.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
328
- codemie_test_harness-0.1.145.dist-info/entry_points.txt,sha256=n98t-EOM5M1mnMl_j2X4siyeO9zr0WD9a5LF7JyElIM,73
329
- codemie_test_harness-0.1.145.dist-info/RECORD,,
330
+ codemie_test_harness-0.1.147.dist-info/METADATA,sha256=p7qB5ZcTZmcvbvhjgT0nucOvVLqFQRZV54T2v0GCy68,8998
331
+ codemie_test_harness-0.1.147.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
332
+ codemie_test_harness-0.1.147.dist-info/entry_points.txt,sha256=n98t-EOM5M1mnMl_j2X4siyeO9zr0WD9a5LF7JyElIM,73
333
+ codemie_test_harness-0.1.147.dist-info/RECORD,,