Skip to content

Commit 79db792

Browse files
committed
test: add test for expand_dev_sources
1 parent ac81140 commit 79db792

File tree

4 files changed

+178
-5
lines changed

4 files changed

+178
-5
lines changed

crates/pixi_command_dispatcher/tests/integration/main.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,3 +796,128 @@ pub async fn test_get_output_dependencies_output_not_found() {
796796
),
797797
}
798798
}
799+
800+
/// Tests that `expand_dev_sources` correctly extracts dependencies from dev
801+
/// sources and allows them to be merged into a PixiEnvironmentSpec.
802+
#[tokio::test]
803+
pub async fn test_expand_dev_sources() {
804+
use pixi_command_dispatcher::{DependencyOnlySource, ExpandDevSourcesSpec};
805+
use pixi_spec::{PathSourceSpec, SourceSpec};
806+
807+
// Setup: Create a dispatcher with the in-memory backend
808+
let root_dir = workspaces_dir().join("output-dependencies");
809+
let tempdir = tempfile::tempdir().unwrap();
810+
let (tool_platform, tool_virtual_packages) = tool_platform();
811+
812+
let dispatcher = CommandDispatcher::builder()
813+
.with_root_dir(root_dir.clone())
814+
.with_cache_dirs(default_cache_dirs().with_workspace(tempdir.path().to_path_buf()))
815+
.with_executor(Executor::Serial)
816+
.with_tool_platform(tool_platform, tool_virtual_packages.clone())
817+
.with_backend_overrides(BackendOverride::from_memory(
818+
PassthroughBackend::instantiator(),
819+
))
820+
.finish();
821+
822+
// Create dev sources for test-package and package-a
823+
// package-a depends on test-package (also a dev source, should be filtered)
824+
// and on package-b (not a dev source, should be included)
825+
let dev_sources = vec![
826+
DependencyOnlySource {
827+
source: SourceSpec::from(PathSourceSpec {
828+
path: "test-package".into(),
829+
}),
830+
output_name: PackageName::new_unchecked("test-package"),
831+
},
832+
DependencyOnlySource {
833+
source: SourceSpec::from(PathSourceSpec {
834+
path: "package-a".into(),
835+
}),
836+
output_name: PackageName::new_unchecked("package-a"),
837+
},
838+
];
839+
840+
// Create the spec for expanding dev sources
841+
let spec = ExpandDevSourcesSpec {
842+
dev_sources,
843+
channel_config: default_channel_config(),
844+
channels: vec![],
845+
build_environment: BuildEnvironment::simple(tool_platform, tool_virtual_packages.clone()),
846+
variants: None,
847+
enabled_protocols: Default::default(),
848+
};
849+
850+
// Act: Expand the dev sources
851+
let expanded = dispatcher
852+
.expand_dev_sources(spec)
853+
.await
854+
.map_err(|e| format_diagnostic(&e))
855+
.expect("expand_dev_sources should succeed");
856+
857+
// Print the expanded dependencies in JSON format for easy inspection
858+
println!("\n=== Expanded Dependencies ===");
859+
let json_string = serde_json::to_string_pretty(&expanded.dependencies)
860+
.expect("Failed to serialize dependencies to JSON");
861+
println!("{}", json_string);
862+
863+
if !expanded.constraints.is_empty() {
864+
println!("\n=== Expanded Constraints ===");
865+
let constraints_json = serde_json::to_string_pretty(&expanded.constraints)
866+
.expect("Failed to serialize constraints to JSON");
867+
println!("{}", constraints_json);
868+
}
869+
println!("=============================\n");
870+
871+
// Assert: Verify all dependencies were extracted
872+
let all_dep_names: Vec<_> = expanded
873+
.dependencies
874+
.names()
875+
.map(|name| name.as_normalized())
876+
.sorted()
877+
.collect();
878+
879+
// Expected dependencies:
880+
// - From test-package: cmake, make (build), openssl, zlib (host), numpy, python (run)
881+
// - From package-a: gcc (build), requests (run), package-b (run, which is a source)
882+
// - test-package is NOT included even though package-a depends on it (filtered because it's a dev source)
883+
// - package-b IS included (not a dev source)
884+
assert_eq!(
885+
all_dep_names,
886+
vec![
887+
"cmake",
888+
"gcc",
889+
"make",
890+
"numpy",
891+
"openssl",
892+
"package-b",
893+
"python",
894+
"requests",
895+
"zlib"
896+
],
897+
"All dependencies should be extracted, with dev sources filtered out"
898+
);
899+
900+
// Verify that test-package is NOT in the dependencies (it's filtered because it's a dev source)
901+
assert!(
902+
!expanded.dependencies.contains_key("test-package"),
903+
"test-package should be filtered out because it's a dev source"
904+
);
905+
906+
// Verify that package-a is NOT in the dependencies (it's filtered because it's a dev source)
907+
assert!(
908+
!expanded.dependencies.contains_key("package-a"),
909+
"package-a should be filtered out because it's a dev source"
910+
);
911+
912+
// Verify that package-b IS in the dependencies (it's not a dev source)
913+
assert!(
914+
expanded.dependencies.contains_key("package-b"),
915+
"package-b should be included because it's not a dev source"
916+
);
917+
918+
// Assert: Verify constraints are empty (test packages have no constraints)
919+
assert!(
920+
expanded.constraints.is_empty(),
921+
"Test packages have no constraints"
922+
);
923+
}
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
# Output Dependencies Test Workspace
22

3-
This workspace contains a simple test package used to test the `get_output_dependencies` function.
3+
This workspace is used to test the `get_output_dependencies` and `expand_dev_sources` functionality of the command dispatcher.
44

55
## Structure
66

7-
- `test-package/`: A package with build, host, and run dependencies
8-
- Build dependencies: cmake, make
9-
- Host dependencies: zlib, openssl
10-
- Run dependencies: python, numpy
7+
### test-package
8+
A basic package with various dependency types:
9+
- **Build dependencies**: cmake, make
10+
- **Host dependencies**: openssl, zlib
11+
- **Run dependencies**: numpy, python
12+
13+
### package-a
14+
A package that depends on other packages to test dev source filtering:
15+
- **Build dependencies**: gcc
16+
- **Host dependencies**: test-package (path dependency)
17+
- **Run dependencies**: package-b (path dependency), requests
18+
19+
### package-b
20+
A simple package used to test non-dev-source dependencies:
21+
- **Run dependencies**: curl
22+
23+
## Test Scenarios
24+
25+
### test_expand_dev_sources
26+
Tests the dev sources expansion functionality with:
27+
1. **Simple case**: test-package as a dev source
28+
2. **Recursive filtering**: package-a depends on test-package (both are dev sources)
29+
- test-package should be **filtered out** from dependencies (it's a dev source)
30+
3. **Non-dev-source inclusion**: package-a depends on package-b
31+
- package-b should be **included** in dependencies (it's not a dev source)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "package-a"
3+
version = "0.1.0"
4+
5+
[package.build]
6+
backend = { name = "in-memory", version = "*" }
7+
8+
[package.build-dependencies]
9+
gcc = ">=9.0"
10+
11+
[package.host-dependencies]
12+
# This is a dev source, so it should be filtered out
13+
test-package = { path = "../test-package" }
14+
15+
[package.run-dependencies]
16+
# This is NOT a dev source, so it should be included
17+
package-b = { path = "../package-b" }
18+
requests = ">=2.0"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "package-b"
3+
version = "0.1.0"
4+
5+
[package.build]
6+
backend = { name = "in-memory", version = "*" }
7+
8+
[package.run-dependencies]
9+
curl = ">=7.0"

0 commit comments

Comments
 (0)