Skip to content

Commit 02d738d

Browse files
author
Kit (OpenClaw)
committed
Add script/rails7_migration_patterns_check for migration doc structure validation
Closes #912 (WA-VERIFY-048) Adds a read-only Ruby script that scans docs/rails7-migration-patterns/*.md (excluding README.md) and verifies each file contains headings for the four required sections: Symptom, Root cause, Detection, Fix. - Exits 0 with a summary when all docs pass - Exits 1 and lists file(s) + missing sections when structure is incomplete - No modifications to docs; purely a validation tool
1 parent 2ace18c commit 02d738d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# script/rails7_migration_patterns_check
5+
#
6+
# Validates that each Rails 7 migration pattern doc contains the required
7+
# structural headings: Symptom, Root cause, Detection, Fix.
8+
#
9+
# Usage:
10+
# ./script/rails7_migration_patterns_check
11+
#
12+
# Exit codes:
13+
# 0 — all docs pass
14+
# 1 — one or more docs are missing required sections
15+
16+
DOCS_DIR = File.expand_path("../docs/rails7-migration-patterns", __dir__)
17+
REQUIRED_SECTIONS = %w[Symptom Detection Fix].freeze
18+
# "Root cause" contains a space so we match it separately
19+
REQUIRED_SECTIONS_EXTRA = ["Root cause"].freeze
20+
ALL_REQUIRED = (REQUIRED_SECTIONS + REQUIRED_SECTIONS_EXTRA).freeze
21+
22+
docs = Dir.glob(File.join(DOCS_DIR, "*.md")).reject { |f| File.basename(f) == "README.md" }.sort
23+
24+
if docs.empty?
25+
puts "No migration pattern docs found in #{DOCS_DIR}"
26+
exit 1
27+
end
28+
29+
failures = {}
30+
31+
docs.each do |path|
32+
content = File.read(path, encoding: "utf-8")
33+
missing = ALL_REQUIRED.reject do |section|
34+
# Match markdown headings of any level (## Symptom, ### Root cause, etc.)
35+
content.match?(/^#+\s+#{Regexp.escape(section)}\b/i)
36+
end
37+
failures[path] = missing unless missing.empty?
38+
end
39+
40+
if failures.empty?
41+
puts "✅ All #{docs.size} migration pattern doc(s) passed structure check."
42+
puts " Required sections present in every file: #{ALL_REQUIRED.join(', ')}"
43+
exit 0
44+
else
45+
puts "❌ Structure check failed — #{failures.size} file(s) missing required sections:\n\n"
46+
failures.each do |path, missing|
47+
rel = path.sub("#{Dir.pwd}/", "")
48+
puts " #{rel}"
49+
missing.each { |s| puts " • missing: #{s}" }
50+
puts
51+
end
52+
puts "Required sections: #{ALL_REQUIRED.join(', ')}"
53+
exit 1
54+
end

0 commit comments

Comments
 (0)