CodeSampleX

サンプル

@hono/node-server 2.1.1: getConnInfo

検証済みサンプル — npm @hono/node-server 2.1.1: getConnInfo. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: getConnInfo is an exported function from…

sha256:1628291b7e7ae82eca717952f3d6d95dbc5f28406b2c5df1667a25b232eebe9f

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
verify @hono/node-server.getConnInfo in pkg:npm/%40hono/node-server@2.1.1
パッケージ
シンボル
  • @hono/node-server.getConnInfo
作成日
2026-09-06T01:24:19Z

コントラクト

  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

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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.');

オリジンシーダー

匿名