Building and testing
Ez az oldal a nucleus saját dokumentációjából készül, ezért angol nyelvű.
cargo test --workspace # everything
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all
cargo build --target i686-unknown-linux-musl # any target in PLAN.md "Build targets"
CI (.github/workflows/ci.yml) runs fmt and clippy, then builds every build
target and runs the tests on all of them except x86_64-apple-darwin (built
only); on Linux it also runs the real psql against --pg-compat
(scripts/psql-smoke.sh, §9) and mongosh and pymongo against
--mongo-compat (scripts/mongo-smoke.sh, §8.42), the drivers job runs every driver’s
tests and every example against a server (scripts/driver-tests.sh, §11),
and the modules job checks the module boundaries and detaches every
module (§1):
Before a push, scripts/precheck.sh finds what CI would find on the
platforms the machine does not run — most of CI’s failures were code
that builds on one platform and not another (std::os::unix outside
cfg(unix), a C unsigned long taken for 64 bits, a warning only
another platform’s cfg shows, under CI’s -D warnings) or a test
that starts a thread under WASI: format, clippy, the module boundaries,
cargo check of the workspace for Windows and 32-bit Linux and of the
core crates and the embedded edition for WASI, Android and iOS (ring’s
C code compiled for the check by LLVM against stand-in headers), then
the wasm job’s tests under Node’s WASI (--quick leaves them out).
scripts/precheck.sh # before a push (~5 min; --quick ~30 s)
cargo build --release -p nucleus-cli
scripts/driver-tests.sh target/release/nucleus [rust python js java c cpp]
scripts/psql-smoke.sh target/release/nucleus # needs psql
scripts/check-boundaries.py # core ↛ modules; modules → public API only
scripts/detach-test.sh [<module package> …] # cargo package, then test each unpacked copy
scripts/ci-tools.sh # CI's tools, pinned and checked, into target/ci-tools
T=target/ci-tools; PROMTOOL=$T/promtool PROMETHEUS=$T/prometheus OTELCOL=$T/otelcol \
monitoring/test.sh target/release/nucleus # the rules' tests, a real Prometheus and collector
RCLONE=$T/rclone scripts/s3-test.sh target/release/nucleus # backups in a real S3 server
MOTO_PYTHON=$T/moto/bin/python VAULT=$T/vault \
scripts/kms-test.sh target/release/nucleus # the root in AWS KMS (moto), Vault Transit, SoftHSM2
A test-kit script whose results claim PostgreSQL’s is checked against a
real one (Docker’s postgres:18-alpine, or --psql): scripts/slt-pg.py check crates/testkit/slt/65_json.slt; fill writes PostgreSQL’s results
in. Records after # nucleus-only: are nucleus’s on purpose, and left
out.
The detachability test packages the core crates and the modules
(cargo package, which also builds each from its package against the
others’; in a target directory of its own, fresh each run, since cargo
reuses a registry crate of an unchanged version), unpacks each module
into an empty directory, points its nucleus dependencies at the packaged
core crates ([patch.crates-io]) and runs its tests there.
The i686 musl tests run as 32-bit binaries on a 64-bit Linux
kernel, which is what catches 64-bit usize assumptions. The tls module’s
cryptography (ring) has C and assembly, so a musl target needs a C
compiler for it: musl-gcc (Debian / Ubuntu musl-tools) for x86_64 and
aarch64, the multilib gcc for i686 — CI sets CC_<target>, e.g.
CC_x86_64_unknown_linux_musl=musl-gcc.
Simulation tests take their seeds from harness::run (§3.4). The test
profile builds with opt-level = 1 (debug assertions on), because the crash
sweeps replay workloads thousands of times:
NUCLEUS_SEED=0xf4a13e02e1757317 cargo test crash_keeps # rerun one failing seed
NUCLEUS_SIM_CASES=10000 cargo test -p nucleus-platform # search more seeds
Fuzzing (PLAN.md §M14.29 S2; fuzz/README.md): fuzz/ is a crate of
its own (its own workspace, built only by cargo fuzz on a nightly
toolchain with AddressSanitizer) with a target for every input that
crosses a trust boundary — sql_parse, values (every type’s text
input), text_search, copy, ncp, pg_wire, scram, jwt, disk
(a real database’s pages and WAL patched, checksums sealed again or not,
then opened, checked and read) and model_files. An error is an answer;
a panic, a hang, a memory error or an allocation past the limit is a
finding. The front ends serve any byte stream
(nucleus_server::handle_native_stream, nucleus_pg_compat::handle_stream:
no TLS, no client address), so the protocol targets need no socket;
their database is in memory under the machine’s clock with
statement_timeout at 250 ms. Seeds are kept in fuzz/seeds/
(fuzz/seeds.py makes them: the sqllogictest statements, recorded
driver and psycopg sessions, a computed SCRAM exchange, tiny model
files); CI’s fuzz job runs each target three minutes a change, its
corpus kept between runs:
cd fuzz && cargo +nightly fuzz run -O ncp corpus/ncp seeds/ncp -- -max_total_time=300 -rss_limit_mb=2048 -timeout=10