CodeSampleX

Пример

hono 4.13.7: Hono

Проверенный пример — npm hono 4.13.7: Hono. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: hono.Hono is exported as a constructor class…

sha256:5f6a88b281ce7f70addf93f256b4725dafc6869b5bcdb59bc7e2b02f26d10494

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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-06

Кейс

HOW
Цель
verify pkg:npm/hono@4.13.7
Пакеты
Символы
  • hono.Hono
Окружение
node 22.23.2
Создан
2026-09-06T03:33:10Z

Контракт

  1. hono.Hono is exported as a constructor class from hono
  2. Hono instance handles GET routes with middleware context and custom headers
  3. Hono instance extracts path parameters and query parameters from request context
  4. Hono instance processes POST requests with JSON payload and returns structured response
  5. Hono mounts sub-applications using route method preserving nested path prefixes
  6. Hono instance returns 404 response for unmatched routes

Файлы

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

Use EXACTLY these public packages and versions:
  - pkg:npm/hono@4.13.7
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:36434f4c0c00e8f671a2838e997ef640f7c566d9cb1cf2c5af07746a6ed95c76","constraints":{"executionContext":"node"},"contract":["hono.Hono is exported as a constructor class from hono","Hono instance handles GET routes with middleware context and custom headers","Hono instance extracts path parameters and query parameters from request context","Hono instance processes POST requests with JSON payload and returns structured response","Hono mounts sub-applications using route method preserving nested path prefixes","Hono instance returns 404 response for unmatched routes"],"goal":"verify pkg:npm/hono@4.13.7","kind":"HOW","packages":["pkg:npm/hono@4.13.7"],"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.13.7"],"schemaVersion":1,"subject":"pkg:npm/hono@4.13.7","symbols":["hono.Hono"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-hono-core",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hono-core",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "hono": "4.13.7"
      }
    },
    "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",
      "engines": {
        "node": ">=16.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-core",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of hono.Hono in pkg:npm/hono@4.13.7",
  "main": "src/index.js",
  "dependencies": {
    "hono": "4.13.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/hono@4.13.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hono@4.13.7"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { Hono } = require('hono');

/**
 * Creates and configures a clean-room Hono application instance.
 * @returns {Hono} Configured Hono application.
 */
function createApp() {
  const app = new Hono();

  // Middleware: sets context variable and custom response header
  app.use('*', async (c, next) => {
    c.set('traceId', 'trace-hono-4137');
    await next();
    c.header('X-App-Framework', 'Hono');
  });

  // GET route with context variable and custom header
  app.get('/api/health', (c) => {
    const traceId = c.get('traceId');
    return c.json({ status: 'healthy', traceId });
  });

  // Route with path parameter and query parameter
  app.get('/api/items/:id', (c) => {
    const id = c.req.param('id');
    const filter = c.req.query('filter') || 'all';
    return c.json({ id, filter });
  });

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

  // Sub-application mounted via app.route
  const subApp = new Hono();
  subApp.get('/info', (c) => {
    return c.json({ module: 'sub-service' });
  });
  app.route('/api/nested', subApp);

  return app;
}

module.exports = {
  Hono,
  createApp
};
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { Hono, createApp } = require('../src/index.js');

// Contract 1: hono.Hono is exported as a constructor class from hono
{
  assert.strictEqual(typeof Hono, 'function', 'Hono must be a function/constructor');
  const instance = new Hono();
  assert.ok(instance instanceof Hono, 'new Hono() creates an instance of Hono');
  assert.strictEqual(typeof instance.fetch, 'function', 'Hono instance must implement fetch');
  assert.strictEqual(typeof instance.request, 'function', 'Hono instance must implement request');
  assert.strictEqual(typeof instance.get, 'function', 'Hono instance must implement get');
  assert.strictEqual(typeof instance.post, 'function', 'Hono instance must implement post');
  assert.strictEqual(typeof instance.use, 'function', 'Hono instance must implement use');
  assert.strictEqual(typeof instance.route, 'function', 'Hono instance must implement route');

  // Verify pinned package version
  const honoEntryUrl = import.meta.resolve('hono');
  const pkgJsonPath = fileURLToPath(new URL('../package.json', honoEntryUrl));
  assert.ok(fs.existsSync(pkgJsonPath));
  const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
  assert.strictEqual(pkgJson.name, 'hono');
  assert.strictEqual(pkgJson.version, '4.13.7');
}

// Contract 2: Hono instance handles GET routes with middleware context and custom headers
{
  const app = createApp();
  const req = new Request('http://localhost/api/health');
  const res = await app.fetch(req);

  assert.strictEqual(res.status, 200, 'GET /api/health returns HTTP 200');
  assert.strictEqual(res.headers.get('x-app-framework'), 'Hono', 'Middleware sets custom header');
  const data = await res.json();
  assert.deepStrictEqual(data, {
    status: 'healthy',
    traceId: 'trace-hono-4137'
  });
}

// Contract 3: Hono instance extracts path parameters and query parameters from request context
{
  const app = createApp();
  const req = new Request('http://localhost/api/items/item-101?filter=active');
  const res = await app.fetch(req);

  assert.strictEqual(res.status, 200, 'GET /api/items/item-101 returns HTTP 200');
  const data = await res.json();
  assert.deepStrictEqual(data, {
    id: 'item-101',
    filter: 'active'
  });
}

// Contract 4: Hono instance processes POST requests with JSON payload and returns structured response
{
  const app = createApp();
  const payload = { title: 'Sample item', count: 5 };
  const req = new Request('http://localhost/api/items', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload)
  });
  const res = await app.fetch(req);

  assert.strictEqual(res.status, 201, 'POST /api/items returns HTTP 201 Created');
  const data = await res.json();
  assert.deepStrictEqual(data, {
    created: true,
    item: payload
  });
}

// Contract 5: Hono mounts sub-applications using route method preserving nested path prefixes
{
  const app = createApp();
  const req = new Request('http://localhost/api/nested/info');
  const res = await app.fetch(req);

  assert.strictEqual(res.status, 200, 'Mounted sub-app responds on prefixed path');
  const data = await res.json();
  assert.deepStrictEqual(data, { module: 'sub-service' });
}

// Contract 6: Hono instance returns 404 response for unmatched routes
{
  const app = createApp();
  const req = new Request('http://localhost/non-existent-endpoint');
  const res = await app.fetch(req);

  assert.strictEqual(res.status, 404, 'Unmatched route returns HTTP 404 Not Found');
}

console.log('CONTRACT PASS: All hono.Hono contract assertions passed.');

Исходный сидер

аноним