Files
litellm/.github/workflows/test-code-quality.yml
T
mateo-berri 23724c4392 feat(translation): wire the four deterministic rule gates and make them pass
- pyright strict scoped to the folder (litellm/translation/pyrightconfig.json),
  0 errors: standardized the exhaustiveness pattern to match-on-Literal-tag
  with assert_never AFTER the match (a 'case never:' capture arm is flagged
  by strict as unmatchable), restructured narrowing-hostile spots instead of
  suppressing
- ruff folder config (litellm/translation/ruff.toml): PLR1702 (preview), C901,
  PLR0915, ANN incl. ANN401, PLW0603 + complexity caps; picked up by the
  repo-wide ruff run through hierarchical discovery; folder also modernized
  to PEP-604/builtin generics and black-formatted (CI formatter)
- semgrep tenet rules (.semgrep/rules/python/translation/): no raise outside
  errors.py, no mutation methods/subscript/augmented assignment, no
  module-level mutable state (the rule that would have caught audit F2);
  rides the existing semgrep workflow; effort maps frozen behind
  MappingProxyType and the name-collision loop rewritten without +=
- import-linter contracts in pyproject (forbidden v1-stack imports + downward-
  only layers), import-linter==2.3 added to the dev group (uv.lock updated)
- CI: code-quality job gains translation_v2_pyright_strict and
  translation_v2_import_contracts steps; 'make lint-translation' runs all
  four gates plus the package tests locally in one command
- CLAUDE.md rewritten to match the real tree and conventions
2026-06-11 19:47:44 +00:00

141 lines
5.2 KiB
YAML

name: Code Quality Checks
on:
pull_request:
branches:
- main
- litellm_internal_staging
- litellm_oss_branch
- "litellm_**"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
code-quality:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
persist-credentials: false
- name: Checkout litellm-docs into docs/my-website (for documentation_tests)
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
repository: BerriAI/litellm-docs
path: docs/my-website
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: Set up uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
with:
version: "0.10.9"
- name: Cache uv dependencies
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync --frozen --all-groups --all-extras
- name: check_licenses
run: uv run --no-sync python ./tests/code_coverage_tests/check_licenses.py
- name: check_provider_folders_documented
run: uv run --no-sync python ./tests/code_coverage_tests/check_provider_folders_documented.py
- name: router_code_coverage
run: uv run --no-sync python ./tests/code_coverage_tests/router_code_coverage.py
- name: test_chat_completion_imports
run: uv run --no-sync python ./tests/code_coverage_tests/test_chat_completion_imports.py
- name: info_log_check
run: uv run --no-sync python ./tests/code_coverage_tests/info_log_check.py
- name: check_guardrail_apply_decorator
run: uv run --no-sync python ./tests/code_coverage_tests/check_guardrail_apply_decorator.py
- name: test_ban_set_verbose
run: uv run --no-sync python ./tests/code_coverage_tests/test_ban_set_verbose.py
- name: code_qa_check_tests
run: uv run --no-sync python ./tests/code_coverage_tests/code_qa_check_tests.py
- name: check_get_model_cost_key_performance
run: uv run --no-sync python ./tests/code_coverage_tests/check_get_model_cost_key_performance.py
- name: test_proxy_types_import
run: uv run --no-sync python ./tests/code_coverage_tests/test_proxy_types_import.py
- name: callback_manager_test
run: uv run --no-sync python ./tests/code_coverage_tests/callback_manager_test.py
- name: recursive_detector
run: uv run --no-sync python ./tests/code_coverage_tests/recursive_detector.py
- name: test_router_strategy_async
run: uv run --no-sync python ./tests/code_coverage_tests/test_router_strategy_async.py
- name: litellm_logging_code_coverage
run: uv run --no-sync python ./tests/code_coverage_tests/litellm_logging_code_coverage.py
- name: ensure_async_clients_test
run: uv run --no-sync python ./tests/code_coverage_tests/ensure_async_clients_test.py
- name: enforce_llms_folder_style
run: uv run --no-sync python ./tests/code_coverage_tests/enforce_llms_folder_style.py
- name: prevent_key_leaks_in_exceptions
run: uv run --no-sync python ./tests/code_coverage_tests/prevent_key_leaks_in_exceptions.py
- name: check_unsafe_enterprise_import
run: uv run --no-sync python ./tests/code_coverage_tests/check_unsafe_enterprise_import.py
- name: ban_copy_deepcopy_kwargs
run: uv run --no-sync python ./tests/code_coverage_tests/ban_copy_deepcopy_kwargs.py
- name: check_fastuuid_usage
run: uv run --no-sync python ./tests/code_coverage_tests/check_fastuuid_usage.py
- name: memory_test
run: uv run --no-sync python ./tests/code_coverage_tests/memory_test.py
- name: documentation_test_env_keys
run: uv run --no-sync python ./tests/documentation_tests/test_env_keys.py
- name: documentation_test_router_settings
run: uv run --no-sync python ./tests/documentation_tests/test_router_settings.py
- name: documentation_test_api_docs
run: uv run --no-sync python ./tests/documentation_tests/test_api_docs.py
# translation v2 rule gates (02-mateo-scope.md "What good code looks
# like here"). Ruff's folder config (litellm/translation/ruff.toml) and
# the semgrep rules (.semgrep/rules/python/translation/) ride the
# existing lint and semgrep workflows; pyright strict and the
# import-linter layer contracts run here. `make lint-translation` is
# the local equivalent of all four.
- name: translation_v2_pyright_strict
run: uv tool run --from 'pyright==1.1.406' pyright --project litellm/translation
- name: translation_v2_import_contracts
run: uv run --no-sync lint-imports