import tempfile
import unittest
from pathlib import Path

from fgai.config import ConfigStore


class ConfigTests(unittest.TestCase):
    def test_public_config_hides_token_and_preserves_blank_update(self):
        with tempfile.TemporaryDirectory() as directory:
            store = ConfigStore(str(Path(directory) / "config.json"))
            store.update({"log_source": "graylog_mcp", "graylog_mcp_token": "secret"})
            public = store.update({"graylog_mcp_token": ""})
            self.assertEqual(public["log_source"], "graylog_mcp")
            self.assertTrue(public["graylog_mcp_token_configured"])
            self.assertNotIn("graylog_mcp_token", public)


if __name__ == "__main__":
    unittest.main()
