from src.modules.execution.contracts import SandboxConfig, HttpCase CONTRACT = '''Implement demo.App with Java17 standard library com.sun.net.httpserver.HttpServer on 8080. GET /health=>200 {"status":"ok"}. Known /api endpoints require Authorization: Bearer demo-maintenance; missing/invalid =>401 {"error":"UNAUTHORIZED"}. Unknown paths=>404 {"error":"NOT_FOUND"}. POST /api/work-orders/open?id=WO1&device=PUMP1 creates an in-memory order OPEN, returns200 {"id":"WO1","device":"PUMP1","state":"OPEN"}. Existing id =>409 {"error":"ORDER_EXISTS"}, no replacement. id/device matches [A-Z][A-Z0-9_-]{0,31}. GET /api/work-orders?id=WO1 returns current object; absent=>404 {"error":"ORDER_NOT_FOUND"}. POST /api/work-orders/transition?id=WO1&action=START allows only OPEN->IN_PROGRESS; action=CLOSE allows only IN_PROGRESS->CLOSED. Successful response is the current id/device/state object. Invalid transition=>409 {"error":"INVALID_TRANSITION"}; unknown action=>400 {"error":"INVALID_INPUT"}. GET /api/inspection/next?last=2026-10-01&days=30 returns200 {"next":"2026-10-31"}. Use strict ISO LocalDate (exact yyyy-MM-dd, year2000..2100), days integer digits 1..365, actual calendar/leap-year arithmetic. Missing/duplicate/extra/malformed inputs=>400 {"error":"INVALID_INPUT"}; exact query keys, reject unknown keys. Wrong methods on known paths=>405 {"error":"METHOD_NOT_ALLOWED"} before auth. Mutations synchronized, failed requests leave state unchanged. UTF-8 JSON, close exchanges, bounded or default single-thread executor, no dependencies. 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-maintenance'} if auth else {})) def order(state):return {'id':'WO1','device':'PUMP1','state':state} add('/api/work-orders?id=WO1',{'error':'ORDER_NOT_FOUND'},404) add('/api/work-orders/open?id=WO1&device=PUMP1',order('OPEN'),method='POST') add('/api/work-orders/open?id=WO1&device=PUMP2',{'error':'ORDER_EXISTS'},409,'POST') add('/api/work-orders/transition?id=WO1&action=CLOSE',{'error':'INVALID_TRANSITION'},409,'POST') add('/api/work-orders?id=WO1',order('OPEN')) add('/api/work-orders/transition?id=WO1&action=START',order('IN_PROGRESS'),method='POST') add('/api/work-orders/transition?id=WO1&action=START',{'error':'INVALID_TRANSITION'},409,'POST') add('/api/work-orders/transition?id=WO1&action=CLOSE',order('CLOSED'),method='POST') add('/api/work-orders/transition?id=WO1&action=START',{'error':'INVALID_TRANSITION'},409,'POST') add('/api/work-orders?id=WO1',order('CLOSED')) add('/api/inspection/next?last=2026-10-01&days=30',{'next':'2026-10-31'}) add('/api/inspection/next?last=2024-02-28&days=1',{'next':'2024-02-29'}) add('/api/inspection/next?last=2025-02-28&days=1',{'next':'2025-03-01'}) for query in ['last=2025-02-29&days=1','last=2026-10-01&days=0','last=2026-10-01&days=366', 'last=2026-10-01&days=1&days=2','last=2026-10-01','last=1999-01-01&days=1']: add('/api/inspection/next?'+query,{'error':'INVALID_INPUT'},400) add('/api/work-orders/open?id=bad&device=PUMP1',{'error':'INVALID_INPUT'},400,'POST') add('/api/work-orders?id=WO1',{'error':'UNAUTHORIZED'},401,auth=False) add('/api/work-orders/open?id=WO1&device=PUMP1',{'error':'METHOD_NOT_ALLOWED'},405) return SandboxConfig(image=image,skill_ids=['equipment-ops-java-development'],api_contract=CONTRACT,command_seconds=120,tests=cases,health=h)