CodeSampleX

Пример

proxy-from-env 2.1.0

Проверенный пример — npm proxy-from-env 2.1.0. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: getProxyForUrl returns an empty string…

sha256:b1cf59cdb08c2c224a026b14beff33b1cbb7ee65c6941206ba6fba4fe5059ba3

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Кейс

HOW
Цель
verify pkg:npm/proxy-from-env@2.1.0
Пакеты
Окружение
node 22.23.2
Создан
2026-08-27T13:03:18Z

Контракт

  1. getProxyForUrl returns an empty string when no proxy environment variables are set
  2. getProxyForUrl returns the HTTP_PROXY URL for an HTTP request URL
  3. getProxyForUrl returns the HTTPS_PROXY URL for an HTTPS request URL
  4. getProxyForUrl returns ALL_PROXY URL when specific protocol proxy is not set
  5. getProxyForUrl returns an empty string when NO_PROXY wildcard is set or host matches NO_PROXY
  6. getProxyForUrl respects port-specific NO_PROXY filtering
  7. getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme
  8. getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname
  9. getProxyForUrl accepts URL instance as input

Файлы

  • 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/proxy-from-env@2.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proxy-from-env@2.1.0
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:c360ff2e679af3025192a0035f6979c07df81298c6e5b51e64e005aba36af941","constraints":{"executionContext":"node"},"contract":["getProxyForUrl returns an empty string when no proxy environment variables are set","getProxyForUrl returns the HTTP_PROXY URL for an HTTP request URL","getProxyForUrl returns the HTTPS_PROXY URL for an HTTPS request URL","getProxyForUrl returns ALL_PROXY URL when specific protocol proxy is not set","getProxyForUrl returns an empty string when NO_PROXY wildcard is set or host matches NO_PROXY","getProxyForUrl respects port-specific NO_PROXY filtering","getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme","getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname","getProxyForUrl accepts URL instance as input"],"goal":"verify pkg:npm/proxy-from-env@2.1.0","kind":"HOW","packages":["pkg:npm/proxy-from-env@2.1.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","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","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 pkg:npm/proxy-from-env@2.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proxy-from-env@2.1.0"
  ],
  "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 the HTTP_PROXY URL for an HTTP request URL
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	const proxy = getProxyForUrl('http://example.com/api');
	assert.equal(proxy, 'http://proxy.example.com:8080');
}

// 3. getProxyForUrl returns the HTTPS_PROXY URL for an HTTPS request URL
{
	clearProxyEnv();
	process.env.HTTPS_PROXY = 'http://secure-proxy.example.com:8443';
	const proxy = getProxyForUrl('https://example.com/secure');
	assert.equal(proxy, 'http://secure-proxy.example.com:8443');
}

// 4. getProxyForUrl returns ALL_PROXY URL when specific protocol proxy is not set
{
	clearProxyEnv();
	process.env.ALL_PROXY = 'socks5://proxy.example.com:1080';
	const proxy = getProxyForUrl('http://example.com/other');
	assert.equal(proxy, 'socks5://proxy.example.com:1080');
}

// 5. getProxyForUrl returns an empty string when NO_PROXY wildcard is set or host matches NO_PROXY
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'example.org,.example.net';
	assert.equal(getProxyForUrl('http://example.org/index'), '');
	assert.equal(getProxyForUrl('http://sub.example.net/'), '');
	assert.equal(getProxyForUrl('http://other.example.com/'), 'http://proxy.example.com:8080');

	process.env.NO_PROXY = '*';
	assert.equal(getProxyForUrl('http://other.example.com/'), '');
}

// 6. getProxyForUrl respects port-specific NO_PROXY filtering
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'example.com:8080';
	assert.equal(getProxyForUrl('http://example.com:8080/path'), '');
	assert.equal(getProxyForUrl('http://example.com:80/path'), '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 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(''), '');
}

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

Исходный сидер

аноним