CodeSampleX

示例

statuses 2.0.1: message

已验证示例 — npm statuses 2.0.1: message. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: statuses.message is an object mapping HTTP status codes to…

sha256:4fb3b990b20c43e8af39803f882451455036a608fe31c852c25711448a4826ad

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify statuses.message in pkg:npm/statuses@2.0.1
包
符号
  • statuses.message
环境
node 22.23.2
创建时间
2026-09-06T20:39:41Z

契约

  1. statuses.message is an object mapping HTTP status codes to standard message strings
  2. statuses.message allows lookup by numeric status code or string representation
  3. statuses.message maps informational 1xx status codes to messages
  4. statuses.message maps successful 2xx status codes to messages
  5. statuses.message maps redirection 3xx status codes to messages
  6. statuses.message maps client error 4xx status codes to messages
  7. statuses.message maps server error 5xx status codes to messages
  8. statuses.message returns undefined for unknown or unassigned status codes
  9. every entry in statuses.message has a status code key and a non-empty string message

文件

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

下载源代码构件 (tar.gz)

源代码

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 statuses.message in pkg:npm/statuses@2.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/statuses@2.0.1
Demonstrate these symbols/APIs:
  - statuses.message

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:871bc2755e86a0a9c3ed1f57dde1787fc0929228e4edd9075af33bd00038fee3","constraints":{"executionContext":"node"},"contract":["statuses.message is an object mapping HTTP status codes to standard message strings","statuses.message allows lookup by numeric status code or string representation","statuses.message maps informational 1xx status codes to messages","statuses.message maps successful 2xx status codes to messages","statuses.message maps redirection 3xx status codes to messages","statuses.message maps client error 4xx status codes to messages","statuses.message maps server error 5xx status codes to messages","statuses.message returns undefined for unknown or unassigned status codes","every entry in statuses.message has a status code key and a non-empty string message"],"goal":"verify statuses.message in pkg:npm/statuses@2.0.1","kind":"HOW","packages":["pkg:npm/statuses@2.0.1"],"schemaVersion":1,"symbols":["statuses.message"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/statuses@2.0.1"],"schemaVersion":1,"subject":"pkg:npm/statuses@2.0.1","symbols":["statuses.message"],"verifierAdapter":"node-typescript@1"}
index.js
const statuses = require('statuses');

/**
 * Direct reference to the status code to message map.
 */
const message = statuses.message;

/**
 * Retrieve status message by numeric or string status code.
 * @param {number|string} code
 * @returns {string|undefined}
 */
function getStatusMessage(code) {
  if (typeof code !== 'number' && typeof code !== 'string') {
    return undefined;
  }
  return message[code];
}

/**
 * Check whether a status code exists in statuses.message.
 * @param {number|string} code
 * @returns {boolean}
 */
function hasStatusCode(code) {
  if (typeof code !== 'number' && typeof code !== 'string') {
    return false;
  }
  return Object.prototype.hasOwnProperty.call(message, code);
}

module.exports = {
  statuses,
  message,
  getStatusMessage,
  hasStatusCode,
};
package-lock.json
{
  "name": "sample-statuses-message",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-statuses-message",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "statuses": "2.0.1"
      }
    },
    "node_modules/statuses": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
      "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    }
  }
}
package.json
{
  "name": "sample-statuses-message",
  "version": "1.0.0",
  "description": "Minimal clean-room sample verifying statuses.message in statuses",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "statuses": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify statuses.message in pkg:npm/statuses@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/statuses@2.0.1"
  ],
  "symbols": [
    "statuses.message"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import statuses from 'statuses';
import {
  message,
  getStatusMessage,
  hasStatusCode,
} from '../index.js';

// 1. statuses.message is an object mapping HTTP status codes to standard message strings
assert.strictEqual(typeof statuses.message, 'object', 'statuses.message must be an object');
assert.strictEqual(message, statuses.message, 'exported message must reference statuses.message');
assert.strictEqual(statuses.message[200], 'OK', 'statuses.message[200] must be "OK"');
assert.strictEqual(statuses.message[404], 'Not Found', 'statuses.message[404] must be "Not Found"');
assert.strictEqual(getStatusMessage(200), 'OK', 'getStatusMessage(200) must return "OK"');

// 2. statuses.message allows lookup by numeric status code or string representation
assert.strictEqual(statuses.message[200], 'OK', 'numeric lookup 200 must be "OK"');
assert.strictEqual(statuses.message['200'], 'OK', 'string lookup "200" must be "OK"');
assert.strictEqual(getStatusMessage('404'), 'Not Found', 'getStatusMessage("404") must return "Not Found"');
assert.strictEqual(hasStatusCode(200), true, 'hasStatusCode(200) must be true');
assert.strictEqual(hasStatusCode('200'), true, 'hasStatusCode("200") must be true');
assert.strictEqual(hasStatusCode(999), false, 'hasStatusCode(999) must be false');

// 3. statuses.message maps informational 1xx status codes to messages
assert.strictEqual(statuses.message[100], 'Continue', '100 must map to Continue');
assert.strictEqual(statuses.message[101], 'Switching Protocols', '101 must map to Switching Protocols');

// 4. statuses.message maps successful 2xx status codes to messages
assert.strictEqual(statuses.message[200], 'OK', '200 must map to OK');
assert.strictEqual(statuses.message[201], 'Created', '201 must map to Created');
assert.strictEqual(statuses.message[202], 'Accepted', '202 must map to Accepted');
assert.strictEqual(statuses.message[204], 'No Content', '204 must map to No Content');

// 5. statuses.message maps redirection 3xx status codes to messages
assert.strictEqual(statuses.message[300], 'Multiple Choices', '300 must map to Multiple Choices');
assert.strictEqual(statuses.message[301], 'Moved Permanently', '301 must map to Moved Permanently');
assert.strictEqual(statuses.message[302], 'Found', '302 must map to Found');
assert.strictEqual(statuses.message[303], 'See Other', '303 must map to See Other');
assert.strictEqual(statuses.message[304], 'Not Modified', '304 must map to Not Modified');

// 6. statuses.message maps client error 4xx status codes to messages
assert.strictEqual(statuses.message[400], 'Bad Request', '400 must map to Bad Request');
assert.strictEqual(statuses.message[401], 'Unauthorized', '401 must map to Unauthorized');
assert.strictEqual(statuses.message[403], 'Forbidden', '403 must map to Forbidden');
assert.strictEqual(statuses.message[404], 'Not Found', '404 must map to Not Found');
assert.strictEqual(statuses.message[405], 'Method Not Allowed', '405 must map to Method Not Allowed');

// 7. statuses.message maps server error 5xx status codes to messages
assert.strictEqual(statuses.message[500], 'Internal Server Error', '500 must map to Internal Server Error');
assert.strictEqual(statuses.message[501], 'Not Implemented', '501 must map to Not Implemented');
assert.strictEqual(statuses.message[502], 'Bad Gateway', '502 must map to Bad Gateway');
assert.strictEqual(statuses.message[503], 'Service Unavailable', '503 must map to Service Unavailable');
assert.strictEqual(statuses.message[504], 'Gateway Timeout', '504 must map to Gateway Timeout');

// 8. statuses.message returns undefined for unknown or unassigned status codes
assert.strictEqual(statuses.message[999], undefined, 'code 999 must return undefined');
assert.strictEqual(statuses.message['999'], undefined, 'string "999" must return undefined');
assert.strictEqual(getStatusMessage(1234), undefined, 'getStatusMessage(1234) must return undefined');

// 9. every entry in statuses.message has a status code key and a non-empty string message
const entries = Object.entries(statuses.message);
assert(entries.length > 0, 'statuses.message must contain entries');
for (const [codeStr, msg] of entries) {
  const codeNum = Number(codeStr);
  assert(Number.isInteger(codeNum), `Key "${codeStr}" must be a numeric status code`);
  assert(codeNum >= 100 && codeNum <= 599, `Status code ${codeNum} must be in range 100-599`);
  assert.strictEqual(typeof msg, 'string', `Message for ${codeNum} must be a string`);
  assert(msg.length > 0, `Message for ${codeNum} must not be empty`);
}

console.log('All statuses.message contract assertions passed.');

原始种子者

匿名