CodeSampleX

Ejemplo

http-errors 2.0.1

Muestra verificada para npm http-errors 2.0.1. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: createError(status, message) creates an…

sha256:29bdb75fec5affb75e39de6458dff09ad1729b16d79407547721bc7e063a6f0f

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Caso

HOW
Objetivo
verify pkg:npm/http-errors@2.0.1
Paquetes
Creado
2026-08-20T13:53:31Z

Contrato

  1. createError(status, message) creates an HttpError instance with status, statusCode, name, message, and expose (true for 4xx, false for 5xx)
  2. createError(status, properties) and createError(status, message, properties) attach custom properties and headers to the error
  3. createError(error) and createError(status, error, properties) extend existing Error instances without altering prototype inheritance
  4. createError[code] and createError[name] direct constructors instantiate specific HttpError subclasses with correct prototypes
  5. createError.HttpError abstract base class throws TypeError when directly instantiated
  6. createError.isHttpError(val) correctly identifies HttpError instances and duck-typed error objects while rejecting plain objects and primitives
  7. createError throws TypeError for unsupported argument types and falls back to status 500 for unknown status numbers

Archivos

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

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/http-errors@2.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/http-errors@2.0.1

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:780f2a4b018741a5a0b53ba46a968d64b34fd6047ff521dfa2dcc5282dfdea96","contract":["createError(status, message) creates an HttpError instance with status, statusCode, name, message, and expose (true for 4xx, false for 5xx)","createError(status, properties) and createError(status, message, properties) attach custom properties and headers to the error","createError(error) and createError(status, error, properties) extend existing Error instances without altering prototype inheritance","createError[code] and createError[name] direct constructors instantiate specific HttpError subclasses with correct prototypes","createError.HttpError abstract base class throws TypeError when directly instantiated","createError.isHttpError(val) correctly identifies HttpError instances and duck-typed error objects while rejecting plain objects and primitives","createError throws TypeError for unsupported argument types and falls back to status 500 for unknown status numbers"],"goal":"verify pkg:npm/http-errors@2.0.1","kind":"HOW","packages":["pkg:npm/http-errors@2.0.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/http-errors@2.0.1"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-http-errors",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-http-errors",
      "version": "1.0.0",
      "dependencies": {
        "http-errors": "2.0.1"
      }
    },
    "node_modules/depd": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
      "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/http-errors": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
      "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
      "license": "MIT",
      "dependencies": {
        "depd": "~2.0.0",
        "inherits": "~2.0.4",
        "setprototypeof": "~1.2.0",
        "statuses": "~2.0.2",
        "toidentifier": "~1.0.1"
      },
      "engines": {
        "node": ">= 0.8"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/express"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/setprototypeof": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
      "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
      "license": "ISC"
    },
    "node_modules/statuses": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
      "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    },
    "node_modules/toidentifier": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
      "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.6"
      }
    }
  }
}
package.json
{
  "name": "sample-http-errors",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for http-errors",
  "dependencies": {
    "http-errors": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/http-errors@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/http-errors@2.0.1"
  ]
}
test/contract.cjs
const assert = require('node:assert/strict');
const createError = require('http-errors');

// 1. createError(status, message) creates an HttpError instance with status, statusCode, name, message, and expose (true for 4xx, false for 5xx)
const err404 = createError(404);
assert.equal(err404.status, 404);
assert.equal(err404.statusCode, 404);
assert.equal(err404.name, 'NotFoundError');
assert.equal(err404.message, 'Not Found');
assert.equal(err404.expose, true);
assert.ok(err404 instanceof Error);
assert.ok(err404 instanceof createError.HttpError);
assert.ok(err404 instanceof createError.NotFound);

const err500 = createError(500, 'Custom server failure');
assert.equal(err500.status, 500);
assert.equal(err500.statusCode, 500);
assert.equal(err500.name, 'InternalServerError');
assert.equal(err500.message, 'Custom server failure');
assert.equal(err500.expose, false);
assert.ok(err500 instanceof createError.InternalServerError);

// 2. createError(status, properties) and createError(status, message, properties) attach custom properties and headers to the error
const errProps = createError(401, 'Unauthorized', {
  headers: { 'WWW-Authenticate': 'Bearer' },
  code: 'AUTH_FAILED'
});
assert.equal(errProps.status, 401);
assert.equal(errProps.code, 'AUTH_FAILED');
assert.deepEqual(errProps.headers, { 'WWW-Authenticate': 'Bearer' });

const errPropsOnly = createError(400, { detail: 'missing field' });
assert.equal(errPropsOnly.status, 400);
assert.equal(errPropsOnly.message, 'Bad Request');
assert.equal(errPropsOnly.detail, 'missing field');

// 3. createError(error) and createError(status, error, properties) extend existing Error instances without altering prototype inheritance
const baseErr = new TypeError('Database error');
const extendedErr = createError(503, baseErr, { expose: false });
assert.equal(extendedErr, baseErr);
assert.equal(extendedErr.status, 503);
assert.equal(extendedErr.statusCode, 503);
assert.equal(extendedErr.expose, false);
assert.ok(extendedErr instanceof TypeError);

// 4. createError[code] and createError[name] direct constructors instantiate specific HttpError subclasses with correct prototypes
const notFoundErr = new createError.NotFound('Resource not found');
assert.equal(notFoundErr.status, 404);
assert.equal(notFoundErr.statusCode, 404);
assert.equal(notFoundErr.name, 'NotFoundError');
assert.equal(notFoundErr.message, 'Resource not found');
assert.ok(notFoundErr instanceof createError.NotFound);
assert.ok(notFoundErr instanceof createError.HttpError);

const forbiddenErr = new createError[403]('Access denied');
assert.equal(forbiddenErr.status, 403);
assert.equal(forbiddenErr.name, 'ForbiddenError');
assert.ok(forbiddenErr instanceof createError.Forbidden);

// 5. createError.HttpError abstract base class throws TypeError when directly instantiated
assert.throws(
  () => new createError.HttpError(),
  (err) => err instanceof TypeError && err.message === 'cannot construct abstract class'
);

// 6. createError.isHttpError(val) correctly identifies HttpError instances and duck-typed error objects while rejecting plain objects and primitives
assert.equal(createError.isHttpError(err404), true);
assert.equal(createError.isHttpError(extendedErr), true);
assert.equal(createError.isHttpError(notFoundErr), true);

const duckTypedErr = new Error('duck typed');
duckTypedErr.expose = true;
duckTypedErr.status = 400;
duckTypedErr.statusCode = 400;
assert.equal(createError.isHttpError(duckTypedErr), true);

assert.equal(createError.isHttpError(new Error('plain')), false);
assert.equal(createError.isHttpError({ status: 404, statusCode: 404, expose: true }), false);
assert.equal(createError.isHttpError(null), false);
assert.equal(createError.isHttpError(undefined), false);
assert.equal(createError.isHttpError(404), false);
assert.equal(createError.isHttpError('NotFoundError'), false);

// 7. createError throws TypeError for unsupported argument types and falls back to status 500 for unknown status numbers
assert.throws(() => createError(true), (err) => err instanceof TypeError && /unsupported type/.test(err.message));
assert.throws(() => createError(404, 12345), (err) => err instanceof TypeError && /unsupported type/.test(err.message));

const unknownCodeErr = createError(999);
assert.equal(unknownCodeErr.status, 500);

console.log('Contract passed');

Seeder de origen

anónimo