Files
leleka/scripts/check-local.sh
T
Pavlo Ratushnyi 40896ba217 STRA-338 S24: peel the pure host-side models out of cuda-driver into leleka-cuda-model
New L1 crate crates/cuda-model (leleka-cuda-model, forbid(unsafe_code), depends on leleka-context only) holds:
Error/Result with Display, DenseFormat, RoutedFormat, ProjectionKind (+ layout/alignment/required_modes), ProjectionSpec,
the Bf16/Q5K/Q6K projection shapes, bringup_trace_enabled, and the modules serving_context, host_profile, command_profile,
original_mtp_loader, original_prefill_schedule, qsa_prompt_attention_select, original_expert_slots, native_flash_attn,
s_gemv_legacy, device_arena, mmq_original_prefill_misc (moved with git mv; code unchanged apart from pub visibility and
#[inline] on the tiny cached-switch readers, host_profile::add split into an inlined gate and a cold body).

leleka-cuda-driver re-exports every item at its old path, so no use path in the driver, engine-qwen35-cuda or
native-parity-bench changes. Tests moved with their modules; they read the .cu sources and oracle fixtures of the driver
through driver_source!; the one loader test that needs the driver's session geometry stays in the driver.

Housekeeping: workspace members/default-members, Cargo.lock, architecture.json (L1), hexagonal.md, ci-coverage.json,
check-local.sh, port.yml, linux-tests/run.sh, AGENTS.md. architecture-baseline.json: the source ratchets of the moved code
change crate key (dyn-trait driver 56 to 49 + model 3, env-read 72 to 67 + 5, process-global 110 to 99 + 11), regenerated
with --allow-increase for the new keys only; per-pattern totals do not rise. limits-baseline.json is unchanged: no moved
function is over a limit.
2026-11-07 17:40:24 +01:00

257 lines
17 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
# scripts/check-local.sh --product what ships (docs/ci-audit.md): the CI coverage gate, a build of every default-member,
# the release build of the six product binaries (leleka, strata-next, leleka-inference,
# leleka-daemon, leleka-cli, leleka-seal-exec), the tests of the product crates, the
# type-check of the CUDA-feature crates, Clippy and rustfmt (known debt is reported)
# scripts/check-local.sh --clippy-limits opt-in, slow: ratchet of the Clippy length/complexity/argument lints (STRA-367,
# scripts/check-clippy-limits.sh); alone it runs only that, next to a mode it runs last
#
# 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=""
clippy_limits=0
for arg in "$@"; do
case "${arg}" in
""|--full) mode=full ;;
--fast) mode=fast ;;
--port) mode=port ;;
--product) mode=product ;;
--clippy-limits) clippy_limits=1 ;;
-h|--help) sed -n '2,22p' "${BASH_SOURCE[0]}"; exit 0 ;;
*) echo "usage: $0 [--fast|--port|--product|--full] [--clippy-limits]" >&2; exit 2 ;;
esac
done
if [[ -z "${mode}" ]]; then
if ((clippy_limits)); then mode=clippy-limits; else mode=full; fi
fi
# 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
# leleka-experimental-ref includes tests/literal_port.rs, the drift guard between engine/strata/src/kernels/cuda and the checked-in
# experimental ports (re-synced to the upstream 41cf05a0 kernels on 2026-11-03, docs/experiments/2026-10-14-experimental-modes-port.md).
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-model -p leleka-cuda-driver --features cuda-driver -p leleka-engine-qwen35-cuda -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
}
# What ships. Everything here runs without a GPU, model weights or network access to model hosts; the CUDA crates are built and
# their Linux-gated tests run, but no kernel is executed (docs/ci-audit.md lists what this cannot prove).
product_path() {
# A failing step is recorded and the rest still runs, so one red run lists everything that is broken.
local failed=()
gate() { if "$@"; then return 0; fi; failed+=("$*"); echo "PRODUCT STEP FAILED: $*" >&2; return 0; }
echo "== product: coverage gate"
gate python3 "${repo_root}/scripts/check-ci-coverage.py"
echo "== product: architecture gate (layers, adapter edges, size and source ratchets; STRA-338)"
gate python3 "${repo_root}/scripts/check_architecture_test.py"
gate python3 "${repo_root}/scripts/check-architecture.py"
echo "== product: limits gate (function 30 lines, complexity 10, nesting 4, width 120 on new and changed code; legacy census only falls; STRA-367)"
gate python3 "${repo_root}/scripts/check_limits_test.py"
gate python3 "${repo_root}/scripts/check-limits.py"
echo "== product: sealed PTX are byte-exact LF (a CRLF checkout makes the engine refuse to start)"
if grep -rl --include='*.ptx' $'\r' "${repo_root}/crates/cuda-driver" >&2; then
echo "CR found in the sealed PTX listed above: check out with core.autocrlf=false (.gitattributes marks them -text)" >&2
failed+=("sealed PTX contain CR")
fi
local manifest=(--manifest-path "${repo_root}/Cargo.toml" --locked)
echo "== product: build every default-member"
gate cargo build "${manifest[@]}"
echo "== product: release build of the six shipped binaries (docs/deploy.md section 8)"
gate cargo build "${manifest[@]}" --release -p leleka-deploy --bin leleka
gate cargo build "${manifest[@]}" --release -p strata-control --bin strata-next
gate cargo build "${manifest[@]}" --release -p strata-desktop-core --features sm86 \
--bin leleka-inference --bin leleka-daemon --bin leleka-cli --bin leleka-seal-exec
local out="${CARGO_TARGET_DIR:-${repo_root}/target}/release" exe="" bin
[[ "${host_os}" == Linux ]] || exe=".exe"
for bin in leleka strata-next leleka-inference leleka-daemon leleka-cli leleka-seal-exec; do
[[ -x "${out}/${bin}${exe}" ]] || { echo "missing release binary: ${out}/${bin}${exe}" >&2; failed+=("missing release binary ${bin}"); }
done
echo "== product: type-check the CUDA-feature crates (nothing is executed on a GPU)"
gate cargo check "${manifest[@]}" --all-targets -p leleka-cuda-model -p leleka-cuda-driver --features cuda-driver -p leleka-engine-qwen35-cuda -p leleka-runtime -p leleka-native-parity-bench
echo "== product: tests of the crates that ship"
# The deploy end-to-end tests read the host GPU through nvidia-smi and the default loopback ports; the stand-in makes them
# independent of the machine (a CI host has no GPU, a workstation has a busy one). LELEKA_REAL_NVIDIA_SMI=1 keeps the real tool.
local smi_path="${PATH}"
[[ "${LELEKA_REAL_NVIDIA_SMI:-0}" == 1 ]] || smi_path="${repo_root}/scripts/ci:${PATH}"
# Two end-to-end tests depend on the class of the host GPU, on >= 142 GiB free disk and on the default loopback ports, and expect
# opposite GPUs (dry_run wants a 5090-class host, a_failing_preflight wants one that cannot hold the 5090 profile): they cannot both
# pass on one stand-in. They are reported as debt until the tests carry their own nvidia-smi (docs/ci-audit.md, finding 7).
local host_tests=(dry_run_prints_the_plan_and_changes_nothing a_failing_preflight_stops_before_any_change_and_says_how_to_fix_it)
PATH="${smi_path}" gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-deploy --features test-fakes -- --skip "${host_tests[0]}" --skip "${host_tests[1]}"
PATH="${smi_path}" gate debt cargo test "${manifest[@]}" -p leleka-deploy --features test-fakes --test e2e -- "${host_tests[@]}"
gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-memory -p leleka-runtime-client -p leleka-gateway-text -p leleka-gateway-domain -p leleka-worker-protocol -p leleka-engine-core -p leleka-engine-fake -p strata-control -p strata-desktop-core
gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-cuda-model
gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-cuda-driver --features cuda-driver
gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-engine-qwen35-cuda -p leleka-native-cpu-expert
# the remaining default-members (CPU, iGPU and NPU runtime, formats); the strict crates and experimental-ref run in the fast path
gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-cpu-kernels -p leleka-cpu-sys -p leleka-cpu-worker -p leleka-gguf \
-p leleka-gptoss -p leleka-gptoss-igpu -p leleka-harmony -p leleka-igpu -p leleka-kar-codec -p leleka-igpu-worker \
-p leleka-shm -p leleka-openvino -p leleka-npu-service -p leleka-gptoss-npu -p leleka-npu-worker \
-p leleka-gpu-npu-worker -p leleka-model-format -p leleka-obs
echo "== product: rustfmt and Clippy on the shipped crates"
# Clean today, so they are hard gates: the control plane, the desktop-core binaries and the runtime client for rustfmt; these plus the
# memory governor and the deploy tool for Clippy (-D warnings).
gate cargo fmt -p strata-control -p strata-desktop-core -p leleka-runtime-client --check
local crate
for crate in leleka-memory leleka-runtime-client strata-control strata-desktop-core leleka-deploy; do
gate cargo clippy "${manifest[@]}" -p "${crate}" --all-targets --no-deps -- -D warnings
done
# Known debt (docs/ci-audit.md lists the counts); STRICT_DEBT=1 makes it fatal. Other agents own these sources.
gate debt cargo fmt -p leleka-deploy -p leleka-memory -p leleka-cuda-model -p leleka-cuda-driver -p leleka-engine-qwen35-cuda -p leleka-native-cpu-expert --check
gate debt cargo clippy "${manifest[@]}" -p leleka-cuda-driver --all-targets --all-features --no-deps -- -D warnings
gate debt cargo clippy "${manifest[@]}" -p leleka-engine-qwen35-cuda --all-targets --no-deps -- -D warnings
if ((clippy_limits)); then
echo "== product: Clippy limits ratchet (opt-in, slow; STRA-367)"
gate "${repo_root}/scripts/check-clippy-limits.sh"
fi
if ((${#failed[@]})); then
echo "== product: ${#failed[@]} step(s) failed:" >&2
printf ' %s\n' "${failed[@]}" >&2
return 1
fi
echo "== product: all steps passed"
}
if [[ "${mode}" == clippy-limits ]]; then exec "${repo_root}/scripts/check-clippy-limits.sh"; fi
if [[ "${mode}" == product ]]; then product_path; exit 0; fi
if ((clippy_limits)); then echo "--clippy-limits runs alone or together with --product" >&2; exit 2; 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-model -p leleka-cuda-driver -p leleka-engine-qwen35-cuda -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
# the crate does not compile without its `cuda-driver` feature (lib.rs gates only part of the modules); leleka-runtime always enables it
cargo test --manifest-path "${repo_root}/Cargo.toml" --locked -p leleka-cuda-model -p leleka-cuda-driver --features cuda-driver
# Stale since leleka-cuda-driver gained path dependencies (leleka-context, -model-format, -experimental-ref): the script builds a
# synthetic workspace of the crate alone (cargo metadata fails) and also runs `cargo fmt --check` / Clippy `-D warnings` on it, which
# carry the debt of finding 9 in docs/ci-audit.md. scripts/linux-tests/run.sh --mocks runs the same mock-ELF gates on the real tree.
debt "${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
# glibc/libstdc++ hosts: clang's CUDA frontend needs macOS-only stub overloads, so the C++-only pass (--plain) is the advisory check here
python3 "${repo_root}/scripts/cuda-stubs/check-cu.py" --plain || 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 --no-deps -- -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"