Skip to content

Add store support for Spin adapter (KV, config, secret)#253

Open
prk-Jr wants to merge 19 commits intomainfrom
feat/spin-store-support
Open

Add store support for Spin adapter (KV, config, secret)#253
prk-Jr wants to merge 19 commits intomainfrom
feat/spin-store-support

Conversation

@prk-Jr
Copy link
Copy Markdown
Contributor

@prk-Jr prk-Jr commented Apr 24, 2026

Summary

  • Implements SpinKvStore, SpinConfigStore, and SpinSecretStore so Spin handlers can access key-value, configuration, and secret data through the same ctx.kv_handle(), ctx.config_store(), and ctx.secret_handle() API as every other adapter.
  • Wires all three store handles into the Spin request dispatch pipeline so they are available on every request without any extra setup in user code.
  • Adds a spin-adapter-tests CI job, store injection contract tests, and Spin support to all three smoke test scripts.

Changes

Crate / File Change
crates/edgezero-adapter-spin/src/config_store.rs New — SpinConfigStore backed by spin_sdk::variables; dual-backend (Spin / in-memory for tests); contract tests via macro
crates/edgezero-adapter-spin/src/key_value_store.rs New — SpinKvStore backed by spin_sdk::key_value; in-process prefix filter + pagination; configurable max_list_keys cap (warn + truncate); TTL silently ignored
crates/edgezero-adapter-spin/src/secret_store.rs New — SpinSecretStore backed by spin_sdk::variables; key normalised to lowercase to match Spin variable naming rules
crates/edgezero-adapter-spin/src/request.rs dispatch() now injects ConfigStoreHandle, KvHandle, and SecretHandle into every request's extensions
crates/edgezero-adapter-spin/src/lib.rs Re-exports new store types
crates/edgezero-adapter-spin/tests/contract.rs Store injection smoke tests + wasm32 compile-time trait checks for SpinKvStore and SpinSecretStore
crates/edgezero-core/src/manifest.rs Added "spin" to SUPPORTED_CONFIG_STORE_ADAPTERS
crates/edgezero-core/src/config_store.rs Updated ConfigStore trait doc to list SpinConfigStore
.github/workflows/test.yml New spin-adapter-tests job: native tests + wasm32-wasip1 compilation check
examples/app-demo/crates/app-demo-adapter-spin/spin.toml Added key_value_stores = ["default"] binding and variable declarations for greeting and smoke_secret
examples/app-demo/edgezero.toml Added "spin" to adapters for config, KV, and secrets routes
scripts/smoke_test_kv.sh Added spin case
scripts/smoke_test_config.sh Added spin case; skips dotted-key checks (Spin variable names cannot contain dots)
scripts/smoke_test_secrets.sh Added spin case; passes secret value via SPIN_VARIABLE_SMOKE_SECRET at startup
.gitignore Added .spin/ (runtime SQLite KV database and component logs)

Closes

Closes #73
Closes #74

Test plan

  • cargo test --workspace --all-targets
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM builds: cargo check -p edgezero-adapter-spin --target wasm32-wasip1 --features spin
  • ./scripts/smoke_test_kv.sh spin
  • ./scripts/smoke_test_config.sh spin
  • ./scripts/smoke_test_secrets.sh spin

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • Route params use {id} syntax (not :id)
  • Types imported from edgezero_core (not http crate)
  • New code has tests
  • No secrets or credentials committed

prk-Jr added 14 commits April 24, 2026 20:05
- dispatch() in request.rs now injects ConfigStoreHandle, KvHandle, and
  SecretHandle into request extensions on every request
- SpinSecretStore normalises the lookup key to lowercase so conventional
  uppercase names (e.g. SMOKE_SECRET) resolve to the correct Spin variable
- contract.rs gains store injection smoke tests (config, kv, secret) and
  wasm32 compile-time trait checks for SpinKvStore and SpinSecretStore
- spin.toml gains key_value_stores = ["default"] binding and variables
  declarations for greeting and smoke_secret
- edgezero.toml adds "spin" to adapters for config, kv, and secrets routes
- smoke_test_kv/config/secrets.sh each gain a spin case that builds the
  WASM binary and starts spin up --listen 127.0.0.1:3000; the config
  script skips dotted-key checks (Spin variable names cannot contain dots);
  the secrets script passes SPIN_VARIABLE_SMOKE_SECRET at startup
spin up creates .spin/ (SQLite KV database and component logs) in the
adapter directory during local development, mirroring .wrangler/ for CF.
@prk-Jr prk-Jr self-assigned this Apr 24, 2026
prk-Jr added 2 commits April 25, 2026 18:12
  instead of silently truncating; callers now get an explicit signal
  rather than incomplete pagination results
- Correct DEFAULT_MAX_LIST_KEYS, with_max_list_keys, and module-level
  docs to accurately describe error-return behaviour (not truncation,
  not "unbounded allocation" guarding)
- Add log::debug in SpinSecretStore::get_bytes when store_name is
  non-empty so callers learn the flat-namespace constraint at runtime
- Add comment in config_store contract tests explaining the InMemory
  backend accepts dotted/uppercase keys that the real Spin backend
  would reject via InvalidName
- Add comment in lib.rs explaining why SpinConfigStore has different
  feature gating than SpinKvStore and SpinSecretStore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spin config/secret store implementation Spin KV store implementation

1 participant