File size: 8,256 Bytes
22087d0 | 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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | #!/usr/bin/env python3
"""
Comprehensive build verification script.
Checks:
1. All critical imports work
2. Syntax errors
3. Import path correctness
4. Can start API server (briefly)
5. Can start worker (briefly)
"""
import subprocess
import sys
import os
import tempfile
def run_command(cmd, timeout=30, cwd=None):
"""Run a command and return success, output."""
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
timeout=timeout,
cwd=cwd or os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
)
return result.returncode == 0, result.stdout + result.stderr
except subprocess.TimeoutExpired:
return False, f"Command timed out after {timeout}s"
except Exception as e:
return False, str(e)
def check_imports():
"""Test critical imports."""
print("π Step 1: Checking critical imports...")
imports = [
"from core.services.supabase import DBConnection",
"from core.agents.api import router",
"from core.threads.api import router",
"from core.memory.background_jobs import start_memory_extraction",
"from core.agents.api import _load_agent_config",
"from core.agents.agent_loader import get_agent_loader",
"from core.agents.api import start_agent_run",
]
errors = []
for import_stmt in imports:
success, output = run_command(
f'uv run python -c "{import_stmt}"',
timeout=10
)
if not success:
if "ModuleNotFoundError" in output or "ImportError" in output:
error_line = [l for l in output.split('\n') if 'ModuleNotFoundError' in l or 'ImportError' in l]
errors.append(f" β {import_stmt}\n {error_line[0] if error_line else output[:200]}")
if errors:
print(f"β Found {len(errors)} import error(s):")
for error in errors:
print(error)
return False
else:
print("β
All imports successful!")
return True
def check_old_imports():
"""Check for old import paths that should have been updated."""
print("\nπ Step 2: Checking for old import paths...")
# Only check for actual module imports, not package imports
old_patterns = [
("core.runtime_cache", "core.cache.runtime_cache"),
("core.suna_config", "core.config.suna_config"),
("core.config_helper", "core.config.config_helper"),
]
errors = []
for old_pattern, new_pattern in old_patterns:
success, output = run_command(
f"grep -r 'from {old_pattern} import' core/ --include='*.py' | grep -v '__pycache__' | grep -v '^#' | head -5",
timeout=10
)
if success and output.strip():
lines = [l for l in output.split('\n') if f'from {old_pattern} import' in l]
if lines:
errors.append(f" β οΈ Found '{old_pattern}' imports (should be '{new_pattern}'):")
for line in lines[:3]:
errors.append(f" {line.strip()}")
if errors:
print("β οΈ Found old import patterns:")
for error in errors:
print(error)
return False
else:
print("β
No old import patterns found!")
return True
def check_syntax():
"""Check Python syntax."""
print("\nπ Step 3: Checking Python syntax...")
success, output = run_command(
"find core -name '*.py' -exec python -m py_compile {} \\; 2>&1",
timeout=60
)
if not success:
# Filter out permission errors, focus on syntax errors
syntax_errors = [l for l in output.split('\n') if 'SyntaxError' in l or 'IndentationError' in l]
if syntax_errors:
print(f"β Syntax errors found:")
for error in syntax_errors[:10]:
print(f" {error}")
return False
else:
print("β οΈ Some files couldn't be checked (may be permission issues)")
return True
else:
print("β
All Python files have valid syntax!")
return True
def check_with_ruff():
"""Check with ruff for critical import errors."""
print("\nπ Step 4: Checking with ruff (critical import errors only)...")
# Only check for F821 (undefined names) which are real errors
# F811 (redefinition) are warnings, not critical
success, output = run_command(
"uv run ruff check --select F821 core/ 2>&1 | head -20 || true",
timeout=30
)
# Filter for actual undefined name errors
undefined_errors = [line for line in output.split('\n') if 'F821' in line and 'Undefined name' in line]
if undefined_errors:
print(f"β Found undefined name errors:")
for error in undefined_errors[:10]:
print(f" {error}")
return False
else:
print("β
No undefined name errors found!")
return True
def test_api_import():
"""Test if API can be imported."""
print("\nπ Step 5: Testing API module import...")
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
f.write("""
import sys
sys.path.insert(0, '.')
try:
from core.services.supabase import DBConnection
print('β
DBConnection imports successfully')
except Exception as e:
print(f'β DBConnection import failed: {e}')
sys.exit(1)
""")
temp_file = f.name
try:
success, output = run_command(
f'uv run python {temp_file}',
timeout=15
)
if success and "β
" in output:
print("β
API can be imported!")
return True
else:
print(f"β API import failed:\n{output[:500]}")
return False
finally:
os.unlink(temp_file)
def test_background_jobs_import():
"""Test if background jobs can be imported."""
print("\nπ Step 6: Testing background jobs import...")
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
f.write("""
import sys
sys.path.insert(0, '.')
try:
from core.memory.background_jobs import start_memory_extraction
print('β
Background jobs module imports successfully')
except Exception as e:
print(f'β Background jobs import failed: {e}')
import traceback
traceback.print_exc()
sys.exit(1)
""")
temp_file = f.name
try:
success, output = run_command(
f'uv run python {temp_file}',
timeout=15
)
if success and "β
" in output:
print("β
Background jobs can be imported!")
return True
else:
print(f"β Background jobs import failed:\n{output[:500]}")
return False
finally:
os.unlink(temp_file)
def main():
"""Run all checks."""
print("=" * 60)
print("π Starting Build Verification")
print("=" * 60)
checks = [
("Imports", check_imports),
("Old Import Paths", check_old_imports),
("Syntax", check_syntax),
("Ruff Undefined Names", check_with_ruff),
("API Import", test_api_import),
("Background Jobs Import", test_background_jobs_import),
]
results = []
for name, check_func in checks:
try:
result = check_func()
results.append((name, result))
except Exception as e:
print(f"β {name} check failed with exception: {e}")
results.append((name, False))
print("\n" + "=" * 60)
print("π Build Verification Summary")
print("=" * 60)
all_passed = True
for name, result in results:
status = "β
PASS" if result else "β FAIL"
print(f"{status} - {name}")
if not result:
all_passed = False
print("=" * 60)
if all_passed:
print("β
All checks passed! Build is ready.")
return 0
else:
print("β Some checks failed. Please fix errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())
|