Spaces:
Sleeping
Sleeping
Download src/modules/execution/scenarios/erp.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 3.85 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/execution/scenarios/erp.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/modules/execution/scenarios/erp.py
-
curl -L -o erp.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/execution/scenarios/erp.py
3.85 kB
| """Public scenario contract and independently owned acceptance suite.""" | |
| from src.modules.execution.contracts import SandboxConfig, HttpCase | |
| CONTRACT = '''Implement demo.App, a Java17 standard-library HTTP service on port 8080 (HttpServer). | |
| GET /health -> 200 {"status":"ok"}. | |
| GET /api/purchase/quote accepts exactly quantity, unitPrice, department query parameters (no duplicates or extras). | |
| First reject non-GET methods with 405 {"error":"METHOD_NOT_ALLOWED"}. | |
| Then require Authorization: Bearer demo-sales, a PUBLIC DEMO credential that maps to sales department; | |
| missing/invalid credential -> 401 {"error":"UNAUTHORIZED"}. Never accept department identity from query parameters. | |
| Validate input: quantity is decimal digits only, integer 1..10000; unitPrice is decimal digits optionally | |
| followed by a dot and 1 or 2 decimal digits, >0 and <=1000000; department matches [A-Za-z][A-Za-z0-9_-]{0,31}. | |
| Missing, extra, repeated, malformed, out-of-range input -> 400 {"error":"INVALID_INPUT"}. | |
| Valid department other than sales -> 403 {"error":"FORBIDDEN"}. | |
| Compute total with BigDecimal; return 200 JSON with exactly {"total":"<two decimal digits>","approval":"...","department":"sales"}. | |
| Approval: total <10000 -> SELF, 10000 <= total <100000 -> MANAGER, total >=100000 -> DIRECTOR. | |
| Unknown paths -> 404 {"error":"NOT_FOUND"}. JSON UTF-8, no external dependencies. | |
| Public demo credential is not production authentication. Use bounded request handling and close response bodies. | |
| Only create src/main/java/demo/App.java, optional docs/README.md. No tests, scripts, dependencies or protected probe changes.''' | |
| def scenario(image): | |
| cases = [HttpCase(path='/health', status=200, expected_json={'status': 'ok'})] | |
| def quote(query, status=200, expected=None, auth=True, method='GET'): | |
| cases.append(HttpCase(path='/api/purchase/quote?' + query, method=method, | |
| headers={'Authorization': 'Bearer demo-sales'} if auth else {}, status=status, expected_json=expected)) | |
| for quantity, price, total, approval in [('3', '0.10', '0.30', 'SELF'), ('1', '9999.99', '9999.99', 'SELF'), | |
| ('1', '10000', '10000.00', 'MANAGER'), ('1', '99999.99', '99999.99', 'MANAGER'), | |
| ('1', '100000', '100000.00', 'DIRECTOR'), ('10000', '1000000', '10000000000.00', 'DIRECTOR'), | |
| ('7', '19.99', '139.93', 'SELF')]: | |
| quote(f'quantity={quantity}&unitPrice={price}&department=sales', expected={'total': total, 'approval': approval, 'department': 'sales'}) | |
| for query in ['quantity=0&unitPrice=10&department=sales', 'quantity=-1&unitPrice=10&department=sales', | |
| 'quantity=10001&unitPrice=10&department=sales', 'quantity=1.5&unitPrice=10&department=sales', | |
| 'quantity=1&unitPrice=0&department=sales', 'quantity=1&unitPrice=1.234&department=sales', | |
| 'quantity=1&unitPrice=1000000.01&department=sales', 'quantity=1&unitPrice=NaN&department=sales', | |
| 'quantity=1&unitPrice=1e2&department=sales', 'quantity=1&unitPrice=10', | |
| 'quantity=1&quantity=2&unitPrice=10&department=sales', | |
| 'quantity=1&unitPrice=10&department=sales&actorDepartment=finance', | |
| 'quantity=1&unitPrice=10&department=123']: | |
| quote(query, 400, {'error': 'INVALID_INPUT'}) | |
| quote('quantity=1&unitPrice=10&department=finance', 403, {'error': 'FORBIDDEN'}) | |
| quote('quantity=1&unitPrice=10&department=sales', 401, {'error': 'UNAUTHORIZED'}, auth=False) | |
| quote('quantity=1&unitPrice=10&department=sales', 405, {'error': 'METHOD_NOT_ALLOWED'}, method='POST') | |
| cases.append(HttpCase(path='/unknown', status=404, expected_json={'error': 'NOT_FOUND'})) | |
| return SandboxConfig(image=image, skill_ids=['erp-java-development'], api_contract=CONTRACT, | |
| command_seconds=120, tests=cases, health=cases[0]) | |