Files
GuardDen/.gitea/workflows/nsfw-only-filtering-tests.yml
latte 1250b5573c
Some checks failed
NSFW-Only Filtering Tests / NSFW-Only Filtering Feature Tests (push) Has been cancelled
Add NSFW-only filtering mode for content moderation
- Add nsfw_only_filtering field to GuildSettings model
- Create database migration for new field (20260124_add_nsfw_only_filtering)
- Update AI moderation logic to respect NSFW-only mode
- Add Discord command !ai nsfwonly <true/false> for toggling mode
- Implement filtering logic in image analysis for both attachments and embeds
- Add comprehensive test suite for new functionality
- Update documentation with usage examples and feature description
- Create dedicated CI workflow for testing NSFW-only filtering feature

When enabled, only sexual/nude content is filtered while allowing:
- Violence and gore
- Harassment and bullying
- Hate speech
- Self-harm content
- Other content categories

This mode is useful for gaming communities and mature discussion
servers that have specific content policies allowing violence
but prohibiting sexual material.
2026-01-24 23:51:10 +01:00

196 lines
7.4 KiB
YAML

name: NSFW-Only Filtering Tests
on:
push:
paths:
- 'src/guardden/models/guild.py'
- 'src/guardden/cogs/ai_moderation.py'
- 'migrations/versions/20260124_add_nsfw_only_filtering.py'
- 'tests/test_nsfw_only_filtering.py'
pull_request:
paths:
- 'src/guardden/models/guild.py'
- 'src/guardden/cogs/ai_moderation.py'
- 'migrations/versions/20260124_add_nsfw_only_filtering.py'
- 'tests/test_nsfw_only_filtering.py'
env:
PYTHON_VERSION: "3.11"
jobs:
test-nsfw-only-filtering:
name: NSFW-Only Filtering Feature Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: guardden_test
POSTGRES_USER: guardden_test
POSTGRES_DB: guardden_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-nsfw-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-nsfw-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,ai]"
- name: Set up test environment
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
GUARDDEN_LOG_LEVEL: "DEBUG"
run: echo "Test environment configured"
- name: Run database migration test
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
run: |
echo "Testing database migration for nsfw_only_filtering field..."
python -c "
import asyncio
import sys
sys.path.insert(0, 'src')
from guardden.models.guild import GuildSettings
from guardden.services.database import Database
async def test_migration():
db = Database('postgresql://guardden_test:guardden_test@localhost:5432/guardden_test')
try:
async with db.engine.begin() as conn:
await conn.run_sync(db.Base.metadata.create_all)
print('✅ Database schema created successfully')
# Test that the field exists in the model
if hasattr(GuildSettings, 'nsfw_only_filtering'):
print('✅ nsfw_only_filtering field exists in GuildSettings model')
else:
print('❌ nsfw_only_filtering field missing from GuildSettings model')
sys.exit(1)
except Exception as e:
print(f'❌ Database migration test failed: {e}')
sys.exit(1)
finally:
await db.close()
asyncio.run(test_migration())
"
- name: Run NSFW-only filtering logic tests
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
GUARDDEN_LOG_LEVEL: "DEBUG"
run: |
echo "Running NSFW-only filtering specific tests..."
pytest tests/test_nsfw_only_filtering.py -v --tb=short
- name: Run AI moderation integration tests
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
GUARDDEN_LOG_LEVEL: "DEBUG"
run: |
echo "Running AI moderation tests to ensure no regression..."
pytest tests/test_ai.py -v --tb=short
- name: Test command functionality
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
run: |
echo "Testing Discord command integration..."
python -c "
import sys
sys.path.insert(0, 'src')
from guardden.cogs.ai_moderation import AIModeration
from unittest.mock import MagicMock
# Test that the new command exists
bot = MagicMock()
cog = AIModeration(bot)
if hasattr(cog, 'ai_nsfw_only'):
print('✅ ai_nsfw_only command exists')
else:
print('❌ ai_nsfw_only command missing')
sys.exit(1)
print('✅ All command tests passed')
"
- name: Validate feature completeness
run: |
echo "Validating NSFW-only filtering feature completeness..."
echo "✅ Checking model updates..."
grep -q "nsfw_only_filtering" src/guardden/models/guild.py || (echo "❌ Model not updated" && exit 1)
echo "✅ Checking migration exists..."
test -f migrations/versions/20260124_add_nsfw_only_filtering.py || (echo "❌ Migration missing" && exit 1)
echo "✅ Checking AI moderation logic..."
grep -q "nsfw_only_filtering" src/guardden/cogs/ai_moderation.py || (echo "❌ AI moderation not updated" && exit 1)
echo "✅ Checking new command exists..."
grep -q "ai_nsfw_only" src/guardden/cogs/ai_moderation.py || (echo "❌ New command missing" && exit 1)
echo "✅ Checking documentation updates..."
grep -q "nsfwonly" README.md || (echo "❌ Documentation not updated" && exit 1)
echo "✅ Checking tests exist..."
test -f tests/test_nsfw_only_filtering.py || (echo "❌ Tests missing" && exit 1)
echo "🎉 All NSFW-only filtering feature checks passed!"
- name: Generate test coverage for new feature
env:
GUARDDEN_DISCORD_TOKEN: "test_token_12345678901234567890123456789012345"
GUARDDEN_DATABASE_URL: "postgresql://guardden_test:guardden_test@localhost:5432/guardden_test"
GUARDDEN_AI_PROVIDER: "none"
run: |
echo "Generating coverage report for NSFW-only filtering feature..."
pytest tests/test_nsfw_only_filtering.py --cov=src/guardden/cogs/ai_moderation --cov=src/guardden/models/guild --cov-report=term-missing --cov-report=xml:nsfw-coverage.xml
- name: Upload NSFW-only filtering test results
uses: actions/upload-artifact@v3
if: always()
with:
name: nsfw-only-filtering-test-results
path: |
nsfw-coverage.xml
pytest-report.xml