CodeSampleX

Ejemplo

follow-redirects 1.16.0

Muestra verificada para npm follow-redirects 1.16.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: followRedirects exports http and…

sha256:10bb4eb9761b8a066161ed3654884b7d3fcd66088b437fd14007bdc31ed8f6f1

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

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/follow-redirects@1.16.0
Paquetes
Entorno
node 22.23.2
Creado
2026-08-20T20:35:02Z

Contrato

  1. followRedirects exports http and https drop-in wrappers and wrap function
  2. http.get follows 301 and 302 redirects automatically to destination URL and populates responseUrl
  3. trackRedirects option records redirect history array with status codes and URLs for each hop
  4. maxRedirects option limits maximum redirect count and emits error when limit is exceeded
  5. beforeRedirect callback allows intercepting and inspecting redirect options before following

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/follow-redirects@1.16.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/follow-redirects@1.16.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - runtime: node@22.23.2

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:24396618ab3d586916cac766910334e6fb925c5e4bd0b91e19f846f0b9efbe34","constraints":{"executionContext":"node"},"contract":["followRedirects exports http and https drop-in wrappers and wrap function","http.get follows 301 and 302 redirects automatically to destination URL and populates responseUrl","trackRedirects option records redirect history array with status codes and URLs for each hop","maxRedirects option limits maximum redirect count and emits error when limit is exceeded","beforeRedirect callback allows intercepting and inspecting redirect options before following"],"goal":"verify pkg:npm/follow-redirects@1.16.0","kind":"HOW","packages":["pkg:npm/follow-redirects@1.16.0"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/follow-redirects@1.16.0"],"schemaVersion":1,"subject":"pkg:npm/follow-redirects@1.16.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-follow-redirects",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-follow-redirects",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "follow-redirects": "1.16.0"
      }
    },
    "node_modules/follow-redirects": {
      "version": "1.16.0",
      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz",
      "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==",
      "license": "MIT",
      "engines": {
        "node": ">=4.0"
      },
      "peerDependenciesMeta": {
        "debug": {
          "optional": true
        }
      }
    }
  }
}
package.json
{
  "name": "sample-follow-redirects",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "follow-redirects": "1.16.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/follow-redirects@1.16.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/follow-redirects@1.16.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import http from 'node:http';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const followRedirects = require('follow-redirects');
const { http: fHttp, https: fHttps } = followRedirects;

// 1. followRedirects exports http and https drop-in wrappers and wrap function
assert.equal(typeof fHttp, 'object', 'followRedirects.http should be an object');
assert.equal(typeof fHttp.get, 'function', 'followRedirects.http.get should be a function');
assert.equal(typeof fHttp.request, 'function', 'followRedirects.http.request should be a function');
assert.equal(typeof fHttps, 'object', 'followRedirects.https should be an object');
assert.equal(typeof fHttps.get, 'function', 'followRedirects.https.get should be a function');
assert.equal(typeof fHttps.request, 'function', 'followRedirects.https.request should be a function');
assert.equal(typeof followRedirects.wrap, 'function', 'followRedirects.wrap should be a function');

// Create local test HTTP server for offline testing
const server = http.createServer((req, res) => {
  if (req.url === '/redirect-1') {
    res.writeHead(302, { Location: '/redirect-2' });
    res.end();
  } else if (req.url === '/redirect-2') {
    res.writeHead(301, { Location: '/final' });
    res.end();
  } else if (req.url === '/final') {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('final destination reached');
  } else if (req.url === '/loop-a') {
    res.writeHead(302, { Location: '/loop-b' });
    res.end();
  } else if (req.url === '/loop-b') {
    res.writeHead(302, { Location: '/loop-a' });
    res.end();
  } else {
    res.writeHead(404);
    res.end('not found');
  }
});

await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const port = server.address().port;
const baseUrl = `http://127.0.0.1:${port}`;

try {
  // 2. http.get follows 301 and 302 redirects automatically to destination URL and populates responseUrl
  await new Promise((resolve, reject) => {
    fHttp.get(`${baseUrl}/redirect-1`, (res) => {
      let data = '';
      res.on('data', (chunk) => { data += chunk; });
      res.on('end', () => {
        try {
          assert.equal(res.statusCode, 200);
          assert.equal(data, 'final destination reached');
          assert.equal(res.responseUrl, `${baseUrl}/final`);
          resolve();
        } catch (e) {
          reject(e);
        }
      });
    }).on('error', reject);
  });

  // 3. trackRedirects option records redirect history array with status codes and URLs for each hop
  await new Promise((resolve, reject) => {
    fHttp.get({
      host: '127.0.0.1',
      port,
      path: '/redirect-1',
      trackRedirects: true,
    }, (res) => {
      let data = '';
      res.on('data', (chunk) => { data += chunk; });
      res.on('end', () => {
        try {
          assert.equal(res.statusCode, 200);
          assert.ok(Array.isArray(res.redirects), 'res.redirects should be an array');
          assert.equal(res.redirects.length, 3);
          assert.equal(res.redirects[0].statusCode, 302);
          assert.equal(res.redirects[0].url, `${baseUrl}/redirect-1`);
          assert.equal(res.redirects[1].statusCode, 301);
          assert.equal(res.redirects[1].url, `${baseUrl}/redirect-2`);
          assert.equal(res.redirects[2].statusCode, 200);
          assert.equal(res.redirects[2].url, `${baseUrl}/final`);
          resolve();
        } catch (e) {
          reject(e);
        }
      });
    }).on('error', reject);
  });

  // 4. maxRedirects option limits maximum redirect count and emits error when limit is exceeded
  await new Promise((resolve, reject) => {
    const req = fHttp.get({
      host: '127.0.0.1',
      port,
      path: '/loop-a',
      maxRedirects: 3,
    });
    req.on('error', (err) => {
      try {
        assert.match(err.message, /Maximum number of redirects exceeded/i);
        resolve();
      } catch (e) {
        reject(e);
      }
    });
    req.on('response', () => {
      reject(new Error('Expected maxRedirects error but received response'));
    });
  });

  // 5. beforeRedirect callback allows intercepting and inspecting redirect options before following
  const redirectedHops = [];
  await new Promise((resolve, reject) => {
    fHttp.get({
      host: '127.0.0.1',
      port,
      path: '/redirect-1',
      beforeRedirect: (options, responseDetails) => {
        redirectedHops.push({
          path: options.path,
          statusCode: responseDetails.statusCode,
        });
      },
    }, (res) => {
      res.resume();
      res.on('end', () => {
        try {
          assert.equal(redirectedHops.length, 2);
          assert.equal(redirectedHops[0].statusCode, 302);
          assert.equal(redirectedHops[0].path, '/redirect-2');
          assert.equal(redirectedHops[1].statusCode, 301);
          assert.equal(redirectedHops[1].path, '/final');
          resolve();
        } catch (e) {
          reject(e);
        }
      });
    }).on('error', reject);
  });

  console.log('All contract assertions passed.');
} finally {
  await new Promise((resolve) => server.close(resolve));
}

Seeder de origen

anónimo