File size: 3,093 Bytes
6bd39eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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()