Exemplo
ws 8.21.3
Amostra verificada para npm ws 8.21.3. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: assert WebSocketServer listens on local port and…
sha256:69929ecaa40edc52bce92969ac59b272e4140d8497495908f7df883012ee3ffa
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
- 2
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
| 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 |
Caso
HOW- Objetivo
- verify pkg:npm/ws@8.21.3
- Pacotes
- Criado
- 2026-08-23T06:03:42Z
Contrato
- assert WebSocketServer listens on local port and accepts client connections
- assert WebSocket client sends message and server receives echo payload
- assert WebSocket client and server support ping and pong heartbeats
- assert WebSocket client and server close gracefully with standard status code
Arquivos
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
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/ws@8.21.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ws@8.21.3
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.
{"case":{"caseId":"case:sha256:6cc027a6cfe7ad9f0010c7b791f15493057aafe92204871171c61eab78257928","contract":["assert WebSocketServer listens on local port and accepts client connections","assert WebSocket client sends message and server receives echo payload","assert WebSocket client and server support ping and pong heartbeats","assert WebSocket client and server close gracefully with standard status code"],"goal":"verify pkg:npm/ws@8.21.3","kind":"HOW","packages":["pkg:npm/ws@8.21.3"],"schemaVersion":1},"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/ws@8.21.3"],"schemaVersion":1,"subject":"pkg:npm/ws@8.21.3","verifierAdapter":"node-typescript@1"}
import WebSocket, { WebSocketServer } from 'ws';
/**
* Creates a WebSocket server listening on the specified options.
* @param {import('ws').ServerOptions} [options]
* @param {Function} [callback]
* @returns {WebSocketServer}
*/
export function createServer(options = {}, callback) {
return new WebSocketServer(options, callback);
}
/**
* Creates a WebSocket client connecting to the target address.
* @param {string|URL} address
* @param {string|string[]} [protocols]
* @param {import('ws').ClientOptions} [options]
* @returns {WebSocket}
*/
export function createClient(address, protocols, options) {
return new WebSocket(address, protocols, options);
}
export { WebSocket, WebSocketServer };
export default WebSocket;
{
"name": "sample-ws-verify",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-ws-verify",
"version": "1.0.0",
"dependencies": {
"ws": "8.21.3"
}
},
"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
}
}
}
}
}
{
"name": "sample-ws-verify",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"ws": "8.21.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ws@8.21.3",
"kind": "HOW",
"packages": [
"pkg:npm/ws@8.21.3"
]
}
import assert from 'node:assert/strict';
import { createServer, createClient, WebSocket } from '../index.mjs';
function startServer() {
return new Promise((resolve) => {
const wss = createServer({ host: '127.0.0.1', port: 0 }, () => {
const port = wss.address().port;
resolve({ wss, port });
});
});
}
function closeServer(wss) {
return new Promise((resolve) => {
wss.close(() => resolve());
});
}
// 1. assert WebSocketServer listens on local port and accepts client connections
{
const { wss, port } = await startServer();
let serverSocket = null;
wss.on('connection', (ws) => {
serverSocket = ws;
});
const ws = createClient(`ws://127.0.0.1:${port}`);
await new Promise((resolve, reject) => {
ws.on('open', () => {
assert.strictEqual(ws.readyState, WebSocket.OPEN);
resolve();
});
ws.on('error', reject);
});
assert.ok(serverSocket !== null, 'Server should accept client connection');
assert.strictEqual(serverSocket.readyState, WebSocket.OPEN);
ws.close();
await new Promise((r) => ws.on('close', r));
await closeServer(wss);
}
// 2. assert WebSocket client sends message and server receives echo payload
{
const { wss, port } = await startServer();
wss.on('connection', (ws) => {
ws.on('message', (data, isBinary) => {
ws.send(data, { binary: isBinary });
});
});
const ws = createClient(`ws://127.0.0.1:${port}`);
const payload = 'hello websocket';
const received = await new Promise((resolve, reject) => {
ws.on('open', () => {
ws.send(payload);
});
ws.on('message', (data) => {
resolve(data.toString('utf8'));
});
ws.on('error', reject);
});
assert.strictEqual(received, payload, 'Echoed payload should match original message');
ws.close();
await new Promise((r) => ws.on('close', r));
await closeServer(wss);
}
// 3. assert WebSocket client and server support ping and pong heartbeats
{
const { wss, port } = await startServer();
let serverReceivedPing = false;
wss.on('connection', (ws) => {
ws.on('ping', () => {
serverReceivedPing = true;
});
});
const ws = createClient(`ws://127.0.0.1:${port}`);
await new Promise((resolve, reject) => {
ws.on('open', () => {
ws.ping('heartbeat');
});
ws.on('pong', (data) => {
assert.strictEqual(data.toString('utf8'), 'heartbeat');
resolve();
});
ws.on('error', reject);
});
assert.strictEqual(serverReceivedPing, true, 'Server should receive ping frame');
ws.close();
await new Promise((r) => ws.on('close', r));
await closeServer(wss);
}
// 4. assert WebSocket client and server close gracefully with standard status code
{
const { wss, port } = await startServer();
let serverCloseCode = null;
wss.on('connection', (ws) => {
ws.on('close', (code) => {
serverCloseCode = code;
});
});
const ws = createClient(`ws://127.0.0.1:${port}`);
await new Promise((resolve, reject) => {
ws.on('open', () => {
ws.close(1000, 'normal close');
});
ws.on('close', (code) => {
assert.strictEqual(code, 1000);
resolve();
});
ws.on('error', reject);
});
assert.strictEqual(serverCloseCode, 1000, 'Server should receive close event with code 1000');
await closeServer(wss);
}
console.log('All contracts passed successfully.');
Seeder de origem
anônimo