File size: 5,362 Bytes
ba52031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2058884
ba52031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2058884
ba52031
 
 
 
 
2058884
ba52031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2058884
ba52031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2058884
 
 
 
 
ba52031
 
 
 
 
2058884
ba52031
2058884
ba52031
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
"""
Verification script for OpenEnv Competition Setup

Checks all required components and validates the setup is ready for submission.
"""

import os
import sys
import json
import subprocess
from pathlib import Path
from typing import Tuple
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

def check_file_exists(path: str, description: str) -> Tuple[bool, str]:
    """Check if a required file exists."""
    p = Path(path)
    if p.exists():
        return True, f"[OK] {description}: {path}"
    return False, f"[FAIL] {description}: MISSING - {path}"

def check_python_module(module_name: str) -> Tuple[bool, str]:
    """Check if a Python module is installed."""
    try:
        __import__(module_name)
        return True, f"[OK] {module_name} installed"
    except ImportError:
        return False, f"[FAIL] {module_name} NOT installed"

def check_env_var(var_name: str) -> Tuple[bool, str]:
    """Check if an environment variable is set."""
    value = os.getenv(var_name)
    if value:
        masked = value[:10] + "***" if len(value) > 10 else "***"
        return True, f"[OK] {var_name} is set ({masked})"
    return False, f"[FAIL] {var_name} NOT set"

def check_syntax(file_path: str) -> Tuple[bool, str]:
    """Check Python file syntax."""
    try:
        compile(open(file_path).read(), file_path, 'exec')
        return True, f"[OK] {file_path} syntax OK"
    except SyntaxError as e:
        return False, f"[FAIL] {file_path} has syntax error: {e}"

def check_task_files() -> Tuple[bool, str]:
    """Check that all tasks have required files."""
    for task_num in [1, 2, 3]:
        task_dir = f"debug_env/tasks/task{task_num}"
        broken_code = f"{task_dir}/broken_code.py"
        test_code = f"{task_dir}/test_code.py"

        if not Path(broken_code).exists():
            return False, f"[FAIL] {broken_code} missing"
        if not Path(test_code).exists():
            return False, f"[FAIL] {test_code} missing"

    return True, "[OK] All 3 tasks have required files"

def check_docker_file() -> Tuple[bool, str]:
    """Check Dockerfile exists and is readable."""
    dockerfile = "Dockerfile"
    if Path(dockerfile).exists():
        try:
            with open(dockerfile) as f:
                content = f.read()
                if "FROM" in content and "CMD" in content:
                    return True, f"[OK] Dockerfile is valid"
        except Exception as e:
            return False, f"[FAIL] Dockerfile error: {e}"
    return False, f"[FAIL] Dockerfile missing"

def main():
    print("\n" + "=" * 70)
    print("OpenEnv Competition Setup Verification")
    print("=" * 70 + "\n")

    checks = []

    # 1. File structure
    print("1. Checking file structure...")
    checks.append(check_file_exists("openenv.yaml", "openenv.yaml"))
    checks.append(check_file_exists("inference.py", "inference.py (competition entry point)"))
    checks.append(check_file_exists(".env", ".env configuration"))
    checks.append(check_file_exists(".env.example", ".env.example template"))
    checks.append(check_file_exists("README.md", "README.md"))
    checks.append(check_file_exists("pyproject.toml", "pyproject.toml (root)"))
    checks.append(check_file_exists("uv.lock", "uv.lock (dependency lock file)"))
    checks.append(check_file_exists("docker-compose.yml", "docker-compose.yml"))
    checks.append(check_docker_file())

    # 2. Task files
    print("\n2. Checking task files...")
    checks.append(check_task_files())

    # 3. Python syntax
    print("\n3. Checking Python syntax...")
    checks.append(check_syntax("inference.py"))

    # 4. Required Python modules
    print("\n4. Checking Python dependencies...")
    checks.append(check_python_module("openai"))
    checks.append(check_python_module("httpx"))
    checks.append(check_python_module("openenv"))
    checks.append(check_python_module("fastapi"))

    # 5. Environment variables
    print("\n5. Checking environment configuration...")
    checks.append(check_env_var("HF_TOKEN"))
    checks.append(check_env_var("API_BASE_URL"))
    checks.append(check_env_var("MODEL_NAME"))

    # Print results
    print("\n" + "=" * 70)
    print("Verification Results")
    print("=" * 70 + "\n")

    passed = 0
    failed = 0

    for success, message in checks:
        print(message)
        if success:
            passed += 1
        else:
            failed += 1

    print("\n" + "=" * 70)
    print(f"Summary: {passed} passed, {failed} failed")
    print("=" * 70 + "\n")

    if failed == 0:
        print("[SUCCESS] All checks passed! Your setup is ready for competition.\n")
        print("Next steps:")
        print("  1. Ensure HF_TOKEN is set in .env")
        print("  2. Run: uv run server  (Terminal 1)")
        print("  3. Run: python inference.py  (Terminal 2)")
        print("  4. Check results in results_task1_*.json")
        print("  5. Deploy: openenv push --repo-id your-username/debug-env")
        return 0
    else:
        print(f"[ERROR] {failed} checks failed. Please fix the issues above.\n")
        if failed >= 2:
            print("Start with:")
            print("  1. uv sync")
            print("  2. cp .env.example .env")
            print("  3. Edit .env with your HF_TOKEN")
        return 1

if __name__ == "__main__":
    sys.exit(main())