CodeSampleX

Ejemplo

universalify 2.0.1: fromCallback

Muestra verificada para npm universalify 2.0.1: fromCallback. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:42272e1ca865a06941dda563291672586129c897d9a34400826030495c5eca38

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-20
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 universalify.fromCallback in pkg:npm/universalify@2.0.1
Paquetes
Símbolos
  • universalify.fromCallback
Entorno
node 22.23.2
Creado
2026-08-20T23:24:23Z

Contrato

  1. universalify.fromCallback wraps a callback-style function to return a Promise when no callback argument is provided
  2. universalify.fromCallback wraps a callback-style function to invoke the callback when a callback argument is provided
  3. universalify.fromCallback rejects the returned Promise when the underlying callback returns an error
  4. universalify.fromCallback delivers the error to the callback when a callback argument is provided

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 universalify.fromCallback in pkg:npm/universalify@2.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/universalify@2.0.1
Demonstrate these symbols/APIs:
  - universalify.fromCallback
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:f9a4859b080022b3b58d25392c6a13d2bd9d8d34769f4777a61e0772a96afa89","constraints":{"executionContext":"node"},"contract":["universalify.fromCallback wraps a callback-style function to return a Promise when no callback argument is provided","universalify.fromCallback wraps a callback-style function to invoke the callback when a callback argument is provided","universalify.fromCallback rejects the returned Promise when the underlying callback returns an error","universalify.fromCallback delivers the error to the callback when a callback argument is provided"],"goal":"verify universalify.fromCallback in pkg:npm/universalify@2.0.1","kind":"HOW","packages":["pkg:npm/universalify@2.0.1"],"schemaVersion":1,"symbols":["universalify.fromCallback"]},"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/universalify@2.0.1"],"schemaVersion":1,"subject":"pkg:npm/universalify@2.0.1","symbols":["universalify.fromCallback"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-universalify-from-callback",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-universalify-from-callback",
      "version": "1.0.0",
      "dependencies": {
        "universalify": "2.0.1"
      }
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-universalify-from-callback",
  "version": "1.0.0",
  "private": true,
  "description": "verify universalify.fromCallback in pkg:npm/universalify@2.0.1",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "universalify": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify universalify.fromCallback in pkg:npm/universalify@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/universalify@2.0.1"
  ],
  "symbols": [
    "universalify.fromCallback"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const universalify = require('universalify');

function callbackFn(value, cb) {
  setTimeout(() => {
    if (value === 'error') {
      cb(new Error('failure'));
    } else {
      cb(null, `result: ${value}`);
    }
  }, 10);
}

const universalFn = universalify.fromCallback(callbackFn);

module.exports = {
  callbackFn,
  universalFn
};
test/contract.js
const assert = require('assert');
const universalify = require('universalify');
const { callbackFn, universalFn } = require('../src/index.js');

async function testPromiseSuccess() {
  const res = await universalFn('hello');
  assert.strictEqual(res, 'result: hello');
}

function testCallbackSuccess(done) {
  universalFn('world', (err, res) => {
    assert.strictEqual(err, null);
    assert.strictEqual(res, 'result: world');
    done();
  });
}

async function testPromiseError() {
  let threw = false;
  try {
    await universalFn('error');
  } catch (err) {
    threw = true;
    assert.strictEqual(err.message, 'failure');
  }
  assert.strictEqual(threw, true, 'expected promise rejection');
}

function testCallbackError(done) {
  universalFn('error', (err, res) => {
    assert.ok(err instanceof Error);
    assert.strictEqual(err.message, 'failure');
    assert.strictEqual(res, undefined);
    done();
  });
}

async function run() {
  await testPromiseSuccess();
  await new Promise((resolve) => testCallbackSuccess(resolve));
  await testPromiseError();
  await new Promise((resolve) => testCallbackError(resolve));
  console.log('Contract tests passed successfully.');
}

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

Seeder de origen

anónimo