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/4] 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/4] 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 From 3ec820a0559d4e27c6d362222b34afd406c6ff9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 3 Aug 2026 20:55:45 +0000 Subject: [PATCH 3/4] Skip metadata-dependent tests when frontmatter is malformed Co-authored-by: ahpook <56753+ahpook@users.noreply.github.com> --- test/collections_test.rb | 6 ++++++ test/test_helper.rb | 10 ++++++++++ test/topics_test.rb | 2 ++ 3 files changed, 18 insertions(+) diff --git a/test/collections_test.rb b/test/collections_test.rb index d75cabe903fc..b76a7f3f54a2 100644 --- a/test/collections_test.rb +++ b/test/collections_test.rb @@ -26,6 +26,8 @@ end it "has valid items" do + skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) + invalid_slugs = [] items_for_collection(collection).each do |item| @@ -38,6 +40,8 @@ end it "has valid number of items" do + skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) + items = items_for_collection(collection) assert (1...MAX_COLLECTION_ITEMS_LENGTH + 1).cover?(items.length), "must have no more than #{MAX_COLLECTION_ITEMS_LENGTH} items " \ @@ -76,6 +80,8 @@ end it "has expected metadata in Jekyll front matter" do + skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) + metadata = metadata_for(collections_dir, collection) refute_empty metadata, "expected some metadata for collection" diff --git a/test/test_helper.rb b/test/test_helper.rb index cf205d617803..d9b202ddbc0b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -256,6 +256,16 @@ def metadata_for(dir, name) end end +def frontmatter_malformed?(dir, name) + frontmatter = frontmatter_for(dir, name) + return false unless frontmatter + + YAML.safe_load(frontmatter) + false +rescue Psych::SyntaxError + true +end + def yaml_syntax_error_for(dir, name) frontmatter = frontmatter_for(dir, name) return unless frontmatter diff --git a/test/topics_test.rb b/test/topics_test.rb index 3609e2b262c6..a6636ec1f416 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -275,6 +275,8 @@ end it "has expected metadata in Jekyll front matter" do + skip "malformed YAML frontmatter" if frontmatter_malformed?(topics_dir, topic) + metadata = metadata_for(topics_dir, topic) refute_empty metadata, "expected some metadata for topic" From 94afb0a916a1078a5db8b445a41bc70d5df35997 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 3 Aug 2026 21:11:12 +0000 Subject: [PATCH 4/4] Centralize malformed-frontmatter skip in metadata_for Co-authored-by: ahpook <56753+ahpook@users.noreply.github.com> --- test/collections_test.rb | 6 ------ test/test_helper.rb | 14 +++----------- test/topics_test.rb | 2 -- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/test/collections_test.rb b/test/collections_test.rb index b76a7f3f54a2..d75cabe903fc 100644 --- a/test/collections_test.rb +++ b/test/collections_test.rb @@ -26,8 +26,6 @@ end it "has valid items" do - skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) - invalid_slugs = [] items_for_collection(collection).each do |item| @@ -40,8 +38,6 @@ end it "has valid number of items" do - skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) - items = items_for_collection(collection) assert (1...MAX_COLLECTION_ITEMS_LENGTH + 1).cover?(items.length), "must have no more than #{MAX_COLLECTION_ITEMS_LENGTH} items " \ @@ -80,8 +76,6 @@ end it "has expected metadata in Jekyll front matter" do - skip "malformed YAML frontmatter" if frontmatter_malformed?(collections_dir, collection) - metadata = metadata_for(collections_dir, collection) refute_empty metadata, "expected some metadata for collection" diff --git a/test/test_helper.rb b/test/test_helper.rb index d9b202ddbc0b..461217f2a8a7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -252,20 +252,12 @@ def metadata_for(dir, name) begin YAML.safe_load(frontmatter) rescue Psych::SyntaxError - nil + # Malformed frontmatter is reported by the dedicated YAML syntax test. + # Skip metadata-dependent tests here so that syntax test is the sole failure. + skip "malformed YAML frontmatter in #{File.join(dir, name, 'index.md')}" end end -def frontmatter_malformed?(dir, name) - frontmatter = frontmatter_for(dir, name) - return false unless frontmatter - - YAML.safe_load(frontmatter) - false -rescue Psych::SyntaxError - true -end - def yaml_syntax_error_for(dir, name) frontmatter = frontmatter_for(dir, name) return unless frontmatter diff --git a/test/topics_test.rb b/test/topics_test.rb index a6636ec1f416..3609e2b262c6 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -275,8 +275,6 @@ end it "has expected metadata in Jekyll front matter" do - skip "malformed YAML frontmatter" if frontmatter_malformed?(topics_dir, topic) - metadata = metadata_for(topics_dir, topic) refute_empty metadata, "expected some metadata for topic"