Skip to content

Commit 496327a

Browse files
authored
Removing unresolved memory files (#120)
* Removing unresolved memory files.
1 parent 8a3619e commit 496327a

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

memory_management.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23

34
import file_utils
@@ -20,6 +21,7 @@ def fetch_memory_files(memory_folder: str):
2021
return {}, {}
2122
memory_files = file_utils.list_all_text_files(memory_path)
2223
memory_files_content = file_utils.get_existing_files_content(memory_path, memory_files)
24+
console.info(f"Loaded {len(memory_files_content)} memory files.")
2325
return memory_files, memory_files_content
2426

2527
def __init__(self, codeplain_api, module_build_folder: str):
@@ -95,3 +97,24 @@ def create_conformance_tests_memory(
9597
if len(response_files) > 0:
9698
memory_folder_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
9799
file_utils.store_response_files(memory_folder_path, response_files, existing_files)
100+
101+
def delete_unresolved_memory_files(self):
102+
"""Delete memory files whose resolution_status is not 'RESOLVED'."""
103+
memory_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER)
104+
if not os.path.exists(memory_path):
105+
return
106+
107+
memory_files = file_utils.list_all_text_files(memory_path)
108+
for file_name in memory_files:
109+
file_path = os.path.join(memory_path, file_name)
110+
try:
111+
with open(file_path, "r") as f:
112+
content = json.load(f)
113+
if content.get("resolution_status") == "RESOLVED":
114+
continue
115+
except (json.JSONDecodeError, OSError):
116+
# Not a valid JSON file, unlikely to be a valid memory file, delete it
117+
console.error(f"Memory file is not a valid JSON file: {file_name}. Deleting it.")
118+
os.remove(file_path)
119+
os.remove(file_path)
120+
console.debug(f"Deleted temporary memory file: {file_name}")

render_machine/actions/run_conformance_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
5454
)
5555

5656
if exit_code == 0:
57-
conformance_tests_issue = "All conformance tests passed successfully!"
58-
59-
if exit_code == 0:
57+
render_context.memory_manager.delete_unresolved_memory_files()
6058
return self.SUCCESSFUL_OUTCOME, None
6159

6260
if exit_code in UNRECOVERABLE_ERROR_EXIT_CODES:

0 commit comments

Comments
 (0)