CodeSampleX

Пример

socks 2.8.10: SocksClientError

Проверенный пример — npm socks 2.8.10: SocksClientError. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: assert SocksClientError is an…

sha256:1103a36b263edfdc606446ecd9249633a8e7068eecebd4d0c0c5ceb505ba4ca9

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

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

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

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

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

Окружение Контракт Этапы Запуск
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-07

Кейс

HOW
Цель
verify socks.SocksClientError in pkg:npm/socks@2.8.10
Пакеты
Символы
  • socks.SocksClientError
Создан
2026-09-07T03:02:56Z

Контракт

  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

Файлы

  • PROMPT.md
  • csx.json
  • index.mjs
  • 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 socks.SocksClientError in pkg:npm/socks@2.8.10
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks@2.8.10
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:2d611ca23e8f3524246f6091a44c612fa631294d751827ad265e7c412bd59a39","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.10","kind":"HOW","packages":["pkg:npm/socks@2.8.10"],"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.10"],"schemaVersion":1,"subject":"pkg:npm/socks@2.8.10","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.10"
      }
    },
    "node_modules/ip-address": {
      "version": "10.7.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.0.tgz",
      "integrity": "sha512-BGFsyJd5mpXp3rK6jIdADLNgpJUK1jnjzvYF8lK+VyDab9JAmqN0YOKDdP17HlgKb2+ehPgDc8EtnRLbGCAMhA==",
      "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.10",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.10.tgz",
      "integrity": "sha512-e0VyvkVTwVYViNovRkZ9aodhxVlyoMn7eJhVUPxZ+eK9P/7CBkxvvsBOHqFPEH416726W8tLXXXjKwqgTErrCQ==",
      "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.10"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socks.SocksClientError in pkg:npm/socks@2.8.10",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks@2.8.10"
  ],
  "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.');

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

аноним