feat(runtime): mock backends and a MockRuntime assembly via the builder#202
Open
mfw78 wants to merge 1 commit into
Open
feat(runtime): mock backends and a MockRuntime assembly via the builder#202mfw78 wants to merge 1 commit into
mfw78 wants to merge 1 commit into
Conversation
Ship engine-side fakes under a test-utils feature so an in-process runtime launches entirely on mocks: MockChainProvider (programmable request responses, recorded calls, channel-driven block and chain-log streams), an in-memory MockStateStore with no redb or disk, a pass-through Prebuilt component builder, and the domain-free MockTypes lattice. A self dev-dependency turns the feature on for this crate's own tests. The assembly composes through the public type-state path (with_types::<MockTypes>().with_components(...)), proven by an M0 acceptance launch test that needs no CLI, disk, or network. The two Supervisor empty_for_test call sites move onto the mock components via the real boot path, and that test-only constructor is deleted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #94; part of the epic #80 train, merges in stack order.
Ships engine-side test fakes behind a
test-utilsfeature so a runtime can be assembled and launched entirely through the public builder, on mocks, with no CLI, disk, or network.Changes
crates/nexum-runtime/Cargo.tomladds[features] test-utils = []plus a self dev-dependency (nexum-runtimewithfeatures = ["test-utils"]) so the crate's own tests and doctests see the mocks without every invocation passing--all-features.src/test_utils/chain.rsaddsMockChainProvider, aClone + Send + SyncChainProviderwith programmableon_method/on_requestresponses keyed by(method, params),recorded_requests, andpush_block/push_chain_logfeedingfutures::channel::mpscreceivers returned as the boxedBlockStream/ChainLogStream. Unprogrammed methods returnProviderError::UnknownChain, matchingProviderPool::empty(). A secondsubscribe_*after the receiver is taken parks onstream::pending()so a reconnect loop cannot busy-spin.src/test_utils/store.rsadds an in-memoryMockStateStore/MockStateHandle(Arc<Mutex<HashMap>>, no redb or disk) that mirrors the redb-backed store's behaviour: the sameInvalidNamespacemessage on an empty namespace,Ok(None)on an absent key, idempotent delete, and prefix-filtered, sortedlist_keys.src/test_utils/builders.rsadds a generic pass-throughPrebuilt<T>ComponentBuilder.src/test_utils/types.rsadds the domain-freeMockTypeslattice (Chain = MockChainProvider,Store = MockStateStore,Ext = ()).src/test_utils/mod.rsre-exports the above, addsmock_components/mock_components_fromhelpers, a module doctest, and the M0 acceptance and mock unit tests.src/supervisor.rsdeletes the test-onlyDefaultSupervisor::empty_for_testconstructor and corrects the one doc line that named it.src/supervisor/tests.rsmoves both formerempty_for_testcall sites onto a zero-moduleSupervisor<MockTypes>booted through the realSupervisor::bootpath via a newboot_mock_supervisorhelper;empty_supervisor_returns_no_subscriptionsbecomes#[tokio::test].Cargo.lockgains the one line for the self-dep edge, required for CI--locked.Test plan
cargo fmt --all --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace --all-features --no-fail-fast(0 failed; newtest_utilsand rewrittensupervisor::testscases ran and passed, not skipped)cargo test -p nexum-runtime --locked(no--all-features, confirms the self dev-dependency turns the feature on forjust test)cargo doc --workspace --no-deps --all-featureswithRUSTDOCFLAGS=-D warningsAll runs were under
nix developwith an isolatedCARGO_TARGET_DIR. Module wasms (example, M2/M3, fixture bombs) were built in-tree before the workspace test run.Notes for reviewer
empty_for_testwas deleted outright rather than replaced by a new bespoke test constructor. The two supervisor tests now boot through the real, publicSupervisor::bootpath withmock_components()and a default module-less config, which exercises real assembly instead of a synthetic shortcut and better matches the epic's "launched entirely through the public builder" intent.The M0 acceptance test drives the full
RuntimeBuilder::new(cfg).with_types::<MockTypes>().with_components(...).with_add_ons(&[]).launch()chain, asserts it reaches supervisor boot and bails cleanly on no modules, then does a directrequestround-trip against the mock chain to prove it serves and records. A full fake-driven block-dispatch end-to-end test was deliberately left out of this hermetic acceptance test; it needs a wasm guest and a written manifest (disk), and the channel plumbing it would exercise is already covered bysubscribe_blocks_yields_pushed_headers.futures::channel::mpscwas chosen overtokiofor the mock streams: it is already a dependency, avoids an unused-crate-dep risk, and keeps the wasm cone clean.Response keying uses
(&'static str method name, params)rather than addingHashto the public wire-surfaceChainMethodenum, to keep that closed enum's derive set untouched.Follow-ups intentionally left out of this PR: scriptable error and stream-end injection on the mock chain (so reconnect and backoff can be unit-tested on fakes); a full fake-driven block-dispatch end-to-end test gated on the wasm fixture; promoting a
MockRuntimepreset once presets can accept pre-built instances rather than only building from config; a docs page for the test-utils surface (the module doctest carries the minimal example for now).AI Assistance: Claude Code (Opus 4.8 implementation and adversarial review, Sonnet 5 PR authoring) used for the full change.