Ejemplo
wrappy 1.0.2: wrappy
Muestra verificada para npm wrappy 1.0.2: wrappy. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: wrappy returns a wrapper generator…
sha256:fe88c89d35d48a347a6dcaeb0bb8ca0058a40c22fd24b3d754a9d7a8cc669ea9
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
windows 11 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-19 |
Caso
HOW- Objetivo
- verify pkg:npm/wrappy@1.0.2
- Paquetes
- Símbolos
-
- wrappy
- Creado
- 2026-08-18T18:16:16Z
Contrato
- wrappy returns a wrapper generator function when passed a wrapper function
- wrappy immediately wraps a target callback when passed both wrapper and target
- wrappy copies own enumerable properties from wrapper function to generated wrapper
- wrappy copies own enumerable properties from target callback to the returned wrapped function
- wrappy does not copy properties if returned function is identical to target callback
- wrappy preserves receiver and arguments forwarding to wrapper function
- wrappy throws TypeError with need wrapper function when first argument is not a function
- wrapFunction helper provides wrapper generator and immediate wrapping interfaces
Archivos
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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/wrappy@1.0.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/wrappy@1.0.2
Demonstrate these symbols/APIs:
- wrappy
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:975d92c4a134441a71709898631e648d603e08c40c7f9ab2d934213faf640d01","contract":["wrappy returns a wrapper generator function when passed a wrapper function","wrappy immediately wraps a target callback when passed both wrapper and target","wrappy copies own enumerable properties from wrapper function to generated wrapper","wrappy copies own enumerable properties from target callback to the returned wrapped function","wrappy does not copy properties if returned function is identical to target callback","wrappy preserves receiver and arguments forwarding to wrapper function","wrappy throws TypeError with need wrapper function when first argument is not a function","wrapFunction helper provides wrapper generator and immediate wrapping interfaces"],"goal":"verify pkg:npm/wrappy@1.0.2","kind":"HOW","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/wrappy@1.0.2"],"schemaVersion":1,"symbols":["wrappy"],"verifierAdapter":"node-typescript@1"}
import wrappy from 'wrappy';
/**
* Wraps a transformation function so that it can be applied to a callback
* while preserving callback identity, properties, prototype, and name.
*
* @param {Function} fn - The wrapper function.
* @param {Function} [cb] - Optional target callback to wrap immediately.
* @returns {Function} The wrapped function or wrapper generator.
*/
export function wrapFunction(fn, cb) {
if (cb !== undefined) {
return wrappy(fn, cb);
}
return wrappy(fn);
}
export default wrappy;
{
"name": "sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample",
"version": "1.0.0",
"dependencies": {
"wrappy": "1.0.2"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}
{
"name": "sample",
"version": "1.0.0",
"type": "module",
"dependencies": {
"wrappy": "1.0.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/wrappy@1.0.2",
"kind": "HOW",
"packages": [
"pkg:npm/wrappy@1.0.2"
],
"symbols": [
"wrappy"
]
}
import assert from 'node:assert/strict';
import wrappy from 'wrappy';
import { wrapFunction } from '../index.mjs';
// Case 1: wrappy returns a wrapper generator function when passed a wrapper function
{
const makeMultiplier = wrappy((cb) => {
return function (...args) {
return cb(...args) * 2;
};
});
assert.equal(typeof makeMultiplier, 'function', 'wrappy(fn) should return a wrapper generator function');
const add = (a, b) => a + b;
const wrappedAdd = makeMultiplier(add);
assert.equal(typeof wrappedAdd, 'function', 'wrapper generator should return a function');
assert.equal(wrappedAdd(2, 3), 10, 'wrapped function should apply transformation: (2 + 3) * 2 = 10');
}
// Case 2: wrappy immediately wraps a target callback when passed both wrapper and target
{
function prependHello(cb) {
return function (name) {
return `Hello, ${cb(name)}`;
};
}
function getTarget(name) {
return name.toUpperCase();
}
const greeted = wrappy(prependHello, getTarget);
assert.equal(typeof greeted, 'function', 'wrappy(fn, cb) should return wrapped callback');
assert.equal(greeted('world'), 'Hello, WORLD', 'wrappy(fn, cb) should immediately wrap the callback');
}
// Case 3: wrappy copies own enumerable properties from wrapper function to generated wrapper
{
function myWrapper(cb) {
return function (...args) {
return cb(...args);
};
}
myWrapper.customMetadata = 'wrapper-v1';
myWrapper.version = 42;
const generator = wrappy(myWrapper);
assert.equal(generator.customMetadata, 'wrapper-v1', 'wrapper generator should inherit wrapper custom properties');
assert.equal(generator.version, 42, 'wrapper generator should inherit wrapper version property');
}
// Case 4: wrappy copies own enumerable properties from target callback to the returned wrapped function
{
const once = wrappy((cb) => {
let called = false;
let result;
return function (...args) {
if (called) return result;
called = true;
result = cb.apply(this, args);
return result;
};
});
function originalWorker(x) {
return x * 3;
}
originalWorker.role = 'worker';
originalWorker.taskCount = 5;
const wrappedWorker = once(originalWorker);
assert.equal(wrappedWorker.role, 'worker', 'wrapped function should inherit callback own property role');
assert.equal(wrappedWorker.taskCount, 5, 'wrapped function should inherit callback own property taskCount');
assert.equal(wrappedWorker(4), 12, 'first call should compute 4 * 3 = 12');
assert.equal(wrappedWorker(10), 12, 'subsequent calls should return cached result 12');
}
// Case 5: wrappy does not copy properties if returned function is identical to target callback
{
const identityWrapper = wrappy((cb) => cb);
function noop() {}
noop.flag = true;
const result = identityWrapper(noop);
assert.equal(result, noop, 'identity wrapper returns the original callback unchanged');
}
// Case 6: wrappy preserves receiver and arguments forwarding to wrapper function
{
function withContext(cb) {
return function (...args) {
return `${this.prefix}: ${cb.apply(this, args)}`;
};
}
const wrapWithCtx = wrappy(withContext);
const formatter = wrapWithCtx(function (val) {
return val + this.suffix;
});
const context = { prefix: 'PRE', suffix: 'POST' };
const res = formatter.call(context, 'DATA');
assert.equal(res, 'PRE: DATAPOST', 'this context and arguments should be preserved');
}
// Case 7: wrappy throws TypeError with need wrapper function when first argument is not a function
{
assert.throws(
() => {
wrappy(null);
},
{
name: 'TypeError',
message: 'need wrapper function'
},
'wrappy(null) should throw TypeError with message "need wrapper function"'
);
assert.throws(
() => {
wrappy('not-a-function');
},
{
name: 'TypeError',
message: 'need wrapper function'
},
'wrappy non-function should throw TypeError'
);
}
// Case 8: wrapFunction helper provides wrapper generator and immediate wrapping interfaces
{
const helperGen = wrapFunction((cb) => (x) => cb(x) + 1);
const inc = helperGen((x) => x * 10);
assert.equal(inc(5), 51, 'wrapFunction with 1 arg should act as wrapper generator');
const direct = wrapFunction((cb) => (x) => cb(x) - 1, (x) => x * 2);
assert.equal(direct(5), 9, 'wrapFunction with 2 args should immediately wrap callback');
}
console.log('PASS: all wrappy contract assertions passed');
Seeder de origen
anónimo