Code Quality — Skill
Purpose
Maintain consistent, spec-compliant code throughout the serverless function runtime implementation.
When to Use
- •Writing new source files
- •Reviewing or refactoring existing code
- •Making implementation decisions about structure or patterns
Language and Runtime Conventions
- •Node.js with modern JavaScript or TypeScript. Use ES modules (
import/export). - •Web-standard
Request/Responsefor the handler contract. Use the globalRequestandResponseobjects (Node.js 18+ built-in) or a minimal polyfill. - •Minimal dependencies. Do not add frameworks or libraries unless strictly required by the spec. Prefer Node.js built-ins.
- •No TypeScript compilation complexity. If using TypeScript, keep the build step simple. Plain JavaScript is acceptable.
Code Structure Conventions
- •One module, one responsibility. Each file should have a clear, single purpose.
- •Named exports for public API. Default exports only for handler method functions.
- •Handler functions are named by HTTP method:
export function GET(request) {},export function POST(request) {}. - •No global mutable state except where explicitly required by the spec (warm module reuse via module-level variables is allowed per REQ-RTG-006).
Error Handling Conventions
- •Runtime errors use the spec's JSON format:
{"errorCode": "<CODE>", "message": "<detail>"}. - •Error codes are exactly:
ROUTE_NOT_FOUND,METHOD_NOT_ALLOWED,HANDLER_EXCEPTION,INVALID_HANDLER_RESPONSE,INVOCATION_TIMEOUT. - •HTTP status mapping is fixed: 404, 405, 500, 500, 504 respectively.
- •Handler exceptions must be caught and mapped to
HANDLER_EXCEPTIONwith the original error message. - •Timeout enforcement uses AbortController or equivalent — do not rely on unref'd timers alone.
Testing Conventions
- •E2E tests run via
npm test(REQ-RCV-006). - •Tests start the runtime, send HTTP requests, and assert responses. No mocking of the runtime itself.
- •Each spec scenario (Section 6) maps to at least one test case.
- •Test exit code 0 on success (REQ-RCV-007).
Quality Checklist
- • All source files use ES modules
- • Handler contract uses Web-standard Request/Response
- • No unnecessary dependencies added
- • Error responses match spec JSON format exactly
- • Timeout enforcement is 3000ms per invocation
- • No debug prints or commented-out code in committed files
- • Each file has a single, clear responsibility