Communitygithub.com

django-verification

Django プロジェクトの検証ループ:マイグレーション、リンター、カバレッジ付きテスト、セキュリティスキャン、リリース前/PR前のデプロイ準備チェックを行います。

django-verification とは?

このスキルは、Django プロジェクトの品質とセキュリティを確保するための包括的な検証パイプラインを提供します。PR の作成前、大規模な変更後、デプロイ前などに、環境チェック、コード品質、マイグレーション、テストとカバレッジ、セキュリティスキャン、パフォーマンスチェック、設定レビューなど、12 のフェーズにわたって自動化されたチェックを実行します。各フェーズでは具体的な CLI コマンドと期待される出力が提示され、最終的に統合レポートが生成されます。GitHub Actions のワークフロー例も含まれており、CI 環境への組み込みが容易です。このスキルは、Claude Code、Cursor、Codex などの AI エージェント向けに設計されており、開発者が手動で確認すべき項目を体系化し、見落としを防ぎます。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/django-verification

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Django 検証ループ

PR の前、大きな変更後、デプロイ前に実行し、Django アプリケーションの品質とセキュリティを確保します。

実行タイミング

  • Django プロジェクトのプルリクエストを作成する前
  • モデルの大きな変更、マイグレーションの更新、依存関係のアップグレード後
  • ステージングまたは本番環境へのデプロイ前の検証
  • 環境全体 → リンター → テスト → セキュリティ → デプロイ準備パイプラインの実行
  • マイグレーションの安全性とテストカバレッジの検証

フェーズ 1: 環境チェック

# Python バージョンの確認
python --version  # プロジェクトの要件と一致している必要があります

# 仮想環境の確認
which python
pip list --outdated

# 環境変数の確認
python -c "import os; import environ; print('DJANGO_SECRET_KEY set' if os.environ.get('DJANGO_SECRET_KEY') else 'MISSING: DJANGO_SECRET_KEY')"

環境が正しく構成されていない場合は、停止して修正します。

フェーズ 2: コード品質とフォーマット

# 型チェック
mypy . --config-file pyproject.toml

# ruff によるリンター
ruff check . --fix

# black によるフォーマット
black . --check
black .  # 自動修正

# インポートのソート
isort . --check-only
isort .  # 自動修正

# Django 固有のチェック
python manage.py check --deploy

よくある問題:

  • 公開関数の型ヒントの欠落
  • PEP 8 フォーマット違反
  • ソートされていないインポート
  • 本番環境設定に残っているデバッグ設定

フェーズ 3: マイグレーション

# 未適用のマイグレーションを確認
python manage.py showmigrations

# 不足しているマイグレーションを作成
python manage.py makemigrations --check

# マイグレーション適用のドライラン
python manage.py migrate --plan

# マイグレーションを適用 (テスト環境)
python manage.py migrate

# マイグレーションの競合を確認
python manage.py makemigrations --merge  # 競合がある場合のみ

レポート:

  • 保留中のマイグレーション数
  • マイグレーションの競合の有無
  • マイグレーションがないモデル変更

フェーズ 4: テスト + カバレッジ

# pytest ですべてのテストを実行
pytest --cov=apps --cov-report=html --cov-report=term-missing --reuse-db

# 特定のアプリのテストを実行
pytest apps/users/tests/

# マーカーで実行
pytest -m "not slow"  # 遅いテストをスキップ
pytest -m integration  # 統合テストのみ

# カバレッジレポート
open htmlcov/index.html

レポート:

  • 合計テスト数: X 成功、Y 失敗、Z スキップ
  • 全体カバレッジ: XX%
  • アプリ別カバレッジの内訳

カバレッジ目標:

コンポーネント目標
モデル90%+
シリアライザ85%+
ビュー80%+
サービス90%+
全体80%+

フェーズ 5: セキュリティスキャン

# 依存関係の脆弱性
pip-audit
safety check --full-report

# Django セキュリティチェック
python manage.py check --deploy

# Bandit セキュリティリンター
bandit -r . -f json -o bandit-report.json

# 機密情報のスキャン (gitleaks がインストールされている場合)
gitleaks detect --source . --verbose

# 環境変数のチェック
python -c "from django.core.exceptions import ImproperlyConfigured; from django.conf import settings; settings.DEBUG"

レポート:

  • 脆弱性のある依存関係
  • セキュリティ設定の問題
  • 検出されたハードコードされた機密情報
  • DEBUG モードの状態 (本番環境では False であるべき)

フェーズ 6: Django 管理コマンド

# モデルの問題をチェック
python manage.py check

# 静的ファイルを収集
python manage.py collectstatic --noinput --clear

# スーパーユーザーを作成 (テストに必要な場合)
echo "from apps.users.models import User; User.objects.create_superuser('[email protected]', 'admin')" | python manage.py shell

# データベースの整合性
python manage.py check --database default

# キャッシュの確認 (Redis を使用している場合)
python -c "from django.core.cache import cache; cache.set('test', 'value', 10); print(cache.get('test'))"

フェーズ 7: パフォーマンスチェック

# Django Debug Toolbar の出力 (N+1 クエリをチェック)
# DEBUG=True の開発モードで実行し、ページにアクセス
# SQL パネルで重複クエリを確認

# クエリ数分析
django-admin debugsqlshell  # django-debug-sqlshell がインストールされている場合

# 欠落しているインデックスをチェック
python manage.py shell << EOF
from django.db import connection
with connection.cursor() as cursor:
    cursor.execute("SELECT table_name, index_name FROM information_schema.statistics WHERE table_schema = 'public'")
    print(cursor.fetchall())
EOF

レポート:

  • ページあたりのクエリ数 (通常のページでは 50 未満であるべき)
  • 欠落しているデータベースインデックス
  • 検出された重複クエリ

フェーズ 8: 静的アセット

# npm 依存関係を確認 (npm を使用している場合)
npm audit
npm audit fix

# 静的ファイルをビルド (webpack/vite を使用している場合)
npm run build

# 静的ファイルを確認
ls -la staticfiles/
python manage.py findstatic css/style.css

フェーズ 9: 設定レビュー

# Python シェルで設定を確認
python manage.py shell << EOF
from django.conf import settings
import os

# 重要なチェック
checks = {
    'DEBUG が False': not settings.DEBUG,
    'SECRET_KEY が設定されている': bool(settings.SECRET_KEY and len(settings.SECRET_KEY) > 30),
    'ALLOWED_HOSTS が設定されている': len(settings.ALLOWED_HOSTS) > 0,
    'HTTPS が有効': getattr(settings, 'SECURE_SSL_REDIRECT', False),
    'HSTS が有効': getattr(settings, 'SECURE_HSTS_SECONDS', 0) > 0,
    'データベースが設定されている': settings.DATABASES['default']['ENGINE'] != 'django.db.backends.sqlite3',
}

for check, result in checks.items():
    status = '✓' if result else '✗'
    print(f"{status} {check}")
EOF

フェーズ 10: ログ設定

# ログ出力をテスト
python manage.py shell << EOF
import logging
logger = logging.getLogger('django')
logger.warning('Test warning message')
logger.error('Test error message')
EOF

# ログファイルを確認 (設定されている場合)
tail -f /var/log/django/django.log

フェーズ 11: API ドキュメント (DRF を使用している場合)

# スキーマを生成
python manage.py generateschema --format openapi-json > schema.json

# スキーマを検証
# schema.json が有効な JSON であることを確認
python -c "import json; json.load(open('schema.json'))"

# Swagger UI にアクセス (drf-yasg を使用している場合)
# ブラウザで http://localhost:8000/swagger/ にアクセス

フェーズ 12: 差分レビュー

# 差分統計を表示
git diff --stat

# 実際の変更を表示
git diff

# 変更されたファイルを表示
git diff --name-only

# よくある問題をチェック
git diff | grep -i "todo\|fixme\|hack\|xxx"
git diff | grep "print("  # デバッグ文
git diff | grep "DEBUG = True"  # デバッグモード
git diff | grep "import pdb"  # デバッガ

チェックリスト:

  • デバッグ文 (print, pdb, breakpoint()) がないこと
  • 重要なコードに TODO/FIXME コメントがないこと
  • ハードコードされた機密情報や認証情報がないこと
  • モデル変更に対してデータベースマイグレーションが含まれていること
  • 設定変更が文書化されていること
  • 外部呼び出しに対するエラーハンドリングが実装されていること
  • トランザクション管理が必要な箇所に実装されていること

出力テンプレート

DJANGO 検証レポート
==========================

フェーズ 1: 環境チェック
  ✓ Python 3.11.5
  ✓ 仮想環境がアクティブ
  ✓ すべての環境変数が設定済み

フェーズ 2: コード品質
  ✓ mypy: 型エラーなし
  ✗ ruff: 3 件の問題を検出 (自動修正済み)
  ✓ black: フォーマット問題なし
  ✓ isort: インポートが正しくソート済み
  ✓ manage.py check: 問題なし

フェーズ 3: マイグレーション
  ✓ 未適用のマイグレーションなし
  ✓ マイグレーションの競合なし
  ✓ すべてのモデルにマイグレーションあり

フェーズ 4: テスト + カバレッジ
  テスト: 247 成功、0 失敗、5 スキップ
  カバレッジ:
    全体: 87%
    users: 92%
    products: 89%
    orders: 85%
    payments: 91%

フェーズ 5: セキュリティスキャン
  ✗ pip-audit: 2 件の脆弱性を検出 (修正が必要)
  ✓ safety check: 問題なし
  ✓ bandit: セキュリティ問題なし
  ✓ 機密情報は検出されず
  ✓ DEBUG = False

フェーズ 6: Django コマンド
  ✓ collectstatic 完了
  ✓ データベースの整合性 OK
  ✓ キャッシュバックエンドに接続可能

フェーズ 7: パフォーマンス
  ✓ N+1 クエリは検出されず
  ✓ データベースインデックスが設定済み
  ✓ クエリ数は許容範囲内

フェーズ 8: 静的アセット
  ✓ npm audit: 脆弱性なし
  ✓ アセットのビルド成功
  ✓ 静的ファイルが収集済み

フェーズ 9: 設定
  ✓ DEBUG = False
  ✓ SECRET_KEY が設定済み
  ✓ ALLOWED_HOSTS が設定済み
  ✓ HTTPS が有効
  ✓ HSTS が有効
  ✓ データベースが設定済み

フェーズ 10: ログ
  ✓ ログが設定済み
  ✓ ログファイルが書き込み可能

フェーズ 11: API ドキュメント
  ✓ スキーマが生成済み
  ✓ Swagger UI にアクセス可能

フェーズ 12: 差分レビュー
  変更ファイル数: 12
  +450, -120 行
  ✓ デバッグ文なし
  ✓ ハードコードされた機密情報なし
  ✓ マイグレーションが含まれている

推奨事項: 警告: デプロイ前に pip-audit の脆弱性を修正してください

次のステップ:
1. 脆弱性のある依存関係を更新
2. セキュリティスキャンを再実行
3. 最終テストのためにステージングにデプロイ

デプロイ前チェックリスト

  • すべてのテストが合格
  • カバレッジ ≥ 80%
  • セキュリティ脆弱性なし
  • 未適用のマイグレーションなし
  • 本番環境設定で DEBUG = False
  • SECRET_KEY が正しく設定済み
  • ALLOWED_HOSTS が正しく設定済み
  • データベースのバックアップが有効
  • 静的ファイルが収集され、配信されている
  • ログが設定され、動作している
  • エラーモニタリング (Sentry など) が設定済み
  • CDN が設定済み (該当する場合)
  • Redis/キャッシュバックエンドが設定済み
  • Celery ワーカーが実行中 (該当する場合)
  • HTTPS/SSL が設定済み
  • 環境変数が文書化されている

継続的インテグレーション

GitHub Actions の例

# .github/workflows/django-verification.yml
name: Django Verification

on: [push, pull_request]

jobs:
  verify:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:14
        env:
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'

      - name: Cache pip
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}

      - name: Install dependencies
        run: |
          pip install -r requirements.txt
          pip install ruff black mypy pytest pytest-django pytest-cov bandit safety pip-audit

      - name: Code quality checks
        run: |
          ruff check .
          black . --check
          isort . --check-only
          mypy .

      - name: Security scan
        run: |
          bandit -r . -f json -o bandit-report.json
          safety check --full-report
          pip-audit

      - name: Run tests
        env:
          DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
          DJANGO_SECRET_KEY: test-secret-key
        run: |
          pytest --cov=apps --cov-report=xml --cov-report=term-missing

      - name: Upload coverage
        uses: codecov/codecov-action@v3

クイックリファレンス

チェックコマンド
環境python --version
型チェックmypy .
リンターruff check .
フォーマットblack . --check
マイグレーションpython manage.py makemigrations --check
テストpytest --cov=apps
セキュリティpip-audit && bandit -r .
Django チェックpython manage.py check --deploy
collectstaticpython manage.py collectstatic --noinput
差分統計git diff --stat

注意: 自動検証は一般的な問題を検出しますが、手動によるコードレビューとステージング環境でのテストを代替するものではありません。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

関連スキル