-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreflight_check.py
More file actions
142 lines (121 loc) · 4.27 KB
/
preflight_check.py
File metadata and controls
142 lines (121 loc) · 4.27 KB
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
#!/usr/bin/env python3
"""
CIK-Bench Pre-flight Check
Verifies your environment is ready to run attack cases.
Usage:
python3 preflight_check.py
"""
import json
import os
import subprocess
import sys
from pathlib import Path
errors = []
warnings = []
def ok(label):
print(f" \033[32m✓\033[0m {label}")
def fail(label, msg, warn=False):
if warn:
print(f" \033[33m!\033[0m {label}: {msg}")
warnings.append(msg)
else:
print(f" \033[31m✗\033[0m {label}: {msg}")
errors.append(msg)
def cmd_exists(name):
return subprocess.run(["which", name], capture_output=True).returncode == 0
print()
print(" CIK-Bench Pre-flight Check")
print(" " + "=" * 40)
# ── 1. OpenClaw Workspace ──
print("\n[1] OpenClaw Workspace")
ws = Path.home() / ".openclaw" / "workspace"
if ws.is_dir():
ok("~/.openclaw/workspace/ exists")
for f in ["SOUL.md", "AGENTS.md", "USER.md", "IDENTITY.md", "MEMORY.md"]:
p = ws / f
if p.exists():
content = p.read_text()
if "{{" in content:
fail(f, "still contains {{placeholders}} — run scripts/configure.sh")
else:
ok(f)
else:
fail(f, "not found")
else:
fail("workspace", "~/.openclaw/workspace/ not found — run scripts/setup_openclaw.sh")
# ── 2. OpenClaw Gateway ──
print("\n[2] OpenClaw Gateway")
if cmd_exists("openclaw"):
ok(f"openclaw installed")
r = subprocess.run(["pgrep", "-f", "openclaw"], capture_output=True, text=True)
if r.stdout.strip():
ok("gateway process running")
else:
fail("gateway", "not running — start with: openclaw gateway", warn=True)
else:
fail("openclaw", "not installed — run scripts/setup_openclaw.sh")
# ── 3. Gmail (gog) ──
print("\n[3] Gmail")
if cmd_exists("gog"):
ok("gog installed")
r = subprocess.run(["gog", "auth", "list"], capture_output=True, text=True)
if r.returncode == 0 and r.stdout.strip():
ok(f"gog auth configured")
else:
fail("gog auth", "no accounts — run: gog auth add <gmail> --services gmail --extra-scopes https://mail.google.com/ --force-consent")
else:
fail("gog", "not installed — run: npm install -g gog")
# ── 4. Telegram ──
print("\n[4] Telegram")
api_id = os.environ.get("TELEGRAM_API_ID", "")
api_hash = os.environ.get("TELEGRAM_API_HASH", "")
bot = os.environ.get("OPENCLAW_BOT", "")
if api_id and api_hash:
ok("TELEGRAM_API_ID and TELEGRAM_API_HASH set")
else:
fail("Telegram env", "TELEGRAM_API_ID / TELEGRAM_API_HASH not set — set -a && source .env && set +a")
if bot:
ok(f"OPENCLAW_BOT = {bot}")
else:
fail("OPENCLAW_BOT", "not set — set -a && source .env && set +a", warn=True)
# Check for Telethon session
sessions = list(Path("test_harness").glob("*.session")) if Path("test_harness").is_dir() else []
if sessions:
ok(f"Telethon session: {sessions[0].name}")
else:
fail("Telethon session", "not found — run: python test_harness/login.py", warn=True)
# ── 5. Stripe ──
print("\n[5] Stripe")
stripe_key = ws / ".stripe-key" if ws.is_dir() else None
if stripe_key and stripe_key.exists():
key = stripe_key.read_text().strip()
if key.startswith("sk_test_"):
ok(".stripe-key configured (test mode)")
elif "{{" in key:
fail(".stripe-key", "still contains placeholder — run scripts/configure.sh")
else:
fail(".stripe-key", "doesn't look like a test key (should start with sk_test_)", warn=True)
else:
fail(".stripe-key", "not found", warn=True)
# ── 6. Test Cases ──
print("\n[6] Test Cases")
for d in ["attack_cases", "benign_cases", "defense_assets"]:
p = Path(d)
if p.is_dir():
count = len(list(p.rglob("*.md")))
ok(f"{d}/ ({count} files)")
else:
if Path("templates", d).is_dir():
fail(d, "not found — run scripts/configure.sh to generate from templates/")
else:
fail(d, "directory not found")
# ── Summary ──
print(f"\n {'=' * 40}")
if errors:
print(f" \033[31m{len(errors)} error(s) — fix before running\033[0m")
sys.exit(1)
elif warnings:
print(f" \033[33m{len(warnings)} warning(s), but OK to proceed\033[0m")
else:
print(f" \033[32mAll checks passed — ready to run!\033[0m")
print()