CodeSampleX

샘플

engine.io-client 6.6.6: verify engine.io-client socket instantiation and configuration options

검증된 샘플 — npm engine.io-client 6.6.6: verify engine.io-client socket instantiation and configuration options. node 22 · linux alpine/x64 · docker에서 contract를…

sha256:29684e0758ca039033e7bc3d2e26c51602bbed9aa161ecd69c44709361098288

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-26

케이스

HOW
목표
verify engine.io-client socket instantiation and configuration options
패키지
심벌
  • Socket
환경
node 22.23.2
생성일
2026-08-26T14:26:49Z

컨트랙트

  1. Socket exports protocol version 4 and Socket constructor classes
  2. Socket initializes with default options in node environment with readyState opening and binaryType nodebuffer
  3. Socket supports custom options including transport selection, custom path, and timestamp parameters
  4. Socket emits events via inherited emitter methods
  5. Socket establishes connection, completes handshake, and sends packets over polling transport
  6. Socket closes cleanly and transitions readyState to closed
  7. Socket emits error and close events when connecting to unreachable endpoint

파일

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

소스 아티팩트 내려받기 (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 engine.io-client socket instantiation and configuration options
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/engine.io-client@6.6.6
Demonstrate these symbols/APIs:
  - Socket

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:64e56fbdef1949d627831369d069b60c127d61e2c98be88d7bd9ebc00e011d90","contract":["Socket exports protocol version 4 and Socket constructor classes","Socket initializes with default options in node environment with readyState opening and binaryType nodebuffer","Socket supports custom options including transport selection, custom path, and timestamp parameters","Socket emits events via inherited emitter methods","Socket establishes connection, completes handshake, and sends packets over polling transport","Socket closes cleanly and transitions readyState to closed","Socket emits error and close events when connecting to unreachable endpoint"],"goal":"verify engine.io-client socket instantiation and configuration options","kind":"HOW","packages":["pkg:npm/engine.io-client@6.6.6"],"schemaVersion":1,"symbols":["Socket"]},"contractCommand":["node","test/contract.js"],"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/engine.io-client@6.6.6"],"schemaVersion":1,"subject":"pkg:npm/engine.io-client@6.6.6","symbols":["Socket"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-engine-io-client",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-engine-io-client",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "engine.io-client": "6.6.6"
      }
    },
    "node_modules/@socket.io/component-emitter": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz",
      "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
      "license": "MIT"
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/engine.io-client": {
      "version": "6.6.6",
      "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.6.6.tgz",
      "integrity": "sha512-iY6QdftLQ9pyiPoX082bpf/u1UewnOaJrtJIF9T0++QB34lZrj0uP+Q/bj8AlUsAxqhnkTV2BS8SBZSxOmoV5Q==",
      "license": "MIT",
      "dependencies": {
        "@socket.io/component-emitter": "~3.1.0",
        "debug": "~4.4.1",
        "engine.io-parser": "~5.2.1",
        "ws": "~8.21.0",
        "xmlhttprequest-ssl": "~2.1.1"
      }
    },
    "node_modules/engine.io-parser": {
      "version": "5.2.3",
      "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz",
      "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/ws": {
      "version": "8.21.3",
      "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.3.tgz",
      "integrity": "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      },
      "peerDependencies": {
        "bufferutil": "^4.0.1",
        "utf-8-validate": ">=5.0.2"
      },
      "peerDependenciesMeta": {
        "bufferutil": {
          "optional": true
        },
        "utf-8-validate": {
          "optional": true
        }
      }
    },
    "node_modules/xmlhttprequest-ssl": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.1.2.tgz",
      "integrity": "sha512-TEU+nJVUUnA4CYJFLvK5X9AOeH4KvDvhIfm0vV1GaQRtchnG0hgK5p8hw/xjv8cunWYCsiPCSDzObPyhEwq3KQ==",
      "engines": {
        "node": ">=0.4.0"
      }
    }
  }
}
package.json
{
  "name": "sample-engine-io-client",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for engine.io-client",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "engine.io-client": "6.6.6"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify engine.io-client socket instantiation and configuration options",
  "kind": "HOW",
  "packages": [
    "pkg:npm/engine.io-client@6.6.6"
  ],
  "symbols": [
    "Socket"
  ]
}
src/index.js
'use strict';

const {
  Socket,
  protocol,
  transports,
  SocketWithoutUpgrade,
  SocketWithUpgrade
} = require('engine.io-client');

/**
 * Creates an Engine.IO client socket with specified options.
 * @param {string|object} uri
 * @param {object} [opts]
 * @returns {Socket}
 */
function createSocket(uri, opts) {
  return new Socket(uri, opts);
}

module.exports = {
  Socket,
  protocol,
  transports,
  SocketWithoutUpgrade,
  SocketWithUpgrade,
  createSocket
};
test/contract.js
'use strict';

const assert = require('assert');
const http = require('http');
const {
  Socket,
  protocol,
  transports,
  SocketWithoutUpgrade,
  SocketWithUpgrade,
  createSocket
} = require('../src/index.js');

async function main() {
  // 1. Socket exports protocol version 4 and Socket constructor classes
  {
    assert.strictEqual(typeof protocol, 'number');
    assert.strictEqual(protocol, 4);
    assert.strictEqual(typeof Socket, 'function');
    assert.strictEqual(typeof SocketWithoutUpgrade, 'function');
    assert.strictEqual(typeof SocketWithUpgrade, 'function');
    assert.strictEqual(typeof createSocket, 'function');
  }

  // 2. Socket initializes with default options in node environment with readyState opening and binaryType nodebuffer
  {
    const socket = new Socket('http://localhost:3000');
    assert.strictEqual(socket.readyState, 'opening');
    assert.strictEqual(socket.binaryType, 'nodebuffer');
    assert.strictEqual(Array.isArray(socket.writeBuffer), true);
    assert.strictEqual(socket.writeBuffer.length, 0);
    socket.close();
    assert.strictEqual(socket.readyState, 'closed');
  }

  // 3. Socket supports custom options including transport selection, custom path, and timestamp parameters
  {
    const socket = createSocket('http://localhost:12345', {
      transports: ['polling'],
      path: '/custom-engine/',
      timestampParam: 'ts',
      autoUnref: true
    });
    assert.strictEqual(socket.readyState, 'opening');
    socket.binaryType = 'arraybuffer';
    assert.strictEqual(socket.binaryType, 'arraybuffer');
    socket.close();
    assert.strictEqual(socket.readyState, 'closed');
  }

  // 4. Socket emits events via inherited emitter methods
  {
    const socket = new Socket('http://localhost:12345');
    let emittedValue = null;
    const onCustom = (val) => { emittedValue = val; };
    socket.on('custom-event', onCustom);
    socket.emit('custom-event', 'data-payload');
    assert.strictEqual(emittedValue, 'data-payload');
    socket.off('custom-event', onCustom);
    socket.emit('custom-event', 'ignored-payload');
    assert.strictEqual(emittedValue, 'data-payload');
    socket.close();
  }

  // 5. Socket establishes connection, completes handshake, and sends packets over polling transport
  // 6. Socket closes cleanly and transitions readyState to closed
  {
    const sessionId = 'eio-session-proof-1';
    let receivedPacket = null;

    const server = http.createServer((req, res) => {
      if (req.method === 'GET') {
        const handshake = JSON.stringify({
          sid: sessionId,
          upgrades: [],
          pingInterval: 10000,
          pingTimeout: 5000,
          maxPayload: 100000
        });
        res.writeHead(200, { 'Content-Type': 'text/plain; charset=UTF-8' });
        res.end('0' + handshake);
      } else if (req.method === 'POST') {
        let body = '';
        req.on('data', chunk => { body += chunk; });
        req.on('end', () => {
          receivedPacket = body;
          res.writeHead(200, { 'Content-Type': 'text/plain; charset=UTF-8' });
          res.end('ok');
        });
      }
    });

    await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
    const port = server.address().port;

    const socket = new Socket(`http://127.0.0.1:${port}`, {
      transports: ['polling']
    });

    let opened = false;
    let handshakeReceived = null;

    socket.on('handshake', (data) => {
      handshakeReceived = data;
    });

    await new Promise((resolve, reject) => {
      socket.on('open', () => {
        opened = true;
        resolve();
      });
      socket.on('error', reject);
    });

    assert.strictEqual(opened, true);
    assert.strictEqual(socket.id, sessionId);
    assert.strictEqual(socket.readyState, 'open');
    assert.strictEqual(handshakeReceived.sid, sessionId);
    assert.strictEqual(handshakeReceived.pingInterval, 10000);

    socket.send('hello-engine-proof');
    await new Promise((resolve) => setTimeout(resolve, 80));
    assert.strictEqual(receivedPacket, '4hello-engine-proof');

    let closed = false;
    await new Promise((resolve) => {
      socket.on('close', () => {
        closed = true;
        resolve();
      });
      socket.close();
    });

    assert.strictEqual(closed, true);
    assert.strictEqual(socket.readyState, 'closed');

    await new Promise((resolve) => server.close(resolve));
  }

  // 7. Socket emits error and close events when connecting to unreachable endpoint
  {
    const socket = new Socket('http://127.0.0.1:59999', {
      transports: ['polling'],
      requestTimeout: 300
    });

    let errorFired = false;
    await new Promise((resolve) => {
      socket.on('error', () => {
        errorFired = true;
      });
      socket.on('close', () => {
        resolve();
      });
    });

    assert.strictEqual(errorFired, true);
    assert.strictEqual(socket.readyState, 'closed');
  }

  console.log('Contract tests passed successfully.');
}

main().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명