{"action":"created","issue":{"url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/38","repository_url":"https://api.github.com/repos/CocoaPods/Molinillo","labels_url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/38/comments","events_url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/38/events","html_url":"https://github.com/CocoaPods/Molinillo/pull/38","id":146486794,"number":38,"title":"Remove transitive requirements when swapping children","user":{"login":"danielsdeleo","id":37162,"avatar_url":"https://avatars.githubusercontent.com/u/37162?v=3","gravatar_id":"","url":"https://api.github.com/users/danielsdeleo","html_url":"https://github.com/danielsdeleo","followers_url":"https://api.github.com/users/danielsdeleo/followers","following_url":"https://api.github.com/users/danielsdeleo/following{/other_user}","gists_url":"https://api.github.com/users/danielsdeleo/gists{/gist_id}","starred_url":"https://api.github.com/users/danielsdeleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielsdeleo/subscriptions","organizations_url":"https://api.github.com/users/danielsdeleo/orgs","repos_url":"https://api.github.com/users/danielsdeleo/repos","events_url":"https://api.github.com/users/danielsdeleo/events{/privacy}","received_events_url":"https://api.github.com/users/danielsdeleo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-04-07T02:00:11Z","updated_at":"2016-04-19T20:12:31Z","closed_at":"2016-04-19T17:14:34Z","pull_request":{"url":"https://api.github.com/repos/CocoaPods/Molinillo/pulls/38","html_url":"https://github.com/CocoaPods/Molinillo/pull/38","diff_url":"https://github.com/CocoaPods/Molinillo/pull/38.diff","patch_url":"https://github.com/CocoaPods/Molinillo/pull/38.patch"},"body":"- [x] CHANGELOG\r\n- [x] Tests\r\n\r\n---\r\n\r\nI'm investigating an issue (https://github.com/berkshelf/solve/issues/57) in the solve library, which is using Molinillo. I was able to add a reproduction case (https://github.com/berkshelf/solve/commit/b84500e80c22e0596b530838f7a7d299f6f9f870) as a RSpec test for solve, which fails with the following:\r\n\r\n```\r\n  1) Solutions when using the ruby solver repro case?\r\n     Failure/Error: activated.vertex_named(name).payload ? 0 : 1,\r\n     \r\n     NoMethodError:\r\n       undefined method `payload' for nil:NilClass\r\n     # ./lib/solve/ruby_solver.rb:145:in `block in sort_dependencies'\r\n     # ./lib/solve/ruby_solver.rb:142:in `each'\r\n     # ./lib/solve/ruby_solver.rb:142:in `sort_by'\r\n     # ./lib/solve/ruby_solver.rb:142:in `sort_dependencies'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:131:in `block (2 levels) in <class:Resolution>'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:431:in `push_state_for_requirements'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:423:in `require_nested_dependencies_for'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:411:in `activate_spec'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:353:in `attempt_to_swap_possibility'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:333:in `attempt_to_activate_existing_spec'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:318:in `attempt_to_activate'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:147:in `process_topmost_state'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolution.rb:72:in `resolve'\r\n     # /Users/ddeleo/contrib/Molinillo/lib/molinillo/resolver.rb:42:in `resolve'\r\n     # ./lib/solve/ruby_solver.rb:198:in `resolve_with_error_wrapping'\r\n     # ./lib/solve/ruby_solver.rb:75:in `resolve'\r\n     # ./lib/solve.rb:64:in `it!'\r\n     # ./spec/acceptance/ruby_solver_solutions_spec.rb:300:in `block (2 levels) in <top (required)>'\r\n```\r\n\r\nWhen I enable Molinillo's debugging and add some printf debugging of my own, what I find is that a requirement is added for a grandchild, but the child later gets swapped. The `#detach_vertex_named` method is recursive, so it removes the grandchild's vertex, but the requirements removal is not recursive, so there's a \"zombie\" requirement, so that `activated.vertex_named(name)` returns `nil`.\r\n\r\nIn more concrete terms (these are all Chef cookbooks), there is a cookbook named \"build-essential\". The old version of this depends on a cookbook named \"7-zip\"; the new version of it depends on a replacement named \"seven_zip\". Both \"7-zip\" and \"seven_zip\" depend on a cookbook called \"windows\". When solving the dependencies, Molinillo at first picks the solution using the new version of \"build-essential\", and activates \"seven_zip\" and \"windows\". This conflicts with a version requirement elsewhere (we need the older \"build-essential\"), so Molinillo calls `#fixup_swapped_children` to remove \"seven_zip\". In the meantime, the requirements array has collected a requirement for the windows cookbook. Since only the vertices are recursively removed, the windows requirement stays there, until it triggers the exception case for `activated.vertex_named(\"windows\") #=> nil`.\r\n\r\nAs for the code in this pull request:\r\n1. I'm not sure if this is the proper approach to solving the problem; I don't have a good understanding of most of the moving parts here\r\n2. Even if the approach is right, it's only a partial solution for the reason I wrote in the code comment.\r\n3. In any case there of course should be a test, but my repro case is a little picky based on the order things are returned from `#sort_dependencies` and I haven't yet looked at how the JSON fixtures work.\r\n\r\nDespite that, it does pass Molinillo's specs, and it fixes my repro case."},"comment":{"url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/comments/212107188","html_url":"https://github.com/CocoaPods/Molinillo/pull/38#issuecomment-212107188","issue_url":"https://api.github.com/repos/CocoaPods/Molinillo/issues/38","id":212107188,"user":{"login":"segiddins","id":1946610,"avatar_url":"https://avatars.githubusercontent.com/u/1946610?v=3","gravatar_id":"","url":"https://api.github.com/users/segiddins","html_url":"https://github.com/segiddins","followers_url":"https://api.github.com/users/segiddins/followers","following_url":"https://api.github.com/users/segiddins/following{/other_user}","gists_url":"https://api.github.com/users/segiddins/gists{/gist_id}","starred_url":"https://api.github.com/users/segiddins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/segiddins/subscriptions","organizations_url":"https://api.github.com/users/segiddins/orgs","repos_url":"https://api.github.com/users/segiddins/repos","events_url":"https://api.github.com/users/segiddins/events{/privacy}","received_events_url":"https://api.github.com/users/segiddins/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T20:12:31Z","updated_at":"2016-04-19T20:12:31Z","body":"@danielsdeleo plan on releasing this either today or tomorrow"}}