@@ -17,6 +17,25 @@ def read_win_file_if_exists(path)
1717 { exists : exists , content : exists ? body : '' }
1818end
1919
20+ # ---- NEW: wrappers that always pass the required flags ----
21+ def puppet_flags
22+ [
23+ '--preprocess_deferred' , 'true' ,
24+ '--preferred_serialization_format' , 'json' ,
25+ '--color' , 'false' ,
26+ '--detailed-exitcodes'
27+ ]
28+ end
29+
30+ def apply_manifest_with_flags ( manifest , opts = { } )
31+ apply_manifest ( manifest , opts . merge ( puppet_options : puppet_flags ) )
32+ end
33+
34+ def idempotent_apply_with_flags ( manifest , opts = { } )
35+ idempotent_apply ( manifest , opts . merge ( puppet_options : puppet_flags ) )
36+ end
37+ # ----------------------------------------------------------
38+
2039RSpec . configure do |config |
2140 config . before ( :all ) do
2241 # Ensure Deferred values are preprocessed before provider runs (Puppet 8 default is false)
@@ -29,6 +48,10 @@ def read_win_file_if_exists(path)
2948 fmt = run_shell ( 'puppet config print preferred_serialization_format --section agent' ) . stdout . strip
3049 raise 'preprocess_deferred not true on agent!' unless pp . casecmp ( 'true' ) . zero?
3150 raise 'preferred_serialization_format not json on agent!' unless fmt . casecmp ( 'json' ) . zero?
51+
52+ # Extra visibility: show puppet version & confdir in logs
53+ run_shell ( 'puppet --version' )
54+ run_shell ( 'puppet config print confdir' )
3255 end
3356end
3457
@@ -39,16 +62,28 @@ def read_win_file_if_exists(path)
3962 let ( :dsc_deferred_stringified ) { read_fixture ( '03a_dsc_deferred_stringified.pp' ) }
4063 let ( :dsc_deferred_bad_unwrap ) { read_fixture ( '03b_dsc_deferred_bad_unwrap.pp' ) }
4164
65+ # ---- NEW: diagnostic example to prove effective settings for this process ----
66+ it '00: confirms preprocess_deferred=true and JSON are active in the current apply context' do
67+ print_pp = <<-PP
68+ notify { "preprocess_deferred=#{ Puppet . lookup ( :settings ) . value ( 'preprocess_deferred' ) } ": }
69+ notify { "preferred_serialization_format=#{ Puppet . lookup ( :settings ) . value ( 'preferred_serialization_format' ) } ": }
70+ PP
71+ res = apply_manifest_with_flags ( print_pp )
72+ expect ( res . stdout ) . to match ( %r{preprocess_deferred=true}i )
73+ expect ( res . stdout ) . to match ( %r{preferred_serialization_format=json}i )
74+ end
75+ # ------------------------------------------------------------------------------
76+
4277 it 'control (01): native file + Deferred resolves to hello-file' do
43- result = idempotent_apply ( control_manifest )
78+ result = idempotent_apply_with_flags ( control_manifest )
4479 expect ( result . exit_code ) . to eq ( 0 )
4580 out = read_win_file_if_exists ( 'C:/Temp/deferred_ok.txt' )
4681 expect ( out [ :exists ] ) . to be ( true )
4782 expect ( out [ :content ] . strip ) . to eq ( 'hello-file' )
4883 end
4984
5085 it '02: passing Deferred via variable to DSC resolves to hello-dsc (otherwise flag bug)' do
51- apply = apply_manifest ( dsc_deferred_direct )
86+ apply = apply_manifest_with_flags ( dsc_deferred_direct )
5287 out = read_win_file_if_exists ( 'C:/Temp/from_dsc.txt' )
5388 content = out [ :content ] . strip
5489 if out [ :exists ] && content == 'hello-dsc'
@@ -62,7 +97,7 @@ def read_win_file_if_exists(path)
6297
6398 # NEW 02b: inline Deferred on the DSC property (no variable intermediary)
6499 it '02b: passing Deferred inline to DSC resolves to hello-dsc-inline (otherwise flag bug)' do
65- apply = apply_manifest ( dsc_deferred_inline )
100+ apply = apply_manifest_with_flags ( dsc_deferred_inline )
66101 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_inline.txt' )
67102 content = out [ :content ] . strip
68103 if out [ :exists ] && content == 'hello-dsc-inline'
@@ -75,15 +110,15 @@ def read_win_file_if_exists(path)
75110 end
76111
77112 it '03a: stringifying a Deferred writes the function form (reproduces customer report)' do
78- apply_manifest ( dsc_deferred_stringified )
113+ apply_manifest_with_flags ( dsc_deferred_stringified )
79114 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_string.txt' )
80115 expect ( out [ :exists ] ) . to be ( true )
81116 expect ( out [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
82117 expect ( out [ :content ] ) . not_to match ( %r{\b hello-var\b } )
83118 end
84119
85120 it '03b: unwrap on a non‑Sensitive is a no‑op; also writes the function form' do
86- apply_manifest ( dsc_deferred_bad_unwrap )
121+ apply_manifest_with_flags ( dsc_deferred_bad_unwrap )
87122 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_bad_unwrap.txt' )
88123 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var.txt' ) unless out [ :exists ]
89124 expect ( out [ :exists ] ) . to be ( true )
0 commit comments