#[path = "support/mod.rs"]
mod support;
use std::path::PathBuf;
use greentic_ext_runtime::{DiscoveryPaths, ExtensionRuntime, RuntimeConfig};
use greentic_extension_sdk_contract::ExtensionKind;
use support::{
signed_fixture_with_placeholder_gtpack, signed_fixture_without_root_wasm,
signed_provider_fixture_with_placeholder_gtpack,
};
fn build_runtime() -> ExtensionRuntime {
let config = RuntimeConfig::from_paths(DiscoveryPaths::new(PathBuf::from("/dev/null")));
ExtensionRuntime::new(config).unwrap()
}
#[test]
fn provider_extension_prefers_extension_wasm_at_root() {
let (fixture, _sk) =
signed_provider_fixture_with_placeholder_gtpack("greentic.provider.telegram", "1.3.1");
let placeholder_path = fixture.root().join("runtime").join("provider.gtpack");
assert!(
placeholder_path.exists(),
"test precondition: runtime/provider.gtpack must exist"
);
let wasm_path = fixture.root().join("extension.wasm");
assert!(
wasm_path.exists(),
"test precondition: extension.wasm must exist at root"
);
let mut runtime = build_runtime();
runtime
.register_loaded_from_dir(fixture.root())
.expect("provider extension with extension.wasm at root must load successfully");
let loaded_map = runtime.loaded();
assert!(
loaded_map
.keys()
.any(|id| id.as_str() == "greentic.provider.telegram"),
"loaded extension map must contain 'greentic.provider.telegram'"
);
}
#[test]
fn design_extension_prefers_extension_wasm_at_root() {
let (fixture, _sk) = signed_fixture_with_placeholder_gtpack(
ExtensionKind::Design,
"greentic.test-design-ext-dual",
"1.3.1",
);
let wasm_path = fixture.root().join("extension.wasm");
assert!(
wasm_path.exists(),
"test precondition: extension.wasm must exist at root"
);
let placeholder_path = fixture.root().join("runtime").join("component.gtpack");
assert!(
placeholder_path.exists(),
"test precondition: runtime/component.gtpack placeholder must exist"
);
let mut runtime = build_runtime();
runtime
.register_loaded_from_dir(fixture.root())
.expect("design extension with extension.wasm at root must load successfully");
let loaded_map = runtime.loaded();
assert!(
loaded_map
.keys()
.any(|id| id.as_str() == "greentic.test-design-ext-dual"),
"loaded extension map must contain 'greentic.test-design-ext-dual'"
);
}
#[test]
fn extension_without_root_wasm_loads_from_describe_gtpack_file() {
let (fixture, _sk) = signed_fixture_without_root_wasm(
ExtensionKind::Design,
"greentic.test-fallback-ext",
"0.2.0",
);
let root_wasm = fixture.root().join("extension.wasm");
assert!(
!root_wasm.exists(),
"test precondition: extension.wasm must NOT exist at root"
);
let inner_wasm = fixture.root().join("inner.wasm");
assert!(
inner_wasm.exists(),
"test precondition: inner.wasm (fallback target) must exist"
);
let mut runtime = build_runtime();
runtime
.register_loaded_from_dir(fixture.root())
.expect("extension without root extension.wasm must load via describe.runtime.components");
let loaded_map = runtime.loaded();
assert!(
loaded_map
.keys()
.any(|id| id.as_str() == "greentic.test-fallback-ext"),
"loaded extension map must contain 'greentic.test-fallback-ext'"
);
}