/ docs / test / link_validation_report.jl
link_validation_report.jl
  1  #!/usr/bin/env julia
  2  
  3  """
  4  Link Validation and Repair Script
  5  
  6  This script identifies broken links in the documentation and provides
  7  specific fixes for the most common issues found in the user journey testing.
  8  """
  9  
 10  using Test
 11  
 12  # Track issues found
 13  issues_found = String[]
 14  fixes_applied = String[]
 15  
 16  function validate_and_fix_links()
 17      println("šŸ” Analyzing Documentation Links...")
 18      
 19      # Common broken link patterns and their fixes
 20      link_fixes = Dict(
 21          # Fix malformed links with brackets in URLs
 22          r"\[([^\]]+)\]\(\.\./guides/\[strategy\]\([^)]+\)" => s"[\1](../guides/strategy-development.md)",
 23          r"\[([^\]]+)\]\(\.\./\[exchanges\]\([^)]+\)" => s"[\1](../exchanges.md)",
 24          r"\[([^\]]+)\]\(\.\./\[optimization\]\([^)]+\)" => s"[\1](../optimization.md)",
 25          r"\[([^\]]+)\]\(\.\./\[troubleshooting\]\([^)]+\)" => s"[\1](../troubleshooting/index.md)",
 26          
 27          # Fix double relative paths
 28          r"getting-started/getting-started/" => "getting-started/",
 29          r"guides/guides/" => "guides/",
 30          r"troubleshooting/troubleshooting/" => "troubleshooting/",
 31          
 32          # Fix malformed anchor links
 33          r"\[simulation\]\([^)]+\#simulation-mode\)" => "simulation",
 34          r"\[backtesting\]\([^)]+\#simulation-mode\)" => "backtesting",
 35          r"\[live trading\]\([^)]+\#live-mode\)" => "live trading",
 36          
 37          # Fix nested bracket issues
 38          r"\[([^\]]+)\]\([^)]*\[([^\]]+)\]\([^)]*\)" => s"[\1](../guides/strategy-development.md)",
 39      )
 40      
 41      # Files to check and fix
 42      files_to_fix = [
 43          "docs/src/index.md",
 44          "docs/src/getting-started/index.md",
 45          "docs/src/getting-started/installation.md", 
 46          "docs/src/getting-started/quick-start.md",
 47          "docs/src/getting-started/first-strategy.md"
 48      ]
 49      
 50      for filepath in files_to_fix
 51          if !isfile(filepath)
 52              push!(issues_found, "Missing file: $filepath")
 53              continue
 54          end
 55          
 56          println("šŸ“„ Checking $filepath...")
 57          content = read(filepath, String)
 58          original_content = content
 59          
 60          # Apply fixes
 61          for (pattern, replacement) in link_fixes
 62              if occursin(pattern, content)
 63                  content = replace(content, pattern => replacement)
 64                  push!(fixes_applied, "Fixed pattern in $filepath: $pattern")
 65              end
 66          end
 67          
 68          # Write back if changes were made
 69          if content != original_content
 70              write(filepath, content)
 71              println("  āœ… Applied fixes to $filepath")
 72          else
 73              println("  ā„¹ļø  No fixes needed for $filepath")
 74          end
 75      end
 76      
 77      # Check for missing referenced files
 78      missing_files = [
 79          "docs/src/exchanges.md",
 80          "docs/src/optimization.md", 
 81          "docs/src/resources/community.md",
 82          "docs/src/resources/search.md",
 83          "docs/src/guides/monitoring.md",
 84          "docs/src/advanced/risk-management.md"
 85      ]
 86      
 87      for file in missing_files
 88          if !isfile(file)
 89              push!(issues_found, "Referenced but missing: $file")
 90          end
 91      end
 92      
 93      return length(issues_found), length(fixes_applied)
 94  end
 95  
 96  function create_missing_files()
 97      println("\nšŸ“ Creating Missing Referenced Files...")
 98      
 99      # Create missing files with basic content
100      missing_files_content = Dict(
101          "docs/src/exchanges.md" => """---
102  title: "Exchange Integration"
103  category: "reference"
104  difficulty: "intermediate"
105  topics: [exchanges, configuration]
106  last_updated: "2025-10-04"
107  ---
108  
109  # Exchange Integration
110  
111  Documentation for exchange integration and configuration.
112  
113  ## See Also
114  - [Getting Started](getting-started/index.md)
115  - [Configuration](reference/configuration.md)
116  """,
117          
118          "docs/src/optimization.md" => """---
119  title: "Strategy Optimization"
120  category: "advanced"
121  difficulty: "advanced"
122  topics: [optimization, strategy-development]
123  last_updated: "2025-10-04"
124  ---
125  
126  # Strategy Optimization
127  
128  Guide to optimizing trading strategy parameters.
129  
130  ## See Also
131  - [Strategy Development](guides/strategy-development.md)
132  - [Performance Analysis](guides/performance-analysis.md)
133  """,
134          
135          "docs/src/resources/community.md" => """---
136  title: "Community Resources"
137  category: "resources"
138  difficulty: "beginner"
139  topics: [community, support]
140  last_updated: "2025-10-04"
141  ---
142  
143  # Community Resources
144  
145  Connect with the Planar community for support and collaboration.
146  
147  ## See Also
148  - [Getting Started](../getting-started/index.md)
149  - [Troubleshooting](../troubleshooting/index.md)
150  """,
151          
152          "docs/src/resources/search.md" => """---
153  title: "Search Documentation"
154  category: "resources"
155  difficulty: "beginner"
156  topics: [search, navigation]
157  last_updated: "2025-10-04"
158  ---
159  
160  # Search Documentation
161  
162  Search functionality for finding information quickly.
163  
164  ## See Also
165  - [Documentation Index](../documentation-index.md)
166  """,
167          
168          "docs/src/guides/monitoring.md" => """---
169  title: "Strategy Monitoring"
170  category: "guides"
171  difficulty: "intermediate"
172  topics: [monitoring, live-trading]
173  last_updated: "2025-10-04"
174  ---
175  
176  # Strategy Monitoring
177  
178  Monitor your trading strategies in real-time.
179  
180  ## See Also
181  - [Execution Modes](execution-modes.md)
182  - [Live Trading](../advanced/live-trading.md)
183  """,
184          
185          "docs/src/advanced/risk-management.md" => """---
186  title: "Risk Management"
187  category: "advanced"
188  difficulty: "advanced"
189  topics: [risk-management, trading]
190  last_updated: "2025-10-04"
191  ---
192  
193  # Risk Management
194  
195  Advanced risk management techniques for trading strategies.
196  
197  ## See Also
198  - [Strategy Development](../guides/strategy-development.md)
199  - [Live Trading](live-trading.md)
200  """
201      )
202      
203      created_count = 0
204      for (filepath, content) in missing_files_content
205          if !isfile(filepath)
206              # Create directory if needed
207              mkpath(dirname(filepath))
208              write(filepath, content)
209              println("  āœ… Created $filepath")
210              created_count += 1
211          end
212      end
213      
214      return created_count
215  end
216  
217  function validate_code_examples()
218      println("\nšŸ’» Validating Code Examples...")
219      
220      # Check for common code issues in documentation
221      code_issues = String[]
222      
223      files_to_check = [
224          "docs/src/getting-started/installation.md",
225          "docs/src/getting-started/quick-start.md"
226      ]
227      
228      for filepath in files_to_check
229          if !isfile(filepath)
230              continue
231          end
232          
233          content = read(filepath, String)
234          
235          # Check for malformed code in markdown
236          if occursin(r"\[strategy\]\([^)]+\)", content)
237              push!(code_issues, "$filepath: Contains malformed strategy links in code blocks")
238          end
239          
240          if occursin(r"\[exchange\]\([^)]+\)", content)
241              push!(code_issues, "$filepath: Contains malformed exchange links in code blocks")
242          end
243          
244          # Check for proper Julia code formatting
245          julia_blocks = collect(eachmatch(r"```julia\n(.*?)\n```"s, content))
246          for (i, block) in enumerate(julia_blocks)
247              code = block.captures[1]
248              if occursin("[", code) && occursin("](", code)
249                  push!(code_issues, "$filepath: Julia code block $i contains markdown links")
250              end
251          end
252      end
253      
254      return code_issues
255  end
256  
257  # Main execution
258  println("šŸš€ Starting Link Validation and Repair")
259  println(repeat("=", 50))
260  
261  # Step 1: Fix existing links
262  issues_count, fixes_count = validate_and_fix_links()
263  
264  # Step 2: Create missing files
265  created_count = create_missing_files()
266  
267  # Step 3: Validate code examples
268  code_issues = validate_code_examples()
269  
270  # Report results
271  println("\nšŸ“Š VALIDATION RESULTS")
272  println(repeat("=", 50))
273  println("Issues Found: $issues_count")
274  println("Fixes Applied: $fixes_count") 
275  println("Files Created: $created_count")
276  println("Code Issues: $(length(code_issues))")
277  
278  if !isempty(issues_found)
279      println("\nāŒ ISSUES FOUND:")
280      for issue in issues_found
281          println("  • $issue")
282      end
283  end
284  
285  if !isempty(fixes_applied)
286      println("\nāœ… FIXES APPLIED:")
287      for fix in fixes_applied[1:min(5, length(fixes_applied))]  # Show first 5
288          println("  • $fix")
289      end
290      if length(fixes_applied) > 5
291          println("  • ... and $(length(fixes_applied) - 5) more")
292      end
293  end
294  
295  if !isempty(code_issues)
296      println("\nāš ļø  CODE ISSUES:")
297      for issue in code_issues
298          println("  • $issue")
299      end
300  end
301  
302  println("\nšŸŽ‰ Link validation completed!")