CodeSampleX

Ejemplo

resolve 1.22.12

Muestra verificada para npm resolve 1.22.12. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: resolve.isCore identifies standard Node.js…

sha256:844081ef0309af45ce8984461477ba70b08fc3be28a5e22ba8861319b0621ea6

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

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

Caso

HOW
Objetivo
verify pkg:npm/resolve@1.22.12
Paquetes
Entorno
node 22.23.2
Creado
2026-08-20T17:37:17Z

Contrato

  1. resolve.isCore identifies standard Node.js built-in core modules and node-prefixed specifiers
  2. resolve.sync resolves relative module paths and custom file extensions synchronously
  3. resolve asynchronously resolves module paths and returns resolved target path
  4. resolve.sync throws MODULE_NOT_FOUND error when a module cannot be resolved
  5. resolve.sync supports custom basedir, extensions, packageFilter, and pathFilter options
  6. resolve.sync resolves paths using custom synchronous filesystem overrides

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 pkg:npm/resolve@1.22.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/resolve@1.22.12
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:552e3b932042ddadc520f6277f7e005bc92b70a3d5aeb2fc21ca92a65d478e01","constraints":{"executionContext":"node"},"contract":["resolve.isCore identifies standard Node.js built-in core modules and node-prefixed specifiers","resolve.sync resolves relative module paths and custom file extensions synchronously","resolve asynchronously resolves module paths and returns resolved target path","resolve.sync throws MODULE_NOT_FOUND error when a module cannot be resolved","resolve.sync supports custom basedir, extensions, packageFilter, and pathFilter options","resolve.sync resolves paths using custom synchronous filesystem overrides"],"goal":"verify pkg:npm/resolve@1.22.12","kind":"HOW","packages":["pkg:npm/resolve@1.22.12"],"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/resolve@1.22.12"],"schemaVersion":1,"subject":"pkg:npm/resolve@1.22.12","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-resolve",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-resolve",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "resolve": "1.22.12"
      }
    },
    "node_modules/es-errors": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/hasown": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
      "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
      "license": "MIT",
      "dependencies": {
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/is-core-module": {
      "version": "2.16.2",
      "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz",
      "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==",
      "license": "MIT",
      "dependencies": {
        "hasown": "^2.0.3"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/path-parse": {
      "version": "1.0.7",
      "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
      "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
      "license": "MIT"
    },
    "node_modules/resolve": {
      "version": "1.22.12",
      "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz",
      "integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==",
      "license": "MIT",
      "dependencies": {
        "es-errors": "^1.3.0",
        "is-core-module": "^2.16.1",
        "path-parse": "^1.0.7",
        "supports-preserve-symlinks-flag": "^1.0.0"
      },
      "bin": {
        "resolve": "bin/resolve"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/supports-preserve-symlinks-flag": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
      "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    }
  }
}
package.json
{
  "name": "sample-resolve",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of resolve",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "resolve": "1.22.12"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/resolve@1.22.12",
  "kind": "HOW",
  "packages": [
    "pkg:npm/resolve@1.22.12"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const resolve = require('resolve');

/**
 * Resolves a module specifier synchronously.
 * @param {string} id - Module specifier to resolve
 * @param {object} [opts] - Resolution options
 * @returns {string} Absolute resolved file path
 */
function resolveModuleSync(id, opts) {
  return resolve.sync(id, opts);
}

/**
 * Resolves a module specifier asynchronously.
 * @param {string} id - Module specifier to resolve
 * @param {object} [opts] - Resolution options
 * @returns {Promise<string>} Promise resolving to absolute file path
 */
function resolveModuleAsync(id, opts) {
  return new Promise((resolvePromise, rejectPromise) => {
    resolve(id, opts, (err, res) => {
      if (err) {
        return rejectPromise(err);
      }
      resolvePromise(res);
    });
  });
}

/**
 * Checks whether a specifier is a Node.js core module.
 * @param {string} id - Module specifier
 * @returns {boolean} True if core module
 */
function checkCoreModule(id) {
  return resolve.isCore(id);
}

module.exports = {
  resolve,
  resolveModuleSync,
  resolveModuleAsync,
  checkCoreModule
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { resolve, resolveModuleSync, resolveModuleAsync, checkCoreModule } = require('../src/index.js');

// 1. Export verification
assert.equal(typeof resolve, 'function', 'resolve must be exported as a function');
assert.equal(typeof resolve.sync, 'function', 'resolve.sync must be exported as a function');
assert.equal(typeof resolve.isCore, 'function', 'resolve.isCore must be exported as a function');
assert.equal(typeof resolveModuleSync, 'function', 'resolveModuleSync must be exported as a function');
assert.equal(typeof resolveModuleAsync, 'function', 'resolveModuleAsync must be exported as a function');
assert.equal(typeof checkCoreModule, 'function', 'checkCoreModule must be exported as a function');

// 2. resolve.isCore identifies standard Node.js built-in core modules and node-prefixed specifiers
assert.equal(resolve.isCore('fs'), true, 'fs is a core module');
assert.equal(resolve.isCore('path'), true, 'path is a core module');
assert.equal(resolve.isCore('events'), true, 'events is a core module');
assert.equal(resolve.isCore('node:fs'), true, 'node:fs is a core module');
assert.equal(resolve.isCore('node:path'), true, 'node:path is a core module');
assert.equal(checkCoreModule('node:test'), true, 'node:test is a core module');
assert.equal(resolve.isCore('non-existent-core-module'), false, 'non-existent package is not core');
assert.equal(checkCoreModule('sample-resolve-xyz'), false, 'sample package is not core');

// 3. resolve.sync resolves relative module paths and custom file extensions synchronously
const basedir = process.cwd();
const resolvedSrc = resolveModuleSync('./src/index', { basedir, extensions: ['.js'] });
assert.ok(resolvedSrc.endsWith('src/index.js'), 'should resolve relative index file with extension');

const resolvedJson = resolveModuleSync('./package', { basedir, extensions: ['.json', '.js'] });
assert.ok(resolvedJson.endsWith('package.json'), 'should resolve file with custom .json extension');

// 4. resolve asynchronously resolves module paths and returns resolved target path
const asyncResolved = await resolveModuleAsync('./src/index', { basedir });
assert.ok(asyncResolved.endsWith('src/index.js'), 'async resolution should match target path');

await new Promise((done, fail) => {
  resolve('./package', { basedir, extensions: ['.json'] }, (err, res) => {
    if (err) return fail(err);
    try {
      assert.ok(res.endsWith('package.json'));
      done();
    } catch (e) {
      fail(e);
    }
  });
});

// 5. resolve.sync throws MODULE_NOT_FOUND error when a module cannot be resolved
assert.throws(
  () => resolveModuleSync('./non-existent-target-file-12345', { basedir }),
  (err) => err && err.code === 'MODULE_NOT_FOUND'
);

// 6. resolve.sync supports custom basedir, extensions, packageFilter, and pathFilter options
let packageFilterCalled = false;
let pathFilterCalled = false;

const customResolved = resolve.sync('resolve', {
  basedir,
  packageFilter: (pkg, dir) => {
    packageFilterCalled = true;
    return pkg;
  },
  pathFilter: (pkg, path, relativePath) => {
    pathFilterCalled = true;
    return relativePath;
  }
});
assert.equal(packageFilterCalled, true, 'packageFilter hook should be invoked');
assert.equal(pathFilterCalled, true, 'pathFilter hook should be invoked');
assert.ok(customResolved.endsWith('index.js'), 'custom resolved path should point to resolve index.js');

// 7. resolve.sync resolves paths using custom synchronous filesystem overrides
const virtualFiles = {
  '/virtual/root/package.json': JSON.stringify({ name: 'virtual-mod', main: 'entry.js' }),
  '/virtual/root/entry.js': 'module.exports = "virtual-resolved";'
};

const resolvedVirtual = resolve.sync('./entry', {
  basedir: '/virtual/root',
  extensions: ['.js'],
  readFileSync: (file) => {
    if (virtualFiles[file]) return virtualFiles[file];
    throw new Error('ENOENT: ' + file);
  },
  isFile: (file) => Boolean(virtualFiles[file]),
  isDirectory: (dir) => dir === '/virtual/root',
  realpathSync: (x) => x
});
assert.equal(resolvedVirtual, '/virtual/root/entry.js', 'should resolve using custom virtual filesystem handlers');

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

Seeder de origen

anónimo