Skip to content

refactor(api): decompose api/main.py + test_api.py under 500L; arm file-size wall #103

refactor(api): decompose api/main.py + test_api.py under 500L; arm file-size wall

refactor(api): decompose api/main.py + test_api.py under 500L; arm file-size wall #103

Workflow file for this run

name: "Konjo Quality Gate β€” Wall 2"
#
# Phased arming: steps marked "ARMED (blocking)" have had their
# `continue-on-error` removed and now fail the job (and the aggregate gate) on
# violation β€” they are verified clean repo-wide. Steps marked "WARN-ONLY" still
# carry `continue-on-error: true` because pre-existing debt would break CI; each
# is armed once its debt is cleared (complexity, mutation). Do not add new
# `continue-on-error` steps; clear the debt and arm instead.
#
on:
pull_request: {branches: [main]}
push: {branches: [main]}
concurrency:
group: konjo-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
jobs:
static:
name: "G1 Β· Static Analysis"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Pinned: edition2024 deps need >= 1.85, and an armed clippy::pedantic gate
# must match a locally-verifiable toolchain (bump deliberately + re-verify).
- uses: dtolnay/rust-toolchain@1.94
with: {components: "rustfmt, clippy"}
- uses: Swatinem/rust-cache@v2
with: {shared-key: "konjo-${{ github.repository }}"}
- uses: actions/setup-python@v5
with: {python-version: "3.11"}
- run: pip install ruff mypy vulture bandit --quiet
# ARMED (blocking): verified clean repo-wide. See "phased arming" note below.
- name: cargo fmt
run: cargo fmt --all -- --check
# ARMED (blocking): clean repo-wide (curated pedantic allows in lib.rs /
# main.rs with rationale).
- name: clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::pedantic -D clippy::unwrap_used -D clippy::expect_used -D clippy::panic -D clippy::todo -D clippy::dbg_macro
- name: cargo audit
continue-on-error: true
run: cargo install cargo-audit --locked --quiet 2>/dev/null || true && cargo audit
- name: cargo deny
continue-on-error: true
run: cargo install cargo-deny --locked --quiet 2>/dev/null || true && cargo deny check --config .konjo/deny.toml
- name: dead code (Rust)
continue-on-error: true
run: |
COUNT=$(RUSTFLAGS="-W dead_code" cargo check --workspace 2>&1 | grep -c "warning: dead_code" || true)
echo "Dead code: $COUNT"
[ "$COUNT" -gt 0 ] && exit 1; echo "βœ“"
# ARMED (blocking): verified clean repo-wide.
- name: ruff lint
run: ruff check .
# ARMED (blocking): repo format-swept clean.
- name: ruff format
run: ruff format --check .
# ARMED (blocking): first-party code is mypy --strict clean. Run via
# `python -m mypy` with the package + api deps installed so third-party
# types (numpy/fastapi/pydantic) resolve; ignore_missing_imports in
# python/pyproject.toml covers the rest (sentence-transformers, the Rust ext).
- name: mypy (strict)
run: |
pip install -e "./python[api]" --quiet
cd python && python -m mypy --strict kohaku/
- name: vulture
continue-on-error: true
run: vulture . --min-confidence 80
coverage:
name: "G2 Β· Tests + Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Pinned to match G1 (edition2024 deps need >= 1.85).
- uses: dtolnay/rust-toolchain@1.94
with: {components: llvm-tools-preview}
- uses: Swatinem/rust-cache@v2
with: {shared-key: "konjo-${{ github.repository }}"}
- uses: actions/setup-python@v5
with: {python-version: "3.11"}
- run: |
cargo install cargo-nextest --locked --quiet 2>/dev/null || true
cargo install cargo-llvm-cov --locked --quiet 2>/dev/null || true
pip install -e "./python[api]" pytest pytest-cov pytest-asyncio httpx --quiet
# ARMED (blocking): library kernels are ~97% line-covered. The CLI binary
# (main.rs) and the PyO3 FFI glue (pybindings.rs) are excluded β€” they carry
# no Rust unit tests by design (the CLI is an entrypoint; the bindings are
# covered by the Python suite, see the rust-accel job).
- name: Rust coverage
run: cargo llvm-cov nextest --workspace --all-features --lcov --output-path lcov.info --ignore-filename-regex 'main\.rs|pybindings\.rs' --fail-under-lines 80
# ARMED (blocking): the package is ~93% line-covered by the python/tests
# suite. Runs the real suite (api deps + pytest-asyncio installed above) and
# enforces β‰₯80% on first-party `kohaku`.
- name: Python coverage
run: cd python && python -m pytest tests/ --cov=kohaku --cov-fail-under=80 -q
- uses: codecov/codecov-action@v4
if: always()
with: {files: lcov.info, fail_ci_if_error: false}
mutation:
name: "G3 Β· Mutation Testing"
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with: {shared-key: "konjo-${{ github.repository }}"}
- run: cargo install cargo-mutants --locked --quiet 2>/dev/null || true
- name: Run mutation testing
continue-on-error: true
run: cargo mutants --in-diff <(git diff origin/${{ github.base_ref }}...HEAD) --timeout 60 --jobs 2 2>&1 | tee mutation_report.txt || true
complexity:
name: "G4 Β· Complexity + Size + DRY"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with: {shared-key: "konjo-${{ github.repository }}"}
- uses: actions/setup-python@v5
with: {python-version: "3.11"}
- run: pip install radon --quiet
- name: Rust complexity
continue-on-error: true
run: cargo clippy --workspace --all-targets -- -A clippy::all -W clippy::cognitive_complexity --message-format json 2>/dev/null | python3 -c "import json,sys; count=sum(1 for line in sys.stdin for _ in [json.loads(line)] if _.get('reason')=='compiler-message' and 'cognitive_complexity' in str(_['message'].get('code',{})))" || true
- name: Python complexity
continue-on-error: true
run: |
COUNT=$(radon cc . -n C --json 2>/dev/null | python3 -c "import json,sys; d=json.load(sys.stdin); print(sum(len(v) for v in d.values()))" 2>/dev/null || echo 0)
[ "$COUNT" -gt 0 ] && radon cc . -n C -s && exit 1; echo "βœ“"
# ARMED (blocking): every .rs/.py file is ≀ 500 lines repo-wide.
- name: File size
run: |
OVERSIZED=""
while IFS= read -r -d '' f; do LC=$(wc -l < "$f"); [ "$LC" -gt 500 ] && OVERSIZED="${OVERSIZED}${f}: ${LC}\n"; done < <(find . \( -name "*.rs" -o -name "*.py" \) | grep -v target | grep -v __pycache__ | tr '\n' '\0')
[ -n "$OVERSIZED" ] && printf "%b" "$OVERSIZED" && exit 1; echo "βœ“"
# ARMED (blocking): repo currently at 0 DRY violations.
- name: DRY
run: |
python3 .konjo/scripts/dry_check.py --threshold 0.85 --min-lines 20 --report dry_report.json
COUNT=$(python3 -c "import json; print(json.load(open('dry_report.json'))['count'])")
[ "$COUNT" -gt 0 ] && exit 1; echo "DRY βœ“"
- name: Rustdoc
continue-on-error: true
run: RUSTDOCFLAGS="-D missing_docs" cargo doc --workspace --no-deps 2>&1 | grep -q "error" && exit 1 || echo "βœ“"
# G5 disabled β€” run locally: git diff HEAD~1 | python3 .konjo/scripts/konjo_review.py
konjo-gate:
name: "Konjo Gate β€” All Walls Clear"
runs-on: ubuntu-latest
if: always()
needs: [static, coverage, complexity]
steps:
- name: Evaluate gates
run: |
FAILED=""
[ "${{ needs.static.result }}" != "success" ] && FAILED="$FAILED static"
[ "${{ needs.coverage.result }}" != "success" ] && FAILED="$FAILED coverage"
[ "${{ needs.complexity.result }}" != "success" ] && FAILED="$FAILED complexity"
[ -n "$FAILED" ] && echo "::error::Failed:$FAILED" && exit 1
echo "All Konjo gates passed βœ“ The code is seaworthy."