Hey all, in adding tests to my bit of the P3 work, it would be nice to have some sort of test-time introspection available for the runtime -- in particular I'd like to validate things like component instance state stored in the runtime.
There is some debug machinery that's feature flagged in (and accessible via FFI), but what I'm envisioning is used from Rust land (and I'm guessing has to be snaked up through Engine
somewhere), and only for tests -- being able to validate internal runtime state after doing something very specific with loaded components, etc.
Are there any objections to adding code like this? I can't seem to find something like this that's been done in the past -- and I'm not sure there's a reasonable way to view the results from the "outside" for all cases I'd like to test. I can imagine doing something like calling error-context.debug-message
and expecting a trap, but given that the host-side constructs can hold error context references I don't think that works for testing everything.
In the context of what you're working on, we could perhaps add a #[cfg(feature = "component-model-async-debug")] pub fn sanity_check(store: impl AsContextMut, ...) { ... }
function to futures_and_streams.rs
. Not sure if there's any precedent for something like that, though.
At first I was thinking of adding some if cfg!(debug_assertions) { ... }
code to impl<T> Drop for Store<T>
, but the assertions we'd add there (e.g. that all error-context
tables were empty) wouldn't hold in all cases; there's no rule that says component instances must drop all their handles before being "uninstantiated" (and that wouldn't make sense anyway, since the host decides when to dispose of an instance, and there's no concept in Wasm of uninstantiation AFAIK).
Yeah that makes sense -- I wanted access to one or moreComponentInstance
s so I could check that state, but adding the functionality to futures_and_streams.rs
is probably a good idea.
Still figuring out how to wire it through -- likely the Store
makes more sense than the Engine
possibly.
Last updated: Feb 27 2025 at 23:03 UTC