CodeSampleX

샘플

hono 4.6.0: Hono

검증된 샘플 — npm hono 4.6.0: Hono. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Hono instance handles GET requests and returns JSON response with…

sha256:0e22b158406bffc4ffae9a0eed7f86dc4ea64f95b826a09c681ce4a296708bce

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-05

케이스

HOW
목표
verify hono.Hono in pkg:npm/hono@4.6.0
패키지
심벌
  • hono.Hono
환경
node 22.23.2
생성일
2026-09-05T08:51:36Z

컨트랙트

  1. Hono instance handles GET requests and returns JSON response with status code and headers
  2. Hono router extracts path parameters and query parameters from request context
  3. Hono router dispatches POST requests and parses incoming JSON body
  4. Hono middleware executes in onion model modifying context variables and response headers
  5. Hono mounts sub-applications using route method preserving nested path prefixes
  6. Hono handles unhandled exceptions via onError and unmatched routes via notFound

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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.Hono in pkg:npm/hono@4.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/hono@4.6.0
Demonstrate these symbols/APIs:
  - hono.Hono
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.
csx.json
{"case":{"caseId":"case:sha256:05edf12f16567a6074cbf05f2a010e9141278b277f31353716f693bc3da59dc9","constraints":{"executionContext":"node"},"contract":["Hono instance handles GET requests and returns JSON response with status code and headers","Hono router extracts path parameters and query parameters from request context","Hono router dispatches POST requests and parses incoming JSON body","Hono middleware executes in onion model modifying context variables and response headers","Hono mounts sub-applications using route method preserving nested path prefixes","Hono handles unhandled exceptions via onError and unmatched routes via notFound"],"goal":"verify hono.Hono in pkg:npm/hono@4.6.0","kind":"HOW","packages":["pkg:npm/hono@4.6.0"],"schemaVersion":1,"symbols":["hono.Hono"]},"contractCommand":["node","test/contract.mjs"],"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/hono@4.6.0"],"schemaVersion":1,"subject":"pkg:npm/hono@4.6.0","symbols":["hono.Hono"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-hono-hono",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-hono",
      "version": "1.0.0",
      "dependencies": {
        "hono": "4.6.0"
      }
    },
    "node_modules/hono": {
      "version": "4.6.0",
      "resolved": "https://registry.npmjs.org/hono/-/hono-4.6.0.tgz",
      "integrity": "sha512-2jN7gHRCbfFXpHitg87ZDsComUB+PEm+rf2aDjy6e9SCwgnxkpQBCTKYumWQ4q4D3a+KuSW8VJAHzl4EnqYfeg==",
      "license": "MIT",
      "engines": {
        "node": ">=16.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-hono",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for hono.Hono in pkg:npm/hono@4.6.0",
  "dependencies": {
    "hono": "4.6.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify hono.Hono in pkg:npm/hono@4.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hono@4.6.0"
  ],
  "symbols": [
    "hono.Hono"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import { Hono } from 'hono';

/**
 * Creates and configures a Hono web application demonstrating core features:
 * route definitions, URL parameters, query strings, JSON payloads, middleware,
 * sub-app mounting, and custom error/notFound handling.
 *
 * @returns {Hono} The configured Hono application.
 */
export function createApp() {
  const app = new Hono();

  // Middleware modifying context and downstream headers
  app.use('*', async (c, next) => {
    c.set('customContextKey', 'context-value-123');
    await next();
    c.header('X-Custom-Middleware', 'hono-processed');
  });

  // GET route with JSON response and custom status/headers
  app.get('/api/hello', (c) => {
    return c.json(
      { message: 'Hello Hono', ctx: c.get('customContextKey') },
      200,
      { 'X-Hello-Response': 'true' }
    );
  });

  // Route parameters and query parameters
  app.get('/api/users/:id', (c) => {
    const id = c.req.param('id');
    const role = c.req.query('role');
    return c.json({ id, role });
  });

  // POST route parsing JSON body
  app.post('/api/items', async (c) => {
    const body = await c.req.json();
    return c.json({ success: true, item: body }, 201);
  });

  // Sub-app mounted via app.route
  const subApp = new Hono();
  subApp.get('/status', (c) => c.json({ subStatus: 'operational' }));
  app.route('/api/sub', subApp);

  // Route that throws an error to test onError
  app.get('/api/error', () => {
    throw new Error('Test server exception');
  });

  // Custom error handler
  app.onError((err, c) => {
    return c.json(
      { error: err.message, handled: true },
      500
    );
  });

  // Custom not found handler
  app.notFound((c) => {
    return c.json(
      { error: 'Resource Not Found', pathname: c.req.path },
      404
    );
  });

  return app;
}

export { Hono };
test/contract.mjs
import assert from 'node:assert/strict';
import { createApp, Hono } from '../src/index.mjs';

// Contract 1: Hono instance handles GET requests and returns JSON response with status code and headers
{
  assert.equal(typeof Hono, 'function', 'Hono must be a constructor');
  const app = createApp();
  assert.ok(app instanceof Hono, 'createApp must return a Hono instance');

  const res = await app.request('http://localhost/api/hello');
  assert.equal(res.status, 200, 'GET /api/hello must return 200');
  assert.equal(res.headers.get('x-hello-response'), 'true');
  assert.equal(res.headers.get('x-custom-middleware'), 'hono-processed');

  const body = await res.json();
  assert.equal(body.message, 'Hello Hono');
  assert.equal(body.ctx, 'context-value-123');
}

// Contract 2: Hono router extracts path parameters and query parameters from request context
{
  const app = createApp();

  const res = await app.request('http://localhost/api/users/user-456?role=editor');
  assert.equal(res.status, 200);

  const body = await res.json();
  assert.equal(body.id, 'user-456');
  assert.equal(body.role, 'editor');
}

// Contract 3: Hono router dispatches POST requests and parses incoming JSON body
{
  const app = createApp();

  const payload = { title: 'Sample Item', count: 10 };
  const res = await app.request('http://localhost/api/items', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload)
  });

  assert.equal(res.status, 201, 'POST /api/items must return 201');
  const body = await res.json();
  assert.equal(body.success, true);
  assert.deepEqual(body.item, payload);
}

// Contract 4: Hono middleware executes in onion model modifying context variables and response headers
{
  const app = createApp();

  const res = await app.request('http://localhost/api/hello');
  assert.equal(res.headers.get('x-custom-middleware'), 'hono-processed');
  const body = await res.json();
  assert.equal(body.ctx, 'context-value-123');
}

// Contract 5: Hono mounts sub-applications using route method preserving nested path prefixes
{
  const app = createApp();

  const res = await app.request('http://localhost/api/sub/status');
  assert.equal(res.status, 200);

  const body = await res.json();
  assert.equal(body.subStatus, 'operational');
}

// Contract 6: Hono handles unhandled exceptions via onError and unmatched routes via notFound
{
  const app = createApp();

  // Test custom error handler
  const errorRes = await app.request('http://localhost/api/error');
  assert.equal(errorRes.status, 500);
  const errorBody = await errorRes.json();
  assert.equal(errorBody.error, 'Test server exception');
  assert.equal(errorBody.handled, true);

  // Test custom not found handler
  const notFoundRes = await app.request('http://localhost/api/non-existent-route');
  assert.equal(notFoundRes.status, 404);
  const notFoundBody = await notFoundRes.json();
  assert.equal(notFoundBody.error, 'Resource Not Found');
}

console.log('All contracts for hono.Hono in pkg:npm/hono@4.6.0 passed.');

오리진 시더

익명