CodeSampleX

샘플

follow-redirects 1.16.0

검증된 샘플 — npm follow-redirects 1.16.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: followRedirects exports http and https drop-in wrappers and…

sha256:10bb4eb9761b8a066161ed3654884b7d3fcd66088b437fd14007bdc31ed8f6f1

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript 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/follow-redirects@1.16.0
패키지
환경
node 22.23.2
생성일
2026-08-20T20:35:02Z

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • 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 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));
}

오리진 시더

익명