@@ -7,82 +7,69 @@ def read_fixture(name)
77 File . read ( File . join ( __dir__ , '..' , 'fixtures' , 'manifests' , name ) )
88end
99
10- # Returns a struct-like Hash: { exists: true|false, content: String }
1110def read_win_file_if_exists ( path )
12- # Always exit 0; emit a marker if the file is missing
1311 ps = %{$p='#{ path } '; if (Test-Path -LiteralPath $p) { Get-Content -Raw -LiteralPath $p } else { '<<<FILE_NOT_FOUND>>>' }}
14- r = run_shell ( %(powershell.exe -NoProfile -NonInteractive -Command "#{ ps } ") )
12+ r = run_shell ( %(powershell.exe -NoProfile -NonInteractive -Command "#{ ps } ") )
1513 body = ( r . stdout || '' ) . to_s
16- missing = body . include? ( '<<<FILE_NOT_FOUND>>>' )
17- { exists : !missing , content : ( missing ? '' : body ) }
14+ { exists : !body . include? ( '<<<FILE_NOT_FOUND>>>' ) , content : body . include? ( '<<<FILE_NOT_FOUND>>>' ) ? '' : body }
1815end
1916
2017describe 'deferred values with dsc_lite' do
2118 let ( :control_manifest ) { read_fixture ( '01_file_deferred.pp' ) }
2219 let ( :dsc_deferred_direct ) { read_fixture ( '02_dsc_deferred_direct.pp' ) }
20+ let ( :dsc_deferred_inline ) { read_fixture ( '02b_dsc_deferred_inline.pp' ) } # <— NEW
2321 let ( :dsc_deferred_stringified ) { read_fixture ( '03a_dsc_deferred_stringified.pp' ) }
2422 let ( :dsc_deferred_bad_unwrap ) { read_fixture ( '03b_dsc_deferred_bad_unwrap.pp' ) }
2523
2624 it 'control (01): native file + Deferred resolves to hello-file' do
2725 result = idempotent_apply ( control_manifest )
2826 expect ( result . exit_code ) . to eq ( 0 )
29-
30- r = read_win_file_if_exists ( 'C:/Temp/deferred_ok.txt' )
31- expect ( r [ :exists ] ) . to be ( true ) , 'C:/Temp/deferred_ok.txt was not created'
32- expect ( r [ :content ] . strip ) . to eq ( 'hello-file' )
27+ out = read_win_file_if_exists ( 'C:/Temp/deferred_ok.txt' )
28+ expect ( out [ :exists ] ) . to be ( true )
29+ expect ( out [ :content ] . strip ) . to eq ( 'hello-file' )
3330 end
3431
35- context 'dsc_lite with Deferred' do
36- it '02: passing Deferred directly to DSC resolves to hello-dsc (otherwise flag bug with diagnostics)' do
37- apply = apply_manifest ( dsc_deferred_direct ) # not expecting failures by default
38- apply_output = ( apply . stdout . to_s + apply . stderr . to_s )
39-
40- r = read_win_file_if_exists ( 'C:/Temp/from_dsc.txt' )
41-
42- if r [ :exists ] && r [ :content ] . strip == 'hello-dsc'
43- # ✅ good case
44- expect ( true ) . to be ( true )
45- elsif r [ :exists ] && r [ :content ] =~ %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i
46- # ❌ bug: stringified wrapper made it through to DSC
47- raise <<~MSG
48- BUG: DSC wrote a stringified Deferred instead of the resolved value.
49- Content:
50- #{ r [ :content ] . inspect }
51- Puppet apply output:
52- #{ apply_output }
53- MSG
54- else
55- # ❌ file missing or unexpected content
56- raise <<~MSG
57- Unexpected outcome for 02_dsc_deferred_direct.
58- File exists? #{ r [ :exists ] }
59- Content (trimmed): #{ r [ :content ] . strip . inspect }
60- Puppet apply output:
61- #{ apply_output }
62- MSG
63- end
32+ it '02: passing Deferred via variable to DSC resolves to hello-dsc (otherwise flag bug)' do
33+ apply = apply_manifest ( dsc_deferred_direct )
34+ out = read_win_file_if_exists ( 'C:/Temp/from_dsc.txt' )
35+ content = out [ :content ] . strip
36+ if out [ :exists ] && content == 'hello-dsc'
37+ expect ( true ) . to be ( true )
38+ elsif out [ :exists ] && content =~ %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i
39+ raise "BUG: 02 wrote stringified Deferred: #{ content . inspect } \n Apply:\n #{ apply . stdout } #{ apply . stderr } "
40+ else
41+ raise "Unexpected 02 outcome. Exists=#{ out [ :exists ] } Content=#{ content . inspect } \n Apply:\n #{ apply . stdout } #{ apply . stderr } "
6442 end
43+ end
6544
66- it '03a: stringifying a Deferred writes the function form (reproduces customer report)' do
67- apply = apply_manifest ( dsc_deferred_stringified )
68- expect ( apply . exit_code ) . to eq ( 2 ) . or eq ( 0 ) # change or noop is fine
69-
70- r = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_string.txt' )
71- expect ( r [ :exists ] ) . to be ( true ) , 'C:/Temp/from_dsc_var_string.txt was not created'
72- expect ( r [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
73- expect ( r [ :content ] ) . not_to match ( %r{\b hello-var\b } )
45+ # NEW 02b: inline Deferred on the DSC property (no variable intermediary)
46+ it '02b: passing Deferred inline to DSC resolves to hello-dsc-inline (otherwise flag bug)' do
47+ apply = apply_manifest ( dsc_deferred_inline )
48+ out = read_win_file_if_exists ( 'C:/Temp/from_dsc_inline.txt' )
49+ content = out [ :content ] . strip
50+ if out [ :exists ] && content == 'hello-dsc-inline'
51+ expect ( true ) . to be ( true )
52+ elsif out [ :exists ] && content =~ %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i
53+ raise "BUG: 02b wrote stringified Deferred: #{ content . inspect } \n Apply:\n #{ apply . stdout } #{ apply . stderr } "
54+ else
55+ raise "Unexpected 02b outcome. Exists=#{ out [ :exists ] } Content=#{ content . inspect } \n Apply:\n #{ apply . stdout } #{ apply . stderr } "
7456 end
57+ end
7558
76- it '03b: bad unwrap on a Deferred does NOT fail compilation; it also writes the function form' do
77- # unwrap on non-Sensitive returns the argument unchanged, so this will NOT fail compilation.
78- # It will stringify the Deferred and write that text via DSC (same symptom as 03a). [1](https://docs.huihoo.com/puppet/puppet/2.7/reference/lang_resources.html)
79- apply = apply_manifest ( dsc_deferred_bad_unwrap )
80- expect ( apply . exit_code ) . to eq ( 2 ) . or eq ( 0 )
59+ it '03a: stringifying a Deferred writes the function form (reproduces customer report)' do
60+ apply = apply_manifest ( dsc_deferred_stringified )
61+ out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_string.txt' )
62+ expect ( out [ :exists ] ) . to be ( true )
63+ expect ( out [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
64+ expect ( out [ :content ] ) . not_to match ( %r{\b hello-var\b } )
65+ end
8166
82- r = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_bad_unwrap.txt' )
83- expect ( r [ :exists ] ) . to be ( true ) , 'C:/Temp/from_dsc_var_bad_unwrap.txt was not created'
84- expect ( r [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
85- expect ( r [ :content ] ) . not_to match ( %r{\b hello-var\b } )
86- end
67+ it '03b: unwrap on a non‑Sensitive is a no‑op; also writes the function form' do
68+ apply = apply_manifest ( dsc_deferred_bad_unwrap )
69+ out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var_bad_unwrap.txt' )
70+ out = read_win_file_if_exists ( 'C:/Temp/from_dsc_var.txt' ) unless out [ :exists ]
71+ expect ( out [ :exists ] ) . to be ( true )
72+ expect ( out [ :content ] ) . to match ( %r{Deferred\s *\( |Puppet::Pops::Types::Deferred}i )
73+ expect ( out [ :content ] ) . not_to match ( %r{\b hello-var\b } )
8774 end
8875end
0 commit comments