Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ workflows:
'.github/workflows/bridge-gate.yml':
- 'actions/checkout@v7.0.1'
'.github/workflows/build-validation.yml':
- 'actions/cache@v6.1.0'
- 'actions/checkout@v7.0.1'
- 'dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8'
- 'erlef/setup-beam@v1.24.1'
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,48 @@ jobs:
otp-version: "27"
- run: mix deps.get
- run: mix compile --warnings-as-errors

validate-nif:
# The Rust NIF (rust-core/verisim-nif) can only run inside the BEAM: it is
# built here and loaded by ExUnit, which checks that every operation fails
# loudly ({:error, :not_implemented}) and never fabricates success.
name: NIF loads in the BEAM
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1
id: toolchain
with:
toolchain: stable
- uses: erlef/setup-beam@v1.24.1
with:
elixir-version: "1.17"
otp-version: "27"
# The NIF pulls in six core crates; without a cache every run rebuilds
# them. Keyed on OS, the resolved toolchain and Cargo.lock.
- name: Cache Cargo registry and NIF build
uses: actions/cache@v6.1.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
target
key: ${{ runner.os }}-cargo-nif-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-nif-${{ steps.toolchain.outputs.cachekey }}-
- name: Build the NIF
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
run: |
cargo build --locked -p verisim-nif
mkdir -p elixir-orchestration/priv/native
cp target/debug/libverisim_nif.so elixir-orchestration/priv/native/
- name: Run the NIF tests against the built library
working-directory: elixir-orchestration
env:
VERISIM_REQUIRE_NIF: "1"
run: |
mix deps.get
mix test --only nif
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ hooks/playbook-to-recipe/Cargo.lock
.verisimdb/ecosystem-ingest/Cargo.lock
# Backup/scratch files (never commit)
*.backup

# Rust NIF built for ExUnit (rust-core/verisim-nif); never committed
elixir-orchestration/priv/native/
6 changes: 4 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ All notable changes to VeriSimDB are documented here. This project uses https://

== [Unreleased]

=== Removed — dead `deny.toml` ignore for RUSTSEC-2026-0543 (2026-11-30)
=== Added — the compiled NIF is now tested inside the BEAM (2026-11-30)

- The dated ignore for chrono's "unmaintained" advisory (#354, 2026-11-17) met its own removal condition when #356 removed chrono from the workspace. `cargo deny` reported it as `advisory-not-detected`, so it suppressed nothing. Removed, and the closure in `SECURITY-ADVISORIES.adoc` updated. `cargo deny check advisories bans licenses sources` passes with default features and with `--all-features`.
- *`elixir-orchestration/test/verisim/nif_bridge_loaded_test.exs`* (new, tag `:nif`) loads the real `libverisim_nif.so` and checks every operation returns exactly `{:error, :not_implemented}`. The pure-Elixir fallback answers `{:error, :nif_not_loaded}`, so the exact atom proves the compiled Rust NIF ran. Until now the NIF had never been executed under test: CI never built it, so the existing transport tests only reached the fallback. This pins the fail-loudly property that replaced the old fake-success NIF (silent data loss).
- *CI*: new job "NIF loads in the BEAM" in `build-validation.yml` builds the cdylib, places it in `priv/native/` and runs `mix test --only nif` with `VERISIM_REQUIRE_NIF=1`, so a missing library fails the job instead of skipping it. No new actions; `actions.lock` is unchanged.
- *`test_helper.exs`*: `:nif` tests run automatically when the library is present and are excluded otherwise; `priv/native/` is git-ignored.

=== Changed — chrono replaced by `time` via `verisim-time` (2026-11-18)

Expand Down
2 changes: 1 addition & 1 deletion TESTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ of hyperpolymath/proven-tests-and-benches:
a file exists unregistered, a registered file is missing, a tier is
outside the vocabulary, or an actually-proven suite names no proof.
The counts in this document are the gate's output, not an aspiration:
98 files (10 / 25 / 63 across the tiers). Inline Rust `#[cfg(test)]`
99 files (10 / 25 / 64 across the tiers). Inline Rust `#[cfg(test)]`
modules run under cargo test and are not file-registered.

Any new test file MUST be registered in the same PR, at an honest
Expand Down
17 changes: 16 additions & 1 deletion elixir-orchestration/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,19 @@
# Integration tests (federation adapters and anything else needing live
# external services) are excluded by default so plain \`mix test\` is
# self-contained. Run them with: mix test --include integration
ExUnit.start(exclude: [:integration])
#
# Tests tagged :nif exercise the compiled Rust NIF itself
# (rust-core/verisim-nif) and run only when it has been built into
# priv/native/. CI sets VERISIM_REQUIRE_NIF=1 so a missing library fails the
# run instead of silently skipping it.
nif_path = Path.join(:code.priv_dir(:verisim), "native/libverisim_nif.so")
nif_required? = System.get_env("VERISIM_REQUIRE_NIF") == "1"

if nif_required? and not File.exists?(nif_path) do
raise "VERISIM_REQUIRE_NIF=1 but #{nif_path} does not exist; " <>
"build it with `cargo build -p verisim-nif` and copy " <>
"target/debug/libverisim_nif.so into elixir-orchestration/priv/native/"
end

exclude = if File.exists?(nif_path), do: [:integration], else: [:integration, :nif]
ExUnit.start(exclude: exclude)
63 changes: 63 additions & 0 deletions elixir-orchestration/test/verisim/nif_bridge_loaded_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# SPDX-License-Identifier: MPL-2.0

defmodule VeriSim.NifBridgeLoadedTest do
@moduledoc """
Exercises the compiled Rust NIF (`rust-core/verisim-nif`), not the
pure-Elixir fallback.

Every operation is still a scaffold, and the property that matters is that
each one fails loudly. An earlier NIF returned canned success (`delete_octad`
replied "deleted" having deleted nothing), which was silent data loss.

The fallback stubs answer `{:error, :nif_not_loaded}`; the real library
answers `{:error, :not_implemented}`. Asserting the exact atom therefore
proves the compiled NIF was loaded and answered.

Tagged `:nif`: runs only when the library is in `priv/native/`
(see `test_helper.exs`).
"""
use ExUnit.Case, async: true

alias VeriSim.{NifBridge, Transport}

@moduletag :nif

@operations [
create_octad: [~s({"document":{"title":"t","body":"b"}})],
get_octad: ["e-1"],
delete_octad: ["e-1"],
search_text: ["q", 10],
search_vector: ["[0.1,0.2,0.3]", 5],
list_octads: [10, 0],
get_drift_score: ["e-1"],
trigger_normalise: ["e-1"]
]

setup_all do
nif_path = Path.join(:code.priv_dir(:verisim), "native/libverisim_nif.so")
assert File.exists?(nif_path), "built NIF missing at #{nif_path}"
:ok
end

for {fun, args} <- @operations do
test "#{fun} is answered by the compiled NIF and fails loudly" do
assert {:error, :not_implemented} =
apply(NifBridge, unquote(fun), unquote(Macro.escape(args)))
end
end

test "the loaded NIF is not reported as operational" do
# loaded? is true only for a success result, which no operation returns.
refute NifBridge.loaded?()
end

test "auto transport keeps using HTTP while the NIF is non-operational" do
previous = System.get_env("VERISIM_TRANSPORT")
System.put_env("VERISIM_TRANSPORT", "auto")
on_exit(fn -> restore_env("VERISIM_TRANSPORT", previous) end)
refute Transport.use_nif?()
end

defp restore_env(key, nil), do: System.delete_env(key)
defp restore_env(key, value), do: System.put_env(key, value)
end
4 changes: 3 additions & 1 deletion rust-core/verisim-nif/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ publish = false # workspace-internal; path deps cannot be published to crates.i
name = "verisim_nif"
crate-type = ["cdylib"]
# NIF symbols (enif_*) only resolve inside the BEAM, so a Rust test binary
# cannot link. There are no Rust-side tests; the NIF is exercised from Elixir.
# cannot link. There are no Rust-side tests; the NIF is exercised from Elixir:
# elixir-orchestration/test/verisim/nif_bridge_loaded_test.exs loads the built
# library (CI job "NIF loads in the BEAM" in build-validation.yml).
test = false
doctest = false
bench = false
Expand Down
Loading
Loading