test-guide
Skill66 starsChanged 9 months agoMITView on GitHub
Testing patterns for claude-code-discord-bridge — pytest, async testing, mocking Discord objects, TDD workflow
- Deletes or force-pushes
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
When asked to "add tests", "test this", or "improve coverage"
- Distinctive: line 17
Follow the Red-Green-Refactor cycle:
- Distinctive: line 19
RED: Write a failing test that describes the desired behavior
- Distinctive: line 20
GREEN: Write the minimum code to make the test pass
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Guide — Testing Patterns for claude-code-discord-bridge
When to Activate
- Writing tests for new features
- Fixing test failures
- Adding test coverage for existing code
- When asked to "add tests", "test this", or "improve coverage"
TDD Workflow
Follow the Red-Green-Refactor cycle:
- RED: Write a failing test that describes the desired behavior
- GREEN: Write the minimum code to make the test pass
- REFACTOR: Clean up while keeping tests green
Project Test Setup
# pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]- pytest-asyncio: Auto mode — all async test functions run automatically
- pytest-cov: Coverage reporting
- No test markers needed: asyncio_mode = "auto" handles async tests
Test Patterns by Module
Pure Logic (parser, chunker, types) — Full Unit Tests
These have no external dependencies. Test exhaustively:
def test_parse_system_message():
line = '{"type":"system","session_id":"abc-123"}'
event = parse_line(line)
assert event.message_type == MessageType.SYSTEM
assert event.session_id == "abc-123"
def test_parse_invalid_json():
event = parse_line("not json")
assert event is NoneRepository (database) — Integration Tests with Real SQLite
@pytest.fixture
async def repo(tmp_path):
db_path = str(tmp_path / "test.db")
await init_db(db_path)
return SessionRepository(db_path)
async def test_save_and_get(repo):
await repo.save(thread_id=123, session_id="abc-def")
result = await repo.get_session_id(thread_id=123)
assert result == "abc-def"Runner — Unit Test Args/Env Building
def test_build_args_basic():
runner = ClaudeRunner(command="claude", model="sonnet")
args = runner._build_args("hello", session_id=None)
assert args[0] == "claude"
assert "-p" in args
assert "--" in args
assert args[-1] == "hello"
def test_build_args_rejects_invalid_session():
runner = ClaudeRunner()
with pytest.raises(ValueError):
runner._build_args("hello", session_id="'; DROP TABLE --")
def test_env_strips_secrets():
runner = ClaudeRunner()
import os
os.environ["DISCORD_BOT_TOKEN"] = "test-token"
env = runner._build_env()
assert "DISCORD_BOT_TOKEN" not in envCogs — Mock Discord Objects
from unittest.mock import AsyncMock, MagicMock
def make_mock_interaction(user_id: int = 12345) -> MagicMock:
interaction = MagicMock()
interaction.user = MagicMock()
interaction.user.id = user_id
interaction.response = AsyncMock()
interaction.followup = AsyncMock()
return interactionChunker — Edge Cases Are Critical
def test_chunk_empty_string():
assert chunk_message("") == []
def test_chunk_preserves_code_blocks():
text = "```python\nprint('hello')\n```"
chunks = chunk_message(text)
assert len(chunks) == 1
def test_chunk_splits_at_boundary():
long_text = "a" * 3000
chunks = chunk_message(long_text)
assert all(len(c) <= 2000 for c in chunks)Running Tests
# Full suite with coverage
uv run pytest tests/ -v --cov=claude_discord --cov-report=term-missing
# Single file
uv run pytest tests/test_parser.py -v
# Single test
uv run pytest tests/test_parser.py::test_parse_system_message -v
# Stop on first failure
uv run pytest tests/ -xCoverage Goals
- Parser, chunker, types: 90%+ (pure logic, easy to test)
- Repository: 90%+ (real SQLite, no mocks needed)
- Runner: 60%+ (test arg building and env, mock subprocess)
- Cogs, StatusManager: 30%+ (heavy Discord mocking, test validation logic)
- Overall: 50%+ and improving
What NOT to Test
- Discord.py library internals
- SQLite behavior
- asyncio internals
- Simple property access / getters
Other versions4 projects use a version of this.
Word for word · 1
- ebibibi/ebi-agent-chat-relay★ 66100% same
Edited · 0
None found.
Wrote their own version · 3
- lablup/backend.ai★ 675same name
- devfullcycle/skills-mba★ 14same name
- hong9Lee/oms★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- add-cogSkill
- python-qualitySkill
- releaseSkill
- security-auditSkill
- tddSkill
- verifySkill
- relay-thread-managerSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

