From 212d2f6337385476c9ec2831baab6e48abaeeb3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 18:17:23 +0000 Subject: [PATCH 1/2] Add isolated YAML frontmatter validation test for topics and collections --- test/collections_test.rb | 5 +++++ test/test_helper.rb | 17 ++++++++++++++++- test/topics_test.rb | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/collections_test.rb b/test/collections_test.rb index 657c832f40b5..d75cabe903fc 100644 --- a/test/collections_test.rb +++ b/test/collections_test.rb @@ -3,6 +3,11 @@ describe "collections" do collections.each do |collection| describe "#{collection} collection" do + it "has valid YAML frontmatter" do + error = yaml_syntax_error_for(collections_dir, collection) + assert_nil error, error + end + unless ENV["AUTOCORRECT_RENAMED_REPOS"] == "1" it "has a valid name" do assert valid_collection?(collection), invalid_collection_message(collection) diff --git a/test/test_helper.rb b/test/test_helper.rb index b7af1b1b983c..7022ebab5cae 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -244,8 +244,23 @@ def metadata_for(dir, name) begin YAML.safe_load(parts[1]) + rescue Psych::SyntaxError + nil + end +end + +def yaml_syntax_error_for(dir, name) + path = File.join(dir, name, "index.md") + return unless File.file?(path) + + parts = File.read(path).split("---", 3) + return unless parts.size >= 2 + + begin + YAML.safe_load(parts[1]) + nil rescue Psych::SyntaxError => error - flunk "invalid YAML: #{error.message}" + "invalid YAML in #{path}: #{error.message}" end end diff --git a/test/topics_test.rb b/test/topics_test.rb index fd7ea440e960..3609e2b262c6 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -9,6 +9,11 @@ topics.each do |topic| describe "#{topic} topic" do + it "has valid YAML frontmatter" do + error = yaml_syntax_error_for(topics_dir, topic) + assert_nil error, error + end + it "has a valid name" do assert valid_topic?(topic), invalid_topic_message(topic) end From e14fdd66512fbf0f517dc5c0a440d64290fa6de4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 18:18:06 +0000 Subject: [PATCH 2/2] Extract shared frontmatter_for helper to reduce duplication --- test/test_helper.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 7022ebab5cae..cf205d617803 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -235,32 +235,36 @@ def valid_uri_scheme?(scheme) %w[http https].include?(scheme.downcase) end -def metadata_for(dir, name) +def frontmatter_for(dir, name) path = File.join(dir, name, "index.md") return unless File.file?(path) parts = File.read(path).split("---", 3) return unless parts.size >= 2 + parts[1] +end + +def metadata_for(dir, name) + frontmatter = frontmatter_for(dir, name) + return unless frontmatter + begin - YAML.safe_load(parts[1]) + YAML.safe_load(frontmatter) rescue Psych::SyntaxError nil end end def yaml_syntax_error_for(dir, name) - path = File.join(dir, name, "index.md") - return unless File.file?(path) - - parts = File.read(path).split("---", 3) - return unless parts.size >= 2 + frontmatter = frontmatter_for(dir, name) + return unless frontmatter begin - YAML.safe_load(parts[1]) + YAML.safe_load(frontmatter) nil rescue Psych::SyntaxError => error - "invalid YAML in #{path}: #{error.message}" + "invalid YAML in #{File.join(dir, name, 'index.md')}: #{error.message}" end end