from src.modules.execution.contracts import SandboxConfig, HttpCase CONTRACT = '''Implement demo.App using Java17 standard library com.sun.net.httpserver.HttpServer on 8080. GET /health =>200 {"status":"ok"}. All /api/stock endpoints require Authorization: Bearer demo-warehouse; otherwise 401 {"error":"UNAUTHORIZED"}. Unknown paths =>404 {"error":"NOT_FOUND"}. In-memory stock initially empty. GET /api/stock?sku=SKU1 returns200 {"sku":"SKU1","quantity":0} (zero for absent SKU). POST /api/stock/move?sku=SKU1&delta=10&requestId=receipt1 changes stock atomically and returns200 {"sku":"SKU1","quantity":10}. sku matches [A-Z][A-Z0-9_-]{0,31}; delta is integer digits optionally prefixed with minus, -100..100 excluding zero; requestId matches [A-Za-z][A-Za-z0-9_-]{0,39}. Exact query keys only; missing/duplicate/extra/malformed =>400 {"error":"INVALID_INPUT"}. Wrong methods on known endpoints =>405 {"error":"METHOD_NOT_ALLOWED"} before authentication. Successful requestId is global idempotency key: same sku+delta returns EXACT ORIGINAL response even after later moves, with no extra effect; different payload with same key =>409 {"error":"IDEMPOTENCY_CONFLICT"}. Stock must stay 0..10000; underflow =>409 {"error":"INSUFFICIENT_STOCK"}; overflow =>409 {"error":"STOCK_LIMIT"}. Rejected mutations must not change stock or reserve requestId. Synchronize mutation and idempotency as one atomic operation. Use a bounded executor or default single thread; no file/database/network dependencies. UTF-8 JSON, close exchanges. This public demo credential is not production auth. Files only src/main/java/demo/App.java and optional docs/README.md.''' def scenario(image): h = HttpCase(path='/health', status=200, expected_json={'status': 'ok'}) cases = [h] def add(path, expected, status=200, method='GET', auth=True): cases.append(HttpCase(path=path, status=status, expected_json=expected, method=method, headers={'Authorization':'Bearer demo-warehouse'} if auth else {})) add('/api/stock?sku=SKU1', {'sku':'SKU1','quantity':0}) add('/api/stock/move?sku=SKU1&delta=10&requestId=in1', {'sku':'SKU1','quantity':10}, method='POST') add('/api/stock/move?sku=SKU1&delta=10&requestId=in1', {'sku':'SKU1','quantity':10}, method='POST') add('/api/stock/move?sku=SKU1&delta=-3&requestId=out1', {'sku':'SKU1','quantity':7}, method='POST') add('/api/stock/move?sku=SKU1&delta=10&requestId=in1', {'sku':'SKU1','quantity':10}, method='POST') add('/api/stock?sku=SKU1', {'sku':'SKU1','quantity':7}) add('/api/stock/move?sku=SKU1&delta=11&requestId=in1', {'error':'IDEMPOTENCY_CONFLICT'},409,'POST') add('/api/stock/move?sku=SKU1&delta=-8&requestId=bad1', {'error':'INSUFFICIENT_STOCK'},409,'POST') add('/api/stock?sku=SKU1', {'sku':'SKU1','quantity':7}) add('/api/stock/move?sku=SKU1&delta=-7&requestId=bad1', {'sku':'SKU1','quantity':0},method='POST') for query in ['sku=SKU1&delta=0&requestId=x','sku=SKU1&delta=101&requestId=x','sku=SKU1&delta=1.5&requestId=x', 'sku=bad&delta=1&requestId=x','sku=SKU1&delta=1','sku=SKU1&delta=1&delta=2&requestId=x', 'sku=SKU1&delta=1&requestId=x&warehouse=other']: add('/api/stock/move?'+query, {'error':'INVALID_INPUT'},400,'POST') add('/api/stock?sku=SKU1', {'error':'UNAUTHORIZED'},401,auth=False) add('/api/stock/move?sku=SKU1&delta=1&requestId=x', {'error':'METHOD_NOT_ALLOWED'},405) add('/unknown', {'error':'NOT_FOUND'},404) return SandboxConfig(image=image,skill_ids=['wms-java-development'],api_contract=CONTRACT,command_seconds=120,tests=cases,health=h)