|
7 | 7 | import plain_spec |
8 | 8 | from codeplain_REST_api import CodeplainAPI |
9 | 9 | from event_bus import EventBus |
10 | | -from memory_management import MemoryStore, fingerprint_output |
| 10 | +from memory_management import MemoryStore, Suite, fingerprint_output |
11 | 11 | from plain2code_console import RETRY_COLOR, console |
12 | 12 | from plain2code_events import RenderContextSnapshot |
13 | 13 | from plain2code_state import RunState |
@@ -123,29 +123,63 @@ def create_snapshot(self) -> RenderContextSnapshot: |
123 | 123 | module_name=self.module_name, |
124 | 124 | ) |
125 | 125 |
|
126 | | - def retrieve_memory_for_current_failure(self, failure_output: Optional[str]) -> dict[str, str]: |
127 | | - """Select the memory records relevant to the failure currently being fixed. |
| 126 | + def retrieve_memory_for_conformance_failure(self, failure_output: Optional[str]) -> dict[str, str]: |
| 127 | + """Select memory records relevant to the conformance failure being fixed.""" |
| 128 | + running_context = self.conformance_tests_running_context |
| 129 | + |
| 130 | + return self._retrieve_memory( |
| 131 | + failure_output, |
| 132 | + suite=Suite.CONFORMANCE.value, |
| 133 | + test_name=( |
| 134 | + running_context.get_current_conformance_test_folder_name() |
| 135 | + if running_context and running_context.current_conformance_tests_exist() |
| 136 | + else None |
| 137 | + ), |
| 138 | + fix_attempts=running_context.fix_attempts if running_context else 0, |
| 139 | + ) |
128 | 140 |
|
129 | | - The retrieval query comes entirely from render state - the failure being worked on, |
130 | | - the test that produced it, and how many fix attempts have been made - so no planner |
131 | | - call is needed. Retrieval depth grows with the attempt count: an early attempt gets |
132 | | - little or nothing, a deep fix loop gets the full picture. |
| 141 | + def retrieve_memory_for_unittest_failure(self, failure_output: Optional[str]) -> dict[str, str]: |
| 142 | + """Select memory records relevant to the unit-test failure being fixed. |
| 143 | +
|
| 144 | + Unit-test observations rank first; conformance observations can still surface once |
| 145 | + the same-surface evidence is exhausted, since both loops change the same code. |
| 146 | + """ |
| 147 | + running_context = self.unit_tests_running_context |
| 148 | + |
| 149 | + return self._retrieve_memory( |
| 150 | + failure_output, |
| 151 | + suite=Suite.UNITTEST.value, |
| 152 | + files_changed=sorted(running_context.changed_files) if running_context else None, |
| 153 | + fix_attempts=running_context.fix_attempts if running_context else 0, |
| 154 | + ) |
| 155 | + |
| 156 | + def _retrieve_memory( |
| 157 | + self, |
| 158 | + failure_output: Optional[str], |
| 159 | + suite: str, |
| 160 | + test_name: Optional[str] = None, |
| 161 | + files_changed: Optional[list[str]] = None, |
| 162 | + fix_attempts: int = 0, |
| 163 | + ) -> dict[str, str]: |
| 164 | + """Query the memory store for the failure currently being fixed. |
| 165 | +
|
| 166 | + The query comes entirely from render state - the failure being worked on, the test |
| 167 | + that produced it, and how many fix attempts have been made - so no planner call is |
| 168 | + needed. Depth grows with the attempt count: an early attempt gets little or nothing, |
| 169 | + a deep fix loop gets the full picture. |
133 | 170 | """ |
134 | 171 | if failure_output is None: |
135 | 172 | return {} |
136 | 173 |
|
137 | 174 | fingerprint, signature, _ = fingerprint_output(failure_output) |
138 | | - running_context = self.conformance_tests_running_context |
139 | 175 |
|
140 | 176 | return self.memory_store.retrieve( |
141 | 177 | fingerprint=fingerprint, |
142 | | - test_name=( |
143 | | - running_context.get_current_conformance_test_folder_name() |
144 | | - if running_context and running_context.current_conformance_tests_exist() |
145 | | - else None |
146 | | - ), |
| 178 | + test_name=test_name, |
| 179 | + files_changed=files_changed, |
147 | 180 | signature=signature, |
148 | | - fix_attempts=running_context.fix_attempts if running_context else 0, |
| 181 | + fix_attempts=fix_attempts, |
| 182 | + suite=suite, |
149 | 183 | ) |
150 | 184 |
|
151 | 185 | def get_required_modules_functionalities(self): |
|
0 commit comments