Files
leleka/scripts/check-local.sh
T
Pavlo Ratushnyi 618a3fa253 Merge branch 'claude/port-rv-kernels' into claude/port-main
# Conflicts:
#	docs/cuda-seal-plan-additions-window.json
#	scripts/check-local.sh
2026-10-14 17:04:06 +02:00

155 lines
8.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Local and CI gate.
#
# scripts/check-local.sh fast path, Linux type-check, port oracles, then the full legacy suite
# scripts/check-local.sh --fast only the fast path (seconds to a few minutes, works on macOS)
# scripts/check-local.sh --port fast path, Linux type-check and the CPU oracle differentials of the Rust port
#
# Environment:
# STRICT_DEBT=1 fail on the known format/Clippy debt listed below instead of warning
# SKIP_LINUX_TYPECHECK=1 skip the x86_64-unknown-linux-gnu type-check (needs `rustup target add` otherwise)
# OFFLINE_ORACLE_PYTHON, STRATA_GGUF_PY
# enable the live Python-oracle differentials (docs/offline-port.md)
# LELEKA_LINUX_TESTS=1 also run scripts/linux-tests/run.sh (Docker Linux harness, branch claude/port-linux-tests)
#
# No model weights, tokens or network access to model hosts are used by any step.
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
mode=full
case "${1:-}" in
""|--full) ;;
--fast) mode=fast ;;
--port) mode=port ;;
-h|--help) sed -n '2,15p' "${BASH_SOURCE[0]}"; exit 0 ;;
*) echo "usage: $0 [--fast|--port|--full]" >&2; exit 2 ;;
esac
# Known debt on the port branch: these crates are not rustfmt/Clippy clean (other agents own the sources, so the gate
# reports them instead of reformatting). New debt-free crates must be added to strict_crates below, not here.
debt() {
if "$@"; then return 0; fi
if [[ "${STRICT_DEBT:-0}" == 1 ]]; then
echo "FAILED (STRICT_DEBT=1): $*" >&2
return 1
fi
echo "WARNING: known debt, not failing: $*" >&2
}
host_os="$(uname -s)"
# Crates that build natively on macOS and Linux and are fmt-, Clippy- and test-clean.
strict_crates=(leleka-backend-api leleka-tokenizer leleka-quant-core leleka-context leleka-sampler-ref leleka-serving-policy leleka-offline-tools)
strict_args=(); for c in "${strict_crates[@]}"; do strict_args+=(-p "$c"); done
fast_path() {
echo "== fast path: fmt, Clippy, tests on ${strict_crates[*]}"
cargo fmt "${strict_args[@]}" --check
cargo clippy --manifest-path "${repo_root}/Cargo.toml" --locked "${strict_args[@]}" --all-targets --no-deps -- -D warnings
cargo test --manifest-path "${repo_root}/Cargo.toml" --locked "${strict_args[@]}"
# Host-buildable crates with known debt: tests and Clippy still run; formatting is reported only.
debt cargo fmt -p leleka-model-format -p leleka-experimental-ref --check
cargo clippy --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-experimental-ref --all-targets --no-deps -- -D warnings
debt cargo clippy --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-model-format --all-targets --no-deps -- -D warnings
cargo test --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-experimental-ref -p leleka-model-format
}
linux_typecheck() {
if [[ "${SKIP_LINUX_TYPECHECK:-0}" == 1 ]]; then
echo "== linux type-check skipped (SKIP_LINUX_TYPECHECK=1)"
return 0
fi
echo "== type-check for x86_64-unknown-linux-gnu (leleka-cuda-driver with cuda-driver, leleka-runtime)"
if [[ "${host_os}" != Linux ]] && ! rustup target list --installed 2>/dev/null | grep -qx x86_64-unknown-linux-gnu; then
echo "missing target: run 'rustup target add x86_64-unknown-linux-gnu' or set SKIP_LINUX_TYPECHECK=1" >&2
return 1
fi
cargo check --manifest-path "${repo_root}/Cargo.toml" --locked --target x86_64-unknown-linux-gnu --all-targets \
-p leleka-cuda-driver --features cuda-driver -p leleka-runtime
}
port_oracles() {
echo "== port CPU oracles that need no Python: sampler host shim"
# Pure-host tests of the Linux-only sampler files, against fixtures built from the unmodified Original host code.
"${repo_root}/crates/sampler-ref/oracle/run_port_host_tests.sh"
# Golden fixtures built from the Original C++/Python (rope, memory plan, serving policy, conversation, experimental
# references, offline tools, tokenizer) are replayed by the cargo tests above. Live Python differentials follow.
offline_oracles
}
# Live differentials against the unmodified Python oracle (docs/offline-port.md). Opt in with a venv that has
# numpy, pyyaml, tqdm, jinja2 and regex, and the pinned llama.cpp gguf-py:
# OFFLINE_ORACLE_PYTHON=/venv/bin/python STRATA_GGUF_PY=/llama.cpp/gguf-py scripts/check-local.sh
offline_oracles() {
if [[ -n "${OFFLINE_ORACLE_PYTHON:-}" && -n "${STRATA_GGUF_PY:-}" ]]; then
cargo build --manifest-path "${repo_root}/Cargo.toml" --locked -p strata-control --bin strata-next
local strata_next="${CARGO_TARGET_DIR:-${repo_root}/target}/debug/strata-next"
local oracle
for oracle in native_pack gguf_header tokenizer dequant tools mtp_fetch chat_template; do
"${OFFLINE_ORACLE_PYTHON}" "${repo_root}/scripts/offline/diff_${oracle}.py" "${strata_next}"
done
else
echo "== live Python oracle differentials skipped (set OFFLINE_ORACLE_PYTHON and STRATA_GGUF_PY)"
fi
}
linux_harness() {
if [[ "${LELEKA_LINUX_TESTS:-0}" == 1 ]]; then
if [[ -x "${repo_root}/scripts/linux-tests/run.sh" ]]; then
echo "== Docker Linux test harness"
"${repo_root}/scripts/linux-tests/run.sh"
else
echo "scripts/linux-tests/run.sh is not present (it lives on branch claude/port-linux-tests until merged)" >&2
return 1
fi
fi
}
fast_path
[[ "${mode}" == fast ]] && exit 0
linux_typecheck
port_oracles
linux_harness
[[ "${mode}" == port ]] && exit 0
python3 -m py_compile "${repo_root}/scripts/prepare-keyless-routing.py" "${repo_root}/scripts/calibrate-keyless-routing.py" "${repo_root}/scripts/test-keyless-routing.py" "${repo_root}/scripts/bench-chat-paired.py" "${repo_root}/scripts/compare-chat-reports.py" "${repo_root}/scripts/bench-chat-sequential-server.py" "${repo_root}/scripts/check-kar-cuda-records.py" "${repo_root}/scripts/strata-agent-profile.py" "${repo_root}/scripts/strata-dual-256-experiment.py" "${repo_root}/scripts/strata-dual-request-proxy.py" "${repo_root}/scripts/kv-keyless-feasibility.py" "${repo_root}/scripts/kv-keyless-attention.py" "${repo_root}/scripts/bench-expert-reserve.py" "${repo_root}/scripts/ple-cache-reuse.py" "${repo_root}/scripts/split-ple-row-trace.py" "${repo_root}/scripts/bench-kar-ple-device.py" "${repo_root}/scripts/bench-kar-ple-serve.py"
python3 "${repo_root}/scripts/test-benchmark-harness.py"
python3 "${repo_root}/scripts/test-native-service.py"
python3 "${repo_root}/scripts/test-native-api.py"
python3 "${repo_root}/scripts/test-native-menu.py"
python3 "${repo_root}/scripts/test-model-switch.py"
python3 "${repo_root}/scripts/test-cuda-bootstrap.py"
python3 "${repo_root}/scripts/test-static-cuda-profile.py"
python3 "${repo_root}/scripts/test-static-cuda-elf.py"
python3 "${repo_root}/scripts/test-linux-package.py"
python3 "${repo_root}/scripts/test-runtime-image.py"
python3 "${repo_root}/scripts/test-ple-config-parity.py"
python3 "${repo_root}/scripts/test-gitea-release.py"
python3 "${repo_root}/scripts/test-keyless-routing.py"
# leleka-cuda-driver and leleka-runtime build only for Linux; on other hosts the type-check above is the check.
if [[ "${host_os}" == Linux ]]; then
debt cargo fmt -p leleka-cuda-driver -p leleka-runtime -p leleka-native-cpu-expert --check
debt cargo clippy --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-cuda-driver --all-targets --all-features -- -D warnings
cargo test --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-cuda-driver
"${repo_root}/scripts/test-cuda-driver-bootstrap.sh"
else
echo "== Linux-only crate tests skipped on ${host_os}"
fi
# every ported .cu parses against the CUDA stub headers (no nvcc needed; see scripts/cuda-stubs/cuda_stub.h)
# (verified on macOS/Apple clang; on other hosts libstdc++'s math headers may need stub additions, so it is advisory there)
if command -v clang++ >/dev/null 2>&1; then
if [ "$(uname -s)" = Darwin ]; then
python3 "${repo_root}/scripts/cuda-stubs/check-cu.py"
else
python3 "${repo_root}/scripts/cuda-stubs/check-cu.py" || echo "warning: cuda stub syntax check failed (advisory off macOS)" >&2
fi
fi
cargo fmt --manifest-path "${repo_root}/control-plane/Cargo.toml" --check
cargo clippy --manifest-path "${repo_root}/control-plane/Cargo.toml" --locked --all-targets -- -D warnings
cargo test --manifest-path "${repo_root}/control-plane/Cargo.toml" --locked
replay="$(cargo run --quiet --manifest-path "${repo_root}/control-plane/Cargo.toml" --locked --bin replay-responses -- --sse "${repo_root}/benchmarks/fixtures/responses/structured-tool.json")"
[[ "${replay}" == *"event: response.completed"* ]]
"${repo_root}/scripts/build-cpu.sh"