Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
32998df
feat: allow spin as a supported config store adapter
Apr 24, 2026
1022cd7
docs: update adapters field comment to include spin
Apr 24, 2026
5bb8051
feat: add SpinConfigStore backed by spin_sdk::variables
Apr 24, 2026
d64e95d
fix: rename SpinConfigBackend and remove feature gate on config_store…
Apr 24, 2026
53dfa1c
fix: fmt ordering in lib.rs and add SpinConfigStore to ConfigStore tr…
Apr 24, 2026
917ff57
feat: add SpinSecretStore backed by spin_sdk::variables
Apr 24, 2026
8a4e227
feat: add SpinKvStore backed by spin_sdk::key_value
Apr 24, 2026
ac8facb
chore: remove stale 'not yet implemented' note from run_app doc comment
Apr 24, 2026
a0ec8e6
ci: add spin-adapter-tests job
Apr 24, 2026
cf57f58
fix: handle InvalidName in SpinSecretStore and restore allow(unused_v…
Apr 24, 2026
ec7dc14
feat: add configurable max_list_keys cap to SpinKvStore
Apr 24, 2026
a905d5a
feat: wire store handles into Spin dispatch and add contract tests
Apr 24, 2026
11aa462
feat: add Spin adapter support to smoke test scripts
Apr 24, 2026
58c7b6e
chore: ignore .spin/ runtime directory
Apr 24, 2026
b5129da
- Return KvError::Validation when key count exceeds max_list_keys
prk-Jr Apr 25, 2026
c001103
fix CI cache conflict
prk-Jr Apr 25, 2026
3b995e5
Fix test.yml to use matrix run
prk-Jr Apr 29, 2026
4644225
Fix pin viceroy pin and wasmtime install flag
prk-Jr Apr 29, 2026
ff0633b
Fix type mismatch for wasm32-wasip1
prk-Jr Apr 29, 2026
c9d1e25
Address pr review findings
prk-Jr May 14, 2026
8956aba
chore: merge main into feat/spin-store-support
prk-Jr May 14, 2026
d0d6d60
fix: address spin store review feedback
prk-Jr May 20, 2026
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
119 changes: 57 additions & 62 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ jobs:
- name: Add wasm targets
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown

- name: Setup Viceroy
run: cargo install viceroy --locked --force

- name: Fetch dependencies (locked)
run: cargo fetch --locked

Expand All @@ -57,12 +54,25 @@ jobs:
- name: Check feature compilation
run: cargo check --workspace --all-targets --features "fastly cloudflare spin"

- name: Check Spin wasm32 compilation
run: cargo check -p edgezero-adapter-spin --target wasm32-wasip1 --features spin

cloudflare-wasm-tests:
name: cloudflare wasm tests
adapter-wasm-tests:
name: ${{ matrix.adapter }} wasm tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- adapter: cloudflare
target: wasm32-unknown-unknown
runner_env: CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER
runner_value: wasm-bindgen-test-runner
- adapter: fastly
target: wasm32-wasip1
runner_env: CARGO_TARGET_WASM32_WASIP1_RUNNER
runner_value: viceroy run
- adapter: spin
target: wasm32-wasip1
runner_env: CARGO_TARGET_WASM32_WASIP1_RUNNER
runner_value: wasmtime run
steps:
- uses: actions/checkout@v4

Expand All @@ -73,25 +83,27 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.wasmtime/bin/
target/
key: ${{ runner.os }}-cargo-cloudflare-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ matrix.adapter }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-cloudflare-
${{ runner.os }}-cargo-${{ matrix.adapter }}-

- name: Retrieve Rust version
id: rust-version-cloudflare
id: rust-version
run: echo "rust-version=$(grep '^rust ' .tool-versions | awk '{print $2}')" >> $GITHUB_OUTPUT
shell: bash

- name: Set up Rust tool chain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ steps.rust-version-cloudflare.outputs.rust-version }}
toolchain: ${{ steps.rust-version.outputs.rust-version }}

- name: Add wasm32 target
run: rustup target add wasm32-unknown-unknown
- name: Add wasm target
run: rustup target add ${{ matrix.target }}

- name: Resolve wasm-bindgen CLI version
if: matrix.adapter == 'cloudflare'
id: wasm-bindgen-version
shell: bash
run: |
Expand All @@ -109,60 +121,43 @@ jobs:
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Install wasm-bindgen test runner
run: cargo install wasm-bindgen-cli --version "${{ steps.wasm-bindgen-version.outputs.version }}" --locked --force

- name: Fetch dependencies (locked)
run: cargo fetch --locked
if: matrix.adapter == 'cloudflare'
run: |
required="${{ steps.wasm-bindgen-version.outputs.version }}"
if ! command -v wasm-bindgen-test-runner &>/dev/null \
|| ! wasm-bindgen --version 2>/dev/null | grep -q "$required"; then
cargo install wasm-bindgen-cli --version "$required" --locked --force
fi

- name: Run Cloudflare wasm tests
- name: Setup Viceroy
if: matrix.adapter == 'fastly'
env:
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
run: cargo test -p edgezero-adapter-cloudflare --features cloudflare --target wasm32-unknown-unknown --test contract

- name: Check Cloudflare wasm target
run: cargo check -p edgezero-adapter-cloudflare --features cloudflare --target wasm32-unknown-unknown

fastly-wasm-tests:
name: fastly wasm tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-fastly-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-fastly-

- name: Retrieve Rust version
id: rust-version-fastly
run: echo "rust-version=$(grep '^rust ' .tool-versions | awk '{print $2}')" >> $GITHUB_OUTPUT
shell: bash

- name: Set up Rust tool chain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ steps.rust-version-fastly.outputs.rust-version }}

- name: Add wasm targets
run: rustup target add wasm32-wasip1
VICEROY_VERSION: 0.16.5
run: |
if ! command -v viceroy &>/dev/null \
|| ! viceroy --version 2>/dev/null | grep -qF "$VICEROY_VERSION"; then
cargo install viceroy --version "$VICEROY_VERSION" --locked
fi

- name: Setup Viceroy
run: cargo install viceroy --locked --force
- name: Setup Wasmtime
Comment thread
prk-Jr marked this conversation as resolved.
if: matrix.adapter == 'spin'
env:
WASMTIME_VERSION: v44.0.0
run: |
export PATH="$HOME/.wasmtime/bin:$PATH"
echo "$HOME/.wasmtime/bin" >> "$GITHUB_PATH"
if ! command -v wasmtime &>/dev/null \
|| ! wasmtime --version 2>/dev/null | grep -qF "${WASMTIME_VERSION#v}"; then
curl https://wasmtime.dev/install.sh -sSf | bash -s -- --version "$WASMTIME_VERSION"
fi

- name: Fetch dependencies (locked)
run: cargo fetch --locked

- name: Run Fastly wasm tests
- name: Run ${{ matrix.adapter }} wasm tests
env:
CARGO_TARGET_WASM32_WASIP1_RUNNER: "viceroy run"
run: cargo test -p edgezero-adapter-fastly --features fastly --target wasm32-wasip1 --test contract
${{ matrix.runner_env }}: ${{ matrix.runner_value }}
run: cargo test -p edgezero-adapter-${{ matrix.adapter }} --features ${{ matrix.adapter }} --target ${{ matrix.target }} --test contract

- name: Check Fastly wasm target
run: cargo check -p edgezero-adapter-fastly --features fastly --target wasm32-wasip1
- name: Check ${{ matrix.adapter }} wasm target
run: cargo check -p edgezero-adapter-${{ matrix.adapter }} --features ${{ matrix.adapter }} --target ${{ matrix.target }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bin/
pkg/
target/
.wrangler/
.spin/
.edgezero/

# env
Expand Down
82 changes: 82 additions & 0 deletions crates/edgezero-adapter-spin/src/config_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//! Spin adapter config store: wraps `spin_sdk::variables`.

use edgezero_core::config_store::{ConfigStore, ConfigStoreError};

/// Config store backed by Spin component variables.
pub struct SpinConfigStore {
inner: SpinConfigBackend,
}

enum SpinConfigBackend {
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
Spin,
#[cfg(test)]
InMemory(std::collections::HashMap<String, String>),
/// Never constructed; keeps the enum inhabited outside production Spin and tests.
#[cfg(not(any(all(feature = "spin", target_arch = "wasm32"), test)))]
_Uninhabited(std::convert::Infallible),
}

impl SpinConfigStore {
/// Create a new `SpinConfigStore` using the Spin variables API.
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
pub fn new() -> Self {
Self {
inner: SpinConfigBackend::Spin,
}
}

#[cfg(test)]
fn from_entries(entries: impl IntoIterator<Item = (String, String)>) -> Self {
Self {
inner: SpinConfigBackend::InMemory(entries.into_iter().collect()),
}
}
}

#[cfg(all(feature = "spin", target_arch = "wasm32"))]
impl Default for SpinConfigStore {
fn default() -> Self {
Self::new()
}
}

impl ConfigStore for SpinConfigStore {
fn get(&self, _key: &str) -> Result<Option<String>, ConfigStoreError> {
match &self.inner {
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
SpinConfigBackend::Spin => {
use spin_sdk::variables;
Comment thread
prk-Jr marked this conversation as resolved.
match variables::get(_key) {
Ok(value) => Ok(Some(value)),
Err(variables::Error::Undefined(_)) => Ok(None),
Err(variables::Error::InvalidName(msg)) => {
Err(ConfigStoreError::invalid_key(msg))
}
Err(e) => Err(ConfigStoreError::unavailable(e.to_string())),
}
}
#[cfg(test)]
SpinConfigBackend::InMemory(data) => Ok(data.get(_key).cloned()),
#[cfg(not(any(all(feature = "spin", target_arch = "wasm32"), test)))]
SpinConfigBackend::_Uninhabited(never) => match *never {},
}
}
}

#[cfg(test)]
mod tests {
use super::*;

// These contract tests exercise the InMemory backend (not the real Spin
// variables API). Dotted keys such as "contract.key.a" are valid here but
// would trigger `InvalidName` on the real Spin backend, which requires
// lowercase variable names without dots. Real-backend behaviour is
// verified by the smoke tests in scripts/smoke_test_config.sh.
edgezero_core::config_store_contract_tests!(spin_config_store_contract, {
SpinConfigStore::from_entries([
("contract.key.a".to_string(), "value_a".to_string()),
("contract.key.b".to_string(), "value_b".to_string()),
])
});
}
107 changes: 107 additions & 0 deletions crates/edgezero-adapter-spin/src/key_value_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//! Spin KV store adapter.
//!
//! Wraps `spin_sdk::key_value::Store` to implement the
//! `edgezero_core::key_value_store::KvStore` trait.
//!
//! # Limitations
//!
//! - **TTL**: The Spin KV API has no TTL support. Calls to
//! `put_bytes_with_ttl` return `KvError::Validation` without writing.
//! - **Listing**: `spin_sdk::key_value::Store::get_keys()` returns all keys
//! with no prefix or cursor support. `list_keys_page` therefore returns
//! `KvError::Validation` instead of materializing the whole store.
//!
//! # Note
//!
//! This module is only compiled when the `spin` feature is enabled and the
//! target is `wasm32`.

#[cfg(all(feature = "spin", target_arch = "wasm32"))]
use async_trait::async_trait;
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
use bytes::Bytes;
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
use edgezero_core::key_value_store::{KvError, KvPage, KvStore};
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
use std::time::Duration;

/// KV store backed by the Spin KV API.
///
/// Wraps a `spin_sdk::key_value::Store` handle obtained via
/// `Store::open(label)`.
#[cfg(all(feature = "spin", target_arch = "wasm32"))]
pub struct SpinKvStore {
store: spin_sdk::key_value::Store,
}

#[cfg(all(feature = "spin", target_arch = "wasm32"))]
impl SpinKvStore {
/// Open a Spin KV store by label.
///
/// The `label` must match a `key_value_stores` entry in `spin.toml`.
/// Returns `KvError::Internal` if the store cannot be opened.
pub fn open(label: &str) -> Result<Self, KvError> {
let store = spin_sdk::key_value::Store::open(label)
.map_err(|e| KvError::Internal(anyhow::anyhow!("failed to open kv store: {e}")))?;
Ok(Self { store })
}

/// Open the default EdgeZero KV store label (`"EDGEZERO_KV"`).
pub fn open_default() -> Result<Self, KvError> {
Self::open(edgezero_core::manifest::DEFAULT_KV_STORE_NAME)
}
}

#[cfg(all(feature = "spin", target_arch = "wasm32"))]
#[async_trait(?Send)]
impl KvStore for SpinKvStore {
async fn get_bytes(&self, key: &str) -> Result<Option<Bytes>, KvError> {
self.store
.get(key)
.map(|opt| opt.map(Bytes::from))
.map_err(|e| KvError::Internal(anyhow::anyhow!("get failed: {e}")))
}

async fn put_bytes(&self, key: &str, value: Bytes) -> Result<(), KvError> {
self.store
.set(key, value.as_ref())
.map_err(|e| KvError::Internal(anyhow::anyhow!("set failed: {e}")))
}

async fn put_bytes_with_ttl(
Comment thread
prk-Jr marked this conversation as resolved.
&self,
_key: &str,
_value: Bytes,
_ttl: Duration,
) -> Result<(), KvError> {
Err(KvError::Validation(
"Spin KV does not support TTL; use put_bytes for non-expiring values".to_string(),
))
}

async fn delete(&self, key: &str) -> Result<(), KvError> {
self.store
.delete(key)
.map_err(|e| KvError::Internal(anyhow::anyhow!("delete failed: {e}")))
}

async fn exists(&self, key: &str) -> Result<bool, KvError> {
self.store
.exists(key)
.map_err(|e| KvError::Internal(anyhow::anyhow!("exists failed: {e}")))
}

async fn list_keys_page(
Comment thread
prk-Jr marked this conversation as resolved.
&self,
_prefix: &str,
_cursor: Option<&str>,
_limit: usize,
) -> Result<KvPage, KvError> {
Err(KvError::Validation(
"Spin KV key listing is unsupported because Store::get_keys() is unbounded".to_string(),
))
}
}

// TODO: integration tests require the Spin runtime.
// Test `SpinKvStore` as part of a Spin E2E test suite.
Loading
Loading