示例
hono 4.6.0: Hono
已验证示例 — npm hono 4.6.0: Hono. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Hono constructor initializes an instance that registers route handlers
sha256:5729673478850131e78d1a12716eb3bf9818a77447684cc0bf9f055aedd6d9b8
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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-05 |
案例
HOW- 目标
- verify pkg:npm/hono@4.6.0
- 符号
-
- Hono
- 创建时间
- 2026-09-05T07:30:30Z
契约
- Hono constructor initializes an instance that registers route handlers
- Hono router matches GET requests and extracts path and query parameters
- Hono router dispatches POST requests and parses incoming JSON payload
- Hono middleware executes in onion model modifying context variables and headers
- Hono mounts sub-applications using route method preserving nested path prefixes
- Hono handles custom error responses via onError and unmatched routes via notFound
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
源代码
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.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/hono@4.6.0
Demonstrate these symbols/APIs:
- Hono
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:7b80e48eed58f07b50860beb78124e9a8f35bed2053139d3d84b5fb4c582b105","contract":["Hono constructor initializes an instance that registers route handlers","Hono router matches GET requests and extracts path and query parameters","Hono router dispatches POST requests and parses incoming JSON payload","Hono middleware executes in onion model modifying context variables and headers","Hono mounts sub-applications using route method preserving nested path prefixes","Hono handles custom error responses via onError and unmatched routes via notFound"],"goal":"verify pkg:npm/hono@4.6.0","kind":"HOW","packages":["pkg:npm/hono@4.6.0"],"schemaVersion":1,"symbols":["Hono"]},"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/hono@4.6.0"],"schemaVersion":1,"subject":"pkg:npm/hono@4.6.0","symbols":["Hono"],"verifierAdapter":"node-typescript@1"}
{
"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.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"
}
}
}
}
{
"name": "sample-hono-core",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for Hono in hono@4.6.0",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"hono": "4.6.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/hono@4.6.0",
"kind": "HOW",
"packages": [
"pkg:npm/hono@4.6.0"
],
"symbols": [
"Hono"
]
}
'use strict';
const { Hono } = require('hono');
/**
* Creates and configures a Hono web application demonstrating core features:
* routing, URL parameters, query strings, JSON payloads, middleware,
* sub-application mounting, onError and notFound handling.
*
* @returns {Hono} The configured Hono application.
*/
function createApp() {
const app = new Hono();
// Middleware modifying context and response 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, status code and custom header
app.get('/api/hello', (c) => {
return c.json(
{ message: 'Hello Hono', ctx: c.get('customContextKey') },
200,
{ 'X-Hello-Response': 'true' }
);
});
// Route with path parameter and query parameter
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-application mounted via route()
const subApp = new Hono();
subApp.get('/status', (c) => c.json({ subStatus: 'operational' }));
app.route('/api/sub', subApp);
// Route that throws 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;
}
module.exports = {
createApp,
Hono
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { createApp, Hono } = require('../src/index.js');
async function testAll() {
// Contract 1: Hono constructor initializes an instance that registers route handlers
assert.equal(typeof Hono, 'function', 'Hono must be a constructor function');
const app = createApp();
assert.ok(app instanceof Hono, 'createApp must return a Hono instance');
// Contract 2: Hono router matches GET requests and extracts path and query parameters
const userRes = await app.fetch(new Request('http://localhost/api/users/user-456?role=editor'));
assert.equal(userRes.status, 200, 'GET /api/users/:id must return 200');
const userBody = await userRes.json();
assert.deepEqual(userBody, { id: 'user-456', role: 'editor' });
// Contract 3: Hono router dispatches POST requests and parses incoming JSON payload
const payload = { title: 'Sample Item', count: 10 };
const postRes = await app.fetch(
new Request('http://localhost/api/items', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
);
assert.equal(postRes.status, 201, 'POST /api/items must return 201');
const postBody = await postRes.json();
assert.deepEqual(postBody, { success: true, item: payload });
// Contract 4: Hono middleware executes in onion model modifying context variables and headers
const helloRes = await app.fetch(new Request('http://localhost/api/hello'));
assert.equal(helloRes.status, 200, 'GET /api/hello must return 200');
assert.equal(helloRes.headers.get('x-hello-response'), 'true');
assert.equal(helloRes.headers.get('x-custom-middleware'), 'hono-processed');
const helloBody = await helloRes.json();
assert.equal(helloBody.message, 'Hello Hono');
assert.equal(helloBody.ctx, 'context-value-123');
// Contract 5: Hono mounts sub-applications using route method preserving nested path prefixes
const subRes = await app.fetch(new Request('http://localhost/api/sub/status'));
assert.equal(subRes.status, 200, 'GET /api/sub/status must return 200');
const subBody = await subRes.json();
assert.deepEqual(subBody, { subStatus: 'operational' });
// Contract 6: Hono handles custom error responses via onError and unmatched routes via notFound
const errorRes = await app.fetch(new Request('http://localhost/api/error'));
assert.equal(errorRes.status, 500, 'Error route must return status 500');
const errorBody = await errorRes.json();
assert.deepEqual(errorBody, { error: 'Test server exception', handled: true });
const notFoundRes = await app.fetch(new Request('http://localhost/api/unmatched-route'));
assert.equal(notFoundRes.status, 404, 'Unmatched route must return status 404');
const notFoundBody = await notFoundRes.json();
assert.deepEqual(notFoundBody, { error: 'Resource Not Found', pathname: '/api/unmatched-route' });
console.log('All contract assertions for Hono in pkg:npm/hono@4.6.0 passed successfully.');
}
testAll().catch((err) => {
console.error('Contract test failure:', err);
process.exit(1);
});
原始种子者
匿名