CodeSampleX

Exemple

proxy-from-env 2.1.0: getProxyForUrl

Échantillon vérifié pour npm proxy-from-env 2.1.0: getProxyForUrl. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:3556451b175837841c95be340422e5436b1fc5329b6300af9d31d9268041c8a3

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-04

Cas

HOW
Objectif
verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0
Paquets
Symboles
  • proxy-from-env.getProxyForUrl
Environnement
node 22.23.2
Créé
2026-09-04T05:23:52Z

Contrat

  1. getProxyForUrl returns an empty string when no proxy environment variables are set
  2. getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs
  3. getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset
  4. getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk
  5. getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes
  6. getProxyForUrl respects port-specific NO_PROXY rules
  7. getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme
  8. getProxyForUrl accepts URL object instances as input
  9. getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

.npmrc
audit=false
fund=false
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 proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proxy-from-env@2.1.0
Demonstrate these symbols/APIs:
  - proxy-from-env.getProxyForUrl
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:3a13665158a48056ab5fb4f19f7564042c8659fcfbc74ffb32b3bfdf20b8fb95","constraints":{"executionContext":"node"},"contract":["getProxyForUrl returns an empty string when no proxy environment variables are set","getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs","getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset","getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk","getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes","getProxyForUrl respects port-specific NO_PROXY rules","getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme","getProxyForUrl accepts URL object instances as input","getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname"],"goal":"verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0","kind":"HOW","packages":["pkg:npm/proxy-from-env@2.1.0"],"schemaVersion":1,"symbols":["proxy-from-env.getProxyForUrl"]},"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/proxy-from-env@2.1.0"],"schemaVersion":1,"subject":"pkg:npm/proxy-from-env@2.1.0","symbols":["proxy-from-env.getProxyForUrl"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-proxy-from-env",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-proxy-from-env",
      "version": "1.0.0",
      "dependencies": {
        "proxy-from-env": "2.1.0"
      }
    },
    "node_modules/proxy-from-env": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz",
      "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-proxy-from-env",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "proxy-from-env": "2.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proxy-from-env@2.1.0"
  ],
  "symbols": [
    "proxy-from-env.getProxyForUrl"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import process from 'node:process';
import { getProxyForUrl } from 'proxy-from-env';

function clearProxyEnv() {
	delete process.env.http_proxy;
	delete process.env.HTTP_PROXY;
	delete process.env.https_proxy;
	delete process.env.HTTPS_PROXY;
	delete process.env.all_proxy;
	delete process.env.ALL_PROXY;
	delete process.env.no_proxy;
	delete process.env.NO_PROXY;
}

// 1. getProxyForUrl returns an empty string when no proxy environment variables are set
{
	clearProxyEnv();
	const proxy = getProxyForUrl('http://example.com/test');
	assert.equal(proxy, '');
}

// 2. getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.HTTPS_PROXY = 'http://secure-proxy.example.com:8443';
	assert.equal(getProxyForUrl('http://example.com/api'), 'http://proxy.example.com:8080');
	assert.equal(getProxyForUrl('https://example.com/api'), 'http://secure-proxy.example.com:8443');
}

// 3. getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset
{
	clearProxyEnv();
	process.env.ALL_PROXY = 'socks5://all-proxy.example.com:1080';
	assert.equal(getProxyForUrl('http://example.com/data'), 'socks5://all-proxy.example.com:1080');
	assert.equal(getProxyForUrl('https://example.com/data'), 'socks5://all-proxy.example.com:1080');
}

// 4. getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = '*';
	assert.equal(getProxyForUrl('http://example.com/test'), '');
	assert.equal(getProxyForUrl('http://other.example.com/test'), '');
}

// 5. getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'sub.example.com,.corp.example.com';
	assert.equal(getProxyForUrl('http://sub.example.com/index'), '');
	assert.equal(getProxyForUrl('http://app.corp.example.com/'), '');
	assert.equal(getProxyForUrl('http://other.example.com/'), 'http://proxy.example.com:8080');
}

// 6. getProxyForUrl respects port-specific NO_PROXY rules
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'example.com:8080';
	assert.equal(getProxyForUrl('http://example.com:8080/test'), '');
	assert.equal(getProxyForUrl('http://example.com:3000/test'), 'http://proxy.example.com:8080');
}

// 7. getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme
{
	clearProxyEnv();
	process.env.HTTP_PROXY = '127.0.0.1:8080';
	const proxy = getProxyForUrl('http://example.com/data');
	assert.equal(proxy, 'http://127.0.0.1:8080');
}

// 8. getProxyForUrl accepts URL object instances as input
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	const urlObj = new URL('http://example.com/object-test');
	assert.equal(getProxyForUrl(urlObj), 'http://proxy.example.com:8080');
}

// 9. getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	assert.equal(getProxyForUrl('not-a-valid-url'), '');
	assert.equal(getProxyForUrl(''), '');
}

Seeder d'origine

anonyme