@@ -117,6 +117,35 @@ def test_nav_yml_paths_exist():
117117 assert not errors , f"Missing nav paths:\n { error_msg } "
118118
119119
120+ def test_internal_directory_links_valid (markdown_files ):
121+ """Test that internal directory-style links (trailing slash) resolve to existing paths."""
122+ errors = []
123+ # Match relative links with trailing slash: ](path/) or href="path/"
124+ md_pattern = re .compile (r"\]\(([^)h][^)]*?/)\)" )
125+ href_pattern = re .compile (r'href="([^"h][^"]*?/)"' )
126+
127+ for md_file in markdown_files :
128+ with open (md_file ) as f :
129+ content = f .read ()
130+ file_dir = os .path .dirname (md_file )
131+
132+ for pattern in [md_pattern , href_pattern ]:
133+ for match in pattern .finditer (content ):
134+ link = match .group (1 )
135+ target_dir = os .path .normpath (os .path .join (file_dir , link ))
136+ target_index = os .path .join (target_dir , "index.md" )
137+ # A trailing-slash link is valid if the directory has index.md
138+ # or if a .md file exists with the same name (MkDocs resolves both)
139+ target_md = os .path .normpath (os .path .join (file_dir , link .rstrip ("/" ))) + ".md"
140+
141+ if not (os .path .exists (target_index ) or os .path .exists (target_md )):
142+ rel_path = os .path .relpath (md_file , DOCS_DIR )
143+ errors .append (f"{ rel_path } -> { link } " )
144+
145+ error_msg = "\n " .join (errors )
146+ assert not errors , f"Broken internal directory links:\n { error_msg } "
147+
148+
120149def test_no_trailing_spaces_in_urls (markdown_files ):
121150 """Test that URLs don't have trailing spaces before closing paren."""
122151 errors = []
0 commit comments