CodeSampleX

Exemple

socks 2.8.9: SocksClientError

Échantillon vérifié pour npm socks 2.8.9: SocksClientError. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:c9bb71b18a2a435767fa1e9feac89a549666e034faf875908410b0e873176836

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é linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

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

Cas

HOW
Objectif
verify socks.SocksClientError in pkg:npm/socks@2.8.9
Paquets
Symboles
  • socks.SocksClientError
Créé
2026-08-23T13:40:31Z

Contrat

  1. assert SocksClientError is an instance of Error
  2. assert SocksClientError retains error message and client options
  3. assert SocksClient emits or rejects with SocksClientError on connection failure

Fichiers

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

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

Code source

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 socks.SocksClientError in pkg:npm/socks@2.8.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks@2.8.9
Demonstrate these symbols/APIs:
  - socks.SocksClientError

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:4c9dd4f2f0dcf92d91dd95e1b1541a006d44dadefef1643ebcb2947127599199","contract":["assert SocksClientError is an instance of Error","assert SocksClientError retains error message and client options","assert SocksClient emits or rejects with SocksClientError on connection failure"],"goal":"verify socks.SocksClientError in pkg:npm/socks@2.8.9","kind":"HOW","packages":["pkg:npm/socks@2.8.9"],"schemaVersion":1,"symbols":["socks.SocksClientError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/socks@2.8.9"],"schemaVersion":1,"subject":"pkg:npm/socks@2.8.9","symbols":["socks.SocksClientError"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { SocksClient, SocksClientError } from 'socks';

/**
 * Creates a SocksClient error with custom options.
 * @param {string} message
 * @param {object} options
 * @returns {SocksClientError}
 */
export function createClientError(message, options) {
  return new SocksClientError(message, options);
}

/**
 * Attempts to connect through a SOCKS proxy, catching any SocksClientError.
 * @param {object} options
 * @returns {Promise<object>}
 */
export async function attemptConnection(options) {
  try {
    const info = await SocksClient.createConnection(options);
    return { success: true, info };
  } catch (err) {
    if (err instanceof SocksClientError) {
      return { success: false, error: err };
    }
    throw err;
  }
}

export { SocksClient, SocksClientError };
package-lock.json
{
  "name": "socks-client-error-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "socks-client-error-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "socks": "2.8.9"
      }
    },
    "node_modules/ip-address": {
      "version": "10.5.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.5.0.tgz",
      "integrity": "sha512-R5SnVLJmgYYvf2F2ZgwSBnelz5G4q5AxIC277GDfUaNbrZKNANcBC7RHqYYePlszf4kBolVkJauG0ZjHHFh55g==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/smart-buffer": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
      "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
      "license": "MIT",
      "engines": {
        "node": ">= 6.0.0",
        "npm": ">= 3.0.0"
      }
    },
    "node_modules/socks": {
      "version": "2.8.9",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.9.tgz",
      "integrity": "sha512-LJhUYUvItdQ0LkJTmPeaEObWXAqFyfmP85x0tch/ez9cahmhlBBLbIqDFnvBnUJGagb0JbIQrkBs1wJ+yRYpEw==",
      "license": "MIT",
      "dependencies": {
        "ip-address": "^10.1.1",
        "smart-buffer": "^4.2.0"
      },
      "engines": {
        "node": ">= 10.0.0",
        "npm": ">= 3.0.0"
      }
    }
  }
}
package.json
{
  "name": "socks-client-error-sample",
  "version": "1.0.0",
  "description": "Demonstrate socks.SocksClientError usage and behavior",
  "main": "index.mjs",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "socks": "2.8.9"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socks.SocksClientError in pkg:npm/socks@2.8.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks@2.8.9"
  ],
  "symbols": [
    "socks.SocksClientError"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { SocksClient, SocksClientError } from 'socks';
import { createClientError, attemptConnection } from '../index.mjs';

// 1. Assert SocksClientError class exists and extends Error
assert.equal(typeof SocksClientError, 'function', 'SocksClientError should be a constructor function');
const sampleOptions = {
  proxy: {
    ipaddress: '127.0.0.1',
    port: 1080,
    type: 5
  },
  command: 'connect',
  destination: {
    host: 'localhost',
    port: 80
  }
};

const customError = createClientError('connection failed to proxy', sampleOptions);
assert(customError instanceof Error, 'customError must be an instance of Error');
assert(customError instanceof SocksClientError, 'customError must be an instance of SocksClientError');
assert.equal(customError.message, 'connection failed to proxy', 'error message must match');
assert.deepEqual(customError.options, sampleOptions, 'error options must match');

// 2. Assert SocksClient.createConnection emits/rejects with SocksClientError on unreachable proxy
const unreachableOptions = {
  proxy: {
    ipaddress: '127.0.0.1',
    port: 59998,
    type: 5
  },
  command: 'connect',
  destination: {
    host: '127.0.0.1',
    port: 8080
  },
  timeout: 1000
};

const result = await attemptConnection(unreachableOptions);
assert.equal(result.success, false, 'connection should fail on closed port');
assert(result.error instanceof SocksClientError, 'error should be an instance of SocksClientError');
assert(result.error instanceof Error, 'error should be an instance of Error');
assert(result.error.message.length > 0, 'error message should not be empty');
assert.equal(result.error.options.proxy.port, 59998, 'error options proxy port should match');

console.log('All contract tests passed.');

Seeder d'origine

anonyme