CodeSampleX

Ejemplo

@hono/node-server 2.1.1: getConnInfo

Muestra verificada para npm @hono/node-server 2.1.1: getConnInfo. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:1628291b7e7ae82eca717952f3d6d95dbc5f28406b2c5df1667a25b232eebe9f

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 linux 24 · ubuntu · glibc 2.39 x64 npm

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-09-06

Caso

HOW
Objetivo
verify @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1
Paquetes
Símbolos
  • @hono/node-server.getConnInfo
Creado
2026-09-06T01:24:19Z

Contrato

  1. getConnInfo is an exported function from @hono/node-server/conninfo
  2. getConnInfo extracts remote address, port, and IPv4 addressType from c.env.incoming.socket
  3. getConnInfo extracts remote connection details when incoming socket is under c.env.server.incoming
  4. getConnInfo detects IPv6 addressType when remoteFamily is IPv6
  5. getConnInfo sets addressType to undefined when remoteFamily is neither IPv4 nor IPv6
  6. getConnInfo extracts live connection information from a running HTTP server request socket

Archivos

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
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 @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40hono/node-server@2.1.1
Demonstrate these symbols/APIs:
  - @hono/node-server.getConnInfo

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.
csx.json
{"case":{"caseId":"case:sha256:43ab6114a17ab044f150e20fb8fb52570f37247b9ba0b2a923e8399d9c8b3036","contract":["getConnInfo is an exported function from @hono/node-server/conninfo","getConnInfo extracts remote address, port, and IPv4 addressType from c.env.incoming.socket","getConnInfo extracts remote connection details when incoming socket is under c.env.server.incoming","getConnInfo detects IPv6 addressType when remoteFamily is IPv6","getConnInfo sets addressType to undefined when remoteFamily is neither IPv4 nor IPv6","getConnInfo extracts live connection information from a running HTTP server request socket"],"goal":"verify @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1","kind":"HOW","packages":["pkg:npm/%40hono/node-server@2.1.1"],"schemaVersion":1,"symbols":["@hono/node-server.getConnInfo"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40hono/node-server@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/%40hono/node-server@2.1.1","symbols":["@hono/node-server.getConnInfo"],"verifierAdapter":"node-typescript@1"}
index.js
export { getConnInfo } from '@hono/node-server/conninfo';
package-lock.json
{
  "name": "sample-hono-node-server-getconninfo",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-node-server-getconninfo",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@hono/node-server": "2.1.1"
      }
    },
    "node_modules/@hono/node-server": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.1.tgz",
      "integrity": "sha512-ELuehkj5VCBdgEw9zs+ivkKwyzzUCSQuE96YmiPvn1ECBoZCczbFXJLeEGMTYjphP6gydh4pHMqEYPVMYUVgQg==",
      "license": "MIT",
      "engines": {
        "node": ">=20"
      },
      "peerDependencies": {
        "hono": "^4"
      }
    },
    "node_modules/hono": {
      "version": "4.13.7",
      "resolved": "https://registry.npmjs.org/hono/-/hono-4.13.7.tgz",
      "integrity": "sha512-c8/gF9ac8Y78/agExVocyLevgR+JlpNB444Py0FSX8pJoPdYUfUzRcXtYEYGwt6l19qIlVZPN5Mfsw9jFShmQQ==",
      "license": "MIT",
      "peer": true,
      "engines": {
        "node": ">=16.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-node-server-getconninfo",
  "version": "1.0.0",
  "private": true,
  "description": "verify @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@hono/node-server": "2.1.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40hono/node-server@2.1.1"
  ],
  "symbols": [
    "@hono/node-server.getConnInfo"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import http from 'node:http';
import { getConnInfo } from '../index.js';

// 1. getConnInfo is an exported function from @hono/node-server/conninfo
assert.strictEqual(typeof getConnInfo, 'function', 'getConnInfo must be an exported function');

// 2. getConnInfo extracts remote address, port, and IPv4 addressType from c.env.incoming.socket
const ctxDirect = {
  env: {
    incoming: {
      socket: {
        remoteAddress: '127.0.0.1',
        remotePort: 54321,
        remoteFamily: 'IPv4'
      }
    }
  }
};
const directInfo = getConnInfo(ctxDirect);
assert.deepStrictEqual(directInfo, {
  remote: {
    address: '127.0.0.1',
    port: 54321,
    addressType: 'IPv4'
  }
});

// 3. getConnInfo extracts remote connection details when incoming socket is under c.env.server.incoming
const ctxNested = {
  env: {
    server: {
      incoming: {
        socket: {
          remoteAddress: '192.168.1.100',
          remotePort: 8080,
          remoteFamily: 'IPv4'
        }
      }
    }
  }
};
const nestedInfo = getConnInfo(ctxNested);
assert.deepStrictEqual(nestedInfo, {
  remote: {
    address: '192.168.1.100',
    port: 8080,
    addressType: 'IPv4'
  }
});

// 4. getConnInfo detects IPv6 addressType when remoteFamily is IPv6
const ctxIPv6 = {
  env: {
    incoming: {
      socket: {
        remoteAddress: '::1',
        remotePort: 9000,
        remoteFamily: 'IPv6'
      }
    }
  }
};
const ipv6Info = getConnInfo(ctxIPv6);
assert.deepStrictEqual(ipv6Info, {
  remote: {
    address: '::1',
    port: 9000,
    addressType: 'IPv6'
  }
});

// 5. getConnInfo sets addressType to undefined when remoteFamily is neither IPv4 nor IPv6
const ctxUnknownFamily = {
  env: {
    incoming: {
      socket: {
        remoteAddress: 'custom-pipe',
        remotePort: undefined,
        remoteFamily: 'UnknownFamily'
      }
    }
  }
};
const unknownInfo = getConnInfo(ctxUnknownFamily);
assert.deepStrictEqual(unknownInfo, {
  remote: {
    address: 'custom-pipe',
    port: undefined,
    addressType: undefined
  }
});

// 6. getConnInfo extracts live connection information from a running HTTP server request socket
const server = http.createServer((req, res) => {
  const liveContext = {
    env: {
      incoming: req
    }
  };
  const liveInfo = getConnInfo(liveContext);
  assert(liveInfo && liveInfo.remote, 'remote property must exist');
  assert(typeof liveInfo.remote.address === 'string', 'address must be string');
  assert(typeof liveInfo.remote.port === 'number' && liveInfo.remote.port > 0, 'port must be positive number');
  assert(['IPv4', 'IPv6'].includes(liveInfo.remote.addressType), 'addressType must be IPv4 or IPv6');

  res.statusCode = 200;
  res.end('ok');
});

await new Promise((resolve, reject) => {
  server.listen(0, '127.0.0.1', () => {
    const addressInfo = server.address();
    const port = addressInfo.port;
    const clientReq = http.get(`http://127.0.0.1:${port}`, (res) => {
      res.resume();
      res.on('end', () => {
        server.close((err) => {
          if (err) reject(err);
          else resolve();
        });
      });
    });
    clientReq.on('error', reject);
  });
});

console.log('Contract tests passed successfully.');

Seeder de origen

anónimo