From f4e4e3af877fcc781c21a05abdf485211683aac6 Mon Sep 17 00:00:00 2001 From: "John-Mason P. Shackelford" Date: Sat, 1 Jun 2024 11:50:43 -0400 Subject: [PATCH] Added check to ensure verbose output contains environment variables set with .env --- aider/main.py | 6 ++++++ aider/tests/test_main.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/aider/main.py b/aider/main.py index 8799acd6c..ac8281d4d 100644 --- a/aider/main.py +++ b/aider/main.py @@ -124,6 +124,12 @@ def check_gitignore(git_root, io, ask=True): def format_settings(parser, args): show = scrub_sensitive_info(args, parser.format_values()) + # clean up the headings for consistency w/ new lines + heading_env = "Environment Variables:" + heading_defaults = "Defaults:" + if heading_env in show: + show = show.replace(heading_env, "\n" + heading_env) + show = show.replace(heading_defaults, "\n" + heading_defaults) show += "\n" show += "Option settings:\n" for arg, val in sorted(vars(args).items()): diff --git a/aider/tests/test_main.py b/aider/tests/test_main.py index 7eebe1351..83e0d1234 100644 --- a/aider/tests/test_main.py +++ b/aider/tests/test_main.py @@ -1,6 +1,7 @@ import os import subprocess import tempfile +from io import StringIO from pathlib import Path from unittest import TestCase from unittest.mock import MagicMock, patch @@ -304,3 +305,18 @@ class TestMain(TestCase): MockCoder.assert_called_once() _, kwargs = MockCoder.call_args self.assertEqual(kwargs["show_diffs"], True) + + def test_verbose_mode_lists_env_vars(self): + self.create_env_file(".env", "AIDER_DARK_MODE=on") + with patch("sys.stdout", new_callable=StringIO) as mock_stdout: + main(["--no-git", "--verbose"], input=DummyInput(), output=DummyOutput()) + output = mock_stdout.getvalue() + relevant_output = "\n".join( + line + for line in output.splitlines() + if "AIDER_DARK_MODE" in line or "dark_mode" in line + ) # this bit just helps failing assertions to be easier to read + self.assertIn("AIDER_DARK_MODE", relevant_output) + self.assertIn("dark_mode", relevant_output) + self.assertRegex(relevant_output, r"AIDER_DARK_MODE:\s+on") + self.assertRegex(relevant_output, r"dark_mode:\s+True")