CodeSampleX

Ejemplo

iconv-lite 0.6.3

Muestra verificada para npm iconv-lite 0.6.3. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: assert encoding existence checks return…

sha256:f60f315dc0de02e8a7114f0760fabd8c5bafaa9d10a90a30a020b2d7a02fd37b

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-24

Caso

HOW
Objetivo
verify pkg:npm/iconv-lite@0.6.3
Paquetes
Entorno
node 22.23.2
Creado
2026-08-24T20:22:07Z

Contrato

  1. assert encoding existence checks return true for supported legacy encodings and false for unknown encodings
  2. assert Korean EUC-KR encoding and decoding roundtrip preserves original text and produces valid byte buffer
  3. assert Japanese Shift_JIS encoding and decoding roundtrip preserves original multibyte text
  4. assert Cyrillic Windows-1251 encoding and decoding roundtrip preserves original text accurately
  5. assert UTF-8 encoding with addBOM prepends byte order mark 0xEF 0xBB 0xBF and default decoding strips BOM while explicit option retains BOM
  6. assert stateful chunked decoder correctly decodes multibyte character stream split across chunk boundaries

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/iconv-lite@0.6.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/iconv-lite@0.6.3
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:a2785b19ff6ed21b3fa8fa700c3bd4a33062c2851b6d6b94a2b74af8d92c83f5","constraints":{"executionContext":"node"},"contract":["assert encoding existence checks return true for supported legacy encodings and false for unknown encodings","assert Korean EUC-KR encoding and decoding roundtrip preserves original text and produces valid byte buffer","assert Japanese Shift_JIS encoding and decoding roundtrip preserves original multibyte text","assert Cyrillic Windows-1251 encoding and decoding roundtrip preserves original text accurately","assert UTF-8 encoding with addBOM prepends byte order mark 0xEF 0xBB 0xBF and default decoding strips BOM while explicit option retains BOM","assert stateful chunked decoder correctly decodes multibyte character stream split across chunk boundaries"],"goal":"verify pkg:npm/iconv-lite@0.6.3","kind":"HOW","packages":["pkg:npm/iconv-lite@0.6.3"],"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","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/iconv-lite@0.6.3"],"schemaVersion":1,"subject":"pkg:npm/iconv-lite@0.6.3","verifierAdapter":"node-typescript@1"}
index.js
const iconv = require('iconv-lite');

function convertEncoding(text, fromEncoding, toEncoding) {
  const buf = iconv.encode(text, fromEncoding);
  return iconv.decode(buf, toEncoding);
}

function encodeToBuffer(text, encoding, options) {
  return iconv.encode(text, encoding, options);
}

function decodeFromBuffer(buf, encoding, options) {
  return iconv.decode(buf, encoding, options);
}

function isEncodingSupported(encoding) {
  return iconv.encodingExists(encoding);
}

function createChunkedDecoder(encoding, options) {
  return iconv.getDecoder(encoding, options);
}

function createChunkedEncoder(encoding, options) {
  return iconv.getEncoder(encoding, options);
}

module.exports = {
  convertEncoding,
  encodeToBuffer,
  decodeFromBuffer,
  isEncodingSupported,
  createChunkedDecoder,
  createChunkedEncoder,
  iconv,
};
package-lock.json
{
  "name": "sample-iconv-lite",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-iconv-lite",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "iconv-lite": "0.6.3"
      }
    },
    "node_modules/iconv-lite": {
      "version": "0.6.3",
      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
      "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
      "license": "MIT",
      "dependencies": {
        "safer-buffer": ">= 2.1.2 < 3.0.0"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/safer-buffer": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-iconv-lite",
  "version": "1.0.0",
  "description": "Minimal clean-room sample verifying iconv-lite character encoding conversions",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "iconv-lite": "0.6.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/iconv-lite@0.6.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/iconv-lite@0.6.3"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import iconv from 'iconv-lite';
import {
  convertEncoding,
  encodeToBuffer,
  decodeFromBuffer,
  isEncodingSupported,
  createChunkedDecoder,
} from '../index.js';

// 1. Encoding existence checks
assert.strictEqual(isEncodingSupported('utf-8'), true, 'UTF-8 must be supported');
assert.strictEqual(isEncodingSupported('windows-1252'), true, 'Windows-1252 must be supported');
assert.strictEqual(isEncodingSupported('euc-kr'), true, 'EUC-KR must be supported');
assert.strictEqual(isEncodingSupported('shift_jis'), true, 'Shift_JIS must be supported');
assert.strictEqual(isEncodingSupported('win1251'), true, 'Windows-1251 must be supported');
assert.strictEqual(isEncodingSupported('unknown-encoding-xyz-12345'), false, 'Unknown encoding must return false');

// 2. Korean EUC-KR encode/decode roundtrip
const koreanText = '안녕하세요 세계';
const eucKrBuf = encodeToBuffer(koreanText, 'euc-kr');
assert(Buffer.isBuffer(eucKrBuf), 'encodeToBuffer must return a Buffer');
const decodedKorean = decodeFromBuffer(eucKrBuf, 'euc-kr');
assert.strictEqual(decodedKorean, koreanText, 'EUC-KR roundtrip decode must match original');

// 3. Japanese Shift_JIS encode/decode roundtrip
const japaneseText = 'こんにちは世界';
const shiftJisBuf = encodeToBuffer(japaneseText, 'shift_jis');
const decodedJapanese = decodeFromBuffer(shiftJisBuf, 'shift_jis');
assert.strictEqual(decodedJapanese, japaneseText, 'Shift_JIS roundtrip decode must match original');

// 4. Cyrillic Windows-1251 encode/decode roundtrip
const cyrillicText = 'Привет мир';
const win1251Buf = encodeToBuffer(cyrillicText, 'windows-1251');
const decodedCyrillic = decodeFromBuffer(win1251Buf, 'windows-1251');
assert.strictEqual(decodedCyrillic, cyrillicText, 'Windows-1251 roundtrip decode must match original');

// 5. UTF-8 BOM handling
const asciiText = 'Hello World';
const withBOM = encodeToBuffer(asciiText, 'utf-8', { addBOM: true });
assert.strictEqual(withBOM[0], 0xef, 'First byte of UTF-8 BOM must be 0xEF');
assert.strictEqual(withBOM[1], 0xbb, 'Second byte of UTF-8 BOM must be 0xBB');
assert.strictEqual(withBOM[2], 0xbf, 'Third byte of UTF-8 BOM must be 0xBF');

const strippedBOM = decodeFromBuffer(withBOM, 'utf-8');
assert.strictEqual(strippedBOM, asciiText, 'decode must strip BOM by default');

const retainedBOM = decodeFromBuffer(withBOM, 'utf-8', { stripBOM: false });
assert.strictEqual(retainedBOM.charCodeAt(0), 0xfeff, 'decode with stripBOM: false must retain BOM');

// 6. Stateful / Chunked decoding across byte boundaries
const decoder = createChunkedDecoder('utf-8');
const partial1 = Buffer.from([0xec, 0x95]);
const partial2 = Buffer.from([0x88, 0xeb, 0x85, 0x95]);
const chunk1 = decoder.write(partial1);
const chunk2 = decoder.write(partial2);
const finalChunk = decoder.end() || '';
const streamResult = (chunk1 || '') + (chunk2 || '') + finalChunk;
assert.strictEqual(streamResult, '안녕', 'Chunked decoding across multibyte split must reconstruct characters accurately');

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

Seeder de origen

anónimo