CodeSampleX

Exemplo

proxy-from-env 1.1.0

Amostra verificada para npm proxy-from-env 1.1.0. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: assert getProxyForUrl returns proxy url…

sha256:20fca09b299083a2fa9781654699a2604afd649c73b5824b987fb97f8fe91d7e

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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/proxy-from-env@1.1.0
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-20T20:32:58Z

Contrato

  1. assert getProxyForUrl returns proxy url matching protocol from environment variables
  2. assert getProxyForUrl prepends protocol scheme if proxy address lacks scheme
  3. assert getProxyForUrl returns empty string when no proxy environment variables are set
  4. assert getProxyForUrl respects NO_PROXY exact domain and wildcard matching
  5. assert getProxyForUrl respects NO_PROXY domain suffix matching with leading dot or asterisk
  6. assert getProxyForUrl respects NO_PROXY specific port filtering
  7. assert getProxyForUrl returns empty string for invalid or missing URL inputs

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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@1.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proxy-from-env@1.1.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:0579f60110fc32ffa2665fb76b05beb038a19261485af945219305402a079d9b","constraints":{"executionContext":"node"},"contract":["assert getProxyForUrl returns proxy url matching protocol from environment variables","assert getProxyForUrl prepends protocol scheme if proxy address lacks scheme","assert getProxyForUrl returns empty string when no proxy environment variables are set","assert getProxyForUrl respects NO_PROXY exact domain and wildcard matching","assert getProxyForUrl respects NO_PROXY domain suffix matching with leading dot or asterisk","assert getProxyForUrl respects NO_PROXY specific port filtering","assert getProxyForUrl returns empty string for invalid or missing URL inputs"],"goal":"verify pkg:npm/proxy-from-env@1.1.0","kind":"HOW","packages":["pkg:npm/proxy-from-env@1.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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/proxy-from-env@1.1.0"],"schemaVersion":1,"subject":"pkg:npm/proxy-from-env@1.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",
      "license": "MIT-0",
      "dependencies": {
        "proxy-from-env": "1.1.0"
      }
    },
    "node_modules/proxy-from-env": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
      "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-proxy-from-env",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "proxy-from-env": "1.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/proxy-from-env@1.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proxy-from-env@1.1.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 { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { getProxyForUrl } = require('proxy-from-env');

function withEnv(env, fn) {
  const originalEnv = { ...process.env };
  const proxyKeys = [
    'http_proxy', 'HTTP_PROXY',
    'https_proxy', 'HTTPS_PROXY',
    'all_proxy', 'ALL_PROXY',
    'no_proxy', 'NO_PROXY',
    'npm_config_http_proxy', 'npm_config_https_proxy',
    'npm_config_proxy', 'npm_config_no_proxy'
  ];
  for (const k of proxyKeys) {
    delete process.env[k];
  }
  Object.assign(process.env, env);
  try {
    fn();
  } finally {
    for (const k of proxyKeys) {
      delete process.env[k];
    }
    Object.assign(process.env, originalEnv);
  }
}

// 1. Returns proxy url matching protocol from environment variables
withEnv({
  HTTP_PROXY: 'http://proxy.example.com:8080',
  HTTPS_PROXY: 'https://secure.example.com:8443',
  ALL_PROXY: 'socks://all.example.com:1080'
}, () => {
  assert.equal(getProxyForUrl('http://example.com/api'), 'http://proxy.example.com:8080');
  assert.equal(getProxyForUrl('https://example.com/api'), 'https://secure.example.com:8443');
  assert.equal(getProxyForUrl('ws://example.com/socket'), 'socks://all.example.com:1080');
});

// 2. Prepends protocol scheme if proxy address lacks scheme
withEnv({
  HTTP_PROXY: 'proxy.example.com:8080',
  HTTPS_PROXY: 'secure.example.com:8443'
}, () => {
  assert.equal(getProxyForUrl('http://example.com'), 'http://proxy.example.com:8080');
  assert.equal(getProxyForUrl('https://example.com'), 'https://secure.example.com:8443');
});

// 3. Returns empty string when no proxy environment variables are set
withEnv({}, () => {
  assert.equal(getProxyForUrl('http://example.com'), '');
  assert.equal(getProxyForUrl('https://example.com'), '');
  assert.equal(getProxyForUrl('ftp://example.com'), '');
});

// 4. Respects NO_PROXY exact domain and wildcard matching
withEnv({
  HTTP_PROXY: 'http://proxy.example.com:8080',
  NO_PROXY: 'example.com, example.org'
}, () => {
  assert.equal(getProxyForUrl('http://example.com/page'), '');
  assert.equal(getProxyForUrl('http://example.org/data'), '');
  assert.equal(getProxyForUrl('http://example.net/page'), 'http://proxy.example.com:8080');
});

withEnv({
  HTTP_PROXY: 'http://proxy.example.com:8080',
  NO_PROXY: '*'
}, () => {
  assert.equal(getProxyForUrl('http://example.com'), '');
  assert.equal(getProxyForUrl('http://example.net'), '');
});

// 5. Respects NO_PROXY domain suffix matching with leading dot or asterisk
withEnv({
  HTTP_PROXY: 'http://proxy.example.com:8080',
  NO_PROXY: '.example.com, *.example.org'
}, () => {
  assert.equal(getProxyForUrl('http://api.example.com'), '');
  assert.equal(getProxyForUrl('http://service.example.org'), '');
  assert.equal(getProxyForUrl('http://example.com'), 'http://proxy.example.com:8080');
});

// 6. Respects NO_PROXY specific port filtering
withEnv({
  HTTP_PROXY: 'http://proxy.example.com:8080',
  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. Returns empty string for invalid or missing URL inputs
assert.equal(getProxyForUrl(''), '');
assert.equal(getProxyForUrl(null), '');
assert.equal(getProxyForUrl(undefined), '');
assert.equal(getProxyForUrl('no-protocol-host'), '');
assert.equal(getProxyForUrl({}), '');

Seeder de origem

anônimo