File size: 4,398 Bytes
494c89b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
Анализ существующей debug сессии

Использование:
    python -m debugger.analyze_session debug_20251220_174313
    python -m debugger.analyze_session --latest
"""

import sys
import json
from pathlib import Path


def find_latest_session(sessions_dir: Path) -> Path:
    """Находит последнюю сессию"""
    sessions = sorted(
        [d for d in sessions_dir.iterdir() if d.is_dir() and d.name.startswith('debug_')],
        key=lambda x: x.stat().st_mtime,
        reverse=True
    )
    if not sessions:
        raise FileNotFoundError("No debug sessions found")
    return sessions[0]


def analyze_session(session_dir: Path):
    """Анализирует сессию"""
    print(f"\n{'='*60}")
    print(f"ANALYZING: {session_dir.name}")
    print(f"{'='*60}")
    
    # Читаем report.json если есть
    report_file = session_dir / 'report.json'
    if report_file.exists():
        report = json.loads(report_file.read_text(encoding='utf-8'))
        
        print(f"\nSession ID: {report.get('session_id')}")
        print(f"Duration: {report.get('total_duration', 0):.1f}s")
        
        summary = report.get('summary', {})
        print(f"\nSummary:")
        print(f"  Steps: {summary.get('total_steps', 0)}")
        print(f"  Requests: {summary.get('total_requests', 0)}")
        print(f"  URL Changes: {summary.get('total_url_changes', 0)}")
        print(f"  Final URL: {summary.get('final_url', '')[:60]}...")
        
        # Cookies
        cookies = summary.get('final_cookies', {})
        print(f"\nImportant Cookies:")
        important = ['workflow-step-id', 'directory-csrf-token', 'login-interview-token']
        for name in important:
            value = cookies.get(name, 'NOT SET')
            print(f"  {name}: {str(value)[:40]}")
        
        # Steps
        print(f"\nSteps:")
        for step in report.get('steps', []):
            status = '✅' if not step.get('error') else '❌'
            print(f"  {status} {step['name']}: {step.get('duration', 0):.1f}s")
            if step.get('error'):
                print(f"      Error: {step['error']}")
            for note in step.get('notes', [])[-3:]:
                print(f"      📝 {note}")
    
    # Проверяем HAR
    har_file = session_dir / 'traffic.har'
    if har_file.exists():
        har = json.loads(har_file.read_text(encoding='utf-8'))
        entries = har.get('log', {}).get('entries', [])
        print(f"\nHAR: {len(entries)} entries")
        
        # Показываем важные запросы
        important_urls = ['signin', 'oauth', 'token', 'fwcim', 'shortbread', 'api/']
        important_entries = [e for e in entries if any(x in e.get('request', {}).get('url', '').lower() for x in important_urls)]
        
        if important_entries:
            print(f"\nImportant requests ({len(important_entries)}):")
            for entry in important_entries[:10]:
                req = entry.get('request', {})
                resp = entry.get('response', {})
                url = req.get('url', '')[:50]
                status = resp.get('status', 0)
                print(f"  [{status}] {req.get('method', 'GET')} {url}...")
    
    # Проверяем скриншоты
    screenshots = list(session_dir.glob('*.png'))
    if screenshots:
        print(f"\nScreenshots: {len(screenshots)}")
        for ss in screenshots:
            print(f"  📷 {ss.name}")
    
    # Проверяем HTML отчёт
    html_file = session_dir / 'report.html'
    if html_file.exists():
        print(f"\n📊 HTML Report: {html_file}")
    
    print(f"\n{'='*60}\n")


def main():
    sessions_dir = Path(__file__).parent.parent / 'debug_sessions'
    
    if len(sys.argv) < 2 or sys.argv[1] == '--latest':
        session_dir = find_latest_session(sessions_dir)
    else:
        session_name = sys.argv[1]
        session_dir = sessions_dir / session_name
        if not session_dir.exists():
            print(f"Session not found: {session_name}")
            print(f"\nAvailable sessions:")
            for d in sorted(sessions_dir.iterdir()):
                if d.is_dir() and d.name.startswith('debug_'):
                    print(f"  {d.name}")
            sys.exit(1)
    
    analyze_session(session_dir)


if __name__ == '__main__':
    main()