from sample_permutations import ProjectType, PROJECT_TYPE_FUNCTIONS from state import state from common_functions_v4 import fetch_session def test_project_workflow(session_id="62"): """Test the project workflow with an existing session""" try: # 1. Use the project from global state project = state.quotation_project project.project_type = None project.session_id = None # 2. Fetch existing session data print(f"\nFetching session {session_id}...") status, requirements, message = fetch_session(session_id) if "Error" in message or "not found" in message: print(f"Failed to fetch session: {message}") return print("\nSession loaded successfully!") print(f"Status: {status}") print(f"Requirements: {requirements}") # 3. Generate PRD first print("\nGenerating PRD...") project.generated_prd = project.execute_prompt( "generate_prd", { "project_detail": project.get_project_detail() } ) print("\nGenerated PRD:") print(project.generated_prd) # 4. Get project type from user input print("\nPlease select a project type:") for i, project_type in enumerate(ProjectType, 1): print(f"{i}. {project_type.value}") while True: try: choice = int(input("\nEnter the number of your choice (1-4): ")) if 1 <= choice <= len(ProjectType): selected_type = list(ProjectType)[choice - 1] break print("Invalid choice. Please select a number between 1 and 4.") except ValueError: print("Please enter a valid number.") # 5. Update project type project.project_type = selected_type print(f"\nSelected project type: {selected_type.value}") # 6. Execute functions based on project type functions_to_execute = PROJECT_TYPE_FUNCTIONS[selected_type] print(f"\nExecuting functions for {selected_type.value}:") for function_name in functions_to_execute: print(f"\nExecuting {function_name}...") # Let execute_prompt handle input requirements automatically result = project.execute_prompt(function_name) # Store result in corresponding project attribute output_attr = f"generated_{function_name.replace('generate_', '')}" setattr(project, output_attr, result) print(f"Generated {function_name.replace('generate_', '')}") print(f"Result preview:") print(result[:500] + "..." if len(result) > 500 else result) print("-" * 80) print("\nWorkflow completed successfully!") except Exception as e: print(f"Error in test workflow: {str(e)}") raise if __name__ == "__main__": test_project_workflow()