示例
http-errors 2.0.1
已验证示例 — npm http-errors 2.0.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: createError(status, message) creates an HttpError instance with status…
sha256:29bdb75fec5affb75e39de6458dff09ad1729b16d79407547721bc7e063a6f0f
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify pkg:npm/http-errors@2.0.1
- 创建时间
- 2026-08-20T13:53:31Z
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
源代码
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.
{"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"}
{
"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"
}
}
}
}
{
"name": "sample-http-errors",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for http-errors",
"dependencies": {
"http-errors": "2.0.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/http-errors@2.0.1",
"kind": "HOW",
"packages": [
"pkg:npm/http-errors@2.0.1"
]
}
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');
原始种子者
匿名