Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/pantograph-embedded-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ mod node_io_artifacts;
pub mod package_readiness_provider;
#[allow(dead_code)]
mod pumas_dispatch_package_facts;
#[cfg(test)]
mod pumas_test_support;
pub mod python_package_readiness_probe;
pub mod python_runtime;
mod python_runtime_env_resolution;
Expand Down
2 changes: 1 addition & 1 deletion crates/pantograph-embedded-runtime/src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn runtime_extensions_apply_workflow_service_for_stream_artifacts() {
async fn runtime_extensions_apply_pumas_selector_access() {
let temp_dir = TempDir::new().expect("temporary Pumas root should be created");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async fn execute_edit_session_graph_reconciles_registry_after_restore() {
let (model_id, embedding_model_path) = write_imported_embedding_model(temp.path());

let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp.path())
crate::pumas_test_support::builder(temp.path())
.build()
.await
.expect("build pumas api"),
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn execute_edit_session_graph_restore_keeps_scheduler_runtime_registry_dia
let (model_id, embedding_model_path) = write_imported_embedding_model(temp.path());

let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp.path())
crate::pumas_test_support::builder(temp.path())
.build()
.await
.expect("build pumas api"),
Expand Down Expand Up @@ -278,7 +278,7 @@ async fn execute_edit_session_graph_reconciles_registry_after_embedding_prepare(
let (model_id, embedding_model_path) = write_imported_embedding_model(temp.path());

let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp.path())
crate::pumas_test_support::builder(temp.path())
.build()
.await
.expect("build pumas api"),
Expand Down Expand Up @@ -404,7 +404,7 @@ async fn execute_edit_session_graph_reconciles_registry_after_failed_restore() {
let (model_id, embedding_model_path) = write_imported_embedding_model(temp.path());

let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp.path())
crate::pumas_test_support::builder(temp.path())
.build()
.await
.expect("build pumas api"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn workflow_execution_session_dispatches_through_production_embedded_image
let pumas_root = temp.path().join("pumas");
std::fs::create_dir_all(&pumas_root).expect("pumas root");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(pumas_root)
crate::pumas_test_support::builder(pumas_root)
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ mod tests {
write_test_diffusers_bundle(&model_dir);
write_imported_diffusion_metadata(&model_dir, model_id, &model_dir);
let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -400,7 +400,7 @@ mod tests {
write_test_diffusers_bundle(&model_dir);
write_imported_diffusion_metadata(&model_dir, model_id, &model_dir);
let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -490,7 +490,7 @@ mod tests {
#[tokio::test]
async fn read_only_selector_access_does_not_promote_summaries() {
let temp_dir = create_test_env();
let api = pumas_library::PumasApi::builder(temp_dir.path())
let api = crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down
83 changes: 83 additions & 0 deletions crates/pantograph-embedded-runtime/src/pumas_test_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Shared startup preparation for Pumas owner API fixtures.

use std::path::{Path, PathBuf};
use std::sync::OnceLock;

use pumas_library::registry::LibraryRegistry;

pub(crate) fn builder(launcher_root: impl Into<PathBuf>) -> pumas_library::PumasApiBuilder {
static REGISTRY: OnceLock<LibraryRegistry> = OnceLock::new();

// Fixture model directories are independent, but every owner API opens the
// same platform registry. Finish its first WAL/schema initialization once
// before parallel builders open additional connections, and keep it alive
// for the test process. Initialization errors still fail the test.
let db_path = pumas_library::platform::registry_db_path().expect("Pumas test registry path");
prepare_registry(&REGISTRY, &db_path);
pumas_library::PumasApi::builder(launcher_root)
}

fn prepare_registry(registry: &OnceLock<LibraryRegistry>, db_path: &Path) {
registry
.get_or_init(|| LibraryRegistry::open_at(db_path).expect("Pumas test registry startup"));
}

#[cfg(test)]
mod tests {
use super::*;
use std::sync::Barrier;

#[test]
fn concurrent_owner_registry_connections_follow_completed_cold_startup() {
const OWNERS: usize = 32;

for _ in 0..8 {
let temp = tempfile::tempdir().expect("isolated registry directory");
let db_path = temp.path().join("registry.db");
let registry = OnceLock::new();
let barrier = Barrier::new(OWNERS);

std::thread::scope(|scope| {
let mut owners = Vec::new();
for owner in 0..OWNERS {
let library_path = temp.path().join(format!("owner-{owner}"));
std::fs::create_dir(&library_path).expect("owner library directory");
let db_path = &db_path;
let registry = &registry;
let barrier = &barrier;
owners.push(scope.spawn(move || {
barrier.wait();
prepare_registry(registry, db_path);
let connection =
LibraryRegistry::open_at(db_path).expect("owner registry connection");
connection
.register(&library_path, "test-owner")
.expect("owner registration");
assert!(matches!(
connection
.try_claim_instance(&library_path, std::process::id())
.expect("owner instance claim"),
pumas_library::registry::InstanceClaimResult::Claimed(_)
));
connection
.unregister_instance(&library_path)
.expect("owner instance cleanup");
}));
}
for owner in owners {
owner.join().expect("owner startup should succeed");
}
});

assert_eq!(
registry
.get()
.expect("prepared registry")
.list()
.expect("registered owners")
.len(),
OWNERS
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ mod tests {
let pumas_root = temp.path().join("pumas");
std::fs::create_dir_all(&pumas_root).expect("pumas launcher root");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(pumas_root)
crate::pumas_test_support::builder(pumas_root)
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn puma_lib_execution_hydrates_model_ref_from_model_id_without_path_output
write_imported_diffusion_metadata(&model_dir, "diffusion/imported/test-bundle", &bundle_root);

let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize"),
Expand Down Expand Up @@ -157,7 +157,7 @@ async fn puma_lib_execution_does_not_rebind_model_id_from_raw_pumas_api() {
write_imported_diffusion_metadata(&model_dir, model_id, &bundle_root);

let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize"),
Expand Down Expand Up @@ -227,7 +227,7 @@ async fn puma_lib_execution_hydrates_model_ref_from_selector_access_without_puma
.join(model_id);
write_imported_diffusion_metadata(&model_dir, model_id, &bundle_root);

let api = pumas_library::PumasApi::builder(temp_dir.path())
let api = crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize");
Expand Down Expand Up @@ -310,7 +310,7 @@ async fn puma_lib_execution_does_not_emit_inference_settings_from_saved_or_selec
write_imported_diffusion_metadata(&model_dir, model_id, &bundle_root);

let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize"),
Expand Down Expand Up @@ -373,7 +373,7 @@ async fn puma_lib_execution_does_not_resolve_saved_model_name_without_model_id()
write_imported_diffusion_metadata(&model_dir, model_id, &bundle_root);

let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.build()
.await
.expect("pumas api should initialize"),
Expand Down
4 changes: 2 additions & 2 deletions crates/pantograph-embedded-runtime/src/technical_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ mod tests {
let temp_dir = tempfile::tempdir().expect("temp dir");
let model_id = "llm/test/live-technical-fit-facts";
let api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -2960,7 +2960,7 @@ mod tests {
let temp_dir = tempfile::tempdir().expect("temp dir");
std::fs::create_dir_all(temp_dir.path().join("shared-resources/models"))
.expect("models dir");
let api = pumas_library::PumasApi::builder(temp_dir.path())
let api = crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ mod tests {
async fn builds_resource_backed_hosted_workflow_service_before_sharing() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -808,7 +808,7 @@ mod tests {
write_test_diffusers_bundle(&model_dir);
write_imported_diffusion_metadata(&model_dir, model_id, &model_dir);
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -909,7 +909,7 @@ mod tests {
write_test_diffusers_bundle(&model_dir);
write_imported_diffusion_metadata(&model_dir, model_id, &model_dir);
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1084,7 +1084,7 @@ mod tests {
async fn hosted_resource_backed_factory_requires_artifact_writer_before_sharing() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1117,7 +1117,7 @@ mod tests {
#[tokio::test]
async fn hosted_resource_backed_factory_rejects_non_owner_pumas_access() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = pumas_library::PumasApi::builder(temp_dir.path())
let pumas_api = crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1157,7 +1157,7 @@ mod tests {
async fn resource_backed_hosted_bundle_returns_service_and_lifecycle_handle() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1194,7 +1194,7 @@ mod tests {
async fn resource_backed_hosted_bundle_rejects_invalid_producer_config_before_sharing() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1283,7 +1283,7 @@ mod tests {
async fn hosted_startup_composition_returns_service_extensions_and_lifecycle_handle() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1394,7 +1394,7 @@ mod tests {
#[tokio::test]
async fn hosted_startup_composition_rejects_non_owner_pumas_selector_access() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = pumas_library::PumasApi::builder(temp_dir.path())
let pumas_api = crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down Expand Up @@ -1440,7 +1440,7 @@ mod tests {
async fn hosted_startup_composition_rejects_service_error_before_starting_sidecar() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let pumas_api = Arc::new(
pumas_library::PumasApi::builder(temp_dir.path())
crate::pumas_test_support::builder(temp_dir.path())
.with_hf_client(false)
.with_process_manager(false)
.build()
Expand Down
Loading
Loading