fix: Deferred resolution of Puppet-language functions (e.g. mocks in tests) failing due to lack of :global_scope - #350
Conversation
Deferred resolution of Puppet-language functions (e.g. mocks in tests) failing due to lack of global_contextDeferred resolution of Puppet-language functions (e.g. mocks in tests) failing due to lack of :global_scope
fd96244 to
24ac2d0
Compare
24ac2d0 to
5ed0bcd
Compare
df1fad7 to
409b81a
Compare
|
I went back through the original PR to add deferred functions and I believe this is the correct fix. @griggi-ws apologies for the delay. Can you rebase this to current please? |
409b81a to
55c1ad1
Compare
|
@hlindberg could you give this a 👍 before we merge it? @griggi-ws would be great to get your commits signed. Apologies for not noticing it the other day. https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification |
|
@binford2k I think fix is correct. Think this issue was missed since puppet language functions aren't plugin synced. Good catch! |
Ah yeah can do, signature was there when you last looked, just lost em because I used the interface rebase button |
55c1ad1 to
d9f984c
Compare
Signed-off-by: griggi-ws <gavin.riggi@wellspring.com>
…pet-lang functions Signed-off-by: griggi-ws <gavin.riggi@wellspring.com>
d9f984c to
65bd814
Compare
|
I asked Claude to review this PR. Here is its feedback:
DeferredValue.new(
proc {
resolved_arguments = mapped_arguments.map { |arg| resolve_lazy_args(arg) }
@compiler.with_context_overrides do
@scope.call_function(func_name, resolved_arguments)
end
}
)
|
Hey folks, found an issue with Deferred resolution of Puppet-language functions while testing a control-repo with Onceover that makes heavy use of some custom functions that are mocked in Onceover's config, and did some digging.
The error was:
Puppet-language functions use the
NamedClosure, which explicitly looks up:global_scopeand returns an empty Hash as a fallback.The
DeferredResolvercreates a new compiler instance which includes:global_scopein itscontext_overrides, but the resolver's call toresolve_futuresdoes not use them.This means when a Puppet-lang Deferred function is resolved,
enclosing_scopeis{}, and when theClosure'sinvokeis called (expecting aScopeobject with the methodwith_global_scope), it errors out since we have an emptyHashinstead of aScope.By wrapping the
resolve_futurescall in acompiler.with_context_overridesblock,:global_scopeis a valid instance ofScope, and the function can be resolved.I added a spec test for Deferred processing of Puppet-lang functions, validated the failure, and applied the fix.