CodeSampleX

Beispiel

statuses 2.0.1: redirect

Verifiziertes Beispiel für npm statuses 2.0.1: redirect. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:d24bb57dff3a68ab7ce5c50879cf618c3c71c5329c0abcd1cebfe649c5bd3271

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-03

Fall

HOW
Ziel
verify statuses.redirect in pkg:npm/statuses@2.0.1
Pakete
Symbole
  • statuses.redirect
Erstellt
2026-09-03T15:53:00Z

Contract

  1. status.redirect is an object dictionary mapping numeric redirect status codes to true, not a callable function
  2. status.redirect[code] returns true for standard redirect codes 300, 301, 302, 303, 305, 307, and 308 using either number or numeric string keys
  3. status.redirect contains exactly the 7 standard redirect status codes and excludes 304 Not Modified and 306
  4. status.redirect[code] returns undefined rather than boolean false for non-redirect status codes
  5. status.redirect does not index by status message strings; checking redirection by status message requires resolving to a numeric status code first

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

NOTES.md
# statuses.redirect Contract and Semantics

## search_known_solution Result
`search_known_solution` returned `NO_SAFE_MATCH` for `statuses.redirect` in `pkg:npm/statuses@2.0.1`.
Existing samples for the `statuses` package (`sha256:0085962`, `sha256:25c91e0`, `sha256:bdc9891`) verified general package status lookup functions, but did not prove granular contract behaviors, boundary conditions, or common pitfalls of `statuses.redirect`.

## What a Model or Developer Would Have Written
A model or developer commonly assumes that:
1. `status.redirect` is a callable helper function like `status.redirect(301)` or `status.isRedirect(code)`.
2. All 3xx HTTP status codes represent redirects, including HTTP 304 (Not Modified).
3. `status.redirect[code]` returns a boolean (`true` or `false`) for any status code.
4. `status.redirect` accepts status message strings such as `status.redirect['Moved Permanently']`.

## Observed Behaviour and Contract Proofs
1. **Object Dictionary, Not a Function**:
   `status.redirect` is an object dictionary mapping numeric status code keys to `true`. Calling `status.redirect(...)` throws a `TypeError: status.redirect is not a function`.
2. **Exact Redirect Codes**:
   `status.redirect` maps exactly seven HTTP status codes: `300` (Multiple Choices), `301` (Moved Permanently), `302` (Found), `303` (See Other), `305` (Use Proxy), `307` (Temporary Redirect), and `308` (Permanent Redirect).
3. **Exclusion of 304 Not Modified**:
   HTTP 304 (Not Modified) is a conditional cache revalidation status code with an empty response body (`status.empty[304] === true`), not a redirect. `status.redirect[304]` is `undefined` (falsy).
4. **Undefined for Non-Redirects**:
   Non-redirect codes (such as 200, 404, 500) yield `undefined`, not `false`. Assertions expecting `=== false` fail unless coerced with `Boolean(...)`.
5. **Key Types and Message Resolution**:
   Both integer keys (`status.redirect[301]`) and numeric string keys (`status.redirect['301']`) resolve to `true`. Passing status message strings directly (e.g. `'Moved Permanently'`) returns `undefined`. Message strings must be resolved to numeric codes first via `status(message)` before checking `status.redirect[code]`.
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.redirect 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.redirect

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:751dbee77fb7d6ee7bbab1abf4d0e05bb45dc981905c257c286220b794954a74","contract":["status.redirect is an object dictionary mapping numeric redirect status codes to true, not a callable function","status.redirect[code] returns true for standard redirect codes 300, 301, 302, 303, 305, 307, and 308 using either number or numeric string keys","status.redirect contains exactly the 7 standard redirect status codes and excludes 304 Not Modified and 306","status.redirect[code] returns undefined rather than boolean false for non-redirect status codes","status.redirect does not index by status message strings; checking redirection by status message requires resolving to a numeric status code first"],"goal":"verify statuses.redirect in pkg:npm/statuses@2.0.1","kind":"HOW","packages":["pkg:npm/statuses@2.0.1"],"schemaVersion":1,"symbols":["statuses.redirect"]},"contractCommand":["node","test/contract.mjs"],"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/statuses@2.0.1"],"schemaVersion":1,"subject":"pkg:npm/statuses@2.0.1","symbols":["statuses.redirect"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-statuses-redirect",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-statuses-redirect",
      "version": "1.0.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": "verify-statuses-redirect",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "statuses": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify statuses.redirect in pkg:npm/statuses@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/statuses@2.0.1"
  ],
  "symbols": [
    "statuses.redirect"
  ]
}
src/index.mjs
import status from 'statuses';

/**
 * Checks whether a given status code or status message represents an HTTP redirect.
 *
 * @param {number|string} codeOrMessage - The numeric HTTP status code (e.g. 301, "301") or status message (e.g. "Moved Permanently")
 * @returns {boolean} True if the code or message represents an HTTP redirect, false otherwise.
 */
export function isRedirectStatus(codeOrMessage) {
  if (codeOrMessage === null || codeOrMessage === undefined) {
    return false;
  }
  const code = typeof codeOrMessage === 'number'
    ? codeOrMessage
    : (/^\d+$/.test(codeOrMessage) ? Number(codeOrMessage) : status(codeOrMessage));

  return Boolean(status.redirect[code]);
}

/**
 * Returns all HTTP status codes that represent redirects.
 *
 * @returns {number[]} Array of numeric HTTP redirect status codes.
 */
export function getRedirectCodes() {
  return Object.keys(status.redirect).map(Number).sort((a, b) => a - b);
}

export default status;
test/contract.mjs
import assert from 'node:assert/strict';
import status, { isRedirectStatus, getRedirectCodes } from '../src/index.mjs';

// 1. status.redirect is an object dictionary, not a callable function
assert.strictEqual(typeof status.redirect, 'object');
assert.strictEqual(status.redirect !== null, true);
assert.throws(
  () => status.redirect(301),
  {
    name: 'TypeError',
    message: 'status.redirect is not a function'
  }
);

// 2. status.redirect[code] returns true for standard redirect codes using number or string keys
const standardRedirectCodes = [300, 301, 302, 303, 305, 307, 308];
for (const code of standardRedirectCodes) {
  assert.strictEqual(status.redirect[code], true, `status.redirect[${code}] must be true`);
  assert.strictEqual(status.redirect[String(code)], true, `status.redirect['${code}'] must be true`);
}

// 3. status.redirect contains exactly 7 redirect codes, excluding 304 Not Modified and 306
const keys = Object.keys(status.redirect).sort();
const expectedKeys = ['300', '301', '302', '303', '305', '307', '308'].sort();
assert.deepStrictEqual(keys, expectedKeys);

// 304 Not Modified is an empty-body cache validator, not a redirect
assert.strictEqual(status.redirect[304], undefined);
assert.strictEqual(Boolean(status.redirect[304]), false);
assert.strictEqual(status.empty[304], true);

// 4. Non-redirect codes return undefined, NOT boolean false
assert.strictEqual(status.redirect[200], undefined);
assert.notStrictEqual(status.redirect[200], false);
assert.strictEqual(status.redirect[404], undefined);
assert.strictEqual(status.redirect[500], undefined);

// 5. status.redirect does not index by status message strings
assert.strictEqual(status.redirect['Moved Permanently'], undefined);
assert.strictEqual(status.redirect['Found'], undefined);
assert.strictEqual(status.redirect['OK'], undefined);

// 6. isRedirectStatus helper correctly handles numbers, numeric strings, and message strings
assert.strictEqual(isRedirectStatus(301), true);
assert.strictEqual(isRedirectStatus('301'), true);
assert.strictEqual(isRedirectStatus(302), true);
assert.strictEqual(isRedirectStatus(307), true);
assert.strictEqual(isRedirectStatus(308), true);
assert.strictEqual(isRedirectStatus('Moved Permanently'), true);
assert.strictEqual(isRedirectStatus('moved permanently'), true);
assert.strictEqual(isRedirectStatus('Temporary Redirect'), true);

assert.strictEqual(isRedirectStatus(200), false);
assert.strictEqual(isRedirectStatus('200'), false);
assert.strictEqual(isRedirectStatus('OK'), false);
assert.strictEqual(isRedirectStatus(304), false);
assert.strictEqual(isRedirectStatus('Not Modified'), false);
assert.strictEqual(isRedirectStatus(404), false);
assert.strictEqual(isRedirectStatus('Not Found'), false);

// 7. getRedirectCodes helper returns sorted array of redirect status numbers
const redirectCodes = getRedirectCodes();
assert.deepStrictEqual(redirectCodes, [300, 301, 302, 303, 305, 307, 308]);

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

Ursprungs-Seeder

anonym