-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-slack-flow.py
More file actions
85 lines (74 loc) · 4.01 KB
/
Copy pathtest-slack-flow.py
File metadata and controls
85 lines (74 loc) · 4.01 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
#!/usr/bin/env python3
"""
End-to-end test for the Slack session-thread routing.
Steps:
1. Submit a prompt
2. Analyze it (generates questions)
3. Route ALL questions to Slack (creates session thread + numbered replies)
4. Print the question IDs so you can verify thread-reply capture manually
Usage:
python3 test-slack-flow.py
"""
import json, urllib.request, urllib.error, sys, time
BACKEND = "http://44.200.186.86/reasoning"
REPO = "/Users/manishkumar/Documents/reasoning-layer" # any existing path
def api(method, path, body=None):
url = BACKEND + path
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(
url, data=data,
headers={"Content-Type": "application/json"} if data else {},
method=method,
)
try:
resp = urllib.request.urlopen(req, timeout=30)
return json.loads(resp.read())
except urllib.error.HTTPError as e:
print(f" ✗ HTTP {e.code} on {method} {path}: {e.read().decode()}")
sys.exit(1)
# ── Step 1: submit prompt ──────────────────────────────────────────────────────
print("\n1. Submitting prompt…")
prompt = api("POST", "/api/prompts", {
"content": "Add a multi-tenant billing system: each org gets its own Stripe customer, "
"usage-based pricing tiers, invoice generation, and a grace-period for failed payments.",
"repo_path": REPO,
})
pid = prompt["prompt_id"]
print(f" prompt_id = {pid}")
# ── Step 2: analyze ───────────────────────────────────────────────────────────
print("2. Analyzing (LLM call — ~10s)…")
analysis = api("POST", f"/api/prompts/{pid}/analyze", {})
questions = analysis.get("questions", [])
print(f" risk={analysis['analysis']['risk_level']} domain={analysis['analysis']['domain']}")
print(f" {len(questions)} question(s) generated:")
for i, q in enumerate(questions, 1):
print(f" Q{i}: [{q['risk_level']}] {q['text'][:80]}")
if not questions:
print(" No questions generated — nothing to route.")
sys.exit(0)
# ── Step 3: fetch question IDs from DB ────────────────────────────────────────
print("3. Fetching question IDs…")
detail = api("GET", f"/api/prompts/{pid}")
db_questions = detail["questions"]
# ── Step 4: route to Slack ────────────────────────────────────────────────────
print("4. Routing questions to Slack…")
for i, dbq in enumerate(db_questions, 1):
print(f" Routing Q{i}: {dbq['question_id'][:8]}… ", end="", flush=True)
result = api("POST", f"/api/questions/{dbq['question_id']}/route", {})
print(f"status={result.get('status')} ts={result.get('slack_message_ts', '?')[:10]}")
if i < len(db_questions):
time.sleep(0.5) # small gap between routes
# ── Done ──────────────────────────────────────────────────────────────────────
print("\n✅ Done. Check Slack now:")
print(" • One session thread should have appeared in your escalation channel")
print(f" • It contains {len(db_questions)} numbered question replies (Q1 of N … QN of N)")
print(" • Reply to any question reply in that thread → should be captured")
print(" • Or click '✏️ Answer with rationale' on any question for the modal")
print()
print("To verify capture after replying, run:")
print(f" python3 -c \"")
print(f" import json, urllib.request")
print(f" r = urllib.request.urlopen('{BACKEND}/api/prompts/{pid}')")
print(f" d = json.loads(r.read())")
print(f" [print(q['question_id'][:8], q['status']) for q in d['questions']]")
print(f" \"")