Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
ci: fix what the first run of the feature legs exposed
Nicolas Geysse77b6fb0d0a17
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 4f6e51c6..1f09dfdb 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -44,7 +44,7 @@ jobs:# dependency trees they pull in (sqlx, duckdb, tract-onnx, tokenizers,# instant-distance).#- # It is also why seven test files under tests/ had never been collected once.+ # It is also why eight test files under tests/ had never been collected once.# tests/schema_test.rs is gated on `postgres` and covers# SchemaIntrospector::sql_to_xsd, which carried a real defect the whole time# (#76, fixed in #80): the test existed, and it was dark.@@ -61,6 +61,7 @@ jobs:# Breadth: everything compiles and lints, including causal-pywhy,# whose Rust side has no dependencies of its own.- name: breadth (all-features)+ cache_key: breadthflags: --all-featurestest: false# Depth: everything whose tests run without external services.@@ -68,9 +69,9 @@ jobs:# to Python/DoWhy at runtime, which is a service dependency in all but# name. It is still compiled and linted by the breadth leg.- name: depth (postgres,duckdb,embeddings,sql)+ cache_key: depthflags: --features postgres,duckdb,embeddings,sqltest: true- features_list: postgres duckdb embeddings sqlenv:CARGO_INCREMENTAL: 0CARGO_PROFILE_DEV_DEBUG: 0@@ -88,9 +89,12 @@ jobs:components: clippy- uses: Swatinem/rust-cache@v2with:- # Keyed on the feature set: the legs build disjoint dependency trees,- # and sharing one cache between them would thrash it on every run.- key: ${{ matrix.name }}+ # Keyed per leg: they build disjoint dependency trees, and sharing one+ # cache between them would thrash it on every run. Not `matrix.name` —+ # GitHub rejects cache keys containing commas, and the rejection is a+ # log annotation rather than a failing step, so the leg would keep+ # running uncached and silent.+ key: ${{ matrix.cache_key }}- name: Checkrun: cargo check ${{ matrix.flags }} --all-targets- name: Clippy@@ -104,4 +108,7 @@ jobs:cargo test ${{ matrix.flags }} 2>&1 | tee cargo-test.log- name: Verify every enabled test file collected testsif: matrix.test- run: bash scripts/check-test-collection.sh cargo-test.log "${{ matrix.features_list }}"+ # Same flags as the test step, so the enabled set cannot drift from what+ # was actually built. The script expands them through [features], which+ # a hand-written list would not: `sql` implies postgres + duckdb.+ run: bash scripts/check-test-collection.sh cargo-test.log "${{ matrix.flags }}"diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cfd8f64d..58bff6b5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,10 +13,16 @@ All notable changes to Open Ontologies are documented here.`tract-onnx`, `tokenizers` and `instant-distance` trees — was compiled byanything in CI before this.+ The first run of the breadth leg found `clippy::large_enum_variant` in+ `src/embed.rs`, a lint that could not have fired before because nothing+ compiled `embeddings`.+`scripts/check-test-collection.sh` fails the run when a test file whose gate- is enabled collects zero tests. Seven files under `tests/` had never been- collected once, 53 tests in total; a file that collects nothing reports- "test result: ok" and is indistinguishable from a passing one. Files whose+ is enabled collects zero tests. Eight files under `tests/` had never been+ collected once, 56 tests in total; a file that collects nothing reports+ "test result: ok" and is indistinguishable from a passing one. The enabled+ set is derived from the cargo flags the test step used and expanded through+ `[features]`, so `--features sql` counts as postgres + duckdb; files whosegate is off in a given leg are skipped, so partial-feature legs stay green.- **Opt-in persistent triple store.** A new `[storage]` section selects thebackend for the main graph: `mode = "memory"` (default, unchanged behaviour)diff --git a/scripts/check-test-collection.sh b/scripts/check-test-collection.shold mode 100644new mode 100755index 99239124..d768d2c9--- a/scripts/check-test-collection.sh+++ b/scripts/check-test-collection.sh@@ -3,9 +3,9 @@# Fail when an integration test file compiles to a target that collects no tests.## `cargo test` prints "running 0 tests" followed by "test result: ok" for a file-# whose `#![cfg(feature = "...")]` header is not satisfied. That is-# indistinguishable from passing, which is the worst version of this failure:-# a green badge over a file that has never run.+# whose feature gate is not satisfied. That is indistinguishable from passing,+# which is the worst version of this failure: a green badge over a file that has+# never run.## tests/schema_test.rs sat behind `#![cfg(feature = "postgres")]` while CI ran a# bare `cargo test`, so its six tests were never collected once — including the@@ -16,28 +16,147 @@# expected there, and flagging it would make the check permanently red on any# partial-feature leg.#-# Usage: bash scripts/check-test-collection.sh <cargo-test-log> "<enabled features>"+# The enabled set is derived from the same cargo flags the test step used, and+# expanded through `[features]` in Cargo.toml, so `--features sql` correctly+# counts as postgres + duckdb. Passing a hand-written list instead would go+# stale silently, in the direction that hides files rather than flagging them.+#+# Two gate forms are recognised, because both are in use here:+# #![cfg(feature = "x")] — inner attribute, gates the whole file+# #[cfg(feature = "x")] mod tests {} — outer attribute over the only test mod+# Anything more intricate (several distinct gates, tests outside the gated mod)+# is treated as ungated, i.e. expected to collect. When the shape is unclear the+# check errs toward checking: a spurious red is loud and takes a minute to fix,+# a spurious green is the bug this script exists to prevent.+#+# Platform gates (`#![cfg(unix)]` in tests/socket_test.rs) are out of scope: the+# features job runs on Linux only, where that file does collect.+#+# Usage: bash scripts/check-test-collection.sh <cargo-test-log> "<cargo flags>"+# bash scripts/check-test-collection.sh cargo-test.log "--features postgres,sql"+# bash scripts/check-test-collection.sh cargo-test.log "--all-features"#set -euo pipefail-log=${1:?usage: check-test-collection.sh <cargo-test-log> "<enabled features>"}-enabled=" ${2:-} "+log=${1:?usage: check-test-collection.sh <cargo-test-log> "<cargo flags>"}+flags=${2:-}[ -f "$log" ] || { echo "::error::log file not found: $log"; exit 1; }+[ -f Cargo.toml ] || { echo "::error::Cargo.toml not found — run from the crate root"; exit 1; }++# --- what Cargo.toml declares -------------------------------------------------+# One "<name><TAB><comma-separated members>" line per [features] entry. Handles+# arrays spread over several lines, and strips comments.+feature_table=$(awk '+ /^[[:space:]]*\[/ { in_f = ($0 ~ /^[[:space:]]*\[features\][[:space:]]*$/); next }+ in_f { line = $0; sub(/#.*/, "", line); buf = buf " " line }+ END {+ while (match(buf, /[A-Za-z0-9_-]+[[:space:]]*=[[:space:]]*\[[^]]*\]/)) {+ entry = substr(buf, RSTART, RLENGTH)+ buf = substr(buf, RSTART + RLENGTH)+ name = substr(entry, 1, index(entry, "=") - 1)+ gsub(/[[:space:]]/, "", name)+ members = substr(entry, index(entry, "[") + 1)+ sub(/\][[:space:]]*$/, "", members)+ gsub(/[" \t]/, "", members)+ print name "\t" members+ }+ }+' Cargo.toml)++[ -n "$feature_table" ] || { echo "::error::no [features] section found in Cargo.toml"; exit 1; }++# --- what the cargo flags enable ----------------------------------------------+all_features=0+no_default=0+seeds=""++set -- $flags+while [ $# -gt 0 ]; do+ case "$1" in+ --all-features) all_features=1 ;;+ --no-default-features) no_default=1 ;;+ --features|-F) shift; seeds="$seeds $(printf '%s' "${1:-}" | tr ',' ' ')" ;;+ --features=*) seeds="$seeds $(printf '%s' "${1#--features=}" | tr ',' ' ')" ;;+ -F*) seeds="$seeds $(printf '%s' "${1#-F}" | tr ',' ' ')" ;;+ esac+ shift+done++if [ "$all_features" -eq 1 ]; then+ seeds=$(printf '%s\n' "$feature_table" | cut -f1 | tr '\n' ' ')+elif [ "$no_default" -eq 0 ]; then+ seeds="$seeds default"+fi+# Transitive closure over [features]. `dep:foo` and `pkg/feat` entries name+# dependencies, not gates of ours, and are dropped.+queue=$seeds+enabled=""+while [ -n "${queue// /}" ]; do+ name=${queue%% *}+ if [ "$name" = "$queue" ]; then queue=""; else queue=${queue#* }; fi+ [ -n "$name" ] || continue+ case " $enabled " in *" $name "*) continue ;; esac+ enabled="$enabled $name"+ members=$(printf '%s\n' "$feature_table" | awk -F'\t' -v n="$name" '$1 == n { print $2 }')+ for m in $(printf '%s' "$members" | tr ',' ' '); do+ case "$m" in dep:*|*/*) continue ;; esac+ queue="$queue $m"+ done+done+enabled=" ${enabled# } "++# --- check every test file ----------------------------------------------------missing=()empty=()checked=0+skipped=0for f in tests/*.rs; do[ -e "$f" ] || continue- # File-level gate, if any: `#![cfg(feature = "x")]` in the header.- gate=$(sed -n '1,12p' "$f" \- | sed -n 's/^#!\[cfg(feature = "\([A-Za-z0-9_-]*\)")\].*/\1/p' \- | head -1)+ # Gate for the whole file, or empty when the file is (or looks) ungated.+ gate=$(awk '+ /^#!\[cfg\(/ {+ line = $0+ while (match(line, /"[A-Za-z0-9_-]+"/)) {+ crate = crate " " substr(line, RSTART + 1, RLENGTH - 2)+ line = substr(line, RSTART + RLENGTH)+ }+ next+ }+ /^#\[cfg\(feature[[:space:]]*=[[:space:]]*"[A-Za-z0-9_-]+"\)\][[:space:]]*$/ {+ match($0, /"[A-Za-z0-9_-]+"/)+ g = substr($0, RSTART + 1, RLENGTH - 2)+ outer+++ if (mod_gate == "") mod_gate = g+ else if (mod_gate != g) mixed = 1+ if (tests > 0) late = 1+ next+ }+ /^[[:space:]]*#\[(tokio::)?test\]/ { tests++ }+ END {+ if (tests == 0) { print "__no_tests__"; exit }+ if (crate != "") { print substr(crate, 2); exit }+ if (outer == 1 && !mixed && !late) { print mod_gate; exit }+ print ""+ }+ ' "$f")- if [ -n "$gate" ] && [[ "$enabled" != *" $gate "* ]]; then+ if [ "$gate" = "__no_tests__" ]; then+ skipped=$((skipped + 1))+ continue+ fi++ # Several gates on one file (`#![cfg(all(feature = "a", feature = "b"))]`)+ # all have to be enabled for its tests to exist.+ gate_off=0+ for g in $gate; do+ case "$enabled" in *" $g "*) ;; *) gate_off=1 ;; esac+ done+ if [ "$gate_off" -eq 1 ]; then+ skipped=$((skipped + 1))continuefi@@ -73,8 +192,10 @@ if [ ${#missing[@]} -gt 0 ]; thenstatus=1fi+echo "enabled features:${enabled}"+if [ "$status" -eq 0 ]; then- echo "test collection OK — $checked test file(s) expected under [${2:-none}], all collected at least one test"+ echo "test collection OK — $checked test file(s) expected, all collected at least one test ($skipped skipped as gated out)"elseechoecho "A test file that collects nothing reports \"test result: ok\" and is"diff --git a/src/embed.rs b/src/embed.rsindex 660939b9..5eb85a4f 100644--- a/src/embed.rs+++ b/src/embed.rs@@ -137,6 +137,14 @@ impl TextEmbedder {/// Unified text embedder that dispatches to either the local ONNX model or/// an OpenAI-compatible HTTP API, selected by configuration.+// clippy::large_enum_variant fires here (Local is ~1.4 KB against ~100 bytes for+// OpenAI) and the lint had never run, because nothing in CI compiled the+// `embeddings` feature. Boxing is not the right answer for this one: the value+// is built once at startup and immediately parked in an `Arc` (server.rs), then+// only ever borrowed — it is never moved in a hot path or stored in a+// collection. The box would buy an indirection on every embed call and change a+// public type, to save a single move of 1.4 KB at boot.+#[allow(clippy::large_enum_variant)]pub enum TextEmbedderProvider {Local(TextEmbedder),OpenAI(crate::embed_remote::OpenAIEmbedder),