CodeSampleX

Ejemplo

degenerator 5.0.1: degenerator

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

sha256:b5126463e0f8abb7f6c4b92d18cfa43be0e4476a86cd66c1eee34b2b1c4d4df2

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-26

Caso

HOW
Objetivo
verify degenerator in pkg:npm/degenerator@5.0.1
Paquetes
Símbolos
  • degenerator
Entorno
node 22.23.2
Creado
2026-08-26T01:27:09Z

Contrato

  1. degenerator is exported as a function
  2. compileToAsync is exported as a function
  3. throws TypeError when names argument is not an array
  4. transforms sync function call into async function with await
  5. supports RegExp patterns in names array
  6. supports member expression function calls
  7. supports transitive degeneration across dependent functions
  8. transformed code evaluates and executes correctly in a Node vm sandbox

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 degenerator in pkg:npm/degenerator@5.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/degenerator@5.0.1
Demonstrate these symbols/APIs:
  - degenerator
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:9313ca837ee452e5077a651341218f848ec001a116ab205d42b04af7862b63af","constraints":{"executionContext":"node"},"contract":["degenerator is exported as a function","compileToAsync is exported as a function","throws TypeError when names argument is not an array","transforms sync function call into async function with await","supports RegExp patterns in names array","supports member expression function calls","supports transitive degeneration across dependent functions","transformed code evaluates and executes correctly in a Node vm sandbox"],"goal":"verify degenerator in pkg:npm/degenerator@5.0.1","kind":"HOW","packages":["pkg:npm/degenerator@5.0.1"],"schemaVersion":1,"symbols":["degenerator"]},"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/degenerator@5.0.1"],"schemaVersion":1,"subject":"pkg:npm/degenerator@5.0.1","symbols":["degenerator"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-degenerator",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-degenerator",
      "version": "1.0.0",
      "dependencies": {
        "degenerator": "5.0.1"
      }
    },
    "node_modules/ast-types": {
      "version": "0.13.4",
      "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz",
      "integrity": "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==",
      "license": "MIT",
      "dependencies": {
        "tslib": "^2.0.1"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/degenerator": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/degenerator/-/degenerator-5.0.1.tgz",
      "integrity": "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==",
      "license": "MIT",
      "dependencies": {
        "ast-types": "^0.13.4",
        "escodegen": "^2.1.0",
        "esprima": "^4.0.1"
      },
      "engines": {
        "node": ">= 14"
      }
    },
    "node_modules/escodegen": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.1.0.tgz",
      "integrity": "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==",
      "license": "BSD-2-Clause",
      "dependencies": {
        "esprima": "^4.0.1",
        "estraverse": "^5.2.0",
        "esutils": "^2.0.2"
      },
      "bin": {
        "escodegen": "bin/escodegen.js",
        "esgenerate": "bin/esgenerate.js"
      },
      "engines": {
        "node": ">=6.0"
      },
      "optionalDependencies": {
        "source-map": "~0.6.1"
      }
    },
    "node_modules/esprima": {
      "version": "4.0.1",
      "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
      "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
      "license": "BSD-2-Clause",
      "bin": {
        "esparse": "bin/esparse.js",
        "esvalidate": "bin/esvalidate.js"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/estraverse": {
      "version": "5.3.0",
      "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",
      "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=4.0"
      }
    },
    "node_modules/esutils": {
      "version": "2.0.3",
      "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
      "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/source-map": {
      "version": "0.6.1",
      "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
      "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
      "license": "BSD-3-Clause",
      "optional": true,
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/tslib": {
      "version": "2.8.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
      "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sample-degenerator",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of degenerator",
  "main": "src/index.js",
  "dependencies": {
    "degenerator": "5.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify degenerator in pkg:npm/degenerator@5.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/degenerator@5.0.1"
  ],
  "symbols": [
    "degenerator"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { degenerator } = require('degenerator');

/**
 * Transforms synchronous JavaScript code containing target function calls
 * into async functions with injected await expressions.
 *
 * @param {string} code - JavaScript source code to transform
 * @param {Array<string|RegExp>} names - Names or RegExp patterns of functions to await
 * @returns {string} Transformed JavaScript code with async/await
 */
function compileToAsync(code, names) {
  return degenerator(code, names);
}

module.exports = {
  degenerator,
  compileToAsync
};
test/contract.mjs
import assert from 'node:assert';
import vm from 'node:vm';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { degenerator, compileToAsync } = require('../src/index.js');

// 1. Export verification
assert.strictEqual(typeof degenerator, 'function', 'degenerator should be exported as a function');
assert.strictEqual(typeof compileToAsync, 'function', 'compileToAsync should be exported as a function');

// 2. Throws TypeError when names argument is not an array
assert.throws(
  () => degenerator('function test() {}', null),
  {
    name: 'TypeError',
    message: 'an array of async function "names" is required'
  }
);

// 3. Transforms sync function call into async function with await
const code1 = 'function fetchRecord() { return fetch("http://localhost:8080/data"); }';
const result1 = degenerator(code1, ['fetch']);
assert(result1.includes('async function fetchRecord()'), 'Function should be converted to async');
assert(result1.includes('await fetch('), 'Call expression should be awaited');

// 4. Supports RegExp patterns in names array
const codeRegex = 'function loadData() { return getRecord(1) + fetchItem(2); }';
const resultRegex = degenerator(codeRegex, [/^get/, /^fetch/]);
assert(resultRegex.includes('async function loadData()'), 'Function matching RegExp should become async');
assert(resultRegex.includes('await getRecord('), 'getRecord call should be awaited');
assert(resultRegex.includes('await fetchItem('), 'fetchItem call should be awaited');

// 5. Supports member expression function calls
const codeMember = 'function run() { return api.request("/data"); }';
const resultMember = degenerator(codeMember, ['api.request']);
assert(resultMember.includes('async function run()'), 'Function with member expression call should become async');
assert(resultMember.includes('await api.request('), 'Member expression call should be awaited');

// 6. Supports transitive degeneration across dependent functions
const codeTransitive = `
function stepOne() {
  return query();
}
function stepTwo() {
  return stepOne();
}
`;
const resultTransitive = degenerator(codeTransitive, ['query']);
assert(resultTransitive.includes('async function stepOne()'), 'stepOne should be async');
assert(resultTransitive.includes('async function stepTwo()'), 'stepTwo should be async');
assert(resultTransitive.includes('await query()'), 'query should be awaited');
assert(resultTransitive.includes('await stepOne()'), 'stepOne should be awaited');

// 7. Transformed code evaluates and executes correctly in a Node vm sandbox
const codeExecutable = `
function calculate() {
  const a = getValue(10);
  const b = getValue(20);
  return a + b;
}
`;
const transformed = compileToAsync(codeExecutable, ['getValue']);
const sandbox = {
  getValue: async (val) => val * 2
};
const script = new vm.Script(`(${transformed})`);
const context = vm.createContext(sandbox);
const fn = script.runInContext(context);

const total = await fn();
assert.strictEqual(total, 60, 'Transformed async function should resolve with the expected result');

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

Seeder de origen

anónimo