Skip to content

Commit 714b26c

Browse files
dafyddcrosbymeta-codesync[bot]
authored andcommitted
Add JSON recipe literals (reports)
Summary: Now that JSON recipes support including recipes, we need to take those literals into account in downstream reports. Reviewed By: joshuamiller01 Differential Revision: D90605826 fbshipit-source-id: 6aa8fb5a209e9d0572ff4eade8cf1be59902cced
1 parent 31729cd commit 714b26c

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/reports/MissingReferencedRecipes.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def to_h
3535
end
3636
end
3737
end
38+
@kb.recipejsons.each do |kbrecipe, metadata|
39+
metadata['IncludeRecipeLiterals'].each do |recipe|
40+
unless known_recipes.include? recipe
41+
missing['recipes'][kbrecipe] ||= []
42+
missing['recipes'][kbrecipe].append recipe
43+
end
44+
end
45+
end
3846
missing
3947
end
4048

cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/reports/NotReferencedRecipes.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def to_a
2727
referenced_recipes << recipe
2828
end
2929
end
30+
@kb.recipejsons.each do |_, metadata|
31+
metadata['IncludeRecipeLiterals'].each do |recipe|
32+
referenced_recipes << recipe
33+
end
34+
end
3035
all_recipes = Set.new(@kb.recipes.keys + @kb.recipejsons.keys)
3136
# Any recipes which weren't included via roles or include_recipe are not referenced
3237
(all_recipes - referenced_recipes).sort.to_a

cookbooks/fb_bookworm/files/default/bookworm/spec/reports/MissingReferencedRecipes_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,27 @@
7575
expect(output).to include('fb_nonexistent::setup')
7676
end
7777
end
78+
79+
describe 'with JSON recipes referencing missing recipes' do
80+
let(:roles) { {} }
81+
let(:recipes) do
82+
{
83+
'fb_existing::default' => {
84+
'IncludeRecipeLiterals' => [],
85+
},
86+
}
87+
end
88+
let(:recipejsons) do
89+
{
90+
'fb_json::default' => {
91+
'IncludeRecipeLiterals' => ['fb_existing::default', 'fb_missing_from_json::setup'],
92+
},
93+
}
94+
end
95+
96+
it 'returns missing recipes from JSON recipes' do
97+
result = report.to_h
98+
expect(result['recipes']['fb_json::default']).to eq(['fb_missing_from_json::setup'])
99+
end
100+
end
78101
end

cookbooks/fb_bookworm/files/default/bookworm/spec/reports/NotReferencedRecipes_spec.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
end
5757
let(:recipejsons) do
5858
{
59-
'fb_json_unused::default' => {},
59+
'fb_json_unused::default' => {
60+
'IncludeRecipeLiterals' => [],
61+
},
6062
}
6163
end
6264

@@ -74,4 +76,26 @@
7476
])
7577
end
7678
end
79+
80+
describe 'with JSON recipes referencing other recipes' do
81+
let(:roles) { {} }
82+
let(:recipes) do
83+
{
84+
'fb_target::default' => {
85+
'IncludeRecipeLiterals' => [],
86+
},
87+
}
88+
end
89+
let(:recipejsons) do
90+
{
91+
'fb_json::default' => {
92+
'IncludeRecipeLiterals' => ['fb_target::default'],
93+
},
94+
}
95+
end
96+
97+
it 'marks recipes referenced by JSON recipes as referenced' do
98+
expect(report.to_a).to eq(['fb_json::default'])
99+
end
100+
end
77101
end

0 commit comments

Comments
 (0)