feat: add --api-key flag to set provider API keys as env vars

This commit is contained in:
Paul Gauthier (aider) 2024-12-07 08:23:50 -08:00
parent 1d4918dfbf
commit 13ff038e58
3 changed files with 42 additions and 0 deletions

View file

@ -706,6 +706,29 @@ class TestMain(TestCase):
result = main(["--set-env", "INVALID_FORMAT", "--exit", "--yes"])
self.assertEqual(result, 1)
def test_api_key_single(self):
# Test setting a single API key
with GitTemporaryDirectory():
main(["--api-key", "anthropic=test-key", "--exit", "--yes"])
self.assertEqual(os.environ.get("ANTHROPIC_API_KEY"), "test-key")
def test_api_key_multiple(self):
# Test setting multiple API keys
with GitTemporaryDirectory():
main([
"--api-key", "anthropic=key1",
"--api-key", "openai=key2",
"--exit", "--yes"
])
self.assertEqual(os.environ.get("ANTHROPIC_API_KEY"), "key1")
self.assertEqual(os.environ.get("OPENAI_API_KEY"), "key2")
def test_api_key_invalid_format(self):
# Test invalid format handling
with GitTemporaryDirectory():
result = main(["--api-key", "INVALID_FORMAT", "--exit", "--yes"])
self.assertEqual(result, 1)
def test_invalid_edit_format(self):
with GitTemporaryDirectory():
with patch("aider.io.InputOutput.offer_url") as mock_offer_url: