File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1479,7 +1479,7 @@ def from_path(
14791479 """
14801480 # If the config path is a file, we load the YAML content.
14811481 # Otherwise, if it's a folder, we iterate through all files.
1482- if config_path . endswith ( ".yaml" ) or config_path .endswith (". yml" ):
1482+ if os . path . isfile ( config_path ) and config_path .endswith (( ".yaml" , ". yml") ):
14831483 with open (config_path ) as f :
14841484 raw_config = yaml .safe_load (f .read ())
14851485
Original file line number Diff line number Diff line change 1515
1616import logging
1717import os
18+ import tempfile
19+ from pathlib import Path
1820from unittest import mock
1921
2022import pytest
@@ -117,6 +119,33 @@ def test_rails_config_from_path():
117119 assert config .sample_conversation is not None
118120
119121
122+ def test_rails_config_from_path_yml_extension ():
123+ """Test loading RailsConfig when the config directory ends with a .yml suffix.
124+
125+ Ensures a directory mistakenly named with a YAML extension is treated as a directory,
126+ not a file, and its internal YAML config is loaded properly.
127+ """
128+
129+ with tempfile .TemporaryDirectory (suffix = ".yml" ) as temp_dir :
130+ temp_path = Path (temp_dir )
131+
132+ minimal_yaml = (
133+ "models: []\n "
134+ "instructions:\n "
135+ " - type: general\n "
136+ " content: Test instruction\n "
137+ "sample_conversation: Test conversation\n "
138+ )
139+
140+ # place a config file inside the directory-with-.yml suffix
141+ (temp_path / "config.yml" ).write_text (minimal_yaml )
142+
143+ config = RailsConfig .from_path (str (temp_path ))
144+ assert config is not None
145+ assert len (config .instructions ) > 0
146+ assert config .sample_conversation is not None
147+
148+
120149def test_rails_config_parse_obj ():
121150 """Test parsing RailsConfig from object."""
122151
You can’t perform that action at this time.
0 commit comments