The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(storage): cover legacy profile boot migration with richer fixtures
Steven Enamakelb35e1d6b2372
diff --git a/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.toml b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.tomlindex a3d30875c4..1a876f9e62 100644--- a/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.toml+++ b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.toml@@ -7,8 +7,9 @@ publish = false[workspace][dependencies]-tinystoragedrivers = { git = "https://github.com/tinyhumansai/tinystoragedrivers.git", rev = "0c6dcfce57201fadd830431f36fd759c3baa897a", features = ["sqlite"] }+tinystoragedrivers = { git = "https://github.com/tinyhumansai/tinystoragedrivers.git", rev = "0c6dcfce57201fadd830431f36fd759c3baa897a", features = ["sqlite", "secrets"] }chrono = { version = "0.4", features = ["serde"] }serde = { version = "1", features = ["derive"] }serde_json = "1"tokio = { version = "1", features = ["macros", "rt-multi-thread"] }+zeroize = "1"diff --git a/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/src/main.rs b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/src/main.rsindex 9599fc10b2..4f7a0c5434 100644--- a/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/src/main.rs+++ b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/src/main.rs@@ -1,9 +1,12 @@use std::path::PathBuf;+use std::sync::Arc;use chrono::{DateTime, Utc};use serde::{Deserialize, Serialize};use serde_json::{Value, json};+use tinystoragedrivers::secrets::{DerivedKeys, DocumentSecrets, SecretStore};use tinystoragedrivers::{CollectionSpec, Precondition, Scope, StorageConfig, WriteOptions};+use zeroize::Zeroizing;const PROFILE_ID: &str = "u1";const CREATED_AT_MS: i64 = 1_738_548_306_000;@@ -205,6 +208,57 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {).await?;+ // Legacy profile-owned records whose public owners must continue to read+ // them after the profile's real v1-to-v2 boot migration.+ put(+ profile_scope.documents(),+ "approvals",+ "fixture-approval",+ json!({+ "tool_name": "shell",+ "action_summary": "Fixture approval",+ "args_redacted": "{}",+ "session_id": "fixture-session",+ "created_at": "2025-02-03T04:05:06Z",+ "expires_at": "2099-02-03T04:05:06Z",+ "pending": true,+ "agent_id": "default"+ }),+ )+ .await?;+ put(+ profile_scope.documents(),+ "threads_transcript_keys",+ "fixture-thread",+ json!({"transcript_key": "fixture-transcript-key"}),+ )+ .await?;++ let legacy_flow_scope = backend.for_scope(&Scope::local())?;+ put(+ legacy_flow_scope.documents(),+ "flows_definitions",+ "fixture-flow",+ json!({+ "name": "Fixture flow",+ "graph_json": "{\"nodes\":[{\"id\":\"trigger\",\"kind\":\"trigger\",\"name\":\"Manual\"}],\"edges\":[]}",+ "enabled": false,+ "created_at": "2025-02-03T04:05:06Z",+ "updated_at": "2025-02-03T04:05:06Z",+ "require_approval": false,+ "incarnation": "fixture-incarnation"+ }),+ )+ .await?;++ let secret_store = DocumentSecrets::new(+ &profile_scope,+ Arc::new(DerivedKeys::new(Zeroizing::new([0x5a; 32]))),+ );+ secret_store+ .set("fixture-secret", b"historical-secret-value")+ .await?;+backend.checkpoint(tinystoragedrivers::Checkpoint::Truncate).await?;diff --git a/tests/storage_legacy_profile_boot_e2e.rs b/tests/storage_legacy_profile_boot_e2e.rsindex 831a203113..8e27e68269 100644--- a/tests/storage_legacy_profile_boot_e2e.rs+++ b/tests/storage_legacy_profile_boot_e2e.rs@@ -6,6 +6,9 @@ use std::process::{Child, Command, Stdio};use std::time::{Duration, Instant};use serde_json::{Value, json};+use tinystoragedrivers::secrets::DerivedKeys;+use tinystoragedrivers::StorageBackend;+use zeroize::Zeroizing;const TOKEN: &str = "legacy-profile-boot-e2e-token";const FIXTURE: &[u8] = include_bytes!(@@ -92,9 +95,62 @@ fn seed_existing_profile(home: &Path) -> (PathBuf, PathBuf) {.unwrap();let source = workspace.join("storage/storage.db");std::fs::write(&source, FIXTURE).unwrap();+ seed_legacy_session_db(&workspace);(profile, source)}+fn seed_legacy_session_db(workspace: &Path) {+ use openhuman_core::storage::rusqlite::{Connection, params};++ let path = workspace.join("session_db/sessions.db");+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();+ let db = Connection::open(path).unwrap();+ db.execute_batch(+ "CREATE TABLE sessions (+ id TEXT PRIMARY KEY, agent_definition_id TEXT NOT NULL,+ agent_definition_name TEXT NOT NULL, session_key TEXT NOT NULL,+ status TEXT NOT NULL, turn_count INTEGER NOT NULL,+ input_tokens INTEGER NOT NULL, output_tokens INTEGER NOT NULL,+ cached_input_tokens INTEGER NOT NULL, cost_usd REAL NOT NULL,+ started_at TEXT NOT NULL);+ CREATE TABLE session_messages (+ id INTEGER PRIMARY KEY, session_id TEXT NOT NULL, role TEXT NOT NULL,+ content TEXT NOT NULL, created_at TEXT NOT NULL);+ CREATE TABLE session_tool_calls (+ id INTEGER PRIMARY KEY, session_id TEXT NOT NULL, message_id INTEGER,+ tool_name TEXT NOT NULL, status TEXT NOT NULL, created_at TEXT NOT NULL);",+ )+ .unwrap();+ db.execute(+ "INSERT INTO sessions VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)",+ params![+ "fixture-session",+ "default",+ "Default",+ "fixture-thread",+ "completed",+ 1,+ 1,+ 1,+ 0,+ 0.0,+ "2025-02-03T04:05:06Z"+ ],+ )+ .unwrap();+ db.execute(+ "INSERT INTO session_messages VALUES (?1, ?2, ?3, ?4, ?5)",+ params![+ 1,+ "fixture-session",+ "assistant",+ "Preserved fixture answer",+ "2025-02-03T04:06:07Z"+ ],+ )+ .unwrap();+}+#[test]fn desktop_boot_reads_a_preserved_existing_v1_profile_database() {let home = tempfile::tempdir().unwrap();@@ -125,4 +181,23 @@ fn desktop_boot_reads_a_preserved_existing_v1_profile_database() {source_bytes,"boot must leave the historical v1 storage.db byte-for-byte unchanged");++ // Read the confidential record with TinyStorage's document-secret owner+ // API after the desktop boot has installed and migrated the profile DB.+ let url = format!("sqlite:{}", profile.join("storage.db").display());+ let backend = openhuman_core::storage::block_on(async {+ openhuman_core::storage::open(&url).await+ })+ .unwrap();+ let scope = openhuman_core::storage::Scope::new("u:u1").unwrap();+ let scoped = backend.for_scope(&scope).unwrap();+ let secrets = openhuman_core::storage::secrets::over(+ &scoped,+ scope,+ std::sync::Arc::new(DerivedKeys::new(Zeroizing::new([0x5a; 32]))),+ );+ let secret = openhuman_core::storage::secrets::get_blocking(&secrets, "fixture-secret")+ .unwrap()+ .unwrap();+ assert_eq!(secret.as_slice(), b"historical-secret-value");}