Ejemplo
@hono/node-server 2.1.11
Muestra verificada para npm @hono/node-server 2.1.11. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: @hono/node-server exports serve…
sha256:4df787b957b46d28a1f768a72886f4c822041fa39c1de4eebd40d271008e6a3b
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-28 |
Caso
HOW- Objetivo
- verify pkg:npm/%40hono/node-server@2.1.11
- Paquetes
- Entorno
- node 22.23.2
- Creado
- 2026-11-28T04:03:01Z
Contrato
- @hono/node-server exports serve, createAdaptorServer, getRequestListener, RequestError, and upgradeWebSocket in CommonJS, and subpath exports @hono/node-server/conninfo and @hono/node-server/early-hints resolve in CommonJS
- RequestError extends Error, sets name to RequestError, and preserves the cause option
- serve binds an HTTP server on 127.0.0.1 with an ephemeral port, invokes listeningListener with AddressInfo, and dispatches GET and POST JSON requests
- createAdaptorServer returns an unstarted http.Server that passes incoming and outgoing HttpBindings compatible with getConnInfo
- getRequestListener forwards thrown RequestError instances to errorHandler and earlyHints sends 103 Early Hints Link headers for document navigation requests while skipping non-document requests
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/app.cjs
- test/contract.cjs
Código fuente
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/%40hono/node-server@2.1.11
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40hono/node-server@2.1.11
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:502a9ec5182f07b13f56ecf08fc093aecca5a71279dda2d820348d32bb0e4411","constraints":{"executionContext":"node"},"contract":["@hono/node-server exports serve, createAdaptorServer, getRequestListener, RequestError, and upgradeWebSocket in CommonJS, and subpath exports @hono/node-server/conninfo and @hono/node-server/early-hints resolve in CommonJS","RequestError extends Error, sets name to RequestError, and preserves the cause option","serve binds an HTTP server on 127.0.0.1 with an ephemeral port, invokes listeningListener with AddressInfo, and dispatches GET and POST JSON requests","createAdaptorServer returns an unstarted http.Server that passes incoming and outgoing HttpBindings compatible with getConnInfo","getRequestListener forwards thrown RequestError instances to errorHandler and earlyHints sends 103 Early Hints Link headers for document navigation requests while skipping non-document requests"],"goal":"verify pkg:npm/%40hono/node-server@2.1.11","kind":"HOW","packages":["pkg:npm/%40hono/node-server@2.1.11"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40hono/node-server@2.1.11"],"schemaVersion":1,"subject":"pkg:npm/%40hono/node-server@2.1.11","verifierAdapter":"node-typescript@1"}
{
"name": "hono-node-server-verify",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "hono-node-server-verify",
"version": "1.0.0",
"dependencies": {
"@hono/node-server": "2.1.11"
}
},
"node_modules/@hono/node-server": {
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.11.tgz",
"integrity": "sha512-KzKz9vl4vvr1vgLHamj+g5uonbrj5NwAdO3yzOS6cd2HjALVeOgTgeZOyAzNxejbkfOOPIcvuf/Tg8l1pEFLog==",
"license": "MIT",
"engines": {
"node": ">=20"
},
"peerDependencies": {
"hono": "^4 || ^5.0.0-0"
}
},
"node_modules/hono": {
"version": "4.13.23",
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.23.tgz",
"integrity": "sha512-OS90dj7dcsftEEWCOef8jRbnHE5lbrOq0hNRqjSyPsOnaGZvvfof1KS05hQNb4kUOCfDq1mG3PmHoX37DMnHQg==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=16.9.0"
}
}
}
}
{
"name": "hono-node-server-verify",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"@hono/node-server": "2.1.11"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40hono/node-server@2.1.11",
"kind": "HOW",
"packages": [
"pkg:npm/%40hono/node-server@2.1.11"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const http = require('node:http');
const {
serve,
createAdaptorServer,
getRequestListener,
RequestError,
} = require('@hono/node-server');
const { getConnInfo } = require('@hono/node-server/conninfo');
const { earlyHints } = require('@hono/node-server/early-hints');
function createFetchHandler() {
const hintsMiddleware = earlyHints({
link: '</styles.css>; rel=preload; as=style',
});
return async (request, env) => {
const url = new URL(request.url);
if (request.method === 'GET' && url.pathname === '/health') {
return Response.json({ status: 'ok' }, { status: 200 });
}
if (request.method === 'POST' && url.pathname === '/echo') {
const payload = await request.json();
return Response.json(
{
received: payload,
customHeader: request.headers.get('x-trace-id'),
},
{ status: 201 }
);
}
if (request.method === 'GET' && url.pathname === '/conn') {
const conn = getConnInfo({ env });
return Response.json({
hasIncoming: Boolean(env && env.incoming),
hasOutgoing: Boolean(env && env.outgoing),
remote: conn.remote,
});
}
if (request.method === 'GET' && url.pathname === '/hints') {
let response;
const ctx = {
env,
req: {
header(name) {
return request.headers.get(name) ?? undefined;
},
},
};
await hintsMiddleware(ctx, async () => {
response = new Response('<html>ok</html>', {
status: 200,
headers: { 'content-type': 'text/html; charset=utf-8' },
});
});
return response;
}
if (request.method === 'GET' && url.pathname === '/fail') {
throw new RequestError('simulated bad request', {
cause: new Error('invalid query'),
});
}
return new Response('Not Found', { status: 404 });
};
}
function startWithServe(onListening) {
return serve(
{
fetch: createFetchHandler(),
hostname: '127.0.0.1',
port: 0,
},
onListening
);
}
function createServerWithoutListening() {
return createAdaptorServer({
fetch: createFetchHandler(),
hostname: '127.0.0.1',
});
}
function createListenerServer(onError) {
const listener = getRequestListener(createFetchHandler(), {
hostname: '127.0.0.1',
errorHandler(err) {
if (onError) onError(err);
return Response.json(
{
error: err instanceof Error ? err.name : 'UnknownError',
message: err instanceof Error ? err.message : String(err),
},
{ status: 400 }
);
},
});
return http.createServer(listener);
}
module.exports = {
createFetchHandler,
startWithServe,
createServerWithoutListening,
createListenerServer,
};
'use strict';
const assert = require('node:assert/strict');
const http = require('node:http');
const nodeServer = require('@hono/node-server');
const conninfo = require('@hono/node-server/conninfo');
const earlyHintsMod = require('@hono/node-server/early-hints');
const {
startWithServe,
createServerWithoutListening,
createListenerServer,
} = require('../src/app.cjs');
function httpRequest({ port, method = 'GET', path = '/', headers = {}, body = null }) {
return new Promise((resolve, reject) => {
const infoResponses = [];
const req = http.request(
{
hostname: '127.0.0.1',
port,
method,
path,
headers,
},
(res) => {
const chunks = [];
res.on('data', (chunk) => chunks.push(chunk));
res.on('end', () => {
resolve({
statusCode: res.statusCode,
headers: res.headers,
body: Buffer.concat(chunks).toString('utf8'),
infoResponses,
});
});
}
);
req.on('information', (info) => {
infoResponses.push({
statusCode: info.statusCode,
headers: info.headers,
});
});
req.on('error', reject);
if (body !== null) {
req.write(body);
}
req.end();
});
}
function closeServer(server) {
return new Promise((resolve, reject) => {
server.close((err) => (err ? reject(err) : resolve()));
});
}
async function testExportsAndRequestError() {
assert.equal(typeof nodeServer.serve, 'function');
assert.equal(typeof nodeServer.createAdaptorServer, 'function');
assert.equal(typeof nodeServer.getRequestListener, 'function');
assert.equal(typeof nodeServer.RequestError, 'function');
assert.equal(typeof nodeServer.upgradeWebSocket, 'function');
assert.equal(typeof conninfo.getConnInfo, 'function');
assert.equal(typeof earlyHintsMod.earlyHints, 'function');
const rootCause = new Error('underlying failure');
const reqErr = new nodeServer.RequestError('malformed input', { cause: rootCause });
assert.ok(reqErr instanceof Error);
assert.ok(reqErr instanceof nodeServer.RequestError);
assert.equal(reqErr.name, 'RequestError');
assert.equal(reqErr.message, 'malformed input');
assert.equal(reqErr.cause, rootCause);
}
async function testServeGetAndPost() {
let listeningInfo = null;
let server;
await new Promise((resolve) => {
server = startWithServe((info) => {
listeningInfo = info;
resolve();
});
});
try {
assert.ok(listeningInfo);
assert.equal(typeof listeningInfo.port, 'number');
assert.ok(listeningInfo.port > 0);
assert.equal(listeningInfo.address, '127.0.0.1');
const healthRes = await httpRequest({
port: listeningInfo.port,
method: 'GET',
path: '/health',
});
assert.equal(healthRes.statusCode, 200);
assert.deepEqual(JSON.parse(healthRes.body), { status: 'ok' });
const payload = JSON.stringify({ item: 'widget', count: 3 });
const echoRes = await httpRequest({
port: listeningInfo.port,
method: 'POST',
path: '/echo',
headers: {
'content-type': 'application/json',
'content-length': Buffer.byteLength(payload),
'x-trace-id': 'trace-42',
},
body: payload,
});
assert.equal(echoRes.statusCode, 201);
assert.deepEqual(JSON.parse(echoRes.body), {
received: { item: 'widget', count: 3 },
customHeader: 'trace-42',
});
} finally {
await closeServer(server);
}
}
async function testCreateAdaptorServerAndConnInfo() {
const server = createServerWithoutListening();
assert.ok(server instanceof http.Server);
assert.equal(server.listening, false);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
try {
assert.equal(server.listening, true);
const { port } = server.address();
const connRes = await httpRequest({
port,
method: 'GET',
path: '/conn',
});
assert.equal(connRes.statusCode, 200);
const data = JSON.parse(connRes.body);
assert.equal(data.hasIncoming, true);
assert.equal(data.hasOutgoing, true);
assert.equal(data.remote.address, '127.0.0.1');
assert.equal(data.remote.addressType, 'IPv4');
assert.equal(typeof data.remote.port, 'number');
assert.ok(data.remote.port > 0);
} finally {
await closeServer(server);
}
}
async function testGetRequestListenerAndEarlyHints() {
const capturedErrors = [];
const server = createListenerServer((err) => capturedErrors.push(err));
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
try {
const { port } = server.address();
const errRes = await httpRequest({
port,
method: 'GET',
path: '/fail',
});
assert.equal(errRes.statusCode, 400);
assert.equal(capturedErrors.length, 1);
assert.ok(capturedErrors[0] instanceof nodeServer.RequestError);
assert.equal(capturedErrors[0].cause.message, 'invalid query');
assert.deepEqual(JSON.parse(errRes.body), {
error: 'RequestError',
message: 'simulated bad request',
});
const navHintsRes = await httpRequest({
port,
method: 'GET',
path: '/hints',
headers: {
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Dest': 'document',
},
});
assert.equal(navHintsRes.statusCode, 200);
assert.equal(navHintsRes.body, '<html>ok</html>');
assert.equal(navHintsRes.infoResponses.length, 1);
assert.equal(navHintsRes.infoResponses[0].statusCode, 103);
assert.equal(
navHintsRes.infoResponses[0].headers.link,
'</styles.css>; rel=preload; as=style'
);
const apiHintsRes = await httpRequest({
port,
method: 'GET',
path: '/hints',
headers: {
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
},
});
assert.equal(apiHintsRes.statusCode, 200);
assert.equal(apiHintsRes.infoResponses.length, 0);
} finally {
await closeServer(server);
}
}
async function main() {
await testExportsAndRequestError();
await testServeGetAndPost();
await testCreateAdaptorServerAndConnInfo();
await testGetRequestListenerAndEarlyHints();
console.log('contract passed');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Seeder de origen
anónimo