name: Test Suites
permissions:
  contents: read

on:
  push:
    branches: [ main, dev ]
  pull_request:
    branches: [ main, dev ]
    types: [opened, synchronize, reopened, labeled]
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  RUNTIME__LOG_LEVEL: ERROR
  ENV: 'dev'

jobs: 
  pre-test:
    name: basic checks
    uses: ./.github/workflows/pre_test.yml
    
  basic-tests:
    name: Basic Tests
    uses: ./.github/workflows/basic_tests.yml
    needs: [ pre-test ]
    secrets: inherit

  e2e-tests:
    name: End-to-End Tests
    uses: ./.github/workflows/e2e_tests.yml
    needs: [ pre-test ]
    secrets: inherit

  distributed-tests:
    name: Distributed Cognee Test
    needs: [ basic-tests, e2e-tests, graph-db-tests ]
    uses: ./.github/workflows/distributed_test.yml
    secrets: inherit

  cli-tests:
    name: CLI Tests
    uses: ./.github/workflows/cli_tests.yml
    secrets: inherit

  docker-compose-test:
    name: Docker Compose Test
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/docker_compose.yml
    secrets: inherit

  docker-ci-test:
    name: Docker CI test
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/backend_docker_build_test.yml
    secrets: inherit

  graph-db-tests:
    name: Graph Database Tests
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/graph_db_tests.yml
    secrets: inherit

  temporal-graph-tests:
    name: Temporal Graph Test
    needs: [ basic-tests, e2e-tests, graph-db-tests ]
    uses: ./.github/workflows/temporal_graph_tests.yml
    secrets: inherit

  search-db-tests:
    name: Search Test on Different DBs
    uses: ./.github/workflows/search_db_tests.yml
    secrets: inherit

  relational-db-migration-tests:
    name: Relational DB Migration Tests
    needs: [basic-tests, e2e-tests, graph-db-tests]
    uses: ./.github/workflows/relational_db_migration_tests.yml
    secrets: inherit

  notebook-tests:
    name: Notebook Tests
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/notebooks_tests.yml
    secrets: inherit

  different-os-tests-basic:
    name: OS and Python Tests Ubuntu
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/test_different_operating_systems.yml
    with:
      python-versions: '["3.10.x", "3.11.x", "3.12.x", "3.13.x"]'
      os: '["ubuntu-22.04"]'
    secrets: inherit

  different-os-tests-extended:
    name: OS and Python Tests Extended
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/test_different_operating_systems.yml
    with:
      python-versions: '["3.13.x"]'
      os: '["macos-15", "windows-latest"]'
    secrets: inherit

  # Matrix-based vector database tests
  vector-db-tests:
    name: Vector DB Tests
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/vector_db_tests.yml
    secrets: inherit

  # Matrix-based example tests
  example-tests:
    name: Example Tests
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/examples_tests.yml
    secrets: inherit

  mcp-test:
    name: MCP Tests
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/test_mcp.yml
    secrets: inherit

  db-examples-tests:
    name: DB Examples Tests
    needs: [vector-db-tests, graph-db-tests, relational-db-migration-tests, distributed-tests]
    uses: ./.github/workflows/db_examples_tests.yml
    secrets: inherit

  s3-file-storage-test:
    name: S3 File Storage Test
    needs: [basic-tests, e2e-tests]
    uses: ./.github/workflows/test_s3_file_storage.yml
    secrets: inherit

  # Additional LLM tests
  llm-tests:
    name: LLM Test Suite
    needs: [ basic-tests, e2e-tests ]
    uses: ./.github/workflows/test_llms.yml
    secrets: inherit

  # Ollama tests moved to the end
  ollama-tests:
    name: Ollama Tests
    needs: [
      basic-tests,
      e2e-tests,
      graph-db-tests,
      notebook-tests,
      different-os-tests-basic,
      different-os-tests-extended,
      vector-db-tests,
      example-tests,
      llm-tests,
      mcp-test,
      relational-db-migration-tests,
      docker-compose-test,
      docker-ci-test,
    ]
    uses: ./.github/workflows/test_ollama.yml
    secrets: inherit

  notify:
    name: Test Completion Status
    needs: [
      basic-tests,
      e2e-tests,
      cli-tests,
      graph-db-tests,
      notebook-tests,
      different-os-tests-basic,
      different-os-tests-extended,
      vector-db-tests,
      example-tests,
      db-examples-tests,
      mcp-test,
      llm-tests,
      ollama-tests,
      relational-db-migration-tests,
      docker-compose-test,
      docker-ci-test,
    ]
    runs-on: ubuntu-latest
    if: always()
    steps:
      - name: Check Status
        run: |
          if [[ "${{ needs.basic-tests.result }}" == "success" &&
                "${{ needs.e2e-tests.result }}" == "success" &&
                "${{ needs.cli-tests.result }}" == "success" &&
                "${{ needs.graph-db-tests.result }}" == "success" &&
                "${{ needs.notebook-tests.result }}" == "success" &&
                "${{ needs.different-os-tests-basic.result }}" == "success" &&
                "${{ needs.different-os-tests-extended.result }}" == "success" &&
                "${{ needs.vector-db-tests.result }}" == "success" &&
                "${{ needs.example-tests.result }}" == "success" &&
                "${{ needs.db-examples-tests.result }}" == "success" &&
                "${{ needs.relational-db-migration-tests.result }}" == "success" &&
                "${{ needs.llm-tests.result }}" == "success" &&
                "${{ needs.docker-compose-test.result }}" == "success" &&
                "${{ needs.docker-ci-test.result }}" == "success" &&
                "${{ needs.ollama-tests.result }}" == "success" ]]; then
            echo "All test suites completed successfully!"
          else
            echo "One or more test suites failed."
            exit 1
          fi
