Skip to content

Commit 18072f3

Browse files
committed
Skip load_instance_pre for components not referenced by the trigger
This allows the manifest to contain components which exist only to be used in composition and do not necessarily comply with the Spin world - albeit more important for future middleware-style projects than for current import-style dependencies. Signed-off-by: itowlson <[email protected]>
1 parent d3d0903 commit 18072f3

File tree

8 files changed

+798
-16
lines changed

8 files changed

+798
-16
lines changed

crates/factors-executor/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutor<T, U> {
5353
app: App,
5454
runtime_config: T::RuntimeConfig,
5555
component_loader: &impl ComponentLoader<T, U>,
56+
trigger_type: Option<&str>,
5657
) -> anyhow::Result<FactorsExecutorApp<T, U>> {
5758
let configured_app = self
5859
.factors
@@ -63,7 +64,14 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutor<T, U> {
6364
hooks.configure_app(&configured_app).await?;
6465
}
6566

66-
let components = configured_app.app().components();
67+
let components = match trigger_type {
68+
Some(trigger_type) => configured_app
69+
.app()
70+
.triggers_with_type(trigger_type)
71+
.filter_map(|t| t.component().ok())
72+
.collect::<Vec<_>>(),
73+
None => configured_app.app().components().collect(),
74+
};
6775
let mut component_instance_pres = HashMap::with_capacity(components.len());
6876

6977
for component in components {
@@ -334,7 +342,7 @@ mod tests {
334342
let executor = Arc::new(FactorsExecutor::new(engine_builder, env.factors)?);
335343

336344
let factors_app = executor
337-
.load_app(app, Default::default(), &DummyComponentLoader)
345+
.load_app(app, Default::default(), &DummyComponentLoader, None)
338346
.await?;
339347

340348
let mut instance_builder = factors_app.prepare("empty")?;

crates/trigger/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> TriggerAppBuilder<T, B> {
339339
let configured_app = {
340340
let _sloth_guard = warn_if_wasm_build_slothful();
341341
executor
342-
.load_app(app, runtime_config.into(), loader)
342+
.load_app(app, runtime_config.into(), loader, Some(T::TYPE))
343343
.await?
344344
};
345345

tests/integration.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,29 @@ route = "/..."
15021502
Ok(())
15031503
}
15041504

1505+
#[test]
1506+
fn test_does_not_load_triggerless_component() -> anyhow::Result<()> {
1507+
run_test(
1508+
"unsupported-import-unused",
1509+
SpinConfig {
1510+
binary_path: spin_binary(),
1511+
spin_up_args: Vec::new(),
1512+
app_type: SpinAppType::Http,
1513+
},
1514+
ServicesConfig::none(),
1515+
move |env| {
1516+
let spin = env.runtime_mut();
1517+
assert_spin_request(
1518+
spin,
1519+
Request::full(Method::Get, "/", &[], Some("")),
1520+
Response::new_with_body(200, "Hello World!\n"),
1521+
)?;
1522+
Ok(())
1523+
},
1524+
)?;
1525+
Ok(())
1526+
}
1527+
15051528
#[test]
15061529
fn test_outbound_post() -> anyhow::Result<()> {
15071530
run_test(

0 commit comments

Comments
 (0)