diff --git a/CHANGELOG.md b/CHANGELOG.md index 677927fe..54fff9a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 0.1.0 (unreleased) +- Host polish for engine parity: `GET /` serves the engines' minimal index page linking + the actuator endpoints (embedded - no static file service by design); actuator JSON + responses are pretty-printed (the engines' default-serializer presentation); unknown + paths and non-GET methods answer the engines' error shape + `{"status": 404, "message": "Resource not found", "type": "error"}`. - Actuator endpoints `/info`, `/info/routes`, `/env`, `/health` and `/livenessprobe` - the engines' operational surface, for Kubernetes probes and one-dashboard monitoring of polyglot installations. Health check functions are normal registered functions diff --git a/LICENSE b/LICENSE index cd0dd451..33a650e9 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018 - 2025 Accenture. + Copyright 2018-2026 Accenture. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 5c5e225e..02a53df9 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ Kubernetes probes and dashboards treat a Node.js app exactly like a Java or Rust | Endpoint | Purpose | |----------|---------| +| `GET /` | minimal index page linking the endpoints below | | `GET /info` | app identity, runtime, origin id, start time, uptime | | `GET /info/routes` | registered routes split by visibility, with instance counts | | `GET /env` | selected environment variables and configuration parameters | @@ -156,6 +157,10 @@ preload('demo.health', { isPrivate: true }, async (headers, _body) => { }); ``` +JSON responses are pretty-printed — the engines' default-serializer presentation — and +unknown paths answer the engines' error shape +(`{"status": 404, "message": "Resource not found", "type": "error"}`). + Kubernetes wiring: point `livenessProbe` at `/livenessprobe` and `readinessProbe` at `/health`. diff --git a/examples/demo-app.mjs b/examples/demo-app.mjs index 81a33340..0e34549c 100644 --- a/examples/demo-app.mjs +++ b/examples/demo-app.mjs @@ -18,12 +18,13 @@ import { AppException, annotateTrace, getLogger, preload } from '../dist/src/ind const log = getLogger('demo-app'); preload('hello.node', { instances: 10 }, async (headers, body) => { - if (typeof body !== 'object' || body === null || !('text' in body)) { + if (typeof body !== 'object' || body === null + || !('text' in body) || typeof body.text !== 'string') { throw new AppException(400, "missing 'text'"); } annotateTrace('language', 'node.js'); - log.info(`Transforming text of length ${String(body.text).length}`); - return { text: String(body.text).toUpperCase(), language: 'node.js' }; + log.info(`Transforming text of length ${body.text.length}`); + return { text: body.text.toUpperCase(), language: 'node.js' }; }); preload('hello.declarative', { instances: 10 }, async (headers, body) => { @@ -32,7 +33,8 @@ preload('hello.declarative', { instances: 10 }, async (headers, body) => { // Private helper - callable in-app only (the HTTP host answers 403 for it). preload('demo.suffix.helper', { instances: 10, isPrivate: true }, async (_headers, body) => { - return { text: `${body?.text ?? ''}!`, language: 'node.js' }; + const text = typeof body?.text === 'string' ? body.text : ''; + return { text: `${text}!`, language: 'node.js' }; }); // Local composition: a public function calls a private sibling through the bus. diff --git a/src/actuator.ts b/src/actuator.ts index 173ef92f..d423f487 100644 --- a/src/actuator.ts +++ b/src/actuator.ts @@ -40,7 +40,7 @@ import { randomUUID } from 'node:crypto'; import * as http from 'node:http'; import { DeliveryTimeout } from './bus.js'; import { appConfig } from './config.js'; -import { isoUtc } from './envelope.js'; +import { asText, isoUtc } from './envelope.js'; import { getLogger } from './log.js'; import { FunctionRegistry } from './registry.js'; import { VERSION } from './version.js'; @@ -51,6 +51,23 @@ const INFO_TIMEOUT_MS = 3000; // engine value for the advisory type=info lookup const HEALTH_TIMEOUT_MS = 10000; // engine value for the type=health probe const UNHEALTHY = "Unhealthy. Please check '/health' endpoint."; +// The engines' minimal landing page (platform-core public/index.html style); +// the wrappers embed it - no static file service by design. +const INDEX_HTML = ` + + + +

Welcome

+ +

INFO endpoint

+

Service list

+

Environment endpoint

+

Health endpoint

+

Liveness probe

+ + +`; + let origin: string | undefined; /** @@ -101,8 +118,8 @@ export function elapsedTime(milliseconds: number): string { /** A comma/space-separated string (engine syntax) or a YAML list. */ function asList(value: unknown): string[] { const items = Array.isArray(value) - ? value.map((item) => String(item).trim()) - : String(value ?? '').split(/[,\s]+/); + ? value.map((item) => asText(item).trim()) + : asText(value ?? '').split(/[,\s]+/); return items.filter((item) => item.length > 0); } @@ -113,13 +130,27 @@ function isMessageShape(body: unknown): boolean { } function sendText(res: http.ServerResponse, status: number, text: string): void { - res.writeHead(status, { 'content-type': 'text/plain' }); + res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' }); res.end(text); } function sendJson(res: http.ServerResponse, status: number, body: unknown): void { - const bytes = Buffer.from(JSON.stringify(body)); - res.writeHead(status, { 'content-type': 'application/json', 'content-length': bytes.length }); + // the engines' default serializer presentation: pretty-printed JSON + const bytes = Buffer.from(JSON.stringify(body, null, 2)); + res.writeHead(status, + { 'content-type': 'application/json; charset=utf-8', 'content-length': bytes.length }); + res.end(bytes); +} + +/** The engines' host-level error shape (SimpleHttpUtility signature). */ +export function sendError(res: http.ServerResponse, status: number, message: string): void { + sendJson(res, status, { status, message, type: 'error' }); +} + +function sendHtml(res: http.ServerResponse, page: string): void { + const bytes = Buffer.from(page); + res.writeHead(200, + { 'content-type': 'text/html; charset=utf-8', 'content-length': bytes.length }); res.end(bytes); } @@ -153,6 +184,9 @@ export class Actuator { /** Route a GET to its actuator endpoint; false when the path is not ours. */ async handle(pathname: string, res: http.ServerResponse): Promise { switch (pathname) { + case '/': + sendHtml(res, INDEX_HTML); + return true; case '/info': sendJson(res, 200, this.info()); return true; @@ -240,40 +274,44 @@ export class Actuator { for (const route of services) { const entry: Record = { route, required }; dependency.push(entry); - const service = this.registry.get(route); - if (!service) { + if (!await this.checkService(route, entry)) { allUp = false; - entry.status_code = 404; - entry.message = `Please check - Route ${route} not found`; - continue; } - const bus = this.registry.bus; - // info is advisory - merge whatever the service reports about itself; - // the health probe below decides the status - try { - const info = await bus.deliver(service, { type: 'info' }, null, INFO_TIMEOUT_MS); - if (info.body !== null && typeof info.body === 'object' && !Array.isArray(info.body)) { - Object.assign(entry, info.body); - } - } catch (e) { - if (!(e instanceof DeliveryTimeout)) throw e; + } + return allUp; + } + + /** Probe one health-check function; false when it is missing or down. */ + private async checkService(route: string, entry: Record): Promise { + const service = this.registry.get(route); + if (!service) { + entry.status_code = 404; + entry.message = `Please check - Route ${route} not found`; + return false; + } + const bus = this.registry.bus; + // info is advisory - merge whatever the service reports about itself; + // the health probe below decides the status + try { + const info = await bus.deliver(service, { type: 'info' }, null, INFO_TIMEOUT_MS); + if (info.body !== null && typeof info.body === 'object' && !Array.isArray(info.body)) { + Object.assign(entry, info.body); } - try { - const reply = await bus.deliver(service, { type: 'health' }, null, HEALTH_TIMEOUT_MS); - entry.status_code = reply.getStatus(); - if (isMessageShape(reply.body)) { - entry.message = reply.body; - } - if (reply.hasError()) { - allUp = false; - } - } catch (e) { - if (!(e instanceof DeliveryTimeout)) throw e; - allUp = false; - entry.status_code = 408; - entry.message = `Please check - ${e.message}`; + } catch (e) { + if (!(e instanceof DeliveryTimeout)) throw e; + } + try { + const reply = await bus.deliver(service, { type: 'health' }, null, HEALTH_TIMEOUT_MS); + entry.status_code = reply.getStatus(); + if (isMessageShape(reply.body)) { + entry.message = reply.body; } + return !reply.hasError(); + } catch (e) { + if (!(e instanceof DeliveryTimeout)) throw e; + entry.status_code = 408; + entry.message = `Please check - ${e.message}`; + return false; } - return allUp; } } diff --git a/src/bus.ts b/src/bus.ts index 0b67cbc7..755b5bd9 100644 --- a/src/bus.ts +++ b/src/bus.ts @@ -15,6 +15,20 @@ * deadline (the 408 envelope) instead of hoarding work. * - In-memory only; no orchestration, no flows, no persistence, no broadcast. * + * Why a hand-built Mailbox instead of Node's EventEmitter: this contract is + * an ANYCAST WORK QUEUE - each delivery goes to exactly one of N workers and + * waits its FIFO turn while all are busy. EventEmitter is a broadcast + * notifier - emit() invokes every listener synchronously and buffers + * nothing - so a bounded-concurrency bus would still need this queue in + * front of it (the emitter demoted to a wake-up bell), and once()-based + * bridging re-registers a listener per iteration, can drop emissions + * between iterations, and trips MaxListenersExceededWarning right at the + * default instances=10. Bare promise waiters also hold no event-loop + * handles, which is what makes the lifecycle contract exactly true (an idle + * bus lets the process exit; only an in-flight RPC's deadline timer holds + * it). The Mailbox is node's missing asyncio.Queue, keeping the python and + * node twins structurally identical. + * * The bus is internal: application code uses preload() and PostOffice, never * this module - the same way engine developers never touch the engine bus. */ @@ -61,8 +75,8 @@ const CLOSED: unique symbol = Symbol('bus-closed'); /** Unbounded FIFO handing items to awaiting workers. */ class Mailbox { - private items: Array = []; - private waiters: Array<(item: Delivery | typeof CLOSED) => void> = []; + private readonly items: Array = []; + private readonly waiters: Array<(item: Delivery | typeof CLOSED) => void> = []; push(item: Delivery | typeof CLOSED): void { const waiter = this.waiters.shift(); @@ -84,7 +98,7 @@ class Mailbox { /** Per-registry bus: one FIFO mailbox and N workers per registered route. */ export class EventBus { - private mailboxes = new Map(); + private readonly mailboxes = new Map(); private mailbox(service: ServiceDef): Mailbox { let mailbox = this.mailboxes.get(service.route); diff --git a/src/cli.ts b/src/cli.ts index 0abf5663..93fb7909 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,7 +15,7 @@ function parseArgs(argv: string[]): { app?: string; port?: number; host: string; }; for (let i = 0; i < argv.length; i++) { const arg = argv[i]; - if (arg === '--port') result.port = parseInt(argv[++i], 10); + if (arg === '--port') result.port = Number.parseInt(argv[++i], 10); else if (arg === '--host') result.host = argv[++i]; else if (arg === '--config') result.config = argv[++i]; else if (!arg.startsWith('-') && !result.app) result.app = arg; @@ -61,9 +61,10 @@ async function main(): Promise { return 0; } -main().then((code) => { +try { + const code = await main(); if (code !== 0) process.exit(code); -}).catch((e) => { +} catch (e) { process.stderr.write(`${(e as Error).message}\n`); process.exit(1); -}); +} diff --git a/src/config.ts b/src/config.ts index da88cf09..8edce05f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -16,9 +16,12 @@ */ import * as fs from 'node:fs'; import YAML from 'yaml'; +import { asText } from './envelope.js'; const REF = /\$\{([^}]+)\}/g; +const WHOLE_REF = /^\$\{([^}]+)\}$/; + export const DEFAULT_CANDIDATES = [ 'resources/application.yml', 'resources/application.yaml', @@ -61,7 +64,7 @@ function parseProperties(text: string): Map { export class AppConfig { private store = new Map(); - private overrides: Map; + private readonly overrides: Map; readonly source: string; constructor(path?: string, argv?: string[]) { @@ -95,7 +98,7 @@ export class AppConfig { /** Runtime override, checked first on every read (f:setConfig analog). */ set(key: string, value: unknown): void { - if (!key || !key.trim()) { + if (!key?.trim()) { throw new Error('Config key must not be empty'); } this.overrides.set(key, value); @@ -112,7 +115,7 @@ export class AppConfig { getProperty(key: string, defaultValue?: string): string | undefined { const value = this.get(key, defaultValue); - return value === undefined || value === null ? undefined : String(value); + return value === undefined || value === null ? undefined : asText(value); } exists(key: string): boolean { @@ -120,14 +123,14 @@ export class AppConfig { } private substitute(value: string, defaultValue: unknown): unknown { - const whole = value.trim().match(/^\$\{([^}]+)\}$/); + const whole = WHOLE_REF.exec(value.trim()); if (whole) { const resolved = this.resolveRef(whole[1]); return resolved === undefined ? defaultValue : resolved; } return value.replace(REF, (_m, ref: string) => { const resolved = this.resolveRef(ref); - return resolved === undefined || resolved === null ? '' : String(resolved); + return resolved === undefined || resolved === null ? '' : asText(resolved); }); } @@ -151,7 +154,7 @@ let instance: AppConfig | undefined; /** The shared AppConfig singleton (created on first use). */ export function appConfig(): AppConfig { - if (!instance) instance = new AppConfig(); + instance ??= new AppConfig(); return instance; } diff --git a/src/envelope.ts b/src/envelope.ts index 3c5c51b3..b16c2056 100644 --- a/src/envelope.ts +++ b/src/envelope.ts @@ -60,11 +60,24 @@ function normalize(value: unknown): unknown { return value; } +/** Render a scalar as text: primitives via String, structures via JSON. */ +export function asText(value: unknown): string { + if (typeof value === 'string') return value; + if (typeof value === 'number' || typeof value === 'bigint' + || typeof value === 'boolean' || typeof value === 'symbol') { + // positively narrowed to primitives - negating typeof on 'unknown' would + // widen to '{}' and re-admit objects (the S6551 trap) + return String(value); + } + if (typeof value === 'function') return value.toString(); + return value === undefined ? 'undefined' : JSON.stringify(value); +} + function asStringMap(value: unknown): Record { const result: Record = {}; if (value !== null && typeof value === 'object' && !Array.isArray(value)) { for (const [k, v] of Object.entries(value as Record)) { - result[String(k)] = String(v); + result[k] = asText(v); } } return result; @@ -136,9 +149,8 @@ export class EventEnvelope { return new Uint8Array(encoder.encode(this.toMap())); } - static fromMap(data: Record): EventEnvelope { - const event = new EventEnvelope(); - if (data.id !== undefined && data.id !== null) event.id = String(data.id); + /** The optional wire fields that arrive as strings (wire key -> assignment). */ + private static copyStringFields(data: Record, event: EventEnvelope): void { if (typeof data.to === 'string') event.to = data.to; if (typeof data.from === 'string') event.sender = data.from; if (typeof data.reply_to === 'string') event.replyTo = data.reply_to; @@ -146,17 +158,32 @@ export class EventEnvelope { if (typeof data.trace_id === 'string') event.traceId = data.trace_id; if (typeof data.trace_path === 'string') event.tracePath = data.trace_path; if (typeof data.span_id === 'string') event.spanId = data.span_id; + if (typeof data.stack === 'string') event.stack = data.stack; + if (typeof data.obj_type === 'string') event.objType = data.obj_type; + } + + /** The optional numeric fields (absent and nil are equivalent on the wire). */ + private static copyNumericFields(data: Record, event: EventEnvelope): void { if (data.status !== undefined && data.status !== null) event.status = Number(data.status); + if (data.exec_time !== undefined && data.exec_time !== null) { + event.execTime = Number(data.exec_time); + } + if (data.round_trip !== undefined && data.round_trip !== null) { + event.roundTrip = Number(data.round_trip); + } + } + + static fromMap(data: Record): EventEnvelope { + const event = new EventEnvelope(); + if (data.id !== undefined && data.id !== null) event.id = asText(data.id); + EventEnvelope.copyStringFields(data, event); + EventEnvelope.copyNumericFields(data, event); event.headers = asStringMap(data.headers); if (data.body !== undefined) event.body = normalize(data.body); - if (data.exec_time !== undefined && data.exec_time !== null) event.execTime = Number(data.exec_time); - if (data.round_trip !== undefined && data.round_trip !== null) event.roundTrip = Number(data.round_trip); if (data.tags !== undefined && data.tags !== null) event.tags = asStringMap(data.tags); if (data.annotations !== undefined && data.annotations !== null) { event.annotations = normalize(data.annotations) as Record; } - if (typeof data.stack === 'string') event.stack = data.stack; - if (typeof data.obj_type === 'string') event.objType = data.obj_type; if (data.exception instanceof Uint8Array) event.exception = data.exception; return event; } diff --git a/src/log.ts b/src/log.ts index 49799415..ba97ae4f 100644 --- a/src/log.ts +++ b/src/log.ts @@ -41,10 +41,19 @@ function timestamp(): string { function callSite(): string { // frame 0 = Error, 1 = callSite, 2 = Logger method, 3 = the caller - const stack = new Error().stack?.split('\n') ?? []; + const stack = new Error('log call site').stack?.split('\n') ?? []; const frame = stack[4] ?? stack[3] ?? ''; - const match = frame.match(/([^/\\(\s]+?):(\d+):\d+\)?$/); - return match ? `${match[1].replace(/\.[cm]?js$/, '')}:${match[2]}` : 'unknown:0'; + // right-to-left parse of ".../name.js:LINE:COL[)]" - linear, no regex scanning + const end = frame.endsWith(')') ? frame.length - 1 : frame.length; + const colCut = frame.lastIndexOf(':', end - 1); + const lineCut = colCut > 0 ? frame.lastIndexOf(':', colCut - 1) : -1; + if (lineCut <= 0) return 'unknown:0'; + const line = frame.slice(lineCut + 1, colCut); + if (!/^\d+$/.test(line)) return 'unknown:0'; + const start = Math.max(frame.lastIndexOf('/', lineCut), frame.lastIndexOf('\\', lineCut), + frame.lastIndexOf('(', lineCut), frame.lastIndexOf(' ', lineCut)) + 1; + const name = frame.slice(start, lineCut).replace(/\.[cm]?js$/, ''); + return `${name}:${line}`; } function write(level: Level, name: string | undefined, message: string, args: unknown[]): void { diff --git a/src/registry.ts b/src/registry.ts index 0075b598..473bfccd 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -6,12 +6,17 @@ * full control of status and reply headers). */ import { EventBus } from './bus.js'; -import { EventEnvelope } from './envelope.js'; +/** + * A function handler returns the reply body, an EventEnvelope for full + * control of status and reply headers, or a promise of either - the bus + * awaits the result and discriminates with instanceof, so the honest + * static type is simply unknown. + */ export type Handler = ( headers: Record, body: unknown -) => unknown | EventEnvelope | Promise; +) => unknown; export interface ServiceDef { route: string; @@ -37,7 +42,7 @@ export class FunctionRegistry { // HTTP host and the local side of PostOffice readonly bus = new EventBus(); - private services = new Map(); + private readonly services = new Map(); register(route: string, handler: Handler, options: { instances?: number; isPrivate?: boolean } = {}): ServiceDef { diff --git a/src/server.ts b/src/server.ts index 09340535..07854c1c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -15,7 +15,7 @@ * actuator.ts. */ import * as http from 'node:http'; -import { Actuator } from './actuator.js'; +import { Actuator, sendError } from './actuator.js'; import { DeliveryTimeout } from './bus.js'; import { appConfig } from './config.js'; import { EventEnvelope } from './envelope.js'; @@ -58,7 +58,7 @@ export class EventApiServer { private async handleEvent(req: http.IncomingMessage, res: http.ServerResponse, raw: Buffer): Promise { - const ttl = Math.max(1000, parseInt(String(req.headers['x-ttl'] ?? '0'), 10) || 0); + const ttl = Math.max(1000, Number.parseInt(String(req.headers['x-ttl'] ?? '0'), 10) || 0); const isAsync = req.headers['x-async'] === 'true'; let event: EventEnvelope; try { @@ -117,12 +117,10 @@ export class EventApiServer { if (req.method === 'GET') { this.actuator.handle(url.pathname, res).then((handled) => { if (!handled) { - res.writeHead(404, { 'content-type': 'text/plain' }); - res.end('Not found'); + sendError(res, 404, 'Resource not found'); } }).catch((e) => { - res.writeHead(500, { 'content-type': 'text/plain' }); - res.end((e as Error).message ?? String(e)); + sendError(res, 500, (e as Error).message ?? String(e)); }); return; } @@ -137,8 +135,7 @@ export class EventApiServer { req.on('error', () => res.destroy()); return; } - res.writeHead(404, { 'content-type': 'text/plain' }); - res.end('Not found'); + sendError(res, 404, 'Resource not found'); }); } } diff --git a/test/actuator.test.ts b/test/actuator.test.ts index cf122bfc..7776e293 100644 --- a/test/actuator.test.ts +++ b/test/actuator.test.ts @@ -216,3 +216,47 @@ test('origin is stable and engine-shaped', () => { assert.equal(minted, appOrigin()); // minted once per process assert.match(minted, ORIGIN_SHAPE); }); + +test('index page lists the actuator endpoints', async () => { + const { base, stop } = await start(new FunctionRegistry()); + try { + const response = await fetch(`${base}/`); + assert.equal(response.status, 200); + assert.equal(response.headers.get('content-type'), 'text/html; charset=utf-8'); + const page = await response.text(); + for (const link of ['/info', '/info/routes', '/env', '/health', '/livenessprobe']) { + assert.ok(page.includes(`href="${link}"`)); + } + } finally { + await stop(); + } +}); + +test('unknown path answers the engine error shape', async () => { + const { base, stop } = await start(new FunctionRegistry()); + try { + const [status, body] = await getJson(`${base}/no/such/page`); + assert.equal(status, 404); + assert.deepEqual(body, { status: 404, message: 'Resource not found', type: 'error' }); + // non-GET on a known path is equally not a resource (engine semantics) + const post = await fetch(`${base}/info`, { method: 'POST' }); + assert.equal(post.status, 404); + assert.deepEqual(await post.json(), + { status: 404, message: 'Resource not found', type: 'error' }); + } finally { + await stop(); + } +}); + +test('json responses are pretty-printed', async () => { + // the engines' default serializer presentation (SimpleMapper pretty Gson) + const { base, stop } = await start(new FunctionRegistry()); + try { + const response = await fetch(`${base}/info`); + assert.equal(response.headers.get('content-type'), 'application/json; charset=utf-8'); + const text = await response.text(); + assert.ok(text.startsWith('{\n "app": {\n')); + } finally { + await stop(); + } +}); diff --git a/test/envelope.test.ts b/test/envelope.test.ts index 63e74ec7..3b263497 100644 --- a/test/envelope.test.ts +++ b/test/envelope.test.ts @@ -97,7 +97,8 @@ test('golden vectors conformance', () => { const catalog = JSON.parse(fs.readFileSync(VECTORS, 'utf-8')) as { vectors: Vector[] }; const standard = catalog.vectors.filter((v) => v.format === 'standard'); const compact = catalog.vectors.filter((v) => v.format === 'compact'); - assert.ok(standard.length > 0 && compact.length > 0); + assert.ok(standard.length > 0); + assert.ok(compact.length > 0); for (const vector of standard) { const raw = new Uint8Array(Buffer.from(vector.base64, 'base64')); const decoded = EventEnvelope.fromBytes(raw); diff --git a/test/server.test.ts b/test/server.test.ts index 7221f977..09e0ac89 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -66,7 +66,8 @@ test('rpc success with exec_time', async () => { assert.equal(reply.getStatus(), 200); assert.deepEqual((reply.body as Record).body, { a: 1 }); assert.equal(reply.sender, 'unit.echo'); - assert.ok(typeof reply.execTime === 'number' && reply.execTime >= 0); + assert.ok(typeof reply.execTime === 'number'); + assert.ok((reply.execTime as number) >= 0); }); test('sync handler sees trace context', async () => { @@ -109,7 +110,8 @@ test('unexpected exception maps to 500 with stack', async () => { assert.equal(status, 200); assert.equal(reply.getStatus(), 500); assert.equal(reply.body, 'kaboom'); - assert.ok(reply.stack && reply.stack.includes('Error')); + assert.ok(reply.stack); + assert.ok(reply.stack.includes('Error')); }); test('unknown route 404 with engine message', async () => { diff --git a/tsconfig.json b/tsconfig.json index e87706af..f7571436 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "strict": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, - "skipLibCheck": true + "skipLibCheck": true, + "types": ["node"] }, "include": ["src/**/*.ts", "test/**/*.ts"] }