Spaces:
Sleeping
Sleeping
Download src/modules/execution/scenarios/erp_orders.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 5.85 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/execution/scenarios/erp_orders.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/modules/execution/scenarios/erp_orders.py
-
curl -L -o erp_orders.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/execution/scenarios/erp_orders.py
5.85 kB
| """Fixed acceptance contract for the local file-backed purchase-order demo.""" | |
| from src.modules.execution.contracts import HttpCase,SandboxConfig | |
| SKILL='erp-orders-development' | |
| CONTRACT='''Implement demo.App as a Java17 standard library HttpServer on 127.0.0.1:8080. | |
| On first start create /tmp/zkcoding-erp-orders.csv as UTF-8 without a header: exactly 1000 lines, | |
| one row per order PO0001..PO1000. If it exists, load it without resetting it. Store each row as | |
| id,name,supplier,product,quantity,received,returned,paidCents,totalCents. Deterministic initial row n: | |
| id=PO plus 4 zero-padded digits; name=Order- plus those digits; supplier=Supplier- plus 2-digit | |
| ((n-1)%10+1); product=Product- plus 2-digit ((n-1)%20+1); quantity=10, received=0, returned=0, | |
| paidCents=0, totalCents=100000. All integer cents; do not use floating point. Read the file for | |
| every request. Synchronize mutations and replace the file atomically, retaining exactly 1000 rows. | |
| GET /health -> {"status":"ok"}. All /api/orders endpoints require Authorization Bearer demo-sales; | |
| missing/invalid -> 401 {"error":"UNAUTHORIZED"}. Unknown path -> 404 {"error":"NOT_FOUND"}. | |
| GET /api/orders/meta -> {"total":1000,"storage":"file","fileLines":1000}, counting actual file lines. | |
| GET /api/orders?page=1&query=PO0001&filter=all -> {"total":1,"page":1,"pageSize":20,"orders":[order]}. | |
| Require exactly page, query and filter, page integer 1..100000, query (empty allowed), filter=all or pending. Pending means received<quantity. | |
| Match query case-insensitively as substring of id, name, supplier or product; paginate ordered by id in pages of 20. The JSON order contains exactly | |
| id,name,supplier,product,quantity,received,returned,paidCents,totalCents, with numeric fields integers. | |
| GET /api/orders/detail?id=PO0001 -> that single order. Unknown ID -> 404 {"error":"NOT_FOUND"}. | |
| POST /api/orders/receive?id=PO0999&quantity=3 increases received; POST /api/orders/return?id=PO0999&quantity=2 | |
| increases returned; POST /api/orders/pay?id=PO0999¢s=20000 increases paidCents. Success returns the updated | |
| order object. Quantities and cents must be positive integers; received<=quantity, returned<=received, | |
| paidCents<=totalCents. Exceeding a limit -> 409 {"error":"LIMIT_EXCEEDED"}. Bad/missing/extra/duplicate | |
| parameters -> 400 {"error":"INVALID_INPUT"}. Wrong method -> 405 {"error":"METHOD_NOT_ALLOWED"}. | |
| Do not accept request bodies. Demo payment changes local bookkeeping only; no external network/database. | |
| Return JSON UTF-8. Only output src/main/java/demo/App.java, no build scripts, external libraries, tests or docs.''' | |
| def order(n,*,received=0,returned=0,paid=0): | |
| return {'id':f'PO{n:04d}','name':f'Order-{n:04d}','supplier':f'Supplier-{(n-1)%10+1:02d}', | |
| 'product':f'Product-{(n-1)%20+1:02d}','quantity':10,'received':received,'returned':returned, | |
| 'paidCents':paid,'totalCents':100000} | |
| def scenario(image): | |
| auth={'Authorization':'Bearer demo-sales'} | |
| def case(path,expected,status=200,method='GET',headers=auth): | |
| return HttpCase(path=path,method=method,headers=headers,status=status,expected_json=expected) | |
| health=case('/health',{'status':'ok'},headers={}) | |
| cases=[health,case('/api/orders/meta',{'total':1000,'storage':'file','fileLines':1000}), | |
| case('/api/orders?page=1&query=PO0001&filter=all',{'total':1,'page':1,'pageSize':20,'orders':[order(1)]}), | |
| case('/api/orders?page=1&query=PO9999&filter=all',{'total':0,'page':1,'pageSize':20,'orders':[]}), | |
| case('/api/orders?page=1&query=&filter=all',{'total':1000,'page':1,'pageSize':20,'orders':[order(i) for i in range(1,21)]}), | |
| case('/api/orders?query=PO0001&filter=all',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders?page=1&filter=all',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders?page=1&query=PO0001',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders?page=0&query=&filter=all',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders?page=2147483647&query=&filter=all',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders?page=1&query=&filter=invalid',{'error':'INVALID_INPUT'},400), | |
| case('/api/orders/detail?id=PO0999',order(999)), | |
| case('/api/orders/receive?id=PO0999&quantity=3',order(999,received=3),method='POST'), | |
| case('/api/orders/detail?id=PO0999',order(999,received=3)), | |
| case('/api/orders/receive?id=PO0999&quantity=8',{'error':'LIMIT_EXCEEDED'},409,'POST'), | |
| case('/api/orders/return?id=PO0999&quantity=2',order(999,received=3,returned=2),method='POST'), | |
| case('/api/orders/return?id=PO0999&quantity=2',{'error':'LIMIT_EXCEEDED'},409,'POST'), | |
| case('/api/orders/pay?id=PO0999¢s=20000',order(999,received=3,returned=2,paid=20000),method='POST'), | |
| case('/api/orders/pay?id=PO0999¢s=80001',{'error':'LIMIT_EXCEEDED'},409,'POST'), | |
| case('/api/orders/detail?id=PO0999',order(999,received=3,returned=2,paid=20000)), | |
| case('/api/orders/receive?id=PO0998&quantity=10',order(998,received=10),method='POST'), | |
| case('/api/orders?page=1&query=PO0998&filter=pending',{'total':0,'page':1,'pageSize':20,'orders':[]}), | |
| case('/api/orders/meta',{'total':1000,'storage':'file','fileLines':1000}), | |
| case('/api/orders/detail?id=PO1001',{'error':'NOT_FOUND'},404), | |
| case('/api/orders/receive?id=PO0001&quantity=0',{'error':'INVALID_INPUT'},400,'POST'), | |
| case('/api/orders/receive?id=PO0001&quantity=1&quantity=2',{'error':'INVALID_INPUT'},400,'POST'), | |
| case('/api/orders/detail?id=PO0001',{'error':'UNAUTHORIZED'},401,headers={}), | |
| case('/api/orders/pay?id=PO0001¢s=1',{'error':'METHOD_NOT_ALLOWED'},405), | |
| case('/unknown',{'error':'NOT_FOUND'},404,headers={})] | |
| return SandboxConfig(image=image,skill_ids=[SKILL],api_contract=CONTRACT,command_seconds=120,tests=cases,health=health) | |