test(15-01): add failing test for enable_semantic_segmentation field

- Test KBSettings has enable_semantic_segmentation field with bool type
- Test default value is True
- Test environment variable override (KB_ENABLE_SEMANTIC_SEGMENTATION)
- Test boolean string parsing (true/false, yes/no, 1/0)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 23:01:20 +08:00
parent bc26765d17
commit f2a1847557
+66
View File
@@ -148,3 +148,69 @@ class TestKBSettingsEnvFile:
def test_kbsettings_model_config_ignores_extra(self):
"""Test KBSettings model_config ignores extra fields"""
assert KBSettings.model_config.get("extra") == "ignore"
class TestEnableSemanticSegmentationField:
"""Tests for enable_semantic_segmentation field (CONFIG-01)"""
def test_kbsettings_has_enable_semantic_segmentation_field(self):
"""Test KBSettings has enable_semantic_segmentation field"""
settings = KBSettings(
base_path="/tmp/kb",
archive_path="/tmp/archive"
)
assert hasattr(settings, "enable_semantic_segmentation"), \
"KBSettings should have enable_semantic_segmentation field"
assert isinstance(settings.enable_semantic_segmentation, bool), \
"enable_semantic_segmentation should be bool type"
def test_enable_semantic_segmentation_default_value(self):
"""Test default value is True"""
with patch.dict(os.environ, {}, clear=True):
settings = KBSettings(
base_path="/tmp/kb",
archive_path="/tmp/archive",
_env_file=None
)
assert settings.enable_semantic_segmentation is True, \
"enable_semantic_segmentation should default to True"
def test_enable_semantic_segmentation_from_env(self):
"""Test KB_ENABLE_SEMANTIC_SEGMENTATION env var is respected"""
with patch.dict(os.environ, {
"KB_ENABLE_SEMANTIC_SEGMENTATION": "false"
}, clear=False):
get_settings.cache_clear()
settings = KBSettings(
base_path="/tmp/kb",
archive_path="/tmp/archive"
)
assert settings.enable_semantic_segmentation is False, \
"enable_semantic_segmentation should be False when env var is 'false'"
def test_enable_semantic_segmentation_boolean_parsing(self):
"""Test boolean string parsing (true/false, yes/no, 1/0)"""
test_cases = [
("true", True),
("True", True),
("TRUE", True),
("yes", True),
("1", True),
("false", False),
("False", False),
("FALSE", False),
("no", False),
("0", False),
]
for env_value, expected in test_cases:
with patch.dict(os.environ, {
"KB_ENABLE_SEMANTIC_SEGMENTATION": env_value
}, clear=False):
get_settings.cache_clear()
settings = KBSettings(
base_path="/tmp/kb",
archive_path="/tmp/archive"
)
assert settings.enable_semantic_segmentation is expected, \
f"Failed for env_value={env_value}, expected={expected}"