refs #701: load console profile overrides from dotenv

This commit is contained in:
devmrko
2026-07-22 13:01:40 +09:00
parent a2112e07dc
commit 323f746d8a
3 changed files with 35 additions and 5 deletions

View File

@@ -6921,7 +6921,7 @@ def _process_submitted_question(
def main() -> None:
try:
profile = load_app_profile(APP_PROFILE_FILE)
profile = load_app_profile(APP_PROFILE_FILE, ENV_FILE)
except AppProfileError as exc:
st.set_page_config(page_title="AI 업무 에이전트", layout="wide")
st.error(str(exc))

View File

@@ -61,17 +61,38 @@ def resolve_profile_path(default_path: Path) -> Path:
return path if path.is_absolute() else default_path.parent / path
def _apply_environment_overrides(profile: AppProfile) -> AppProfile:
def _dotenv_value(name: str, path: Path | None) -> str:
"""Read one simple KEY=value runtime setting without importing a dotenv lib."""
if path is None:
return ""
try:
lines = path.read_text(encoding="utf-8").splitlines()
except (OSError, UnicodeError):
return ""
prefix = f"{name}="
for line in lines:
stripped = line.strip()
if stripped.startswith(prefix):
return stripped[len(prefix) :].strip().strip('"').strip("'")
return ""
def _apply_environment_overrides(profile: AppProfile, env_file: Path | None) -> AppProfile:
"""Apply deployment-specific presentation values without a code change."""
values = {
field_name: os.environ.get(env_name, "").strip() or getattr(profile, field_name)
field_name: (
os.environ.get(env_name, "").strip()
or _dotenv_value(env_name, env_file)
or getattr(profile, field_name)
)
for field_name, env_name in _ENV_FIELD_NAMES.items()
}
return AppProfile(**values)
def load_app_profile(default_path: Path) -> AppProfile:
def load_app_profile(default_path: Path, env_file: Path | None = None) -> AppProfile:
"""Load the selectable product skin without coupling it to a PoC name."""
path = resolve_profile_path(default_path)
@@ -101,7 +122,7 @@ def load_app_profile(default_path: Path) -> AppProfile:
text_color=_string(theme, "text_color"),
muted_color=_string(theme, "muted_color"),
border_color=_string(theme, "border_color"),
))
), env_file)
required = (
profile.product_name,
profile.short_name,

View File

@@ -28,6 +28,15 @@ class DemoScenarioConfigTest(unittest.TestCase):
self.assertEqual(profile.page_title, "HMM AI 업무 에이전트")
self.assertEqual(profile.primary_color, "#003b70")
def test_profile_reads_dotenv_values(self) -> None:
path = Path(__file__).parents[1] / "config" / "app_profile.json"
with tempfile.TemporaryDirectory() as temp_dir:
env_file = Path(temp_dir) / ".env"
env_file.write_text("AGENT_CONSOLE_SHORT_NAME=HMM\n", encoding="utf-8")
profile = load_app_profile(path, env_file)
self.assertEqual(profile.short_name, "HMM")
def test_hmm_scenarios_are_enabled_and_unique(self) -> None:
path = Path(__file__).parents[1] / "config" / "hmm_demo_scenarios.json"
scenarios = load_demo_scenarios(path)