Skip to content

fix(stdlib::manage) parser fails $type resources#1477

Merged
alexjfisher merged 1 commit into
puppetlabs:mainfrom
jcpunk:strict
Jul 2, 2026
Merged

fix(stdlib::manage) parser fails $type resources#1477
alexjfisher merged 1 commit into
puppetlabs:mainfrom
jcpunk:strict

Conversation

@jcpunk

@jcpunk jcpunk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

When the puppet parser is set to its strictest mode, $type is not converted to the actual type and instead produces a catalog error.

Eventually the strict parser will be required everywhere, so we should prepare for it.

pdk test unit works just fine. It appears to not require the strict parser.

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

3cf1f1e

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

@alexjfisher

Copy link
Copy Markdown
Collaborator

@jcpunk Did this ever work? I think there's an issue with the tests, and the with resources to create ones are not actually being run.

@alexjfisher

Copy link
Copy Markdown
Collaborator

If I comment out the Puppet::Functions.create_function bits in the tests, then they are run.

diff --git a/spec/classes/manage_spec.rb b/spec/classes/manage_spec.rb
index db4b6a64..4b3f6068 100644
--- a/spec/classes/manage_spec.rb
+++ b/spec/classes/manage_spec.rb
@@ -70,12 +70,12 @@ describe 'stdlib::manage' do
       }
     end

-    Puppet::Functions.create_function(:epp) do
-      return 'I am an epp template'
-    end
-    Puppet::Functions.create_function(:template) do
-      return 'I am an erb template'
-    end
+    # Puppet::Functions.create_function(:epp) do
+    #   return 'I am an epp template'
+    # end
+    # Puppet::Functions.create_function(:template) do
+    #   return 'I am an erb template'
+    # end

     it { is_expected.to compile }
     it { is_expected.to contain_file('/etc/motd.d/hello').with_content('I say Hi').with_notify('Service[sshd]') }

but fail with...

Evaluation Error: Illegal Resource Type expression, expected result to be a type name, or untitled Resource, got String

which is presumably the issue you are fixing. (This error happens regardless of the strict setting and across all versions of Puppet I've tested from 5.x to 8.x)

@alexjfisher

Copy link
Copy Markdown
Collaborator

To fix the tests, mock erb and template like this...

diff --git a/spec/classes/manage_spec.rb b/spec/classes/manage_spec.rb
index db4b6a64..509c7c04 100644
--- a/spec/classes/manage_spec.rb
+++ b/spec/classes/manage_spec.rb
@@ -16,6 +16,9 @@ describe 'stdlib::manage' do
       <<-PRECOND
         file { '/etc/motd.d' : }
         service { 'sshd' : }
+
+        function epp(*$args) { 'I am an epp template' }
+        function template(*$args) { 'I am an erb template' }
       PRECOND
     end
     let :params do
@@ -70,13 +73,6 @@ describe 'stdlib::manage' do
       }
     end

-    Puppet::Functions.create_function(:epp) do
-      return 'I am an epp template'
-    end
-    Puppet::Functions.create_function(:template) do
-      return 'I am an erb template'
-    end
-
     it { is_expected.to compile }
     it { is_expected.to contain_file('/etc/motd.d/hello').with_content('I say Hi').with_notify('Service[sshd]') }
     it { is_expected.to contain_file('/etc/motd').with_content(%r{I am an epp template}) }

Without this bundle exec rspec spec/classes/manage_spec.rb produces...

stdlib::manage
  on redhat-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on redhat-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on redhat-9-x86_64
    is expected to compile into a catalogue without dependency cycles
  on centos-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on centos-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on oraclelinux-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on scientific-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on sles-12-x86_64
    is expected to compile into a catalogue without dependency cycles
  on sles-15-x86_64
    is expected to compile into a catalogue without dependency cycles
  on debian-11-x86_64
    is expected to compile into a catalogue without dependency cycles
  on debian-12-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-18.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-20.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-22.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-10-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2012-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2012 R2-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2016-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2019-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2022-x86_64
    is expected to compile into a catalogue without dependency cycles
  on rocky-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on almalinux-8-x86_64
    is expected to compile into a catalogue without dependency cycles

Code coverage
  must cover at least 0% of resources


Coverage Report:

Total resources:   0
Touched resources: 0
Resource coverage: 100.00%

Finished in 0.83279 seconds (files took 2.6 seconds to load)
23 examples, 0 failures

with that change to the spec test, (and your fix)

stdlib::manage
  on redhat-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on redhat-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on redhat-9-x86_64
    is expected to compile into a catalogue without dependency cycles
  on centos-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on centos-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on oraclelinux-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on scientific-7-x86_64
    is expected to compile into a catalogue without dependency cycles
  on sles-12-x86_64
    is expected to compile into a catalogue without dependency cycles
  on sles-15-x86_64
    is expected to compile into a catalogue without dependency cycles
  on debian-11-x86_64
    is expected to compile into a catalogue without dependency cycles
  on debian-12-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-18.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-20.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on ubuntu-22.04-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-10-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2012-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2012 R2-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2016-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2019-x86_64
    is expected to compile into a catalogue without dependency cycles
  on windows-2022-x86_64
    is expected to compile into a catalogue without dependency cycles
  on rocky-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  on almalinux-8-x86_64
    is expected to compile into a catalogue without dependency cycles
  with resources to create
    is expected to compile into a catalogue without dependency cycles
    is expected to contain File[/etc/motd.d/hello] with content  supplied string and notify => "Service[sshd]"
    is expected to contain File[/etc/motd] with content =~ /I am an epp template/
    is expected to contain File[/etc/information] with content =~ /I am an erb template/
    is expected to contain Concat[/tmp/filename]
    is expected to contain Concat::Fragment[rawcontent] with content  supplied string
    is expected to contain Concat::Fragment[eppcontent] with content =~ /I am an epp template/
    is expected to contain Concat::Fragment[erbcontent] with content =~ /I am an erb template/
    is expected to contain Package[example] that subscribes to Service[sshd] and File[/etc/motd.d]

Code coverage
  must cover at least 0% of resources


Coverage Report:

Total resources:   8
Touched resources: 8
Resource coverage: 100.00%

Finished in 1.47 seconds (files took 2.59 seconds to load)
32 examples, 0 failures

@alexjfisher alexjfisher left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please fix the tests too.

@alexjfisher

Copy link
Copy Markdown
Collaborator

Looks good, but please fix the tests too.

(and also update the commit message, as the fix isn't related to strict. Looks like this code was always broken)

The string definition of the type resource is not converted by the
parser to the actual type definition.

Signed-off-by: Pat Riehecky <riehecky@fnal.gov>
@jcpunk

jcpunk commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

When I tested the initial patch I'd swear it did work. But I'm unable to replicate it now. Someone I'm not going to name publicly, swapped out my fetch of my internal fork to a different branch with this fix applied but no internal ticket noting the change.

So, as the initial patch author, I'll own the breakage since it is in fact broken and I wrote it....

I've manually ensured my test environment on my pilot server works from the branch on this PR (rather than my internal mirror).

Does the updated PR look better?

@jcpunk jcpunk changed the title fix(stdlib::manage) strict parser fails $type resources fix(stdlib::manage) parser fails $type resources Jul 1, 2026
@alexjfisher

Copy link
Copy Markdown
Collaborator

When I tested the initial patch I'd swear it did work. But I'm unable to replicate it now. Someone I'm not going to name publicly, swapped out my fetch of my internal fork to a different branch with this fix applied but no internal ticket noting the change.

So, as the initial patch author, I'll own the breakage since it is in fact broken and I wrote it....

I've manually ensured my test environment on my pilot server works from the branch on this PR (rather than my internal mirror).

Does the updated PR look better?

No worries. Fix looks correct however we got here, (and apologies if the tone of my posts came across accusatory).

I can't remember a similar case where rspec-puppet tests were silently not run. I enjoyed figuring that one out!

@alexjfisher alexjfisher merged commit 5ee4ac5 into puppetlabs:main Jul 2, 2026
6 of 7 checks passed
@jcpunk

jcpunk commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

:) no worries

@jcpunk jcpunk deleted the strict branch July 2, 2026 14:32
@jcpunk

jcpunk commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the merge, any chance for a 10.0.2 release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants