From 80eb6d2dba7403d1c2db7089026da49d1f98ef0e Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Wed, 19 Aug 2026 17:56:16 +0000 Subject: [PATCH 1/2] Fix hiera.yaml write race in the pupmod spec_helper template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The config-level before(:all) hook rewrites spec/fixtures/hieradata/hiera.yaml with a truncating write before every top-level example group. Under `rake parallel_spec`, every worker runs this hook, and a catalogue compile in another worker that reads hiera.yaml inside the truncate-to-write window sees an empty hiera config and silently compiles without any custom hieradata. This is the confirmed root cause of the fleet-wide random hieradata-not-applied spec failures (ref #90) — not the set_hieradata global-state design originally suspected. Reproduced deterministically in pupmod-simp-simplib by rewriting hiera.yaml in a tight loop while running dlookup_spec (simp/pupmod-simp-simplib#362, fixed there by simp/pupmod-simp-simplib#363 with this same change). Write the file atomically instead: write to a PID-suffixed temp file in the same directory and rename it into place. Readers then always see a complete hiera.yaml. The temp file must be in the same directory -- rename(2) is only atomic within a filesystem. Ref #90 Co-Authored-By: Claude Fable 5 --- .../profile/templates/pupmod/spec/spec_helper.rb.epp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/profile/templates/pupmod/spec/spec_helper.rb.epp b/modules/profile/templates/pupmod/spec/spec_helper.rb.epp index f9ab869..ed1b829 100644 --- a/modules/profile/templates/pupmod/spec/spec_helper.rb.epp +++ b/modules/profile/templates/pupmod/spec/spec_helper.rb.epp @@ -131,9 +131,13 @@ RSpec.configure do |c| end end - File.open(c.hiera_config, 'w') do |f| - f.write data.to_yaml - end + # Write atomically (write + rename) — every parallel_spec worker runs + # this hook, and a truncating write here can be observed as an empty + # hiera.yaml by a catalogue compile in another worker, silently dropping + # all custom hieradata (simp/pupmod-simp-simplib#362) + tmpfile = "#{c.hiera_config}.#{Process.pid}" + File.write(tmpfile, data.to_yaml) + File.rename(tmpfile, c.hiera_config) end # rubocop:enable RSpec/BeforeAfterAll From fd3be0f29c1474e316abc80e05eab7011582cd98 Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Thu, 20 Aug 2026 16:28:16 +0000 Subject: [PATCH 2/2] Add session config: fleet rollout of the spec_helper write-race fix Co-Authored-By: Claude Fable 5 --- .../configs/20260820-spec-helper-race.yaml | 61 +++++++++++++++++++ data/sync/configs/latest.yaml | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 data/sync/configs/20260820-spec-helper-race.yaml diff --git a/data/sync/configs/20260820-spec-helper-race.yaml b/data/sync/configs/20260820-spec-helper-race.yaml new file mode 100644 index 0000000..2f262ce --- /dev/null +++ b/data/sync/configs/20260820-spec-helper-race.yaml @@ -0,0 +1,61 @@ +--- +# Roll out the spec_helper.rb hiera.yaml write-race fix (PR #91, closes +# #90) to all pupmod repos. +# +# Every parallel_spec worker's before(:all) hook truncate-rewrites the +# shared spec/fixtures/hieradata/hiera.yaml; a catalogue compile in +# another worker during the truncation window sees an empty hiera config +# and silently drops all custom hieradata — the source of the fleet's +# random hieradata-not-applied spec failures. The fix writes atomically +# (write + rename). Validated on pupmod-simp-simplib#363 (merged). +# +# spec/spec_helper.rb is enforce-strategy, and the fleet baseline was +# just re-asserted (#42), so each repo's diff is exactly the atomic-write +# hunk. simplib already carries the fix and will come out "unchanged". +# +# Dynamic-inventory session: run with `repolist=github-org` (or point +# the repolists latest.yaml there). +puppetsync::plan_config: + puppetsync: + permitted_project_types: + - pupmod + - pupmod_skeleton + plans: + sync: + github_api_delay_seconds: 1 + stages: + - install_gems + - checkout_git_feature_branch_in_each_repo + - apply_puppet_role + - git_commit_changes + - ensure_github_fork + - ensure_git_remote + - git_push_to_remote + - ensure_github_pr + + approve_github_prs: + stages: + - approve_github_pr_for_each_repo + + merge_github_prs: + stages: + - merge_github_pr_for_each_repo + + git: + feature_branch: puppetsync/20260820-spec-helper-race + commit_message: | + [puppetsync] Fix hiera.yaml write race in spec_helper + + Every parallel_spec worker's before(:all) hook rewrote the shared + spec/fixtures/hieradata/hiera.yaml in place; a catalogue compile in + another worker during the truncation window saw an empty hiera + config and silently dropped all custom hieradata, producing random + hieradata-not-applied spec failures across the fleet. hiera.yaml is + now written atomically (write + rename). + + See simp/puppetsync#90; validated on simp/pupmod-simp-simplib#363. + + github: + pr_user: silug # This should be the account that *submitted* the PRs + # (Used by idempotency checks when approving/merging PRs) + approval_message: ':+1: :ghost:' diff --git a/data/sync/configs/latest.yaml b/data/sync/configs/latest.yaml index 80132ff..80c24ff 120000 --- a/data/sync/configs/latest.yaml +++ b/data/sync/configs/latest.yaml @@ -1 +1 @@ -20260813-baseline-refresh.yaml \ No newline at end of file +20260820-spec-helper-race.yaml \ No newline at end of file