- scripts/learner-*.sh → scripts/dev-*.sh - docs/learner-*.md → docs/dev-*.md - tests/test-learner-env.sh → tests/test-dev-env.sh - Update all internal references 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.4 KiB
Python
Executable file
95 lines
2.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Test slack-bolt can connect via Socket Mode.
|
|
|
|
Run on server as dev user:
|
|
python3 tests/test-slack-bolt.py
|
|
|
|
Requires: pip install slack-bolt
|
|
Expects: SLACK_BOT_TOKEN and SLACK_APP_TOKEN in environment
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
import threading
|
|
|
|
def main():
|
|
# Check tokens
|
|
bot_token = os.environ.get("SLACK_BOT_TOKEN")
|
|
app_token = os.environ.get("SLACK_APP_TOKEN")
|
|
|
|
if not bot_token:
|
|
print("FAIL: SLACK_BOT_TOKEN not set")
|
|
print(" Hint: source /etc/slack-dev.env")
|
|
sys.exit(1)
|
|
|
|
if not app_token:
|
|
print("FAIL: SLACK_APP_TOKEN not set")
|
|
print(" Hint: source /etc/slack-dev.env")
|
|
sys.exit(1)
|
|
|
|
print(f"Bot token: {bot_token[:10]}...{bot_token[-4:]}")
|
|
print(f"App token: {app_token[:10]}...{app_token[-4:]}")
|
|
|
|
# Try importing slack-bolt
|
|
try:
|
|
from slack_bolt import App
|
|
from slack_bolt.adapter.socket_mode import SocketModeHandler
|
|
print("PASS: slack-bolt imported")
|
|
except ImportError as e:
|
|
print(f"FAIL: Cannot import slack-bolt: {e}")
|
|
print(" Hint: pip install slack-bolt")
|
|
sys.exit(1)
|
|
|
|
# Create app
|
|
print("Creating Slack app...")
|
|
app = App(token=bot_token)
|
|
|
|
# Track connection
|
|
connected = threading.Event()
|
|
error_msg = None
|
|
|
|
@app.event("app_home_opened")
|
|
def handle_home(event, logger):
|
|
# This won't fire in test, just proves handler registration works
|
|
pass
|
|
|
|
print("Starting Socket Mode connection (5 second test)...")
|
|
|
|
def run_socket():
|
|
nonlocal error_msg
|
|
try:
|
|
handler = SocketModeHandler(app, app_token)
|
|
# Start in background, will connect
|
|
handler.connect()
|
|
connected.set()
|
|
time.sleep(5)
|
|
handler.close()
|
|
except Exception as e:
|
|
error_msg = str(e)
|
|
connected.set()
|
|
|
|
thread = threading.Thread(target=run_socket)
|
|
thread.start()
|
|
|
|
# Wait for connection or timeout
|
|
connected.wait(timeout=10)
|
|
|
|
if error_msg:
|
|
print(f"FAIL: Socket Mode error: {error_msg}")
|
|
sys.exit(1)
|
|
|
|
if connected.is_set():
|
|
print("PASS: Socket Mode connected successfully")
|
|
print("")
|
|
print("All tests passed. Bot is ready for development.")
|
|
thread.join(timeout=2)
|
|
sys.exit(0)
|
|
else:
|
|
print("FAIL: Socket Mode connection timed out")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|