diff --git a/features/steps/tdd_plan_generation_validate_steps.py b/features/steps/tdd_plan_generation_validate_steps.py index bc8eba32a..8f78aea4b 100644 --- a/features/steps/tdd_plan_generation_validate_steps.py +++ b/features/steps/tdd_plan_generation_validate_steps.py @@ -1,11 +1,31 @@ """Additional Behave steps for TDD validation scenarios for PlanGenerationGraph.""" from __future__ import annotations -from behave import when from typing import Any + +from behave import given, then, when +from langchain_community.llms import FakeListLLM +from cleveragents.agents.plan_generation import PlanGenerationGraph from cleveragents.domain.models.core import Change, OperationType +def _test_llm() -> FakeListLLM: + """Create a FakeListLLM for test purposes.""" + return FakeListLLM( + responses=[ + "Requirements: Add error handling with try-except blocks", + "Generated code with proper error handling implementation", + "Validation passed: Code follows best practices", + ] + ) + + +@given("I have a langgraph PlanGenerationGraph instance") +def step_have_langgraph_graph_instance(context: Any) -> None: + """Create a PlanGenerationGraph instance with a test LLM.""" + context.graph = PlanGenerationGraph(llm=_test_llm()) + + @when("I execute the langgraph validate node with generated code:") def step_execute_langgraph_validate_with_code(context: Any) -> None: """Execute validate node with provided generated code in the step docstring. @@ -33,3 +53,10 @@ def step_execute_langgraph_validate_with_code(context: Any) -> None: ) state = {"generated_changes": [change]} context.node_result = context.graph._validate(state) + + +@then("the langgraph validation status should be \"{status}\"") +def step_validation_status(context: Any, status: str) -> None: + """Verify the validation result has the expected status.""" + result = context.node_result["validation_result"] + assert result["status"] == status.upper() diff --git a/features/tdd_plan_generation_validate_logic.feature b/features/tdd_plan_generation_validate_logic.feature index 73170420e..012a1003f 100644 --- a/features/tdd_plan_generation_validate_logic.feature +++ b/features/tdd_plan_generation_validate_logic.feature @@ -3,7 +3,7 @@ Feature: TDD — PlanGenerationGraph validation logic I want the PlanGenerationGraph._validate() logic to respect explicit LLM FAIL responses So that generated code is rejected when the LLM indicates failure, regardless of code length - @tdd_issue @tdd_issue_10746 + @tdd_issue_10746 Scenario: FAIL response is respected for code longer than 10 characters Given I have a langgraph PlanGenerationGraph instance When I execute the langgraph validate node with generated code: @@ -12,7 +12,7 @@ Feature: TDD — PlanGenerationGraph validation logic """ Then the langgraph validation status should be "FAIL" - @tdd_issue @tdd_issue_10746 + @tdd_issue_10746 Scenario: PASS response is accepted when no FAIL present Given I have a langgraph PlanGenerationGraph instance When I execute the langgraph validate node with generated code: @@ -21,7 +21,7 @@ Feature: TDD — PlanGenerationGraph validation logic """ Then the langgraph validation status should be "PASS" - @tdd_issue @tdd_issue_10746 + @tdd_issue_10746 Scenario: Mixed PASS and FAIL prefers FAIL Given I have a langgraph PlanGenerationGraph instance When I execute the langgraph validate node with generated code: @@ -31,7 +31,7 @@ Feature: TDD — PlanGenerationGraph validation logic """ Then the langgraph validation status should be "FAIL" - @tdd_issue @tdd_issue_10746 + @tdd_issue_10746 Scenario: No explicit PASS or FAIL and code length > 10 should fail Given I have a langgraph PlanGenerationGraph instance When I execute the langgraph validate node with generated code: @@ -41,7 +41,7 @@ Feature: TDD — PlanGenerationGraph validation logic """ Then the langgraph validation status should be "FAIL" - @tdd_issue @tdd_issue_10746 + @tdd_issue_10746 Scenario: PASS keyword in mixed-case is accepted (case-insensitive) Given I have a langgraph PlanGenerationGraph instance When I execute the langgraph validate node with generated code: