fix: 移除 hardcode 输入文件路径,完善输入验证 - Closes #8
CI / test (pull_request) Successful in 9s

- 移除 _DEFAULT_INPUT 硬编码默认输入文件路径
- INPUT_JSON 仅从 IR_INPUT_JSON 环境变量获取
- load_input_document() 无输入时给出明确错误提示
- 新增 test_no_hardcoded_input_file / test_set_input_file_accepts_none

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 16:16:49 +08:00
parent 73291803b6
commit c2affcad42
2 changed files with 50 additions and 6 deletions
+27
View File
@@ -19,6 +19,33 @@ def test_set_input_file():
config.set_input_file(original)
def test_no_hardcoded_input_file():
"""INPUT_JSON should not have a hardcoded default — comes from env or None."""
# When IR_INPUT_JSON env is not set, INPUT_JSON should be None
env_val = os.environ.pop("IR_INPUT_JSON", None)
try:
import importlib
importlib.reload(config)
# After reload without env var, INPUT_JSON should be None
assert config.INPUT_JSON is None, \
f"INPUT_JSON should be None when env not set, got: {config.INPUT_JSON}"
finally:
if env_val is not None:
os.environ["IR_INPUT_JSON"] = env_val
importlib.reload(config)
def test_set_input_file_accepts_none():
"""set_input_file(None) should work for resetting."""
original = config.INPUT_JSON
try:
config.set_input_file("/tmp/test.json")
config.set_input_file(None)
assert config.INPUT_JSON is None
finally:
config.set_input_file(original)
def test_config_constants_exist():
"""Verify all expected path constants are defined."""
assert config.BASE_DIR