Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Pass plugin manifests to self-contained wasm modules (#5079)

Gabe Kangas0ebc4fe7de2a
diff --git a/Earthfile b/Earthfile
index f20eb804c7..2121636192 100644
--- a/Earthfile
+++ b/Earthfile
@@ -226,13 +226,21 @@ hls-tests:
RUN npm install
RUN ./run.sh
+native-wasm-test-plugin:
+ FROM --platform=linux/amd64 rust:1.97.1-alpine
+ RUN rustup target add wasm32-unknown-unknown
+ COPY test/automated/plugins/native-wasm-plugin /plugin
+ WORKDIR /plugin
+ RUN cargo build --locked --release --target wasm32-unknown-unknown
+ SAVE ARTIFACT /plugin/target/wasm32-unknown-unknown/release/native_wasm_test.wasm
+
plugin-tests:
FROM --platform=linux/amd64 ghcr.io/gabek/go-crosscompile:latest
ENV GOTOOLCHAIN=auto
- # git clones the plugin SDK; npm builds both the SDK-compiled plugin and
- # this test suite; gcompat lets the SDK's prebuilt extism-js (glibc) run on
- # this musl/alpine image.
+ # git clones the plugin SDK. npm builds the SDK examples and this test suite.
+ # gcompat lets the SDK's prebuilt extism-js (glibc) run on this musl/alpine image.
RUN apk add npm git gcompat font-noto && fc-cache -f
COPY . /build
+ COPY +native-wasm-test-plugin/native_wasm_test.wasm /build/test/automated/plugins/native-wasm-plugin/native_wasm_test.wasm
WORKDIR /build/test/automated/plugins
RUN ./run.sh
diff --git a/services/plugins/manager.go b/services/plugins/manager.go
index 169e68099c..712c4243d9 100644
--- a/services/plugins/manager.go
+++ b/services/plugins/manager.go
@@ -56,8 +56,8 @@ type Loaded struct {
adminPaths []string // original path strings, used for "page gates descendants" prefix-matching
plugin *extism.Plugin
// releaseEngine drops this instance's reference on its shared compiled
- // engine (nil for legacy self-contained wasm). Called exactly once by
- // Close, after the instance itself is closed.
+ // engine (nil for self-contained wasm). Called exactly once by Close,
+ // after the instance itself is closed.
releaseEngine func()
mu sync.Mutex
failureMu sync.Mutex
@@ -282,8 +282,8 @@ func (l *Loaded) Close(ctx context.Context) {
if pl != nil {
// Closes this instance only; the shared compiled engine is
// reference-counted and torn down by releaseEngine below when this
- // was the last plugin of its language. Legacy wasm plugins close
- // their own runtime here.
+ // was the last plugin of its language. A self-contained wasm plugin
+ // closes its own runtime here.
_ = pl.Close(ctx)
}
if release != nil {
@@ -1479,7 +1479,7 @@ func runtimeForExt(path string) string {
}
// loadFromBytes is the shared core of LoadPlugin and LoadPackage. artifactBytes
-// is the plugin's wasm (for "wasm"/legacy) or its source (for the shared-engine
+// is the plugin's wasm (for "wasm") or its source (for the shared-engine
// runtimes "javascript"/"python"); runtime — inferred by the caller from the
// code artifact (its filename/extension), not authored in the manifest —
// selects which. It is authoritative over any manifest-declared type.
@@ -1567,15 +1567,16 @@ func loadFromBytes(ctx context.Context, env *HostEnv, manifestBytes, artifactByt
}
// instantiate creates the extism plugin instance for a manifest: a per-plugin
-// instance of the shared engine for "js"/"python", or a self-contained module
-// for "wasm"/legacy. Either way the result is a *extism.Plugin with its
-// identity slug stashed in Config so shared host functions can resolve the
-// caller, and its per-plugin network scope applied.
+// instance of the shared engine for "javascript"/"python", or a self-contained
+// module for "wasm". Either way the result is a *extism.Plugin carrying the
+// reserved Extism config keys (see registry.go), including the identity slug
+// that shared host functions use to resolve the caller and the sidecar manifest
+// that the guest reads back. It also applies the per-plugin network scope.
//
// For shared-engine plugins the returned release func drops the instance's
-// reference on the compiled engine; the caller must invoke it exactly once
-// after closing the instance. nil for legacy self-contained wasm, whose
-// instance close tears down its whole runtime.
+// reference on the compiled engine. The caller must invoke it exactly once
+// after closing the instance. It is nil for self-contained wasm, whose instance
+// close tears down its whole runtime.
func instantiate(ctx context.Context, env *HostEnv, manifest *Manifest, manifestBytes, artifactBytes []byte, displayName string) (*extism.Plugin, func(), error) {
// Give the guest the real host wall and monotonic clocks (wazero's default
// is a frozen 2022 clock). Nanosleep is deliberately NOT wired so a plugin
@@ -1592,8 +1593,8 @@ func instantiate(ctx context.Context, env *HostEnv, manifest *Manifest, manifest
release()
return nil, nil, fmt.Errorf("instantiate %s engine: %w", manifest.Type, err)
}
- // Inject the per-plugin script + manifest the engine bootstrap reads at
- // runtime, plus the slug shared host functions resolve identity by.
+ // The engine bootstrap reads the script and manifest at runtime. The
+ // slug is what shared host functions resolve identity by.
inst.Config = map[string]string{
configKeySlug: manifest.Slug,
configKeyScript: string(artifactBytes),
@@ -1603,11 +1604,11 @@ func instantiate(ctx context.Context, env *HostEnv, manifest *Manifest, manifest
return inst, release, nil
}
- // Legacy self-contained wasm: each plugin compiles into its own runtime,
- // deliberately without a shared compilation cache — a cache entry would
- // pin the compiled native code for the life of the process, so disabling
- // the plugin would never return its memory. Reloads recompile (fast
- // relative to an explicit admin action).
+ // Self-contained wasm (Rust, Go, Zig, and others) compiles into its own
+ // runtime. It deliberately has no shared compilation cache because a cache
+ // entry would pin the compiled native code for the life of the process, so
+ // disabling the plugin would never return its memory. Reloads recompile,
+ // which is fast relative to an explicit admin action.
extismManifest := extism.Manifest{
Wasm: []extism.Wasm{extism.WasmData{Data: artifactBytes, Name: displayName}},
Timeout: 10_000, // milliseconds; enables Wazero's WithCloseOnContextDone
@@ -1632,9 +1633,16 @@ func instantiate(ctx context.Context, env *HostEnv, manifest *Manifest, manifest
if err != nil {
return nil, nil, fmt.Errorf("instantiate wasm: %w", err)
}
- // Even self-contained plugins now use the shared, identity-resolving host
- // functions, so stash the slug for the registry lookup.
- p.Config = map[string]string{configKeySlug: manifest.Slug}
+ // Self-contained plugins use the same identity-resolving host functions, so
+ // stash the slug for the registry lookup. The manifest rides along too: no
+ // SDK bakes it into a hand-authored module, so this is the only way such a
+ // guest can echo it back from register() (and read its own metadata)
+ // without compiling in a second copy that drifts from the packaged
+ // sidecar. There is no "script" key because the module is the code.
+ p.Config = map[string]string{
+ configKeySlug: manifest.Slug,
+ configKeyManifest: string(manifestBytes),
+ }
// Return the compiler's transient scratch space now rather than letting
// the Go runtime sit on it (same reasoning as compileEngine).
debug.FreeOSMemory()
diff --git a/services/plugins/manager_test.go b/services/plugins/manager_test.go
index 9ebe530ce4..64020a59eb 100644
--- a/services/plugins/manager_test.go
+++ b/services/plugins/manager_test.go
@@ -838,3 +838,46 @@ func TestManager_Uninstall_RemovesRegistrySidecar(t *testing.T) {
t.Errorf("uninstall should remove the registry sidecar, stat err = %v", err)
}
}
+
+// TestSelfContainedWasmInstanceConfig pins the reserved Extism config keys a
+// hand-authored wasm module reads at runtime. "__slug" is what shared host
+// functions resolve identity by. The packaged manifest is what such a plugin
+// echoes back from register() because there is no SDK to bake a copy into the
+// module. "script" is shared-engine only. The artifact already is the code for
+// a self-contained module.
+func TestSelfContainedWasmInstanceConfig(t *testing.T) {
+ manifestBytes := validManifestBytes()
+ manifest, err := ParseManifest(manifestBytes)
+ if err != nil {
+ t.Fatalf("parse manifest: %v", err)
+ }
+ manifest.Type = RuntimeWasm
+
+ ctx := context.Background()
+ // An exportless module is enough: instantiate only wires config, memory
+ // limits, and host functions. It never calls into the guest.
+ p, release, err := instantiate(ctx, &HostEnv{}, manifest, manifestBytes, emptyWasmModule(), "hello-world")
+ if err != nil {
+ t.Fatalf("instantiate: %v", err)
+ }
+ defer func() { _ = p.Close(ctx) }()
+
+ if release != nil {
+ t.Error("self-contained wasm holds no shared-engine reference, so its release func must be nil")
+ }
+ if got := p.Config[configKeySlug]; got != manifest.Slug {
+ t.Errorf("config[%q] = %q, want %q", configKeySlug, got, manifest.Slug)
+ }
+ if got := p.Config[configKeyManifest]; got != string(manifestBytes) {
+ t.Errorf("config[%q] = %q, want the packaged sidecar bytes %q", configKeyManifest, got, string(manifestBytes))
+ }
+ if got, ok := p.Config[configKeyScript]; ok {
+ t.Errorf("config[%q] must not be set for self-contained wasm; got %q", configKeyScript, got)
+ }
+}
+
+// emptyWasmModule is a valid module with no imports, exports, or memory: the
+// 8-byte header (magic + version) and nothing else.
+func emptyWasmModule() []byte {
+ return []byte{0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00}
+}
diff --git a/services/plugins/manifest.go b/services/plugins/manifest.go
index 1484f8fa12..d21f7b0336 100644
--- a/services/plugins/manifest.go
+++ b/services/plugins/manifest.go
@@ -298,9 +298,8 @@ func (m *Manifest) usesSharedEngine() bool {
}
// validateConfigKeys rejects author config keys reserved by the host. Keys
-// starting with "__" are used to inject per-instance state (e.g. "__slug") into
-// shared-engine plugins via Extism config, and must not collide with declared
-// plugin config.
+// starting with "__" are used to inject per-instance state (e.g. "__slug") via
+// Extism config, and must not collide with declared plugin config.
func (m *Manifest) validateConfigKeys() error {
for key := range m.Config {
if strings.HasPrefix(key, "__") {
diff --git a/services/plugins/registry.go b/services/plugins/registry.go
index 87312ee24f..da9b00844d 100644
--- a/services/plugins/registry.go
+++ b/services/plugins/registry.go
@@ -12,12 +12,10 @@ import (
)
// pluginIdentity is everything a host function needs to serve a call on behalf
-// of a specific plugin. In the legacy self-contained-wasm model these values
-// were captured in each host function's closure at BuildHostFunctions time. In
-// the shared-engine model host functions are built once and shared across all
-// plugins, so the calling plugin's identity is resolved at call time from this
-// registry instead (keyed by the slug the host stashed in the instance's
-// Extism config under "__slug").
+// of a specific plugin. Host functions are built once and shared across all
+// plugins (of every runtime), so the calling plugin's identity is resolved at
+// call time from this registry, keyed by the slug the host stashed in the
+// instance's Extism config under "__slug".
type pluginIdentity struct {
slug string
granted map[string]bool // permission set, gated at call time
@@ -43,11 +41,13 @@ type pluginRegistry struct {
byslug map[string]*pluginIdentity
}
-// Reserved Extism config keys the host sets per shared-engine instance. They
-// are prefixed with "__" so they can't collide with author-declared config
-// (manifest validation rejects author keys starting with "__"). The guest
-// engine reads "script"/"manifest"; the host reads "__slug" back to resolve
-// identity inside shared host functions.
+// Reserved Extism config keys the host sets on a plugin instance at load. The
+// host reads "__slug" back to resolve identity inside shared host functions.
+// The guest reads "manifest" for every runtime and "script" for shared engines
+// only, since a self-contained module already is its code. These live in
+// Extism's config namespace, which is separate from the author's declared
+// manifest.config that owncast_config_get serves. Manifest validation also
+// rejects declared keys starting with "__".
const (
configKeySlug = "__slug"
configKeyScript = "script"
@@ -76,12 +76,13 @@ func (r *pluginRegistry) remove(slug string) {
}
// resolveCaller resolves the calling plugin's identity and enforces its
-// permission grant. It is the single permission-gating boundary for shared host
-// functions (in the legacy per-plugin model, an ungranted capability simply
-// wasn't linked; now every plugin links every host import, so the gate must
-// live here). Pass perm == "" for ambient capabilities (timer, config, asset
-// read) that need no grant. On a false return the host function must abort
-// (returning zero/empty to the guest); permission denials are logged.
+// permission grant. It is the single permission-gating boundary for host
+// functions. Every plugin links every host import, so an ungranted capability
+// can only be refused here. It used to simply not be linked when host functions
+// were built per plugin. Pass perm == "" for ambient capabilities (timer,
+// config, asset read) that need no grant. On a false return the host function
+// must abort by returning zero or empty to the guest. Permission denials are
+// logged.
func resolveCaller(ctx context.Context, fnName, perm string) (*pluginIdentity, bool) {
id, ok := callerIdentity(ctx)
if !ok {
diff --git a/test/automated/plugins/.gitignore b/test/automated/plugins/.gitignore
index f3b576f013..4f64dfd5f6 100644
--- a/test/automated/plugins/.gitignore
+++ b/test/automated/plugins/.gitignore
@@ -1,3 +1,5 @@
node_modules/
package-lock.json
ffmpeg
+native-wasm-plugin/target/
+native-wasm-plugin/native_wasm_test.wasm
diff --git a/test/automated/plugins/lib/plugins.js b/test/automated/plugins/lib/plugins.js
index 7347ba4d31..85a1285e34 100644
--- a/test/automated/plugins/lib/plugins.js
+++ b/test/automated/plugins/lib/plugins.js
@@ -15,6 +15,7 @@ const ALL = [
'viewer-gate',
'page-content-demo',
'tabs-demo',
+ 'native-wasm-test',
];
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
diff --git a/test/automated/plugins/native-wasm-plugin/Cargo.lock b/test/automated/plugins/native-wasm-plugin/Cargo.lock
new file mode 100644
index 0000000000..1ad4e30fd0
--- /dev/null
+++ b/test/automated/plugins/native-wasm-plugin/Cargo.lock
@@ -0,0 +1,391 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "anyhow"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
+
+[[package]]
+name = "autocfg"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
+
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
+[[package]]
+name = "bytemuck"
+version = "1.25.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797"
+
+[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
+
+[[package]]
+name = "bytes"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
+
+[[package]]
+name = "either"
+version = "1.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e5e8f6c15a24b9a3ee5efec809ccd006d3b30e8b3bb63c39af737c7f87daa1d"
+
+[[package]]
+name = "equivalent"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
+
+[[package]]
+name = "extism-convert"
+version = "1.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad19858c4c462309a8f3a20abec53e8603bda1eefda26c8bfab51d5516b40cbb"
+dependencies = [
+ "anyhow",
+ "base64",
+ "bytemuck",
+ "extism-convert-macros",
+ "prost",
+ "rmp-serde",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "extism-convert-macros"
+version = "1.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f2932799f6d9f9646f97b65287f6bb2addc75a0ee61e40fb24559a7540dd928"
+dependencies = [
+ "manyhow",
+ "proc-macro-crate",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "extism-manifest"
+version = "1.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2f59c8dadb5e0bde9a48c6ed45312e6ef625cbcd5f67c28459dbc8fe8bc0383"
+dependencies = [
+ "base64",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "extism-pdk"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "352fcb5a66eb74145a1c4a01f2bd15d59c62c85be73aac8471880c65b26b798f"
+dependencies = [
+ "anyhow",
+ "base64",
+ "extism-convert",
+ "extism-manifest",
+ "extism-pdk-derive",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "extism-pdk-derive"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d086daea5fd844e3c5ac69ddfe36df4a9a43e7218cf7d1f888182b089b09806c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.17.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
+
+[[package]]
+name = "indexmap"
+version = "2.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
+name = "itertools"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
+dependencies = [
+ "either",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
+name = "manyhow"
+version = "0.11.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b33efb3ca6d3b07393750d4030418d594ab1139cee518f0dc88db70fec873587"
+dependencies = [
+ "manyhow-macros",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "manyhow-macros"
+version = "0.11.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "46fce34d199b78b6e6073abf984c9cf5fd3e9330145a93ee0738a7443e371495"
+dependencies = [
+ "proc-macro-utils",
+ "proc-macro2",
+ "quote",
+]
+
+[[package]]
+name = "memchr"
+version = "2.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
+
+[[package]]
+name = "native-wasm-test"
+version = "0.1.0"
+dependencies = [
+ "extism-pdk",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "paste"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
+
+[[package]]
+name = "proc-macro-crate"
+version = "3.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
+dependencies = [
+ "toml_edit",
+]
+
+[[package]]
+name = "proc-macro-utils"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eeaf08a13de400bc215877b5bdc088f241b12eb42f0a548d3390dc1c56bb7071"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "smallvec",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.107"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "prost"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1"
+dependencies = [
+ "bytes",
+ "prost-derive",
+]
+
+[[package]]
+name = "prost-derive"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf"
+dependencies = [
+ "anyhow",
+ "itertools",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rmp"
+version = "0.8.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4"
+dependencies = [
+ "byteorder",
+ "num-traits",
+ "paste",
+]
+
+[[package]]
+name = "rmp-serde"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db"
+dependencies = [
+ "byteorder",
+ "rmp",
+ "serde",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.3",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.151"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
+dependencies = [
+ "itoa",
+ "memchr",
+ "serde",
+ "serde_core",
+ "zmij",
+]
+
+[[package]]
+name = "smallvec"
+version = "1.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
+
+[[package]]
+name = "syn"
+version = "2.0.119"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "3.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
+
+[[package]]
+name = "toml_edit"
+version = "0.22.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
+dependencies = [
+ "indexmap",
+ "toml_datetime",
+ "winnow",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+
+[[package]]
+name = "winnow"
+version = "0.7.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "zmij"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
diff --git a/test/automated/plugins/native-wasm-plugin/Cargo.toml b/test/automated/plugins/native-wasm-plugin/Cargo.toml
new file mode 100644
index 0000000000..ed50cdb408
--- /dev/null
+++ b/test/automated/plugins/native-wasm-plugin/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+name = "native-wasm-test"
+version = "0.1.0"
+edition = "2021"
+publish = false
+
+[lib]
+crate-type = ["cdylib"]
+
+[dependencies]
+extism-pdk = "1.4.1"
+
+[profile.release]
+opt-level = "z"
+lto = true
+strip = true
+panic = "abort"
+codegen-units = 1
diff --git a/test/automated/plugins/native-wasm-plugin/plugin.manifest.json b/test/automated/plugins/native-wasm-plugin/plugin.manifest.json
new file mode 100644
index 0000000000..9c1fcf9f94
--- /dev/null
+++ b/test/automated/plugins/native-wasm-plugin/plugin.manifest.json
@@ -0,0 +1,16 @@
+{
+ "api": "1",
+ "name": "Native Wasm Test",
+ "slug": "native-wasm-test",
+ "version": "0.1.0",
+ "description": "Core integration fixture compiled directly to wasm with no runtime script.",
+ "permissions": ["chat.send"],
+ "subscriptions": {
+ "notify": [
+ { "event": "chat.message.received" }
+ ]
+ },
+ "bot": {
+ "displayName": "Native Wasm Test"
+ }
+}
diff --git a/test/automated/plugins/native-wasm-plugin/src/lib.rs b/test/automated/plugins/native-wasm-plugin/src/lib.rs
new file mode 100644
index 0000000000..edd629aa8f
--- /dev/null
+++ b/test/automated/plugins/native-wasm-plugin/src/lib.rs
@@ -0,0 +1,24 @@
+use extism_pdk::*;
+
+#[host_fn]
+extern "ExtismHost" {
+ fn owncast_send_chat(text: String);
+}
+
+// A self-contained module has no SDK to bake the sidecar into register(). It
+// must read the exact manifest Owncast loaded from the reserved Extism config.
+#[plugin_fn]
+pub fn register() -> FnResult<String> {
+ Ok(config::get("manifest")?
+ .ok_or_else(|| Error::msg("Owncast did not inject the plugin manifest"))?)
+}
+
+// Echo the raw event envelope. The integration test looks for its unique chat
+// probe in the bot response, proving Owncast loaded the native module, installed
+// the subscription returned by register(), dispatched the event, and allowed
+// the module to call an Owncast host function.
+#[plugin_fn]
+pub fn on_event(envelope: String) -> FnResult<()> {
+ unsafe { owncast_send_chat(envelope)? };
+ Ok(())
+}
diff --git a/test/automated/plugins/native-wasm.test.js b/test/automated/plugins/native-wasm.test.js
new file mode 100644
index 0000000000..c6bab284ab
--- /dev/null
+++ b/test/automated/plugins/native-wasm.test.js
@@ -0,0 +1,41 @@
+// End-to-end: a Rust module compiled directly to wasm reads its packaged
+// manifest from Extism config during register(), receives a real Owncast chat
+// event, and calls the owncast_send_chat host function. No language SDK or
+// runtime script is involved.
+const { test, expect, beforeAll } = require('@jest/globals');
+var request = require('supertest');
+request = request('http://127.0.0.1:8080');
+
+const { registerChat, sendChatMessage } = require('./lib/chat');
+const { enableOnly, sleep, ADMIN } = require('./lib/plugins');
+
+const PLUGIN = 'native-wasm-test';
+const BOT_DISPLAY_NAME = 'Native Wasm Test';
+
+beforeAll(async () => {
+ await enableOnly(PLUGIN);
+});
+
+test('loads and handles chat as a self-contained wasm module', async () => {
+ const { accessToken } = await registerChat();
+ const probe = 'native-wasm-probe-' + Date.now();
+ sendChatMessage({ body: probe, type: 'CHAT' }, accessToken);
+
+ await sleep(3000);
+
+ const messages = (
+ await request
+ .get('/api/admin/chat/messages')
+ .auth(...ADMIN)
+ .expect(200)
+ ).body;
+ const replies = messages.filter(
+ (m) =>
+ m.user &&
+ m.user.displayName === BOT_DISPLAY_NAME &&
+ typeof m.body === 'string' &&
+ m.body.includes(probe),
+ );
+
+ expect(replies.length).toBe(1);
+});
diff --git a/test/automated/plugins/run.sh b/test/automated/plugins/run.sh
index 3f9fa62180..15f90c71a6 100755
--- a/test/automated/plugins/run.sh
+++ b/test/automated/plugins/run.sh
@@ -2,13 +2,14 @@
# Standalone end-to-end plugin integration test.
#
-# Unlike the Go unit tests, this builds plugins from source using the Owncast
-# plugin SDK (so no WASM is bundled in this repo), installs them into a real
-# Owncast instance, and verifies they actually run by exercising chat and HTTP
-# through them. Run by CI via the Earthly `+plugin-tests` target.
+# This builds JavaScript examples from the Owncast plugin SDK and a small Rust
+# fixture directly to wasm. It installs all of them into a real Owncast
+# instance, then exercises chat and HTTP through them. Run by CI via the
+# Earthly `+plugin-tests` target.
#
-# The plugins built here are the SDK's own examples — the suite tracks them
-# rather than maintaining plugin source in this repo.
+# The feature examples come from the SDK so this suite does not duplicate their
+# source. The native-wasm fixture lives here because it tests the core loader
+# without a language SDK or runtime script.
#
# Env overrides:
# PLUGIN_SDK_DIR path to an existing SDK checkout; if set, no clone happens
@@ -42,6 +43,7 @@ PLUGIN_SDK_REF="${PLUGIN_SDK_REF:-main}"
# SDK example plugins exercised by the tests in this directory.
PLUGIN_NAMES=(profanity-filter echo-bot overlay styles-demo scripts-demo viewer-gate page-content-demo tabs-demo)
+NATIVE_WASM_PROJECT="${REPO_ROOT}/test/automated/plugins/native-wasm-plugin"
PLUGIN_DIR="${REPO_ROOT}/data/plugins"
@@ -94,6 +96,19 @@ for name in "${PLUGIN_NAMES[@]}"; do
cp "${SDK_DIR}/plugins/${name}.ocpkg" "${PLUGIN_DIR}/"
done
+NATIVE_WASM_ARTIFACT="${NATIVE_WASM_PROJECT}/native_wasm_test.wasm"
+if [[ ! -f "$NATIVE_WASM_ARTIFACT" ]]; then
+ echo "Building native wasm fixture..."
+ (
+ cd "$NATIVE_WASM_PROJECT"
+ cargo build --locked --release --target wasm32-unknown-unknown
+ )
+ NATIVE_WASM_ARTIFACT="${NATIVE_WASM_PROJECT}/target/wasm32-unknown-unknown/release/native_wasm_test.wasm"
+fi
+cp "$NATIVE_WASM_ARTIFACT" "${PLUGIN_DIR}/native-wasm-test.wasm"
+cp "${NATIVE_WASM_PROJECT}/plugin.manifest.json" \
+ "${PLUGIN_DIR}/native-wasm-test.manifest.json"
+
# Install the JS test framework for this suite.
npm install --quiet --no-progress