Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(storage): add legacy v1 profile import fixture

Steven Enamakel49b448f3b744
diff --git a/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/README.md b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/README.md
new file mode 100644
index 0000000000..5559d7c7f0
--- /dev/null
+++ b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/README.md
@@ -0,0 +1,21 @@
+# Legacy v1 profile storage fixture
+
+This fixture is generated with the public `tinystoragedrivers` ports from the
+historical v1 implementation at commit
+`0c6dcfce57201fadd830431f36fd759c3baa897a`. It is deliberately generated by
+`StorageBackend::for_scope` and `DocumentStore`, not by writing TSD's SQLite
+tables directly. The current host reads this database through its legacy
+inventory adapter.
+
+The standalone generator is under `generator/`; it is not a workspace member
+or product dependency. Regenerate into a persistent caller-selected directory:
+
+```sh
+cargo run --locked --manifest-path crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.toml -- /absolute/path/to/storage.db
+```
+
+The generated database is a small authentic v1 storage database. It includes
+profile registry and lease rows, plus representative old owner records in
+profile and module scopes. The fixture test separately verifies legacy files
+that are not stored in this database; those sources are not conflated with
+TSD's inventory.
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.toml
new file mode 100644
index 0000000000..dd3295bd6a
--- /dev/null
+++ b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "legacy-v1-profile-writer"
+version = "0.1.0"
+edition = "2024"
+publish = false
+
+[dependencies]
+tinystoragedrivers = { git = "https://github.com/tinyhumansai/tinystoragedrivers.git", rev = "0c6dcfce57201fadd830431f36fd759c3baa897a", features = ["sqlite"] }
+serde_json = "1"
+tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
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.rs
new file mode 100644
index 0000000000..41d4e005fd
--- /dev/null
+++ b/crates/openhuman-core/src/storage/import/fixtures/legacy-v1-profile/generator/src/main.rs
@@ -0,0 +1,83 @@
+use std::path::PathBuf;
+
+use serde_json::json;
+use tinystoragedrivers::{CollectionSpec, DocumentStoreExt, Precondition, Scope, StorageConfig};
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let path = std::env::args_os()
+ .nth(1)
+ .map(PathBuf::from)
+ .ok_or("usage: legacy-v1-profile-writer <output-storage.db>")?;
+ if let Some(parent) = path.parent() {
+ std::fs::create_dir_all(parent)?;
+ }
+ let url = format!("sqlite:{}", path.display());
+ let backend = tinystoragedrivers::open(&StorageConfig::parse(&url)?).await?;
+
+ // These are the collection names and v1 document bodies written by the
+ // pre-port profile owners. The old TSD public writer supplies the actual
+ // scoped SQLite storage layout and metadata.
+ let profile = backend.for_scope(&Scope::new("profile:u1")?)?;
+ let docs = profile.documents();
+ for (collection, id, body) in [
+ (
+ "config",
+ "runtime",
+ json!({"workspace": "/legacy/workspace", "theme": "dark", "schema_version": 1}),
+ ),
+ (
+ "cost_records",
+ "cost-0001",
+ json!({"usage": {"timestamp": "2025-02-03T04:05:06.789+02:00", "input_tokens": 12, "output_tokens": 3}, "model": "fixture-model", "ts_ms": 1738548306789}),
+ ),
+ (
+ "artifacts",
+ "artifact-1",
+ json!({"id": "artifact-1", "title": "Fixture plan", "created_at": "2025-02-03T04:05:06Z", "thread_id": "thread-1"}),
+ ),
+ ] {
+ docs.ensure_collection(&CollectionSpec::new(collection))
+ .await?;
+ docs.put(collection, id, body, Precondition::Absent).await?;
+ }
+
+ let cluster = backend.for_scope(&Scope::new("cluster")?)?;
+ let docs = cluster.documents();
+ docs.ensure_collection(&CollectionSpec::new("profiles"))
+ .await?;
+ docs.put(
+ "profiles",
+ "u1",
+ json!({"profile_id": "u1", "created_at": 1738548306_i64, "layout_version": 1}),
+ Precondition::Absent,
+ )
+ .await?;
+ docs.ensure_collection(&CollectionSpec::new("leases"))
+ .await?;
+ docs.put(
+ "leases",
+ "profile:u1",
+ json!({"owner": "desktop-legacy", "epoch": 7, "expires_at_ms": 1738548366789_i64, "endpoint": "local"}),
+ Precondition::Absent,
+ )
+ .await?;
+
+ // One old module-scope source row demonstrates that the inventory reader
+ // preserves identities needed by the host's explicit known-module map.
+ let module = backend.for_scope(&Scope::new("module:tinybox@local")?)?;
+ let docs = module.documents();
+ docs.ensure_collection(&CollectionSpec::new("tinybox_jail_index"))
+ .await?;
+ docs.put(
+ "tinybox_jail_index",
+ "jail-1",
+ json!({"id": "jail-1", "created_at": "2025-02-03T04:05:06Z", "image": "fixture"}),
+ Precondition::Absent,
+ )
+ .await?;
+
+ backend.checkpoint().await?;
+ println!("written {}", path.display());
+ Ok(())
+}