Skip to content

Commit ddfac4a

Browse files
committed
move code from context to action
1 parent 28d396a commit ddfac4a

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

render_machine/actions/refactor_code.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@
77
from render_machine.render_context import RenderContext
88

99

10+
MAX_REFACTORING_ITERATIONS = 5
11+
12+
1013
class RefactorCode(BaseAction):
1114
SUCCESSFUL_OUTCOME = "refactoring_successful"
1215
NO_FILES_REFACTORED_OUTCOME = "no_files_refactored"
16+
ITERATION_LIMIT_EXCEEDED_OUTCOME = "refactoring_iteration_limit_exceeded"
1317

1418
def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
19+
if render_context.frid_context.refactoring_iteration == 0:
20+
console.info("Refactoring the generated code...")
21+
22+
render_context.frid_context.refactoring_iteration += 1
23+
24+
if render_context.frid_context.refactoring_iteration >= MAX_REFACTORING_ITERATIONS:
25+
console.info(
26+
f"Refactoring iterations limit of {MAX_REFACTORING_ITERATIONS} reached for functionality {render_context.frid_context.frid}."
27+
)
28+
return self.ITERATION_LIMIT_EXCEEDED_OUTCOME, None
29+
1530
existing_files, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(
1631
render_context.build_folder
1732
)

render_machine/render_context.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
)
2424

2525
MAX_UNITTEST_FIX_ATTEMPTS = 20
26-
MAX_REFACTORING_ITERATIONS = 5
2726
MAX_FUNCTIONAL_REQUIREMENT_RENDER_ATTEMPTS_FAILED_UNIT_DURING_CONFORMANCE_TESTS = 2
2827

2928

@@ -292,19 +291,6 @@ def _on_unit_test_limit_exceeded_in_refactoring(self):
292291
git_utils.revert_changes(self.build_folder)
293292
self.machine.dispatch(triggers.START_NEW_REFACTORING_ITERATION)
294293

295-
def start_refactoring_code(self):
296-
297-
if self.frid_context.refactoring_iteration == 0:
298-
console.info("Refactoring the generated code...")
299-
300-
self.frid_context.refactoring_iteration += 1
301-
302-
if self.frid_context.refactoring_iteration >= MAX_REFACTORING_ITERATIONS:
303-
console.info(
304-
f"Refactoring iterations limit of {MAX_REFACTORING_ITERATIONS} reached for functionality {self.frid_context.frid}."
305-
)
306-
self.machine.dispatch(triggers.PROCEED_FRID_PROCESSING)
307-
308294
def start_conformance_tests_processing(self):
309295
console.info("Implementing conformance tests...")
310296
current_frid_specifications, _ = plain_spec.get_specifications_for_frid(

render_machine/state_machine_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def get_action_result_triggers_map(self) -> Dict[str, str]:
8080
FixUnitTests.SUCCESSFUL_OUTCOME: triggers.MARK_UNIT_TESTS_READY,
8181
RefactorCode.SUCCESSFUL_OUTCOME: triggers.REFACTOR_CODE,
8282
RefactorCode.NO_FILES_REFACTORED_OUTCOME: triggers.PROCEED_FRID_PROCESSING,
83+
RefactorCode.ITERATION_LIMIT_EXCEEDED_OUTCOME: triggers.PROCEED_FRID_PROCESSING,
8384
CommitImplementationCodeChanges.SUCCESSFUL_OUTCOME: triggers.PROCEED_FRID_PROCESSING,
8485
FinishFunctionalRequirement.SUCCESSFUL_OUTCOME: triggers.PROCEED_FRID_PROCESSING,
8586
CreateDist.SUCCESSFUL_OUTCOME: triggers.FINISH_RENDER,
@@ -160,7 +161,6 @@ def get_states(self, render_context: RenderContext) -> List[Any]:
160161
refactoring_code_states = {
161162
"name": States.REFACTORING_CODE.value,
162163
"initial": States.READY_FOR_REFACTORING.value,
163-
"on_enter": render_context.start_refactoring_code,
164164
"children": [
165165
States.READY_FOR_REFACTORING.value,
166166
self.get_processing_unit_tests_states(

0 commit comments

Comments
 (0)