Add test for var name collision with package name#1361
Conversation
When a namespaced var shares its base name with a separate package (e.g. demo defines var 'samenameaspkg' and package 'samenameaspkg/1.2.3' also exists), the step solver's VarRequirementsValidator incorrectly rejects builds. It matches option keys by base_name, so demo.samenameaspkg=true collides with samenameaspkg=~1.2.3. The test passes for the resolvo solver and correctly expects failure for the cli/checks (step-based) solvers. Signed-off-by: J Robert Ray <jrray@imageworks.com>
d2cc499 to
e81cd37
Compare
|
@rydrman I found a case where the solver implementations disagree, the PR is a little biased to claim that resolvo is correct but this is up for debate. I could use your input because it is about the treatment of namespaced vs non-namespaced vars. If a package a defines a var Do we say that packages are not allowed to define vars that have the same name as other packages, which requires a certain level of omniscience, or do we start treating Resolvo already treats them as distinct and this doesn't run afoul of any of the existing solver tests. But I chalk that up to there being missing tests that demonstrate the desired behavior. My own two cents, I think if two different packages both define a var with the same name, it shouldn't be assumed that this was intentional and that the vars are sharing a meaning or trying to coordinate. I prefer a pattern where if two or more packages want to coordinate on the same var then there should be an additional package |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
It definitely feels to me like there is a bug here, mainly in that I don't see how it's reasonable not to also consider the namespaces here when comparing the request to the var. Unless I'm not reading this code right or missing some key context about where this code is executed... Would considering the namespace as part of this resolve the conflict? |
Comparing the whole thing is how resolvo is wired up which is why it passes this test. If you consider this a bug in the step solver (I prefer this stance) then I can make them both consistent by taking the resolvo behavior as correct. |
Summary
VarRequirementsValidatormiddleinstall-requiresvar: demo.samenameaspkg/trueand the solver's option map containssamenameaspkg=~1.2.3(from resolving thesamenameaspkgpackage), the validator matches bybase_name()and incorrectly rejects the buildBug details
The root cause is in
crates/spk-solve/crates/validation/src/validators/var_requirements.rsline 26:This causes
demo.samenameaspkg(a namespaced var) to match the optionsamenameaspkg(a package version) because they share the base namesamenameaspkg.Test plan
cargo test -p spk-cmd-build test_build_var_name_collides_with_package_namepasses (resolvo succeeds, cli/checks correctly fail)🤖 Generated with Claude Code