@@ -17,23 +17,70 @@ def read_win_file_if_exists(path)
1717 { exists : exists , content : exists ? body : '' }
1818end
1919
20+ # ----- Always pass the flags to each puppet apply/idempotent_apply -----
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+
39+ # Configure the agent once for this file (and assert) so the host is in a known state.
40+ RSpec . configure do |config |
41+ config . before ( :all ) do
42+ # Ensure Deferred values are preprocessed before providers run (Puppet 8 defaults can be lazy)
43+ run_shell ( 'puppet config set preprocess_deferred true --section agent' )
44+ # Avoid PSON quirks with Deferred serialization across the wire
45+ run_shell ( 'puppet config set preferred_serialization_format json --section agent' )
46+
47+ # Assert settings for clear diagnostics in CI logs
48+ pp = run_shell ( 'puppet config print preprocess_deferred --section agent' ) . stdout . strip
49+ fmt = run_shell ( 'puppet config print preferred_serialization_format --section agent' ) . stdout . strip
50+ raise 'preprocess_deferred not true on agent!' unless pp . casecmp ( 'true' ) . zero?
51+ raise 'preferred_serialization_format not json on agent!' unless fmt . casecmp ( 'json' ) . zero?
52+
53+ # Extra visibility
54+ run_shell ( 'puppet --version' )
55+ run_shell ( 'puppet config print confdir' )
56+ end
57+ end
58+
2059describe 'deferred values with dsc_lite' do
2160 let ( :control_manifest ) { read_fixture ( '01_file_deferred.pp' ) }
2261 let ( :dsc_deferred_direct ) { read_fixture ( '02_dsc_deferred_direct.pp' ) }
23- let ( :dsc_deferred_inline ) { read_fixture ( '02b_dsc_deferred_inline.pp' ) } # < — NEW
62+ let ( :dsc_deferred_inline ) { read_fixture ( '02b_dsc_deferred_inline.pp' ) } # — NEW
2463 let ( :dsc_deferred_stringified ) { read_fixture ( '03a_dsc_deferred_stringified.pp' ) }
2564 let ( :dsc_deferred_bad_unwrap ) { read_fixture ( '03b_dsc_deferred_bad_unwrap.pp' ) }
2665
66+ # (Optional) Prove settings are active in this test context
67+ it '00: confirms preprocess_deferred=true and JSON are active in this context' do
68+ pp_out = run_shell ( 'puppet config print preprocess_deferred --section agent' ) . stdout . strip
69+ fmt_out = run_shell ( 'puppet config print preferred_serialization_format --section agent' ) . stdout . strip
70+ expect ( pp_out . downcase ) . to eq ( 'true' )
71+ expect ( fmt_out . downcase ) . to eq ( 'json' )
72+ end
73+
2774 it 'control (01): native file + Deferred resolves to hello-file' do
28- result = idempotent_apply ( control_manifest )
75+ result = idempotent_apply_with_flags ( control_manifest )
2976 expect ( result . exit_code ) . to eq ( 0 )
3077 out = read_win_file_if_exists ( 'C:/Temp/deferred_ok.txt' )
3178 expect ( out [ :exists ] ) . to be ( true )
3279 expect ( out [ :content ] . strip ) . to eq ( 'hello-file' )
3380 end
3481
3582 it '02: passing Deferred via variable to DSC resolves to hello-dsc (otherwise flag bug)' do
36- apply = apply_manifest ( dsc_deferred_direct )
83+ apply = apply_manifest_with_flags ( dsc_deferred_direct )
3784 out = read_win_file_if_exists ( 'C:/Temp/from_dsc.txt' )
3885 content = out [ :content ] . strip
3986 if out [ :exists ] && content == 'hello-dsc'
@@ -47,7 +94,7 @@ def read_win_file_if_exists(path)
4794
4895 # NEW 02b: inline Deferred on the DSC property (no variable intermediary)
4996 it '02b: passing Deferred inline to DSC resolves to hello-dsc-inline (otherwise flag bug)' do
50- apply = apply_manifest ( dsc_deferred_inline )
97+ apply = apply_manifest_with_flags ( dsc_deferred_inline )
5198 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_inline.txt' )
5299 content = out [ :content ] . strip
53100 if out [ :exists ] && content == 'hello-dsc-inline'
@@ -60,15 +107,15 @@ def read_win_file_if_exists(path)
60107 end
61108
62109 it '03a: stringifying a Deferred writes the function form (reproduces customer report)' do
63- apply_manifest ( dsc_deferred_stringified )
110+ apply_manifest_with_flags ( dsc_deferred_stringified )
64111 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_string.txt' )
65112 expect ( out [ :exists ] ) . to be ( true )
66113 expect ( out [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
67114 expect ( out [ :content ] ) . not_to match ( %r{\b hello-var\b } )
68115 end
69116
70117 it '03b: unwrap on a non‑Sensitive is a no‑op; also writes the function form' do
71- apply_manifest ( dsc_deferred_bad_unwrap )
118+ apply_manifest_with_flags ( dsc_deferred_bad_unwrap )
72119 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_bad_unwrap.txt' )
73120 out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var.txt' ) unless out [ :exists ]
74121 expect ( out [ :exists ] ) . to be ( true )
0 commit comments