roksta 0.2.6__cp314-cp314-macosx_10_13_universal2.whl → 0.3.1__cp314-cp314-macosx_10_13_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of roksta might be problematic. Click here for more details.

Files changed (76) hide show
  1. roksta/ai/call_ai.cpython-314-darwin.so +0 -0
  2. roksta/ai/gemini.cpython-314-darwin.so +0 -0
  3. roksta/ai/generic.cpython-314-darwin.so +0 -0
  4. roksta/ai/llm.cpython-314-darwin.so +0 -0
  5. roksta/ai/openai.cpython-314-darwin.so +0 -0
  6. roksta/ai/tools/__init__.cpython-314-darwin.so +0 -0
  7. roksta/ai/tools/delete_file.cpython-314-darwin.so +0 -0
  8. roksta/ai/tools/edit_file.cpython-314-darwin.so +0 -0
  9. roksta/ai/tools/final_response.cpython-314-darwin.so +0 -0
  10. roksta/ai/tools/get_file_summaries.cpython-314-darwin.so +0 -0
  11. roksta/ai/tools/read_file.cpython-314-darwin.so +0 -0
  12. roksta/ai/tools/regex_replace.cpython-314-darwin.so +0 -0
  13. roksta/ai/tools/shell_any.cpython-314-darwin.so +0 -0
  14. roksta/ai/tools/shell_limited.cpython-314-darwin.so +0 -0
  15. roksta/ai/tools/tool_defs.cpython-314-darwin.so +0 -0
  16. roksta/ai/tools/tool_utils.cpython-314-darwin.so +0 -0
  17. roksta/ai/tools/write_file.cpython-314-darwin.so +0 -0
  18. roksta/balance.cpython-314-darwin.so +0 -0
  19. roksta/check_for_updates.cpython-314-darwin.so +0 -0
  20. roksta/command_handlers/__init__.cpython-314-darwin.so +0 -0
  21. roksta/command_handlers/handle_activate_command.cpython-314-darwin.so +0 -0
  22. roksta/command_handlers/handle_add_funds_command.cpython-314-darwin.so +0 -0
  23. roksta/command_handlers/handle_auto_charge_command.cpython-314-darwin.so +0 -0
  24. roksta/command_handlers/handle_auto_commit_command.cpython-314-darwin.so +0 -0
  25. roksta/command_handlers/handle_building_command.cpython-314-darwin.so +0 -0
  26. roksta/command_handlers/handle_chat_command.cpython-314-darwin.so +0 -0
  27. roksta/command_handlers/handle_dev_rate_command.cpython-314-darwin.so +0 -0
  28. roksta/command_handlers/handle_feedback_command.cpython-314-darwin.so +0 -0
  29. roksta/command_handlers/handle_goal_command.cpython-314-darwin.so +0 -0
  30. roksta/command_handlers/handle_help_command.cpython-314-darwin.so +0 -0
  31. roksta/command_handlers/handle_init_command.cpython-314-darwin.so +0 -0
  32. roksta/command_handlers/handle_linting_command.cpython-314-darwin.so +0 -0
  33. roksta/command_handlers/handle_login_command.cpython-314-darwin.so +0 -0
  34. roksta/command_handlers/handle_logout_command.cpython-314-darwin.so +0 -0
  35. roksta/command_handlers/handle_payment_details_command.cpython-314-darwin.so +0 -0
  36. roksta/command_handlers/handle_quit_command.cpython-314-darwin.so +0 -0
  37. roksta/command_handlers/handle_redeem_command.cpython-314-darwin.so +0 -0
  38. roksta/command_handlers/handle_request_activation_command.cpython-314-darwin.so +0 -0
  39. roksta/command_handlers/handle_testing_command.cpython-314-darwin.so +0 -0
  40. roksta/command_handlers/handle_usage_command.cpython-314-darwin.so +0 -0
  41. roksta/default_config.cpython-314-darwin.so +0 -0
  42. roksta/env.cpython-314-darwin.so +0 -0
  43. roksta/extended_text_area.cpython-314-darwin.so +0 -0
  44. roksta/firebase.cpython-314-darwin.so +0 -0
  45. roksta/fix_tests.cpython-314-darwin.so +0 -0
  46. roksta/gen_codebase_summaries.cpython-314-darwin.so +0 -0
  47. roksta/goal_workflow.cpython-314-darwin.so +0 -0
  48. roksta/init_codebase.cpython-314-darwin.so +0 -0
  49. roksta/lint_code.cpython-314-darwin.so +0 -0
  50. roksta/main.cpython-314-darwin.so +0 -0
  51. roksta/new_features.cpython-314-darwin.so +0 -0
  52. roksta/roksta.cpython-314-darwin.so +0 -0
  53. roksta/tips.cpython-314-darwin.so +0 -0
  54. roksta/utils.cpython-314-darwin.so +0 -0
  55. {roksta-0.2.6.dist-info → roksta-0.3.1.dist-info}/METADATA +2 -1
  56. roksta-0.3.1.dist-info/RECORD +109 -0
  57. tests/conftest.py +42 -0
  58. tests/functions/{api_v0_01 → api_v1_01}/__init__.py +1 -1
  59. tests/functions/{api_v0_01 → api_v1_01}/test__analytics.py +2 -3
  60. tests/functions/{api_v0_01 → api_v1_01}/test__gemini_proxy.py +51 -6
  61. tests/functions/{api_v0_01 → api_v1_01}/test__generic_proxy.py +31 -2
  62. tests/functions/{api_v0_01 → api_v1_01}/test__get_payment_details.py +2 -2
  63. tests/functions/{api_v0_01 → api_v1_01}/test__openai_proxy.py +50 -14
  64. tests/functions/{api_v0_01 → api_v1_01}/test__redeem_credit_code.py +2 -2
  65. tests/functions/{api_v0_01 → api_v1_01}/test__sync_emails.py +3 -2
  66. tests/functions/{api_v0_01 → api_v1_01}/test__take_payment.py +2 -2
  67. tests/functions/{api_v0_01 → api_v1_01}/test__use_activation_code.py +3 -2
  68. tests/functions/test_utils.py +484 -0
  69. roksta/ai/tools.cpython-314-darwin.so +0 -0
  70. roksta/command_handlers.cpython-314-darwin.so +0 -0
  71. roksta-0.2.6.dist-info/RECORD +0 -78
  72. tests/functions/test_utils_functions.py +0 -222
  73. {roksta-0.2.6.dist-info → roksta-0.3.1.dist-info}/WHEEL +0 -0
  74. {roksta-0.2.6.dist-info → roksta-0.3.1.dist-info}/entry_points.txt +0 -0
  75. {roksta-0.2.6.dist-info → roksta-0.3.1.dist-info}/top_level.txt +0 -0
  76. /tests/functions/{test_main_functions.py → test_main.py} +0 -0
@@ -1,78 +0,0 @@
1
- roksta-0.2.6.dist-info/RECORD,,
2
- roksta-0.2.6.dist-info/WHEEL,sha256=kTyoa6dywfGfyBeUsEKMOPsM0w-CaDJ_dSETLrKd4uk,142
3
- roksta-0.2.6.dist-info/entry_points.txt,sha256=mzRdYg_DlzZRwjxYUt9-gyoRCkM1QBTeTbwETgiTdGw,44
4
- roksta-0.2.6.dist-info/top_level.txt,sha256=lvciNZQ1dPGXpiCLdWVXK03n9fKHjbQdwjqQbnUjeYM,13
5
- roksta-0.2.6.dist-info/METADATA,sha256=gBXNX4iwCT9vychi5wNnmihf7ptAXoiAymfGKYchiNo,1427
6
- roksta/balance.cpython-314-darwin.so,sha256=Fk1LS4rVuruNwjcKV4pawpa9kTx3FWNHGEmsK9cNAWA,340432
7
- roksta/propose_solution.cpython-314-darwin.so,sha256=Wubg-p21XHZ5NLvvQUzCNkxGnyGq_EwUQUv4WaTWOyM,207496
8
- roksta/gen_codebase_summaries.cpython-314-darwin.so,sha256=IBeUeRqccCV_D39rsktPcvIKkpiR-7mzxuG9spCaRsw,637936
9
- roksta/codebase_listing.cpython-314-darwin.so,sha256=Kxtkn9xa9WOqLXUXrLw_3vGP6VJsfXWe_db-D0EWiLA,155608
10
- roksta/__init__.cpython-314-darwin.so,sha256=EL2fuUK0drBv_kRWrblymcUCrc8PcfoFZkxUTWRE4cE,85648
11
- roksta/default_config.cpython-314-darwin.so,sha256=TC5tHkaMXczwS0jYK7veAzvTFneBt7VPYqd9GaRn1Uw,102248
12
- roksta/create_default_config.cpython-314-darwin.so,sha256=bMeI3fxxRJQ0IJmhtotbYkkUMZun7ymFaa9BmVeYu1M,121608
13
- roksta/make_issue.cpython-314-darwin.so,sha256=NyqUA_THUg1R3iBGLeZhFQVTVw9fS9tDwTF9P7RoIgk,221856
14
- roksta/firebase_auth_web.cpython-314-darwin.so,sha256=uZSGuAUadl1JhHMin_UiVNe7NfLsE-4UQvNgybCQWxo,489048
15
- roksta/fix_tests.cpython-314-darwin.so,sha256=g27HScuadiggXvgdBJlwFIBHz1Qqx3yNbZi67YTemxY,240704
16
- roksta/get_failing_tests.cpython-314-darwin.so,sha256=tZyV_x70kDu92_4gwlACDyAxY2vsEMRJ0XoFuBwSOGQ,224296
17
- roksta/env.cpython-314-darwin.so,sha256=18E4wTcHZhyVuhmuyxRaiol8tNeA8CMlx9pjktFUb30,87832
18
- roksta/roksta.cpython-314-darwin.so,sha256=kI9sTFkuJQHanJV-pFpRjia-sRX8RVZarV3SPYVNsio,588128
19
- roksta/clarify_goal.cpython-314-darwin.so,sha256=jy2iw0fv86k6y7J-nGVm3JAaSHRnU74tnCS0FMRkrbQ,207808
20
- roksta/run_cli_goal.cpython-314-darwin.so,sha256=l1mTdfSfJwCESJS3RgxVsylTe3zTr_E6PTrudP1yf_o,223968
21
- roksta/rewrite_goal.cpython-314-darwin.so,sha256=kUrDcnDo0NPmeoG2sFiEVAKhmTnCqk7PJGktyCrzmCg,191072
22
- roksta/build_project.cpython-314-darwin.so,sha256=SHRxDasBlCqsqQrh4gs45ZMTa5q5WK-rZnvdjIQtYvU,191184
23
- roksta/analytics.cpython-314-darwin.so,sha256=zsP32jnFDlB_O0RUPmsFV8ajEexRMAJEgFuQUSmJmY4,289680
24
- roksta/command_handlers.cpython-314-darwin.so,sha256=La_oUhxiNPXrl8fNXi_8tzoUzbWBskT9Jxw8SLBSPv8,966584
25
- roksta/main.cpython-314-darwin.so,sha256=W3NXMp8keVb_i1gK4R9lAg4pTdVpnu6_HYblY4meYZ0,122184
26
- roksta/utils.cpython-314-darwin.so,sha256=cgeW3SKvZh3nXwHVDvM9iD-EMHNA_dOI9yZic3fZSeM,589128
27
- roksta/check_for_updates.cpython-314-darwin.so,sha256=-aVFV7CiOakaWutOOqGb2Po_E1qFYTAjYWTu9uorjKM,206904
28
- roksta/response_formats.cpython-314-darwin.so,sha256=yLrtRaRY87oQrwk_KHlKbYJxxxwcCmp7sGXLByj8j7I,120968
29
- roksta/select_files.cpython-314-darwin.so,sha256=D2MxqKwSUQDKeSamsAgj2moxwEsBu54N40OQS7DYQks,207792
30
- roksta/goal_workflow.cpython-314-darwin.so,sha256=ttaW0GZJsjayOogc8deCoEzzTsNzC7Lfo6QyJt3vjiw,521008
31
- roksta/parse_readme.cpython-314-darwin.so,sha256=VVKOmQO5Rx9AmvwiYyuHqaS4YZgzF4IdUb5YmwoxFqA,207280
32
- roksta/firebase.cpython-314-darwin.so,sha256=88qE-bZ03ssH1uAA4P6SV-bIZlFvPbAYYWK8tDJjvX0,471792
33
- roksta/write_code.cpython-314-darwin.so,sha256=19cEofGYSpK4lz1bwzGmTkS8kTxjE1HF4WiZzX8OtnM,191152
34
- roksta/enums.cpython-314-darwin.so,sha256=LAFSg6tcRyejdBY1ILo9wy1wXy_ShiE31jyF_9L6k90,338344
35
- roksta/tips.cpython-314-darwin.so,sha256=wJwFDKsOGVPHrbfNfXK6XTb6nu6gmd3Y2rS1vCF1w-8,85688
36
- roksta/firebase_config.cpython-314-darwin.so,sha256=odBL74t5UEMoLoOFJK1rmXTnSbXjNpMIEIO6AU6cycY,86328
37
- roksta/gen_one_line_goal.cpython-314-darwin.so,sha256=zs5gGHfaeXPPvg6OuvXhD-nRBwpYc4_eUEmrBK8UCUI,207768
38
- roksta/new_features.cpython-314-darwin.so,sha256=TO9FNiM3NadDYXsQAbO4Q7SGRk9JkSU-CzwOfRW7nQA,85728
39
- roksta/init_codebase.cpython-314-darwin.so,sha256=Pvzno5CdiS6OoHhOmQ1GtHvaXGqH1vU9qBofiOW8-rA,308208
40
- roksta/chat_workflow.cpython-314-darwin.so,sha256=B6Sp8vQOZM0paNYVuEgMkYm3_lDTGtTn0eXKOXkg7V0,273888
41
- roksta/lint_code.cpython-314-darwin.so,sha256=1N1-eXF8fHrJfplMj0cXgj0_xzAErze6SQ-tpufSqDI,208048
42
- roksta/get_codebase_structure.cpython-314-darwin.so,sha256=d3u3L9M9Q3DMhivR98L3PkS21kFb4gcGmbqfOAY9gRo,206240
43
- roksta/checkpoints.cpython-314-darwin.so,sha256=QJ2smLnbWBmVpUtl0Kdlq0Bvl1Av7fa7lp3kxdseEJc,254320
44
- roksta/extended_text_area.cpython-314-darwin.so,sha256=U-nPzf38_zyB5zcJOvoc5cgf0cSZU8hBbisC40pyYoI,290824
45
- roksta/logger.cpython-314-darwin.so,sha256=10IAF2iGigOpOjYYce5yT3brfc8GxOjGpSKLn4XVeJM,122032
46
- roksta/ai/__init__.cpython-314-darwin.so,sha256=BaV83jdQCG8M2_8ycpRBHVWX-QcoeQt2yq-HyFIGnYI,85648
47
- roksta/ai/generic.cpython-314-darwin.so,sha256=0UJ-foXBtB1QCJkFHxrXf9CapUedTpd722bLeNnhblA,306944
48
- roksta/ai/gemini.cpython-314-darwin.so,sha256=0UdPYE-6aWLfUxoBUGct7i7cHdecgo_AlMQIDPF-XGM,422608
49
- roksta/ai/call_ai.cpython-314-darwin.so,sha256=P9obp-3vEqzPpMHG4CKQIPR9bjm8a02n5VUz0-mWLuI,240768
50
- roksta/ai/llm.cpython-314-darwin.so,sha256=a9OORYZXZS0wn8mdhuDmQMBzOr-tumHc1UYhyVzp7_w,271496
51
- roksta/ai/tools.cpython-314-darwin.so,sha256=EFGdl2fU6SfI0MGd81EKst8EiDuFVEpzegWr4LQ3kyU,653976
52
- roksta/ai/openai.cpython-314-darwin.so,sha256=nhZ4YeH6knV937kO-LVM5x5rHTr6WB19I02ScHa_CiU,306928
53
- tests/conftest.py,sha256=WBja46X2wduZRF2t4LARhbNvLlU8oRhSW_HB6ara8Yg,6295
54
- tests/__init__.py,sha256=J6ztnXNqM8TSQCgHXMWb6NRq1kN_h4ql63Jq-TYR8XE,124
55
- tests/functions/test_auth.py,sha256=I3oFTw2LTuUsnQ75v5SCfgUPnpel_pDKqUH0VAJpXQw,992
56
- tests/functions/__init__.py,sha256=mLXx3UARcv07vs_fGJuy3L5ZRn9IRsF9zIuL5IOnwdk,95
57
- tests/functions/test_utils_functions.py,sha256=gS-SxnK0QnVUooxcXlJKodjqOB1HVmUxufwzUPQ7qAk,7368
58
- tests/functions/test_main_functions.py,sha256=h0W_4ISo95WzRy2HpXZw3cuNOTcYk_2QCIZffZJEfEU,2575
59
- tests/functions/api_v1_00/test__sync_emails.py,sha256=OTyf2YbBK7e4pWIQTUGYR4x6il1Hb3g4FYqQ_fRj1nA,12699
60
- tests/functions/api_v1_00/test__take_payment.py,sha256=I-XJasGuLW5wTMAu4nAgFkA8Mo_zVpGPvkJ2LrrJGCk,18022
61
- tests/functions/api_v1_00/test__gemini_proxy.py,sha256=mf8ubRmNxxxN80H6EA-iDPwu6Oue6Rmgxl6tiFNpfrU,13344
62
- tests/functions/api_v1_00/test__analytics.py,sha256=oKjd7_zjnttcb-5BuA93yllkm0OOF4YWnfTUW1-icnM,15806
63
- tests/functions/api_v1_00/__init__.py,sha256=3RCSoj_5UQPw9Z5NeAgYz2s4gfcZIi7g36qk_Ed5TiA,124
64
- tests/functions/api_v1_00/test__use_activation_code.py,sha256=tNyTkkRtrpjei-7F31UNwrcU-PbP-QnkWNU7h2n5Yqo,16960
65
- tests/functions/api_v1_00/test__redeem_credit_code.py,sha256=7GD3tGgO2Lk0BCjUmzZACJiwocEhLBvXrrut0x13IWU,6347
66
- tests/functions/api_v1_00/test__openai_proxy.py,sha256=xlO2zmG64LlrKrbjFz-ds6Map7vy4SjIuHfZJDAqGK8,17726
67
- tests/functions/api_v1_00/test__get_payment_details.py,sha256=i5Px3NkLxqw8D3tVPrYdRJJF5jlNmysSuX_NNolbIa4,13735
68
- tests/functions/api_v1_00/test__generic_proxy.py,sha256=KZkOtmc71aOnWlz2L7B6CFhRNEV73bExG3GR14oD2L0,17673
69
- tests/functions/api_v0_01/test__sync_emails.py,sha256=zCfuh1M6qJlGaCpCWuUE0Ao9Pp5pVkBJXXjoctldkpk,12698
70
- tests/functions/api_v0_01/test__take_payment.py,sha256=2WDv_7cYTozVMl7hDLNDTF9gmfrgna3oR8xgfRa-plA,18022
71
- tests/functions/api_v0_01/test__gemini_proxy.py,sha256=R-lzyVsNtqJFGILKhgy1cUIHg1SYPSFKNDbKp2fua-k,11152
72
- tests/functions/api_v0_01/test__analytics.py,sha256=nMs_aYuXDEFWz9aY21MYwbgugF-czRbucAzis4-8kgc,15807
73
- tests/functions/api_v0_01/__init__.py,sha256=BOIFrFcANRAbpnX0Bez6rtkj6xJnOli1fqzFX5SpkV0,124
74
- tests/functions/api_v0_01/test__use_activation_code.py,sha256=EgifjM9wkW1fkQoBK9z5PEEM5xwpRHyt_g7QWy6xrec,16959
75
- tests/functions/api_v0_01/test__redeem_credit_code.py,sha256=WSs7CE2pkHsied_tg3XCR3RJ9blwQEkOzy-s3lkV_w0,6347
76
- tests/functions/api_v0_01/test__openai_proxy.py,sha256=Nda-RDUVYBQl2wI5mxxr9Ca-9k9HJV5EgEmdIvyytGs,15761
77
- tests/functions/api_v0_01/test__get_payment_details.py,sha256=3LYAp9m1RDsf928HGJ6P_YTji7F4srkDv0iWcKTwW54,13735
78
- tests/functions/api_v0_01/test__generic_proxy.py,sha256=cJftek6njsphK_yesUX1QxphGcD5TEkhQNC5ROvnaIg,16190
@@ -1,222 +0,0 @@
1
- import importlib
2
- import sys
3
- import types
4
- import json
5
- import pytest
6
-
7
-
8
- def _setup_basic_stubs(secret_data=b'MY_SECRET', secret_side_effect=None, auth_verify=lambda token: {'uid': 'u1'}):
9
- """Install minimal stub modules for google.cloud.secretmanager, firebase_functions and firebase_admin.
10
- Returns a dict of original sys.modules entries for cleanup.
11
- """
12
- orig = {}
13
- names = [
14
- 'google',
15
- 'google.cloud',
16
- 'google.cloud.secretmanager',
17
- 'firebase_functions',
18
- 'firebase_admin',
19
- 'firebase_admin.auth',
20
- ]
21
- for name in names:
22
- orig[name] = sys.modules.get(name)
23
-
24
- # google package and submodules
25
- google_mod = types.ModuleType('google')
26
- cloud_mod = types.ModuleType('google.cloud')
27
- secretmanager_mod = types.ModuleType('google.cloud.secretmanager')
28
-
29
- class _Payload:
30
- def __init__(self, data):
31
- self.data = data
32
-
33
- class _Response:
34
- def __init__(self, data):
35
- self.payload = _Payload(data)
36
-
37
- class SecretManagerServiceClient:
38
- def access_secret_version(self, request=None):
39
- if secret_side_effect:
40
- # raise the provided exception instance for testing
41
- raise secret_side_effect
42
- return _Response(secret_data)
43
-
44
- secretmanager_mod.SecretManagerServiceClient = SecretManagerServiceClient
45
- cloud_mod.secretmanager = secretmanager_mod
46
- google_mod.cloud = cloud_mod
47
-
48
- sys.modules['google'] = google_mod
49
- sys.modules['google.cloud'] = cloud_mod
50
- sys.modules['google.cloud.secretmanager'] = secretmanager_mod
51
-
52
- # firebase_functions stub with a Response type expected by utils.create_json_response
53
- firebase_functions_mod = types.ModuleType('firebase_functions')
54
-
55
- class FakeResponse:
56
- def __init__(self, response=None, mimetype=None, status=200, **kwargs):
57
- self.status_code = status
58
- if isinstance(response, (dict, list)):
59
- self._body_text = json.dumps(response)
60
- else:
61
- self._body_text = '' if response is None else response
62
- self.headers = kwargs.get('headers', {})
63
-
64
- def get_data(self, as_text=False):
65
- if as_text:
66
- return self._body_text
67
- return self._body_text.encode('utf-8')
68
-
69
- firebase_functions_mod.https_fn = types.SimpleNamespace(Request=object, Response=FakeResponse)
70
- sys.modules['firebase_functions'] = firebase_functions_mod
71
-
72
- # firebase_admin + auth stub
73
- firebase_admin_mod = types.ModuleType('firebase_admin')
74
- auth_mod = types.ModuleType('firebase_admin.auth')
75
-
76
- def _verify_id_token(token):
77
- return auth_verify(token)
78
-
79
- auth_mod.verify_id_token = _verify_id_token
80
- firebase_admin_mod.auth = auth_mod
81
- sys.modules['firebase_admin'] = firebase_admin_mod
82
- sys.modules['firebase_admin.auth'] = auth_mod
83
-
84
- return orig
85
-
86
-
87
- def _restore_orig(orig):
88
- for name, val in orig.items():
89
- if val is None:
90
- if name in sys.modules:
91
- del sys.modules[name]
92
- else:
93
- sys.modules[name] = val
94
-
95
-
96
- def test_get_secret_key_returns_decoded_string_on_success():
97
- orig = _setup_basic_stubs(secret_data=b'MY_SECRET')
98
- try:
99
- if 'utils' in sys.modules:
100
- del sys.modules['utils']
101
- utils = importlib.import_module('utils')
102
- res = utils.get_secret_key('any')
103
- assert res == 'MY_SECRET'
104
- finally:
105
- _restore_orig(orig)
106
-
107
-
108
- def test_get_secret_key_raises_exception_on_client_error():
109
- orig = _setup_basic_stubs(secret_side_effect=Exception('boom'))
110
- try:
111
- if 'utils' in sys.modules:
112
- del sys.modules['utils']
113
- utils = importlib.import_module('utils')
114
- with pytest.raises(Exception) as exc:
115
- utils.get_secret_key('any')
116
- assert 'Failed to retrieve secret key' in str(exc.value)
117
- assert 'boom' in str(exc.value)
118
- finally:
119
- _restore_orig(orig)
120
-
121
-
122
- def test_verify_firebase_token_raises_when_header_missing_or_invalid():
123
- orig = _setup_basic_stubs()
124
- try:
125
- if 'utils' in sys.modules:
126
- del sys.modules['utils']
127
- utils = importlib.import_module('utils')
128
-
129
- class DummyRequest:
130
- def __init__(self, headers=None):
131
- self.headers = headers or {}
132
-
133
- # Missing header
134
- req = DummyRequest(headers={})
135
- with pytest.raises(Exception) as exc:
136
- utils.verify_firebase_token(req)
137
- assert 'Missing or invalid Authorization header' in str(exc.value)
138
-
139
- # Header present but not starting with 'Bearer '
140
- req2 = DummyRequest(headers={'Authorization': 'Token abc'})
141
- with pytest.raises(Exception) as exc2:
142
- utils.verify_firebase_token(req2)
143
- assert 'Missing or invalid Authorization header' in str(exc2.value)
144
- finally:
145
- _restore_orig(orig)
146
-
147
-
148
- def test_verify_firebase_token_calls_auth_verify_and_returns_payload():
149
- orig = _setup_basic_stubs(auth_verify=lambda token: {'uid': 'user_1'})
150
- try:
151
- if 'utils' in sys.modules:
152
- del sys.modules['utils']
153
- utils = importlib.import_module('utils')
154
-
155
- class DummyRequest:
156
- def __init__(self, headers=None):
157
- self.headers = headers or {}
158
-
159
- req = DummyRequest(headers={'Authorization': 'Bearer TOK'})
160
- res = utils.verify_firebase_token(req)
161
- assert res == {'uid': 'user_1'}
162
- finally:
163
- _restore_orig(orig)
164
-
165
-
166
- def test_verify_firebase_token_wraps_auth_exceptions():
167
- def _raiser(token):
168
- raise Exception('bad token')
169
-
170
- orig = _setup_basic_stubs(auth_verify=_raiser)
171
- try:
172
- if 'utils' in sys.modules:
173
- del sys.modules['utils']
174
- utils = importlib.import_module('utils')
175
-
176
- class DummyRequest:
177
- def __init__(self, headers=None):
178
- self.headers = headers or {}
179
-
180
- req = DummyRequest(headers={'Authorization': 'Bearer TOK'})
181
- with pytest.raises(Exception) as exc:
182
- utils.verify_firebase_token(req)
183
- assert 'Authentication failed' in str(exc.value)
184
- assert 'bad token' in str(exc.value)
185
- finally:
186
- _restore_orig(orig)
187
-
188
-
189
- def test_get_api_key_uses_lowercase_family_name_and_get_secret_key(monkeypatch):
190
- orig = _setup_basic_stubs()
191
- try:
192
- if 'utils' in sys.modules:
193
- del sys.modules['utils']
194
- utils = importlib.import_module('utils')
195
-
196
- called = {}
197
-
198
- def fake_get_secret_key(name):
199
- called['name'] = name
200
- return 'THE_KEY'
201
-
202
- monkeypatch.setattr(utils, 'get_secret_key', fake_get_secret_key)
203
- from enums import LlmFamily
204
- res = utils.get_api_key(LlmFamily.OPENAI)
205
- assert res == 'THE_KEY'
206
- assert called['name'] == 'openai-api-key'
207
- finally:
208
- _restore_orig(orig)
209
-
210
-
211
- def test_create_json_response_returns_formatted_response():
212
- orig = _setup_basic_stubs()
213
- try:
214
- if 'utils' in sys.modules:
215
- del sys.modules['utils']
216
- utils = importlib.import_module('utils')
217
- resp = utils.create_json_response(True, {'a': 1}, 201)
218
- assert getattr(resp, 'status_code', None) == 201
219
- data = json.loads(resp.get_data(as_text=True))
220
- assert data == {"success": True, "payload": {"a": 1}}
221
- finally:
222
- _restore_orig(orig)
File without changes