CodeSampleX

Ejemplo

hono 4.13.7: etag

Muestra verificada para npm hono 4.13.7: etag. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: etag is exported as a middleware factory…

sha256:aaf7c483531b7e50e8737a2943159abcdd961f0a0845e654d69a78a99ef77368

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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
Paquetes
Símbolos
  • hono/etag
Entorno
node 22.23.2
Creado
2026-09-06T03:25:44Z

Contrato

  1. etag is exported as a middleware factory function from hono/etag
  2. etag middleware computes and sets SHA-1 ETag header for successful GET responses
  3. etag middleware supports weak option to prepend W/ prefix to generated ETag
  4. etag middleware responds with 304 Not Modified when If-None-Match header matches generated ETag or wildcard
  5. etag middleware does not overwrite existing ETag header manually set by route handler
  6. etag middleware skips ETag generation for non-cacheable methods like POST

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

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: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"}
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "sample-hono-etag",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "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"
  ]
}
test/contract.mjs
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 origen

anónimo