بنقرة واحدة
test-guide
Testing patterns for c-lord — pytest, async testing, mocking Discord objects, TDD workflow
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Testing patterns for c-lord — pytest, async testing, mocking Discord objects, TDD workflow
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
c-lord のバージョン/リリース手順。「v1.5.0としてリリースして」等と言われたときに使う。
Step-by-step guide to add a new discord.py Cog to the framework
Python coding patterns, idioms, and quality standards for c-lord development
Security checklist specific to c-lord — subprocess injection, env leaks, input validation
Enforce test-driven development — write tests FIRST, then implement. Mandatory for new features and bug fixes.
Run full verification pipeline (lint, format, test, security) before committing
| name | test-guide |
| description | Testing patterns for c-lord — pytest, async testing, mocking Discord objects, TDD workflow |
Follow the Red-Green-Refactor cycle:
# pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["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 None
@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"
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 env
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 interaction
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)
# Full suite with coverage
uv run pytest tests/ -v --cov=c_lord --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/ -x