Skip to content

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

refactor(artifacts): introduce scoped artifact service builder

Steven Enamakel5960200584c7
diff --git a/crates/openhuman-core/src/artifacts/tiny_store.rs b/crates/openhuman-core/src/artifacts/tiny_store.rs
index ec77d7b22d..1f157a020a 100644
--- a/crates/openhuman-core/src/artifacts/tiny_store.rs
+++ b/crates/openhuman-core/src/artifacts/tiny_store.rs
@@ -415,8 +415,19 @@ fn build_artifacts_service(
ctx: &crate::core::runtime::DispatchCtx,
publisher: Option<&super::publisher_slot::ArtifactPublisherBinder>,
) -> (Artifacts, Option<Arc<dyn FileStore>>) {
- let roots = file_roots(workspace_dir, &files, action_dir);
let scoped = crate::storage::sessions::artifact_scoped_for_in(workspace_dir, ctx);
+ build_artifacts_service_with_scope(workspace_dir, files, action_dir, chat, scoped, publisher)
+}
+
+fn build_artifacts_service_with_scope(
+ workspace_dir: &Path,
+ files: FileRoots,
+ action_dir: Option<&Path>,
+ chat: Option<&ApprovalChatContext>,
+ scoped: Option<crate::storage::ScopedStorage>,
+ publisher: Option<&super::publisher_slot::ArtifactPublisherBinder>,
+) -> (Artifacts, Option<Arc<dyn FileStore>>) {
+ let roots = file_roots(workspace_dir, &files, action_dir);
let file_store = scoped
.as_ref()
.map(|scoped| Arc::new(tiny_artifacts::BlobFileStore::new(scoped)) as Arc<dyn FileStore>);
diff --git a/crates/openhuman-core/src/artifacts/tiny_store_tests.rs b/crates/openhuman-core/src/artifacts/tiny_store_tests.rs
index f1fc39ad23..fa213ef2b3 100644
--- a/crates/openhuman-core/src/artifacts/tiny_store_tests.rs
+++ b/crates/openhuman-core/src/artifacts/tiny_store_tests.rs
@@ -146,13 +146,15 @@ async fn explicit_artifact_context_binds_records_and_blobs_to_the_same_profile()
&context_b,
);
assert!(artifacts_b.get(&id).await.unwrap().is_none());
- assert!(files_b
- .as_ref()
- .unwrap()
- .metadata(&file.key)
- .await
- .unwrap()
- .is_none());
+ assert!(
+ files_b
+ .as_ref()
+ .unwrap()
+ .metadata(&file.key)
+ .await
+ .unwrap()
+ .is_none()
+ );
let card_a = CoreContext::scope(core_a.clone(), async {
super::super::store::get_artifact(&workspace, &id).await
@@ -196,6 +198,55 @@ async fn explicit_artifact_context_binds_records_and_blobs_to_the_same_profile()
.await;
}
+#[tokio::test]
+async fn missing_artifact_storage_binding_does_not_fall_back_to_ambient_records() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+
+ let (workspace, files) = temp_dirs();
+ let context_for = |profile: &'static str| {
+ let overlay = ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::kernel(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .profile(profile);
+ CoreContext::for_test(DomainSet::full(), None).derive_with(overlay)
+ };
+ let core_b = context_for("ambient-b");
+ let context_b = DispatchCtx::new(core_b.clone());
+
+ CoreContext::scope(core_b, async {
+ let ambient_artifacts =
+ artifacts_service(&workspace, FileRoots::new(&files), None, None, &context_b);
+ ambient_artifacts
+ .create(
+ ArtifactKind::Text,
+ "Ambient private",
+ Content::Text("only profile B".into()),
+ &Author::agent("agent-b"),
+ None,
+ )
+ .await
+ .unwrap();
+
+ // A failed tenant binding is represented directly at the production
+ // builder seam, avoiding process-global SaaS-mode configuration.
+ let (unbound_artifacts, _) = build_artifacts_service_with_scope(
+ &workspace,
+ FileRoots::new(&files),
+ None,
+ None,
+ None,
+ None,
+ );
+ assert!(
+ unbound_artifacts.list().await.is_err(),
+ "a missing scoped binding must not expose the ambient profile's records"
+ );
+ })
+ .await;
+}
+
#[tokio::test]
async fn an_edit_is_appended_as_an_operator_version_and_written_to_the_file() {
let (workspace, files) = temp_dirs();
@@ -331,16 +382,20 @@ async fn deleting_an_artifact_removes_its_card() {
.await
.unwrap();
let id = saved.record.id;
- assert!(super::super::store::get_artifact(&workspace, &id)
- .await
- .is_ok());
+ assert!(
+ super::super::store::get_artifact(&workspace, &id)
+ .await
+ .is_ok()
+ );
let (removed, notice) = artifacts.delete(&id).await.unwrap();
assert!(removed);
assert!(notice.is_none(), "{notice:?}");
- assert!(super::super::store::get_artifact(&workspace, &id)
- .await
- .is_err());
+ assert!(
+ super::super::store::get_artifact(&workspace, &id)
+ .await
+ .is_err()
+ );
}
struct NoopPublisher;