fix: regex for api key shell export

This commit is contained in:
ali 2025-09-04 19:26:53 +03:00
parent 8753e54b58
commit 97f658cd6b
No known key found for this signature in database
GPG key ID: 44F9B42770617B9B
2 changed files with 9 additions and 1 deletions

View file

@ -15,7 +15,9 @@ if os.name == "nt": # Windows
SHELL_RC_EXPORT_PATTERN = re.compile(r"^set CODEFLASH_API_KEY=(cf-.*)$", re.MULTILINE)
SHELL_RC_EXPORT_PREFIX = "set CODEFLASH_API_KEY="
else:
SHELL_RC_EXPORT_PATTERN = re.compile(r'^(?!#)export CODEFLASH_API_KEY=[\'"]?(cf-[^\s"]+)[\'"]$', re.MULTILINE)
SHELL_RC_EXPORT_PATTERN = re.compile(
r'^(?!#)export CODEFLASH_API_KEY=(?:"|\')?(cf-[^\s"\']+)(?:"|\')?$', re.MULTILINE
)
SHELL_RC_EXPORT_PREFIX = "export CODEFLASH_API_KEY="

View file

@ -64,6 +64,12 @@ class TestReadApiKeyFromShellConfig(unittest.TestCase):
) as mock_file:
self.assertEqual(read_api_key_from_shell_config(), None)
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
with patch(
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY={self.api_key}\n')
) as mock_file:
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
@patch("codeflash.code_utils.shell_utils.get_shell_rc_path")
def test_no_api_key(self, mock_get_shell_rc_path):