diff --git a/memory_management.py b/memory_management.py index 2c95274..85ca22c 100644 --- a/memory_management.py +++ b/memory_management.py @@ -1,3 +1,4 @@ +import json import os import file_utils @@ -20,6 +21,7 @@ def fetch_memory_files(memory_folder: str): return {}, {} memory_files = file_utils.list_all_text_files(memory_path) memory_files_content = file_utils.get_existing_files_content(memory_path, memory_files) + console.info(f"Loaded {len(memory_files_content)} memory files.") return memory_files, memory_files_content def __init__(self, codeplain_api, module_build_folder: str): @@ -95,3 +97,24 @@ def create_conformance_tests_memory( if len(response_files) > 0: memory_folder_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER) file_utils.store_response_files(memory_folder_path, response_files, existing_files) + + def delete_unresolved_memory_files(self): + """Delete memory files whose resolution_status is not 'RESOLVED'.""" + memory_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER) + if not os.path.exists(memory_path): + return + + memory_files = file_utils.list_all_text_files(memory_path) + for file_name in memory_files: + file_path = os.path.join(memory_path, file_name) + try: + with open(file_path, "r") as f: + content = json.load(f) + if content.get("resolution_status") == "RESOLVED": + continue + except (json.JSONDecodeError, OSError): + # Not a valid JSON file, unlikely to be a valid memory file, delete it + console.error(f"Memory file is not a valid JSON file: {file_name}. Deleting it.") + os.remove(file_path) + os.remove(file_path) + console.debug(f"Deleted temporary memory file: {file_name}") diff --git a/render_machine/actions/run_conformance_tests.py b/render_machine/actions/run_conformance_tests.py index bc8e610..1ad4a7d 100644 --- a/render_machine/actions/run_conformance_tests.py +++ b/render_machine/actions/run_conformance_tests.py @@ -54,9 +54,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any | ) if exit_code == 0: - conformance_tests_issue = "All conformance tests passed successfully!" - - if exit_code == 0: + render_context.memory_manager.delete_unresolved_memory_files() return self.SUCCESSFUL_OUTCOME, None if exit_code in UNRECOVERABLE_ERROR_EXIT_CODES: