|
| 1 | +# Debugging Plugins with CLI Tester |
| 2 | + |
| 3 | +CLI Tester is a built-in platform adapter designed to provide a fast feedback loop for plugin developers. With CLI Tester, you can test and debug your plugin logic directly from the command line without connecting to any messaging platforms (like QQ, WeChat, etc.). |
| 4 | + |
| 5 | +## Core Values |
| 6 | + |
| 7 | +- ⚡ **Instant Feedback**: No need to log into IM platforms; send messages and see results directly in the terminal. |
| 8 | +- 🔄 **Fast Iteration**: Shortens the "edit code -> restart -> test" cycle. |
| 9 | +- 🎯 **Focused Development**: Focus on plugin logic without platform interaction overhead. |
| 10 | +- 🧪 **Independent Testing**: Supports concurrent testing and session isolation. |
| 11 | + |
| 12 | +## Enabling CLI Tester |
| 13 | + |
| 14 | +1. Go to the AstrBot Management Panel. |
| 15 | +2. Navigate to **Settings** -> **Platform Access**. |
| 16 | +3. Find **CLI Tester** (Type: `cli`). |
| 17 | +4. Toggle the **Enable** switch. |
| 18 | +5. The default configuration is usually sufficient: |
| 19 | + - **Mode**: `socket` (Recommended) |
| 20 | + - **Socket Path**: `/tmp/astrbot.sock` |
| 21 | + - **Session Isolation**: `false` (Enable if you need to simulate multi-user concurrent tests) |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### 1. Basic Testing |
| 26 | + |
| 27 | +You can use the `astrbot-cli` tool inside the container to send messages: |
| 28 | + |
| 29 | +```bash |
| 30 | +# Test inside the Docker container |
| 31 | +docker exec -it astrbot python3 /AstrBot/astrbot-cli "Hello" |
| 32 | + |
| 33 | +# Test plugin commands |
| 34 | +docker exec -it astrbot python3 /AstrBot/astrbot-cli "/help" |
| 35 | +``` |
| 36 | + |
| 37 | +### 2. Viewing Rich Media Responses |
| 38 | + |
| 39 | +If your plugin returns rich media content like images, you can use the `-j` flag to view the raw JSON response (including Base64 encoded image data): |
| 40 | + |
| 41 | +```bash |
| 42 | +docker exec -it astrbot python3 /AstrBot/astrbot-cli -j "/time" |
| 43 | +``` |
| 44 | + |
| 45 | +### 3. Creating a Host Shortcut (Optional) |
| 46 | + |
| 47 | +For convenience, you can create a wrapper script on your host machine: |
| 48 | + |
| 49 | +```bash |
| 50 | +# Execute on the host machine |
| 51 | +cat > /usr/local/bin/astrbot-cli << 'EOF' |
| 52 | +#!/bin/bash |
| 53 | +docker exec -i astrbot python3 /AstrBot/astrbot-cli "$@" |
| 54 | +EOF |
| 55 | + |
| 56 | +chmod +x /usr/local/bin/astrbot-cli |
| 57 | + |
| 58 | +# Now you can use it directly on the host |
| 59 | +astrbot-cli "Test message" |
| 60 | +``` |
| 61 | + |
| 62 | +## Running Modes |
| 63 | + |
| 64 | +CLI Tester supports several modes, which can be modified in the configuration: |
| 65 | + |
| 66 | +- **socket** (Default): Communicates via Unix Socket, supporting concurrency and structured responses. |
| 67 | +- **tty**: Interactive mode, input/output directly in the terminal where AstrBot is running (not recommended for Docker production environments). |
| 68 | +- **file**: File polling mode, reads input from a specified file. |
| 69 | + |
| 70 | +## Advanced: Session Isolation |
| 71 | + |
| 72 | +When `use_isolated_sessions` is enabled in the configuration, every request sent via `astrbot-cli` is treated as an independent session. This is useful for testing plugins that require context memory or for concurrent scenarios. |
| 73 | + |
| 74 | +::: tip NOTE |
| 75 | +CLI Tester is automatically exempted from whitelist checks, so you don't have to worry about test messages being blocked. |
| 76 | +::: |
0 commit comments