roksta 0.2.4__cp314-cp314-win_amd64.whl → 0.2.5__cp314-cp314-win_amd64.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 (78) hide show
  1. roksta/__init__.cp314-win_amd64.pyd +0 -0
  2. roksta/ai/__init__.cp314-win_amd64.pyd +0 -0
  3. roksta/ai/call_ai.cp314-win_amd64.pyd +0 -0
  4. roksta/ai/gemini.cp314-win_amd64.pyd +0 -0
  5. roksta/ai/generic.cp314-win_amd64.pyd +0 -0
  6. roksta/ai/llm.cp314-win_amd64.pyd +0 -0
  7. roksta/ai/openai.cp314-win_amd64.pyd +0 -0
  8. roksta/ai/tools.cp314-win_amd64.pyd +0 -0
  9. roksta/analytics.cp314-win_amd64.pyd +0 -0
  10. roksta/balance.cp314-win_amd64.pyd +0 -0
  11. roksta/build_project.cp314-win_amd64.pyd +0 -0
  12. roksta/chat_workflow.cp314-win_amd64.pyd +0 -0
  13. roksta/check_for_updates.cp314-win_amd64.pyd +0 -0
  14. roksta/checkpoints.cp314-win_amd64.pyd +0 -0
  15. roksta/clarify_goal.cp314-win_amd64.pyd +0 -0
  16. roksta/codebase_listing.cp314-win_amd64.pyd +0 -0
  17. roksta/command_handlers.cp314-win_amd64.pyd +0 -0
  18. roksta/create_default_config.cp314-win_amd64.pyd +0 -0
  19. roksta/default_config.cp314-win_amd64.pyd +0 -0
  20. roksta/enums.cp314-win_amd64.pyd +0 -0
  21. roksta/env.cp314-win_amd64.pyd +0 -0
  22. roksta/extended_text_area.cp314-win_amd64.pyd +0 -0
  23. roksta/firebase.cp314-win_amd64.pyd +0 -0
  24. roksta/firebase_auth_web.cp314-win_amd64.pyd +0 -0
  25. roksta/firebase_config.cp314-win_amd64.pyd +0 -0
  26. roksta/fix_tests.cp314-win_amd64.pyd +0 -0
  27. roksta/gen_codebase_summaries.cp314-win_amd64.pyd +0 -0
  28. roksta/gen_one_line_goal.cp314-win_amd64.pyd +0 -0
  29. roksta/get_codebase_structure.cp314-win_amd64.pyd +0 -0
  30. roksta/get_failing_tests.cp314-win_amd64.pyd +0 -0
  31. roksta/goal_workflow.cp314-win_amd64.pyd +0 -0
  32. roksta/init_codebase.cp314-win_amd64.pyd +0 -0
  33. roksta/lint_code.cp314-win_amd64.pyd +0 -0
  34. roksta/logger.cp314-win_amd64.pyd +0 -0
  35. roksta/main.cp314-win_amd64.pyd +0 -0
  36. roksta/make_issue.cp314-win_amd64.pyd +0 -0
  37. roksta/new_features.cp314-win_amd64.pyd +0 -0
  38. roksta/parse_readme.cp314-win_amd64.pyd +0 -0
  39. roksta/propose_solution.cp314-win_amd64.pyd +0 -0
  40. roksta/response_formats.cp314-win_amd64.pyd +0 -0
  41. roksta/rewrite_goal.cp314-win_amd64.pyd +0 -0
  42. roksta/roksta.cp314-win_amd64.pyd +0 -0
  43. roksta/select_files.cp314-win_amd64.pyd +0 -0
  44. roksta/tips.cp314-win_amd64.pyd +0 -0
  45. roksta/utils.cp314-win_amd64.pyd +0 -0
  46. roksta/write_code.cp314-win_amd64.pyd +0 -0
  47. {roksta-0.2.4.dist-info → roksta-0.2.5.dist-info}/METADATA +1 -1
  48. roksta-0.2.5.dist-info/RECORD +77 -0
  49. {roksta-0.2.4.dist-info → roksta-0.2.5.dist-info}/top_level.txt +1 -0
  50. tests/__init__.py +2 -0
  51. tests/conftest.py +169 -0
  52. tests/functions/__init__.py +2 -0
  53. tests/functions/api_v0_01/__init__.py +2 -0
  54. tests/functions/api_v0_01/test__analytics.py +417 -0
  55. tests/functions/api_v0_01/test__gemini_proxy.py +307 -0
  56. tests/functions/api_v0_01/test__generic_proxy.py +399 -0
  57. tests/functions/api_v0_01/test__get_payment_details.py +356 -0
  58. tests/functions/api_v0_01/test__openai_proxy.py +413 -0
  59. tests/functions/api_v0_01/test__redeem_credit_code.py +167 -0
  60. tests/functions/api_v0_01/test__sync_emails.py +324 -0
  61. tests/functions/api_v0_01/test__take_payment.py +491 -0
  62. tests/functions/api_v0_01/test__use_activation_code.py +437 -0
  63. tests/functions/api_v1_00/__init__.py +2 -0
  64. tests/functions/api_v1_00/test__analytics.py +416 -0
  65. tests/functions/api_v1_00/test__gemini_proxy.py +352 -0
  66. tests/functions/api_v1_00/test__generic_proxy.py +428 -0
  67. tests/functions/api_v1_00/test__get_payment_details.py +356 -0
  68. tests/functions/api_v1_00/test__openai_proxy.py +449 -0
  69. tests/functions/api_v1_00/test__redeem_credit_code.py +167 -0
  70. tests/functions/api_v1_00/test__sync_emails.py +325 -0
  71. tests/functions/api_v1_00/test__take_payment.py +491 -0
  72. tests/functions/api_v1_00/test__use_activation_code.py +438 -0
  73. tests/functions/test_auth.py +24 -0
  74. tests/functions/test_main_functions.py +73 -0
  75. tests/functions/test_utils_functions.py +222 -0
  76. roksta-0.2.4.dist-info/RECORD +0 -51
  77. {roksta-0.2.4.dist-info → roksta-0.2.5.dist-info}/WHEEL +0 -0
  78. {roksta-0.2.4.dist-info → roksta-0.2.5.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,417 @@
1
+ import os
2
+ import sys
3
+ import json
4
+ import types
5
+ import importlib
6
+ from unittest.mock import patch, Mock
7
+
8
+
9
+ # Ensure the functions/ directory is importable as a top-level module location
10
+ PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
11
+ FUNCTIONS_DIR = os.path.join(PROJECT_ROOT, 'functions')
12
+ if FUNCTIONS_DIR not in sys.path:
13
+ sys.path.insert(0, FUNCTIONS_DIR)
14
+
15
+ # -----------------------------
16
+ # Provide lightweight fake modules to satisfy imports inside _analytics
17
+ # These are minimal and will be patched in individual tests as needed.
18
+ # -----------------------------
19
+ # Save any originals so we can restore them after import
20
+ _orig_sys_modules = {}
21
+ _names_to_fake = ['firebase_functions', 'utils', 'auth', 'httpx']
22
+ for name in _names_to_fake:
23
+ _orig_sys_modules[name] = sys.modules.get(name)
24
+
25
+ # Fake firebase_functions.https_fn.Response to capture returned data
26
+ firebase_functions = types.ModuleType('firebase_functions')
27
+
28
+ class FakeResponse:
29
+ def __init__(self, response=None, mimetype=None, status=200, **kwargs):
30
+ # Mirror the small subset of the interface tests expect
31
+ self.status_code = status
32
+ if isinstance(response, (dict, list)):
33
+ self._body_text = json.dumps(response)
34
+ else:
35
+ self._body_text = '' if response is None else response
36
+ self.headers = kwargs.get('headers', {})
37
+
38
+ def get_data(self, as_text=False):
39
+ if as_text:
40
+ return self._body_text
41
+ return self._body_text.encode('utf-8')
42
+
43
+ firebase_functions.https_fn = types.SimpleNamespace(Request=object, Response=FakeResponse)
44
+ sys.modules['firebase_functions'] = firebase_functions
45
+
46
+ # Fake utils module (avoid google.cloud import at module import time)
47
+ utils_mod = types.ModuleType('utils')
48
+
49
+ def _dummy_get_secret_key(name: str) -> str:
50
+ return 'DUMMY_SECRET'
51
+
52
+ # create_json_response should return a firebase_functions.https_fn.Response-like object
53
+ # with a JSON body containing at least 'success' and 'message' keys, and an HTTP status code.
54
+ def _dummy_create_json_response(success: bool, payload, status_code: int = 200, headers: dict | None = None):
55
+ body = {'success': success, 'message': payload}
56
+ return firebase_functions.https_fn.Response(response=body, status=status_code, headers=headers or {})
57
+
58
+ utils_mod.get_secret_key = _dummy_get_secret_key
59
+ utils_mod.create_json_response = _dummy_create_json_response
60
+ sys.modules['utils'] = utils_mod
61
+
62
+ # Fake auth module (validate_auth_key will be patched per-test as needed)
63
+ auth_mod = types.ModuleType('auth')
64
+
65
+ def _simple_validate_auth_key(val: str) -> bool:
66
+ return bool(val)
67
+
68
+ auth_mod.validate_auth_key = _simple_validate_auth_key
69
+ sys.modules['auth'] = auth_mod
70
+
71
+ # Fake httpx module to avoid external dependency; tests will patch Client behavior
72
+ httpx_mod = types.ModuleType('httpx')
73
+
74
+ class Request:
75
+ def __init__(self, method, url, headers=None, content=None):
76
+ self.method = method
77
+ self.url = url
78
+ self.headers = headers or {}
79
+ self.content = content
80
+
81
+ class _DummyResponse:
82
+ def __init__(self, status_code=200, text='', json_data=None, request=None, headers=None):
83
+ self.status_code = status_code
84
+ self.text = text if text is not None else ''
85
+ self._json = json_data
86
+ self.request = request
87
+ self.headers = headers or {}
88
+ # Provide a reason_phrase attribute similar to real httpx.Response
89
+ self.reason_phrase = self.text or ''
90
+
91
+ def json(self):
92
+ # Prefer explicit JSON payload if provided, otherwise try to parse text
93
+ if self._json is not None:
94
+ return self._json
95
+ try:
96
+ return json.loads(self.text) if self.text else {}
97
+ except Exception:
98
+ return {}
99
+
100
+ def raise_for_status(self):
101
+ if 400 <= self.status_code:
102
+ raise httpx_mod.HTTPStatusError(response=self)
103
+
104
+ class _DummyHttpxClient:
105
+ def __enter__(self):
106
+ return self
107
+
108
+ def __exit__(self, exc_type, exc, tb):
109
+ return False
110
+
111
+ def post(self, url, json=None, timeout=30):
112
+ resp = _DummyResponse(status_code=200, text='', json_data=None)
113
+ resp.raise_for_status = Mock(return_value=None)
114
+ resp.json = Mock(return_value={})
115
+ return resp
116
+
117
+ class _DummyAsyncClient:
118
+ async def __aenter__(self):
119
+ return self
120
+
121
+ async def __aexit__(self, exc_type, exc, tb):
122
+ return False
123
+
124
+ async def get(self, url, headers=None, timeout=None):
125
+ resp = _DummyResponse(status_code=200, text='', json_data=None)
126
+ resp.raise_for_status = Mock(return_value=None)
127
+ resp.json = Mock(return_value={})
128
+ return resp
129
+
130
+ async def post(self, url, json=None, data=None, headers=None, timeout=None):
131
+ resp = _DummyResponse(status_code=200, text='', json_data=None)
132
+ resp.raise_for_status = Mock(return_value=None)
133
+ resp.json = Mock(return_value={})
134
+ return resp
135
+
136
+ httpx_mod.Client = _DummyHttpxClient
137
+ httpx_mod.AsyncClient = _DummyAsyncClient
138
+ httpx_mod.Response = _DummyResponse
139
+ httpx_mod.Request = Request
140
+ httpx_mod.Headers = dict
141
+
142
+ class _HTTPStatusError(Exception):
143
+ def __init__(self, *args, request=None, response=None):
144
+ # Support both signatures:
145
+ # HTTPStatusError(response)
146
+ # HTTPStatusError(message, request=..., response=...)
147
+ message = ""
148
+ if response is None and len(args) == 1 and not isinstance(args[0], str):
149
+ # Single positional non-string arg -> treated as response
150
+ response = args[0]
151
+ elif len(args) >= 1 and isinstance(args[0], str):
152
+ message = args[0]
153
+ elif len(args) > 1:
154
+ message = args[0]
155
+ super().__init__(message)
156
+ self.request = request
157
+ self.response = response
158
+
159
+ def __str__(self):
160
+ try:
161
+ return f"{self.args[0]} (status={getattr(self.response,'status_code',None)})"
162
+ except Exception:
163
+ return self.args[0] if self.args else "HTTPStatusError"
164
+
165
+ class _RequestError(Exception):
166
+ def __init__(self, message="", request=None):
167
+ super().__init__(message)
168
+ self.request = request
169
+
170
+ httpx_mod.HTTPStatusError = _HTTPStatusError
171
+ httpx_mod.RequestError = _RequestError
172
+ sys.modules['httpx'] = httpx_mod
173
+
174
+ # -----------------------------
175
+ # Import the module under test after preparing the fake imports
176
+ # -----------------------------
177
+ repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
178
+ functions_root = os.path.join(repo_root, 'functions')
179
+ module_path = os.path.join(functions_root, 'api_v0_01', '_analytics.py')
180
+ spec = importlib.util.spec_from_file_location('api_v0_01._analytics', module_path)
181
+ _analytics = importlib.util.module_from_spec(spec)
182
+ spec.loader.exec_module(_analytics)
183
+
184
+
185
+ # Restore original sys.modules mappings to avoid side-effects for other tests
186
+ for name, orig in _orig_sys_modules.items():
187
+ if orig is None:
188
+ try:
189
+ del sys.modules[name]
190
+ except KeyError:
191
+ pass
192
+ else:
193
+ sys.modules[name] = orig
194
+
195
+ # Simple helper request stub used in the tests
196
+ class DummyRequest:
197
+ def __init__(self, headers=None, method='POST', json_data=None, raise_on_get_json=False):
198
+ self.headers = headers or {}
199
+ self.method = method
200
+ self._json_data = json_data
201
+ self._raise = raise_on_get_json
202
+
203
+ def get_json(self, silent=False):
204
+ if self._raise:
205
+ raise Exception('Malformed JSON')
206
+ return self._json_data
207
+
208
+
209
+ def _parse_response(resp):
210
+ data = resp.get_data(as_text=True)
211
+ return json.loads(data)
212
+
213
+
214
+ # -----------------------------
215
+ # Tests
216
+ # -----------------------------
217
+
218
+ def test_missing_auth_header_returns_401():
219
+ req = DummyRequest(headers={}, method='POST')
220
+ resp = _analytics._analytics(req)
221
+ assert resp.status_code == 401
222
+ payload = _parse_response(resp)
223
+ assert payload['success'] is False
224
+ assert 'Missing authentication key' in payload['message']
225
+
226
+
227
+ def test_invalid_auth_key_returns_403():
228
+ headers = {_analytics.AUTH_HEADER_NAME: 'bad-token'}
229
+ req = DummyRequest(headers=headers, method='POST')
230
+ with patch.object(_analytics, 'validate_auth_key', return_value=False):
231
+ resp = _analytics._analytics(req)
232
+ assert resp.status_code == 403
233
+ payload = _parse_response(resp)
234
+ assert payload['success'] is False
235
+ assert 'Invalid authentication key' in payload['message']
236
+
237
+
238
+ def test_non_post_method_returns_405():
239
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
240
+ req = DummyRequest(headers=headers, method='GET')
241
+ with patch.object(_analytics, 'validate_auth_key', return_value=True):
242
+ resp = _analytics._analytics(req)
243
+ assert resp.status_code == 405
244
+ payload = _parse_response(resp)
245
+ assert payload['success'] is False
246
+ assert 'POST method required' in payload['message']
247
+
248
+
249
+ def test_malformed_json_returns_400():
250
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
251
+ req = DummyRequest(headers=headers, method='POST', raise_on_get_json=True)
252
+ with patch.object(_analytics, 'validate_auth_key', return_value=True):
253
+ resp = _analytics._analytics(req)
254
+ assert resp.status_code == 400
255
+ payload = _parse_response(resp)
256
+ assert payload['success'] is False
257
+ assert 'Invalid JSON payload' in payload['message']
258
+
259
+
260
+ def test_missing_required_fields_returns_400():
261
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
262
+ # missing measurement_id
263
+ req = DummyRequest(headers=headers, method='POST', json_data={'client_id': 'c', 'events': [{'name': 'e'}]})
264
+ with patch.object(_analytics, 'validate_auth_key', return_value=True):
265
+ resp = _analytics._analytics(req)
266
+ assert resp.status_code == 400
267
+ payload = _parse_response(resp)
268
+ assert payload['success'] is False
269
+ assert 'Missing required fields' in payload['message']
270
+
271
+
272
+ def test_invalid_events_field_returns_400_for_empty_or_non_list():
273
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
274
+
275
+ # events is empty list
276
+ req_empty = DummyRequest(headers=headers, method='POST', json_data={'measurement_id': 'm', 'client_id': 'c', 'events': []})
277
+ with patch.object(_analytics, 'validate_auth_key', return_value=True):
278
+ resp = _analytics._analytics(req_empty)
279
+ assert resp.status_code == 400
280
+ payload = _parse_response(resp)
281
+ assert payload['success'] is False
282
+ assert 'Missing required fields' in payload['message']
283
+
284
+ # events is not a list
285
+ req_not_list = DummyRequest(headers=headers, method='POST', json_data={'measurement_id': 'm', 'client_id': 'c', 'events': 'nope'})
286
+ with patch.object(_analytics, 'validate_auth_key', return_value=True):
287
+ resp = _analytics._analytics(req_not_list)
288
+ assert resp.status_code == 400
289
+ payload = _parse_response(resp)
290
+ assert payload['success'] is False
291
+ assert "'events' field must be a non-empty list" in payload['message']
292
+
293
+
294
+ def test_secret_retrieval_failure_returns_500():
295
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
296
+ req_payload = {'measurement_id': 'm', 'client_id': 'c', 'events': [{'name': 'e'}]}
297
+ req = DummyRequest(headers=headers, method='POST', json_data=req_payload)
298
+ with patch.object(_analytics, 'validate_auth_key', return_value=True), patch.object(_analytics, 'get_secret_key', side_effect=Exception('boom')):
299
+ resp = _analytics._analytics(req)
300
+ assert resp.status_code == 500
301
+ payload = _parse_response(resp)
302
+ assert payload['success'] is False
303
+ assert 'Could not retrieve GA secret' in payload['message']
304
+
305
+
306
+ def test_successful_flow_calls_httpx_with_expected_url_and_payload():
307
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
308
+ measurement_id = 'MEAS_ABC'
309
+ client_id = 'roksta_console'
310
+ events = [{'name': 'evt', 'params': {'a': 1}}]
311
+ user_id = 'user-123'
312
+ req_payload = {'measurement_id': measurement_id, 'client_id': client_id, 'events': events, 'user_id': user_id}
313
+ req = DummyRequest(headers=headers, method='POST', json_data=req_payload)
314
+
315
+ # Recording client to capture call details
316
+ class RecordingClient:
317
+ def __init__(self):
318
+ self.post_called = False
319
+ self.last_url = None
320
+ self.last_json = None
321
+ self.last_timeout = None
322
+
323
+ def __enter__(self):
324
+ return self
325
+
326
+ def __exit__(self, exc_type, exc, tb):
327
+ return False
328
+
329
+ def post(self, url, json=None, timeout=30):
330
+ self.post_called = True
331
+ self.last_url = url
332
+ self.last_json = json
333
+ self.last_timeout = timeout
334
+ resp = Mock()
335
+ resp.raise_for_status = Mock(return_value=None)
336
+ resp.status_code = 200
337
+ resp.text = ''
338
+ return resp
339
+
340
+ recording = RecordingClient()
341
+
342
+ with patch.object(_analytics, 'validate_auth_key', return_value=True), \
343
+ patch.object(_analytics, 'get_secret_key', return_value='GA-SECRET'), \
344
+ patch.object(_analytics.httpx, 'Client', return_value=recording):
345
+ resp = _analytics._analytics(req)
346
+
347
+ assert resp.status_code == 200
348
+ payload = _parse_response(resp)
349
+ assert payload['success'] is True
350
+
351
+ expected_url = f"https://www.google-analytics.com/mp/collect?measurement_id={measurement_id}&api_secret=GA-SECRET"
352
+ assert recording.post_called is True
353
+ assert recording.last_url == expected_url
354
+ assert recording.last_json['client_id'] == client_id
355
+ assert recording.last_json['events'] == events
356
+ assert recording.last_json['user_id'] == user_id
357
+
358
+
359
+ def test_httpx_http_status_error_is_logged_but_function_returns_200():
360
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
361
+ req_payload = {'measurement_id': 'm', 'client_id': 'c', 'events': [{'name': 'e'}]}
362
+ req = DummyRequest(headers=headers, method='POST', json_data=req_payload)
363
+
364
+ # Client that returns a response whose raise_for_status raises HTTPStatusError
365
+ class ErrClient1:
366
+ def __enter__(self):
367
+ return self
368
+
369
+ def __exit__(self, exc_type, exc, tb):
370
+ return False
371
+
372
+ def post(self, url, json=None, timeout=30):
373
+ resp = Mock()
374
+ # Raise a fake HTTPStatusError instance with a response attribute
375
+ resp.raise_for_status = Mock(side_effect=_analytics.httpx.HTTPStatusError(Mock(status_code=400, text='bad')))
376
+ resp.status_code = 400
377
+ resp.text = 'bad'
378
+ return resp
379
+
380
+ err_client = ErrClient1()
381
+
382
+ with patch.object(_analytics, 'validate_auth_key', return_value=True), \
383
+ patch.object(_analytics, 'get_secret_key', return_value='GA-SECRET'), \
384
+ patch.object(_analytics.httpx, 'Client', return_value=err_client):
385
+ resp = _analytics._analytics(req)
386
+
387
+ assert resp.status_code == 200
388
+ payload = _parse_response(resp)
389
+ assert payload['success'] is True
390
+
391
+
392
+ def test_httpx_request_error_is_logged_but_function_returns_200():
393
+ headers = {_analytics.AUTH_HEADER_NAME: 'ok'}
394
+ req_payload = {'measurement_id': 'm', 'client_id': 'c', 'events': [{'name': 'e'}]}
395
+ req = DummyRequest(headers=headers, method='POST', json_data=req_payload)
396
+
397
+ # Client whose post itself raises a RequestError
398
+ class ErrClient2:
399
+ def __enter__(self):
400
+ return self
401
+
402
+ def __exit__(self, exc_type, exc, tb):
403
+ return False
404
+
405
+ def post(self, url, json=None, timeout=30):
406
+ raise _analytics.httpx.RequestError('network')
407
+
408
+ err_client = ErrClient2()
409
+
410
+ with patch.object(_analytics, 'validate_auth_key', return_value=True), \
411
+ patch.object(_analytics, 'get_secret_key', return_value='GA-SECRET'), \
412
+ patch.object(_analytics.httpx, 'Client', return_value=err_client):
413
+ resp = _analytics._analytics(req)
414
+
415
+ assert resp.status_code == 200
416
+ payload = _parse_response(resp)
417
+ assert payload['success'] is True