v0.3.1-pre.002

This commit is contained in:
2026-08-29 07:38:30 +02:00
parent 62ed72f2b5
commit 11e4cde77f
8 changed files with 297 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
# file: crates/ksp-store-api/Cargo.toml
# version: 1
[package]
name = "ksp-store-api"
version.workspace = true
edition.workspace = true
repository.workspace = true
[dependencies]
ksp-core-lib = { path = "../ksp-core-lib" }
[lints]
workspace = true

View File

@@ -0,0 +1,8 @@
// file: crates/ksp-store-api/src/capability.rs
// version: 1
//! Private home for backend-agnostic Store capability contracts.
//!
//! `0.3.1-pre.002` establishes the ownership boundary only. Concrete read and
//! write capabilities are introduced after the RAW models they operate on are
//! defined; no backend/runtime contract belongs here.

View File

@@ -0,0 +1,31 @@
// file: crates/ksp-store-api/src/lib.rs
// version: 1
#![warn(missing_docs)]
#![deny(unreachable_pub)]
#![forbid(unsafe_code)]
//! Backend-agnostic persistence contracts for KSP Store implementations.
//!
//! `ksp-store-api` owns persistent models plus the contracts that operate on
//! them. The `0.3.1` release is limited to N1 RAW/acquisition data. N2
//! STRUCTURAL is a later, distinct layer and no Program decode belongs to this
//! crate.
//!
//! Models and capabilities deliberately have separate private module homes.
//! Backend implementations, SQL, migrations, Config, Transport and runtime
//! dispatch remain outside this crate.
mod capability;
mod model;
/// Common KSP error type used by Store-facing contracts.
pub use ksp_core_lib::Error;
/// Stable structured code identifying a KSP error category and condition.
pub use ksp_core_lib::ErrorCode;
/// Structured contextual field attached to a KSP error.
pub use ksp_core_lib::ErrorContext;
/// Canonical Solana account address primitive shared by persistent models.
pub use ksp_core_lib::Pubkey;
/// Common KSP result alias using [`Error`].
pub use ksp_core_lib::Result;

View File

@@ -0,0 +1,9 @@
// file: crates/ksp-store-api/src/model.rs
// version: 1
//! Private home for persistent Store models.
//!
//! The current release is N1 RAW-only. Future N2 STRUCTURAL models are a
//! separate data layer and are not introduced by this scaffold. Persistent
//! models and backend capabilities remain separate even when one capability
//! operates on one or more models.

View File

@@ -0,0 +1,95 @@
// file: crates/ksp-store-api/tests/dependency_boundary.rs
// version: 1
//! Dependency canaries for the Store API scaffold.
#[test]
fn pre_002_manifest_has_exact_core_only_runtime_dependency() {
let manifest = include_str!("../Cargo.toml");
let dependencies_tail = manifest.split("[dependencies]").nth(1);
assert!(dependencies_tail.is_some(), "Store API dependencies section must exist");
let dependencies_tail = match dependencies_tail {
std::option::Option::Some(value) => value,
std::option::Option::None => return,
};
let dependencies = match dependencies_tail.split("[lints]").next() {
std::option::Option::Some(value) => value,
std::option::Option::None => return,
};
assert_eq!(manifest_dependency_names(dependencies), std::vec!["ksp-core-lib"]);
for forbidden in [
"ksp-config-lib",
"ksp-interface-lib",
"ksp-logging-lib",
"ksp-materializer-api",
"ksp-offchain-transport-lib",
"ksp-onchain-transport-lib",
"ksp-program-api",
"ksp-program-lib",
"ksp-store-lib",
"ksp-store-postgres-lib",
"ksp-wallet-lib",
"async-trait",
"bincode",
"chrono",
"postgres",
"serde",
"serde_json",
"sqlx",
"tauri",
"tokio",
"tokio-postgres",
"tonic",
"tracing",
"wincode",
] {
assert!(!dependencies.contains(forbidden), "forbidden Store API dependency detected: {forbidden}");
}
return;
}
#[test]
fn pre_002_source_boundary_separates_models_capabilities_and_backend_runtime() {
let crate_root = include_str!("../src/lib.rs");
assert!(crate_root.contains("mod capability;"));
assert!(crate_root.contains("mod model;"));
assert!(!crate_root.contains("pub mod "));
for forbidden in [
"ksp_store_lib",
"ksp_store_postgres_lib",
"ksp_onchain_transport_lib",
"ksp_program_api",
"serde::",
"sqlx::",
"tokio::",
"tokio_postgres::",
"std::env::",
"std::fs::",
"std::net::",
] {
assert!(!crate_root.contains(forbidden), "forbidden Store API crate-root dependency/surface detected: {forbidden}");
}
return;
}
fn manifest_dependency_names(section: &str) -> std::vec::Vec<&str> {
let mut names = std::vec::Vec::new();
for line in section.lines() {
let content = match line.split('#').next() {
std::option::Option::Some(value) => value.trim(),
std::option::Option::None => continue,
};
if content.is_empty() {
continue;
}
let name = match content.split('=').next() {
std::option::Option::Some(value) => value.trim().trim_end_matches(".workspace"),
std::option::Option::None => continue,
};
if !name.is_empty() {
names.push(name);
}
}
names.sort_unstable();
return names;
}

View File

@@ -0,0 +1,32 @@
// file: crates/ksp-store-api/tests/public_api.rs
// version: 1
//! Integration canaries for the public `ksp-store-api` scaffold.
fn consume_result(value: ksp_store_api::Result<ksp_store_api::Pubkey>) -> ksp_store_api::Result<ksp_store_api::Pubkey> {
return value;
}
#[test]
fn public_pre_002_core_facade_is_available_from_crate_root() {
let pubkey = ksp_store_api::Pubkey::new_from_array([0x31_u8; 32]);
let forwarded = consume_result(std::result::Result::Ok(pubkey));
assert!(forwarded.is_ok());
let error_code_type: std::option::Option<ksp_store_api::ErrorCode> = std::option::Option::None;
let error_context_type: std::option::Option<ksp_store_api::ErrorContext> = std::option::Option::None;
let error_type: std::option::Option<ksp_store_api::Error> = std::option::Option::None;
assert!(error_code_type.is_none());
assert!(error_context_type.is_none());
assert!(error_type.is_none());
return;
}
#[test]
fn public_pre_002_scaffold_exposes_no_private_module_paths_or_backend_types() {
let source = include_str!("../src/lib.rs");
assert!(!source.contains("pub mod "));
for forbidden in ["Postgres", "Sql", "Migration", "ProgramInstruction", "RawTransaction"] {
assert!(!source.contains(forbidden), "forbidden pre.002 Store API public concept detected: {forbidden}");
}
return;
}