|
| 1 | +# Local Testing Guide |
| 2 | + |
| 3 | +This guide covers testing a new or modified community configuration locally before deploying. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- OSA repository cloned and dependencies installed (`uv sync`) |
| 8 | +- A valid OpenRouter API key (or community-specific key) |
| 9 | +- Your community `config.yaml` created (see [Adding a Community](quick-start.md)) |
| 10 | + |
| 11 | +## 1. Validate Configuration |
| 12 | + |
| 13 | +Before starting the server, verify your config loads correctly: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Run community config tests |
| 17 | +uv run pytest tests/test_core/ -k "community" -v |
| 18 | +``` |
| 19 | + |
| 20 | +You can also validate programmatically: |
| 21 | + |
| 22 | +```python |
| 23 | +from pathlib import Path |
| 24 | +from src.core.config.community import CommunityConfig |
| 25 | + |
| 26 | +config = CommunityConfig.from_yaml( |
| 27 | + Path("src/assistants/my-tool/config.yaml") |
| 28 | +) |
| 29 | +print(f"Loaded: {config.name} with {len(config.documentation)} docs") |
| 30 | +``` |
| 31 | + |
| 32 | +Common validation errors and fixes: |
| 33 | + |
| 34 | +| Error | Cause | Fix | |
| 35 | +|-------|-------|-----| |
| 36 | +| `Community ID must be kebab-case` | Uppercase or underscore in ID | Use lowercase with hyphens | |
| 37 | +| `DocSource has preload=True but no source_url` | Missing fetch URL | Add `source_url` field | |
| 38 | +| `Repository must be in 'org/repo' format` | Invalid repo format | Use `organization/repository` | |
| 39 | +| `Invalid DOI format` | Malformed DOI | Use `10.xxxx/yyyy` format | |
| 40 | + |
| 41 | +## 2. Set Environment Variables |
| 42 | + |
| 43 | +```bash |
| 44 | +# Required: OpenRouter API key for LLM calls |
| 45 | +export OPENROUTER_API_KEY="your-key-here" |
| 46 | + |
| 47 | +# Optional: API keys for admin functions (sync triggers) |
| 48 | +export API_KEYS="test-key-123" |
| 49 | + |
| 50 | +# Optional: Community-specific key (if using BYOK) |
| 51 | +# export OPENROUTER_API_KEY_MY_TOOL="community-specific-key" |
| 52 | +``` |
| 53 | + |
| 54 | +## 3. Start the Development Server |
| 55 | + |
| 56 | +```bash |
| 57 | +uv run uvicorn src.api.main:app --reload --port 38528 |
| 58 | +``` |
| 59 | + |
| 60 | +The `--reload` flag enables auto-restart on file changes, so you can edit `config.yaml` and see results immediately. |
| 61 | + |
| 62 | +## 4. Test Endpoints |
| 63 | + |
| 64 | +### List all communities |
| 65 | + |
| 66 | +Verify your community appears in the registry: |
| 67 | + |
| 68 | +```bash |
| 69 | +curl http://localhost:38528/communities | jq |
| 70 | +``` |
| 71 | + |
| 72 | +Expected: your community appears with status `available`. |
| 73 | + |
| 74 | +### Get community info |
| 75 | + |
| 76 | +```bash |
| 77 | +curl http://localhost:38528/communities/my-tool | jq |
| 78 | +``` |
| 79 | + |
| 80 | +Expected response includes documentation count, repo count, and sync config status. |
| 81 | + |
| 82 | +### Ask a question |
| 83 | + |
| 84 | +```bash |
| 85 | +curl -X POST http://localhost:38528/my-tool/ask \ |
| 86 | + -H "Content-Type: application/json" \ |
| 87 | + -d '{ |
| 88 | + "question": "What is My Tool?", |
| 89 | + "api_key": "your-openrouter-key" |
| 90 | + }' | jq |
| 91 | +``` |
| 92 | + |
| 93 | +### Test chat endpoint |
| 94 | + |
| 95 | +```bash |
| 96 | +curl -X POST http://localhost:38528/my-tool/chat \ |
| 97 | + -H "Content-Type: application/json" \ |
| 98 | + -d '{ |
| 99 | + "messages": [ |
| 100 | + {"role": "user", "content": "How do I get started?"} |
| 101 | + ], |
| 102 | + "api_key": "your-openrouter-key" |
| 103 | + }' | jq |
| 104 | +``` |
| 105 | + |
| 106 | +## 5. Test via CLI |
| 107 | + |
| 108 | +The CLI is often easier for interactive testing: |
| 109 | + |
| 110 | +```bash |
| 111 | +# Set API key |
| 112 | +export OPENROUTER_API_KEY="your-key-here" |
| 113 | + |
| 114 | +# Interactive chat (standalone mode, no server needed) |
| 115 | +uv run osa chat --community my-tool --standalone |
| 116 | + |
| 117 | +# Single question |
| 118 | +uv run osa ask --community my-tool "What is My Tool?" --standalone |
| 119 | +``` |
| 120 | + |
| 121 | +The `--standalone` flag runs the assistant without needing the backend server. |
| 122 | + |
| 123 | +## 6. Verify Documentation Retrieval |
| 124 | + |
| 125 | +Test that the assistant retrieves documentation correctly by asking specific questions that require doc lookup: |
| 126 | + |
| 127 | +```bash |
| 128 | +curl -X POST http://localhost:38528/my-tool/ask \ |
| 129 | + -H "Content-Type: application/json" \ |
| 130 | + -d '{ |
| 131 | + "question": "How do I configure advanced settings?", |
| 132 | + "api_key": "your-openrouter-key", |
| 133 | + "stream": false |
| 134 | + }' | jq |
| 135 | +``` |
| 136 | + |
| 137 | +Check that: |
| 138 | + |
| 139 | +- The response references your documentation sources |
| 140 | +- Links in the response point to valid URLs |
| 141 | +- Preloaded docs are used without tool calls |
| 142 | +- On-demand docs trigger the `retrieve_*_docs` tool |
| 143 | + |
| 144 | +## 7. Sync Knowledge Database (Optional) |
| 145 | + |
| 146 | +If you configured GitHub repos or citations, test the sync: |
| 147 | + |
| 148 | +```bash |
| 149 | +# Initialize the knowledge database for your community |
| 150 | +uv run osa sync init --community my-tool |
| 151 | + |
| 152 | +# Sync GitHub issues and PRs |
| 153 | +uv run osa sync github --community my-tool --full |
| 154 | + |
| 155 | +# Sync papers and citations |
| 156 | +uv run osa sync papers --community my-tool --citations |
| 157 | + |
| 158 | +# Or sync everything at once |
| 159 | +uv run osa sync all --community my-tool |
| 160 | +``` |
| 161 | + |
| 162 | +After syncing, test knowledge search: |
| 163 | + |
| 164 | +```bash |
| 165 | +curl -X POST http://localhost:38528/my-tool/ask \ |
| 166 | + -H "Content-Type: application/json" \ |
| 167 | + -d '{ |
| 168 | + "question": "What are the latest issues?", |
| 169 | + "api_key": "your-openrouter-key" |
| 170 | + }' | jq |
| 171 | +``` |
| 172 | + |
| 173 | +## What Works Without Sync |
| 174 | + |
| 175 | +| Feature | Without sync | With sync | |
| 176 | +|---------|-------------|-----------| |
| 177 | +| Assistant creation | Yes | Yes | |
| 178 | +| System prompt | Yes | Yes | |
| 179 | +| Documentation retrieval | Yes | Yes | |
| 180 | +| Answering questions | Yes | Yes | |
| 181 | +| GitHub issues/PRs search | No | Yes | |
| 182 | +| Recent activity listing | No | Yes | |
| 183 | +| Paper search | No | Yes | |
| 184 | +| Citation counts | No | Yes | |
| 185 | + |
| 186 | +## Troubleshooting |
| 187 | + |
| 188 | +### Server won't start |
| 189 | + |
| 190 | +```bash |
| 191 | +# Check if port is already in use |
| 192 | +lsof -i :38528 |
| 193 | + |
| 194 | +# Use a different port |
| 195 | +uv run uvicorn src.api.main:app --reload --port 38529 |
| 196 | +``` |
| 197 | + |
| 198 | +### "Assistant not found" error |
| 199 | + |
| 200 | +Verify your community is discovered: |
| 201 | + |
| 202 | +```bash |
| 203 | +uv run python -c " |
| 204 | +from src.assistants import discover_assistants, registry |
| 205 | +discover_assistants() |
| 206 | +print('my-tool' in registry) |
| 207 | +print([a.id for a in registry.list_available()]) |
| 208 | +" |
| 209 | +``` |
| 210 | + |
| 211 | +Common causes: |
| 212 | + |
| 213 | +- Directory not under `src/assistants/` |
| 214 | +- Missing or invalid `config.yaml` |
| 215 | +- YAML syntax errors (check with `python -c "import yaml; yaml.safe_load(open('path/to/config.yaml'))"`) |
| 216 | + |
| 217 | +### Documentation not retrieved |
| 218 | + |
| 219 | +- Check network access to documentation URLs |
| 220 | +- Verify `source_url` fields are valid raw GitHub URLs |
| 221 | +- Test URLs manually: `curl -I <source_url>` should return 200 |
| 222 | + |
| 223 | +### Knowledge base empty |
| 224 | + |
| 225 | +- Requires `API_KEYS` env var for sync operations |
| 226 | +- Run `uv run osa sync init --community my-tool` first |
| 227 | +- Check that GitHub repos in config are accessible (public repos) |
| 228 | + |
| 229 | +### Preloaded docs too large |
| 230 | + |
| 231 | +If the server is slow to start or the system prompt is very long: |
| 232 | + |
| 233 | +- Limit preloaded docs to 2-3 core documents |
| 234 | +- Keep total preloaded content under 15k tokens |
| 235 | +- Move large docs to on-demand retrieval |
| 236 | + |
| 237 | +## Test Checklist |
| 238 | + |
| 239 | +Use this checklist when testing a new community: |
| 240 | + |
| 241 | +- [ ] Config validates without errors (`pytest -k community`) |
| 242 | +- [ ] Community appears in `/communities` endpoint |
| 243 | +- [ ] Community info endpoint returns correct metadata |
| 244 | +- [ ] `/ask` endpoint returns relevant answers |
| 245 | +- [ ] `/chat` endpoint works for multi-turn conversations |
| 246 | +- [ ] Preloaded documentation is used correctly |
| 247 | +- [ ] On-demand docs are retrieved when relevant |
| 248 | +- [ ] Documentation URLs in responses are valid |
| 249 | +- [ ] CLI standalone mode works |
| 250 | +- [ ] Knowledge sync completes (if configured) |
| 251 | +- [ ] GitHub issues/PRs are searchable (after sync) |
| 252 | +- [ ] Paper search works (after sync) |
| 253 | +- [ ] Anti-hallucination: assistant does not fabricate PR/issue numbers |
0 commit comments