CodeSampleX

Ejemplo

yallist 3.1.1

Muestra verificada para npm yallist 3.1.1. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: Yallist creates a doubly-linked list from an…

sha256:1b9dba190ab0f7048661c579dda15e3e01b905635770771397abd3df6e1f86ea

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
2
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

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@1
2026-08-21
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-12

Caso

HOW
Objetivo
verify pkg:npm/yallist@3.1.1
Paquetes
Entorno
node 22.23.2
Creado
2026-08-21T15:45:34Z

Contrato

  1. Yallist creates a doubly-linked list from an iterable or arguments
  2. push and unshift insert elements at the tail and head respectively
  3. pop and shift remove and return elements from the tail and head respectively
  4. forEach and forEachReverse traverse elements in forward and reverse order
  5. map and mapReverse create new Yallist instances with transformed elements
  6. slice and sliceReverse extract sublists in forward and reverse order
  7. toArray and toArrayReverse convert the linked list to forward and reverse arrays
  8. pushNode, unshiftNode, and removeNode manipulate Node instances directly
  9. reverse reverses the linked list elements in place

Archivos

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

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/yallist@3.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yallist@3.1.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:34ac765352117d36ea682f7124d313b9c9b8b991fc16c646eee662c310815ca2","constraints":{"executionContext":"node"},"contract":["Yallist creates a doubly-linked list from an iterable or arguments","push and unshift insert elements at the tail and head respectively","pop and shift remove and return elements from the tail and head respectively","forEach and forEachReverse traverse elements in forward and reverse order","map and mapReverse create new Yallist instances with transformed elements","slice and sliceReverse extract sublists in forward and reverse order","toArray and toArrayReverse convert the linked list to forward and reverse arrays","pushNode, unshiftNode, and removeNode manipulate Node instances directly","reverse reverses the linked list elements in place"],"goal":"verify pkg:npm/yallist@3.1.1","kind":"HOW","packages":["pkg:npm/yallist@3.1.1"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/yallist@3.1.1"],"schemaVersion":1,"subject":"pkg:npm/yallist@3.1.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-yallist",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-yallist",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "yallist": "3.1.1"
      }
    },
    "node_modules/yallist": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
      "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-yallist",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for yallist",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "yallist": "3.1.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/yallist@3.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yallist@3.1.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const Yallist = require('yallist');

function createList(...items) {
  if (items.length === 1 && Array.isArray(items[0])) {
    return new Yallist(items[0]);
  }
  return Yallist.create(...items);
}

function pushItems(list, ...items) {
  list.push(...items);
  return list;
}

function unshiftItems(list, ...items) {
  list.unshift(...items);
  return list;
}

function popItem(list) {
  return list.pop();
}

function shiftItem(list) {
  return list.shift();
}

function toArray(list) {
  return list.toArray();
}

function toArrayReverse(list) {
  return list.toArrayReverse();
}

function mapList(list, fn) {
  return list.map(fn);
}

function mapListReverse(list, fn) {
  return list.mapReverse(fn);
}

function reduceList(list, fn, initialValue) {
  return list.reduce(fn, initialValue);
}

function reverseList(list) {
  list.reverse();
  return list;
}

module.exports = {
  Yallist,
  createList,
  pushItems,
  unshiftItems,
  popItem,
  shiftItem,
  toArray,
  toArrayReverse,
  mapList,
  mapListReverse,
  reduceList,
  reverseList
};
test/contract.js
const assert = require('node:assert');
const Yallist = require('yallist');
const {
  createList,
  pushItems,
  unshiftItems,
  popItem,
  shiftItem,
  toArray,
  toArrayReverse,
  mapList,
  mapListReverse,
  reduceList,
  reverseList
} = require('../src/index.js');

// 1. Creation from array / arguments / factory
const list1 = new Yallist([1, 2, 3]);
assert.strictEqual(list1.length, 3, 'initial array length should be 3');
assert.deepStrictEqual(list1.toArray(), [1, 2, 3], 'initial array values should match');

const list2 = createList('a', 'b', 'c');
assert.strictEqual(list2.length, 3, 'createList length should be 3');
assert.deepStrictEqual(toArray(list2), ['a', 'b', 'c'], 'createList values should match');

const list3 = createList([10, 20, 30]);
assert.strictEqual(list3.length, 3, 'createList from array length should be 3');
assert.deepStrictEqual(toArray(list3), [10, 20, 30], 'createList array values should match');

// 2. push and unshift
const list = new Yallist();
pushItems(list, 10);
pushItems(list, 20, 30);
assert.strictEqual(list.length, 3, 'length after push should be 3');
assert.deepStrictEqual(toArray(list), [10, 20, 30], 'values after push should match');

unshiftItems(list, 5);
assert.strictEqual(list.length, 4, 'length after unshift should be 4');
assert.deepStrictEqual(toArray(list), [5, 10, 20, 30], 'values after unshift should match');

// 3. pop and shift
assert.strictEqual(popItem(list), 30, 'pop should return last item');
assert.strictEqual(shiftItem(list), 5, 'shift should return first item');
assert.strictEqual(list.length, 2, 'length after pop/shift should be 2');
assert.deepStrictEqual(toArray(list), [10, 20], 'remaining values should match');

// 4. head, tail, get, getReverse
assert.strictEqual(list.head.value, 10, 'head value should be 10');
assert.strictEqual(list.tail.value, 20, 'tail value should be 20');
assert.strictEqual(list.get(0), 10, 'get(0) should be 10');
assert.strictEqual(list.get(1), 20, 'get(1) should be 20');
assert.strictEqual(list.getReverse(0), 20, 'getReverse(0) should be 20');
assert.strictEqual(list.getReverse(1), 10, 'getReverse(1) should be 10');

// 5. forEach and forEachReverse
const fwd = [];
list.forEach((item, index) => {
  fwd.push({ item, index });
});
assert.deepStrictEqual(fwd, [
  { item: 10, index: 0 },
  { item: 20, index: 1 }
], 'forEach should traverse forward');

const rev = [];
list.forEachReverse((item, index) => {
  rev.push({ item, index });
});
assert.deepStrictEqual(rev, [
  { item: 20, index: 1 },
  { item: 10, index: 0 }
], 'forEachReverse should traverse in reverse');

// 6. map, mapReverse, reduce, reduceReverse
const doubled = mapList(list, x => x * 2);
assert.ok(doubled instanceof Yallist, 'map result should be Yallist instance');
assert.deepStrictEqual(toArray(doubled), [20, 40], 'mapped values should be doubled');

const doubledRev = mapListReverse(list, x => x * 2);
assert.ok(doubledRev instanceof Yallist, 'mapReverse result should be Yallist instance');
assert.deepStrictEqual(toArray(doubledRev), [40, 20], 'mapReverse values should be reversed doubled');

const sum = reduceList(list, (acc, x) => acc + x, 0);
assert.strictEqual(sum, 30, 'reduce sum should be 30');

const strRev = list.reduceReverse((acc, x) => acc + '-' + x, 'start');
assert.strictEqual(strRev, 'start-20-10', 'reduceReverse string concatenation should match');

// 7. slice and sliceReverse
const multiList = new Yallist([1, 2, 3, 4, 5]);
const sliced = multiList.slice(1, 4);
assert.deepStrictEqual(toArray(sliced), [2, 3, 4], 'sliced values should match');

const slicedRev = multiList.sliceReverse(1, 4);
assert.deepStrictEqual(toArray(slicedRev), [4, 3, 2], 'slicedReverse values should match');

// 8. toArray and toArrayReverse
assert.deepStrictEqual(toArrayReverse(list), [20, 10], 'toArrayReverse should return reverse array');

// 9. Node manipulations: pushNode, unshiftNode, removeNode
const node = new Yallist.Node(99);
list.pushNode(node);
assert.strictEqual(list.tail, node, 'pushed node should be tail');
assert.strictEqual(list.tail.value, 99, 'tail value should match node value');

const headNode = new Yallist.Node(0);
list.unshiftNode(headNode);
assert.strictEqual(list.head, headNode, 'unshifted node should be head');
assert.strictEqual(list.head.value, 0, 'head value should match node value');

list.removeNode(node);
assert.strictEqual(list.tail.value, 20, 'tail should revert after node removal');
list.removeNode(headNode);
assert.strictEqual(list.head.value, 10, 'head should revert after head node removal');

// 10. reverse
reverseList(list);
assert.deepStrictEqual(toArray(list), [20, 10], 'reversed list array should match');

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

Seeder de origen

anónimo