From 75d900c93bfd3d6d824ded157b9dee01e3e177cb Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 7 Jul 2022 11:29:50 -0500 Subject: [PATCH] Fix Type::Booleans leaking through capabilities We had some cases where calling a capability that returned a boolean was not getting correctly unpacked, so instead of `true` or `false` the capability was putting out `VagrantPlugins::CommandServe::Type::Boolean`. This may have been happening in _all_ cases where a boolean was returned from a capability and we just didn't notice it yet because the return value was always truthy. These tweaks should help ensure that Ruby types make it out where they are supposed to be in Args::Direct usage. --- plugins/commands/serve/client/capability_platform.rb | 6 +++--- plugins/commands/serve/util/direct_conversions.rb | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/commands/serve/client/capability_platform.rb b/plugins/commands/serve/client/capability_platform.rb index 788efeb7e..fe4f9dbe5 100644 --- a/plugins/commands/serve/client/capability_platform.rb +++ b/plugins/commands/serve/client/capability_platform.rb @@ -35,15 +35,15 @@ module VagrantPlugins name: cap_name, ) ) - cb = proc do |name, args| + cb = lambda do |name, args| result = client.capability( SDK::Platform::Capability::NamedRequest.new( name: name, func_args: args, ) ) - return nil if result.nil? - mapper.map(result.result) + return nil if result.nil? || result.result.nil? + mapper.map(SDK::Args::Direct.new(arguments: [result.result])).arguments.first end [spec, cb] end diff --git a/plugins/commands/serve/util/direct_conversions.rb b/plugins/commands/serve/util/direct_conversions.rb index 27c7e1ea7..ff4861b24 100644 --- a/plugins/commands/serve/util/direct_conversions.rb +++ b/plugins/commands/serve/util/direct_conversions.rb @@ -373,7 +373,10 @@ end class Hashicorp::Vagrant::Sdk::Args::Direct def to_ruby VagrantPlugins::CommandServe::Type::Direct.new( - arguments: arguments.map(&:to_ruby) + arguments: arguments.map { |arg| + val = arg.to_ruby + val.is_a?(VagrantPlugins::CommandServe::Type) ? val.value : val + } ) end end