refactor: remove old MyPy workflow and add new database adapter MyPy check workflow

This commit is contained in:
Daulet Amirkhanov 2025-08-15 10:02:17 +01:00
parent 9bf5f76169
commit 92b20ab6cd
2 changed files with 127 additions and 197 deletions

View file

@ -1,197 +0,0 @@
name: Reusable Basic Tests with MyPy
on:
workflow_call:
inputs:
python-version:
required: false
type: string
default: '3.11.x'
secrets:
LLM_PROVIDER:
required: true
LLM_MODEL:
required: true
LLM_ENDPOINT:
required: true
LLM_API_KEY:
required: true
LLM_API_VERSION:
required: true
EMBEDDING_PROVIDER:
required: true
EMBEDDING_MODEL:
required: true
EMBEDDING_ENDPOINT:
required: true
EMBEDDING_API_KEY:
required: true
EMBEDDING_API_VERSION:
required: true
env:
RUNTIME__LOG_LEVEL: ERROR
ENV: 'dev'
jobs:
lint:
name: Run Linting
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Linting
uses: astral-sh/ruff-action@v2
format-check:
name: Run Formatting Check
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Formatting Check
uses: astral-sh/ruff-action@v2
with:
args: "format --check"
mypy-check:
name: Run MyPy Type Checking
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run MyPy on Critical Interfaces
shell: bash
run: |
poetry run mypy cognee/infrastructure/databases/graph/graph_db_interface.py
poetry run mypy cognee/infrastructure/databases/graph/neo4j_driver/adapter.py
poetry run mypy cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py
unit-tests:
name: Run Unit Tests
runs-on: ubuntu-22.04
env:
LLM_PROVIDER: openai
LLM_MODEL: ${{ secrets.LLM_MODEL }}
LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }}
EMBEDDING_PROVIDER: openai
EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }}
EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }}
EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }}
EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Unit Tests
run: poetry run pytest cognee/tests/unit/
integration-tests:
name: Run Integration Tests
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Integration Tests
run: poetry run pytest cognee/tests/integration/
simple-examples:
name: Run Simple Examples
runs-on: ubuntu-22.04
env:
LLM_PROVIDER: openai
LLM_MODEL: ${{ secrets.LLM_MODEL }}
LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }}
EMBEDDING_PROVIDER: openai
EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }}
EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }}
EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }}
EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Simple Examples
run: poetry run python ./examples/python/simple_example.py
graph-tests:
name: Run Basic Graph Tests
runs-on: ubuntu-22.04
env:
LLM_PROVIDER: openai
LLM_MODEL: ${{ secrets.LLM_MODEL }}
LLM_ENDPOINT: ${{ secrets.LLM_ENDPOINT }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_API_VERSION: ${{ secrets.LLM_API_VERSION }}
EMBEDDING_PROVIDER: openai
EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }}
EMBEDDING_ENDPOINT: ${{ secrets.EMBEDDING_ENDPOINT }}
EMBEDDING_API_KEY: ${{ secrets.EMBEDDING_API_KEY }}
EMBEDDING_API_VERSION: ${{ secrets.EMBEDDING_API_VERSION }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: ${{ inputs.python-version }}
- name: Run Graph Tests
run: poetry run python ./examples/python/code_graph_example.py --repo_path ./cognee/tasks/graph

View file

@ -0,0 +1,127 @@
name: Database Adapter MyPy Check
on:
push:
branches: [ main, dev ]
paths:
- 'cognee/infrastructure/databases/**'
- 'mypy.ini'
- '.github/workflows/database_protocol_mypy_check.yml'
pull_request:
branches: [ main, dev ]
paths:
- 'cognee/infrastructure/databases/**'
- 'mypy.ini'
- '.github/workflows/database_protocol_mypy_check.yml'
env:
RUNTIME__LOG_LEVEL: ERROR
ENV: 'dev'
jobs:
mypy-database-adapters:
name: MyPy Database Adapter Type Check
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cognee Setup
uses: ./.github/actions/cognee_setup
with:
python-version: '3.11.x'
- name: Discover and Check Vector Database Adapters
run: |
echo "🔍 Discovering Vector Database Adapters..."
# Find all *Adapter.py files in vector database directories
vector_adapters=$(find cognee/infrastructure/databases/vector -name "*Adapter.py" -type f | sort)
if [ -z "$vector_adapters" ]; then
echo "No vector database adapters found"
else
echo "Found vector database adapters:"
echo "$vector_adapters" | sed 's/^/ • /'
echo ""
echo "Running MyPy on vector database adapters..."
for adapter in $vector_adapters; do
echo "Checking: $adapter"
poetry run mypy "$adapter" \
--config-file mypy.ini \
--show-error-codes \
--no-error-summary
done
fi
- name: Discover and Check Graph Database Adapters
run: |
echo "🔍 Discovering Graph Database Adapters..."
# Find all adapter.py and *adapter.py files in graph database directories, excluding utility files
graph_adapters=$(find cognee/infrastructure/databases/graph -name "*adapter.py" -o -name "adapter.py" | grep -v "use_graph_adapter.py" | sort)
if [ -z "$graph_adapters" ]; then
echo "No graph database adapters found"
else
echo "Found graph database adapters:"
echo "$graph_adapters" | sed 's/^/ • /'
echo ""
echo "Running MyPy on graph database adapters..."
for adapter in $graph_adapters; do
echo "Checking: $adapter"
poetry run mypy "$adapter" \
--config-file mypy.ini \
--show-error-codes \
--no-error-summary
done
fi
- name: Discover and Check Hybrid Database Adapters
run: |
echo "🔍 Discovering Hybrid Database Adapters..."
# Find all *Adapter.py files in hybrid database directories
hybrid_adapters=$(find cognee/infrastructure/databases/hybrid -name "*Adapter.py" -type f | sort)
if [ -z "$hybrid_adapters" ]; then
echo "No hybrid database adapters found"
else
echo "Found hybrid database adapters:"
echo "$hybrid_adapters" | sed 's/^/ • /'
echo ""
echo "Running MyPy on hybrid database adapters..."
for adapter in $hybrid_adapters; do
echo "Checking: $adapter"
poetry run mypy "$adapter" \
--config-file mypy.ini \
--show-error-codes \
--no-error-summary
done
fi
- name: Protocol Compliance Summary
run: |
echo "✅ Database Adapter MyPy Check Passed!"
echo ""
echo "🔍 Auto-Discovery Approach:"
echo " • Vector Adapters: cognee/infrastructure/databases/vector/**/*Adapter.py"
echo " • Graph Adapters: cognee/infrastructure/databases/graph/**/*adapter.py"
echo " • Hybrid Adapters: cognee/infrastructure/databases/hybrid/**/*Adapter.py"
echo ""
echo "🎯 Purpose: Enforce that database adapters are properly typed"
echo "🔧 MyPy Configuration: mypy.ini (strict mode enabled)"
echo "🚀 Maintenance-Free: Automatically discovers new adapters"
echo ""
echo "⚠️ This workflow FAILS on any type errors to ensure adapter quality."
echo " All database adapters must be properly typed."
echo ""
echo "🛠️ To fix type issues locally, run:"
echo " source .venv/bin/activate"
echo " mypy <adapter_file_path> --config-file mypy.ini"