Exemplo
hono 4.13.7: etag
Amostra verificada para npm hono 4.13.7: etag. O contrato rodou em node 22 · linux debian/x64 · docker e passou: etag is exported as a middleware factory…
sha256:aaf7c483531b7e50e8737a2943159abcdd961f0a0845e654d69a78a99ef77368
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 pkg:npm/hono@4.13.7
- Pacotes
- Símbolos
-
- hono/etag
- Ambiente
- node 22.23.2
- Criado
- 2026-09-06T03:25:44Z
Contrato
- etag is exported as a middleware factory function from hono/etag
- etag middleware computes and sets SHA-1 ETag header for successful GET responses
- etag middleware supports weak option to prepend W/ prefix to generated ETag
- etag middleware responds with 304 Not Modified when If-None-Match header matches generated ETag or wildcard
- etag middleware does not overwrite existing ETag header manually set by route handler
- etag middleware skips ETag generation for non-cacheable methods like POST
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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
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:95e9f65fbde5e9d14a1c03ca76ea8d58409224145b3addbcd6116efd5acd29bb","contract":["etag is exported as a middleware factory function from hono/etag","etag middleware computes and sets SHA-1 ETag header for successful GET responses","etag middleware supports weak option to prepend W/ prefix to generated ETag","etag middleware responds with 304 Not Modified when If-None-Match header matches generated ETag or wildcard","etag middleware does not overwrite existing ETag header manually set by route handler","etag middleware skips ETag generation for non-cacheable methods like POST"],"goal":"verify pkg:npm/hono@4.13.7","kind":"HOW","packages":["pkg:npm/hono@4.13.7"],"schemaVersion":1,"symbols":["hono/etag"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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/etag"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-hono-etag",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-hono-etag",
"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"
}
}
}
}
{
"name": "sample-hono-etag",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"dependencies": {
"hono": "4.13.7"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/hono@4.13.7",
"kind": "HOW",
"packages": [
"pkg:npm/hono@4.13.7"
]
}
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { Hono } from 'hono';
import { etag, RETAINED_304_HEADERS } from 'hono/etag';
// Contract 1: etag is exported as a middleware factory function from hono/etag
{
assert.strictEqual(typeof etag, 'function');
assert.ok(Array.isArray(RETAINED_304_HEADERS));
assert.ok(RETAINED_304_HEADERS.includes('etag'));
assert.ok(RETAINED_304_HEADERS.includes('cache-control'));
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');
assert.ok(pkgJson.exports['./etag']);
}
// Contract 2: etag middleware computes and sets SHA-1 ETag header for successful GET responses
{
const app = new Hono();
app.use('*', etag());
app.get('/resource', (c) => c.json({ message: 'content' }));
const res = await app.request('http://localhost/resource');
assert.strictEqual(res.status, 200);
const etagHeader = res.headers.get('etag');
assert.ok(etagHeader);
assert.match(etagHeader, /^"[0-9a-f]{40}"$/);
}
// Contract 3: etag middleware supports weak option to prepend W/ prefix to generated ETag
{
const app = new Hono();
app.use('*', etag({ weak: true }));
app.get('/weak-resource', (c) => c.text('weak content'));
const res = await app.request('http://localhost/weak-resource');
assert.strictEqual(res.status, 200);
const etagHeader = res.headers.get('etag');
assert.ok(etagHeader);
assert.match(etagHeader, /^W\/"[0-9a-f]{40}"$/);
}
// Contract 4: etag middleware responds with 304 Not Modified when If-None-Match header matches generated ETag or wildcard
{
const app = new Hono();
app.use('*', etag());
app.get('/cached', (c) => c.text('cached content'));
const initialRes = await app.request('http://localhost/cached');
assert.strictEqual(initialRes.status, 200);
const currentEtag = initialRes.headers.get('etag');
assert.ok(currentEtag);
// Exact ETag match
const matchRes = await app.request('http://localhost/cached', {
headers: { 'If-None-Match': currentEtag },
});
assert.strictEqual(matchRes.status, 304);
assert.strictEqual(await matchRes.text(), '');
assert.strictEqual(matchRes.headers.get('etag'), currentEtag);
// Wildcard match
const wildcardRes = await app.request('http://localhost/cached', {
headers: { 'If-None-Match': '*' },
});
assert.strictEqual(wildcardRes.status, 304);
assert.strictEqual(await wildcardRes.text(), '');
// Mismatched ETag returns 200
const mismatchRes = await app.request('http://localhost/cached', {
headers: { 'If-None-Match': '"mismatched-etag"' },
});
assert.strictEqual(mismatchRes.status, 200);
assert.strictEqual(await mismatchRes.text(), 'cached content');
}
// Contract 5: etag middleware does not overwrite existing ETag header manually set by route handler
{
const app = new Hono();
app.use('*', etag());
app.get('/predefined', (c) => {
c.header('ETag', '"custom-hash-999"');
return c.text('manual etag body');
});
const res = await app.request('http://localhost/predefined');
assert.strictEqual(res.status, 200);
assert.strictEqual(res.headers.get('etag'), '"custom-hash-999"');
}
// Contract 6: etag middleware skips ETag generation for non-cacheable methods like POST
{
const app = new Hono();
app.use('*', etag());
app.post('/submit', (c) => c.json({ ok: true }));
const res = await app.request('http://localhost/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ item: 'data' }),
});
assert.strictEqual(res.status, 200);
assert.strictEqual(res.headers.get('etag'), null);
}
console.log('CONTRACT PASS: All hono/etag assertions passed.');
Seeder de origem
anônimo