Ejemplo
resolve-from 4.0.0
Muestra verificada para npm resolve-from 4.0.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: resolveFrom resolves a relative file…
sha256:79ed2be4d403a02cf7f1980e76ed964a76533064e1df32c36ccc8b89c0686361
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
linux 24 · ubuntu · glibc 2.39 x64 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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
Caso
HOW- Objetivo
- verify pkg:npm/resolve-from@4.0.0
- Paquetes
- Creado
- 2026-08-23T13:48:35Z
Contrato
- resolveFrom resolves a relative file path from a specified directory
- resolveFrom resolves an installed npm package from a specified directory
- resolveFrom throws MODULE_NOT_FOUND error when the target module does not exist
- resolveFrom throws TypeError when fromDirectory or moduleId is not a string
- resolveFrom.silent returns null instead of throwing when the target module does not exist
- resolveFrom.silent returns resolved absolute path when target exists
- resolveModuleFrom and tryResolveModuleFrom helper functions wrap resolveFrom and resolveFrom.silent
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- 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/resolve-from@4.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/resolve-from@4.0.0
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:3817a5d8de81e46e67b5cf8f8913c25571c1d5283d5725c2e5cfb88a963f7985","contract":["resolveFrom resolves a relative file path from a specified directory","resolveFrom resolves an installed npm package from a specified directory","resolveFrom throws MODULE_NOT_FOUND error when the target module does not exist","resolveFrom throws TypeError when fromDirectory or moduleId is not a string","resolveFrom.silent returns null instead of throwing when the target module does not exist","resolveFrom.silent returns resolved absolute path when target exists","resolveModuleFrom and tryResolveModuleFrom helper functions wrap resolveFrom and resolveFrom.silent"],"goal":"verify pkg:npm/resolve-from@4.0.0","kind":"HOW","packages":["pkg:npm/resolve-from@4.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/resolve-from@4.0.0"],"schemaVersion":1,"subject":"pkg:npm/resolve-from@4.0.0","verifierAdapter":"node-typescript@1"}
{
"name": "sample-resolve-from",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-resolve-from",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"resolve-from": "4.0.0"
}
},
"node_modules/resolve-from": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
"license": "MIT",
"engines": {
"node": ">=4"
}
}
}
}
{
"name": "sample-resolve-from",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for resolve-from@4.0.0",
"main": "src/index.js",
"type": "module",
"license": "MIT-0",
"dependencies": {
"resolve-from": "4.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/resolve-from@4.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/resolve-from@4.0.0"
]
}
import resolveFrom from 'resolve-from';
/**
* Resolves the path of a module from a given directory.
*
* @param {string} fromDirectory - Directory to resolve from.
* @param {string} moduleId - Target module ID or file path to resolve.
* @returns {string} Absolute path to the resolved module.
* @throws {TypeError} If fromDirectory or moduleId is not a string.
* @throws {Error} If module cannot be resolved (code: 'MODULE_NOT_FOUND').
*/
export function resolveModuleFrom(fromDirectory, moduleId) {
return resolveFrom(fromDirectory, moduleId);
}
/**
* Safely resolves the path of a module from a given directory without throwing if not found.
*
* @param {string} fromDirectory - Directory to resolve from.
* @param {string} moduleId - Target module ID or file path to resolve.
* @returns {string|null} Absolute path to the resolved module, or null if resolution fails.
*/
export function tryResolveModuleFrom(fromDirectory, moduleId) {
return resolveFrom.silent(fromDirectory, moduleId);
}
export { resolveFrom };
export default resolveFrom;
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import resolveFrom, {
resolveModuleFrom,
tryResolveModuleFrom,
} from '../src/index.mjs';
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-resolve-from-contract-'));
try {
// Set up mock directory structure
const subDir = path.join(tmpDir, 'sub');
const nodeModulesDir = path.join(tmpDir, 'node_modules', 'dummy-pkg');
fs.mkdirSync(subDir, { recursive: true });
fs.mkdirSync(nodeModulesDir, { recursive: true });
const targetFile = path.join(subDir, 'target.js');
const jsonFile = path.join(subDir, 'data.json');
const pkgIndex = path.join(nodeModulesDir, 'index.js');
const pkgJson = path.join(nodeModulesDir, 'package.json');
fs.writeFileSync(targetFile, 'export const val = 42;\n');
fs.writeFileSync(jsonFile, '{"key": "value"}\n');
fs.writeFileSync(pkgIndex, 'module.exports = { name: "dummy" };\n');
fs.writeFileSync(pkgJson, JSON.stringify({ name: 'dummy-pkg', main: 'index.js' }));
// 1. resolveFrom resolves a relative file path from a specified directory
{
const resolved = resolveFrom(tmpDir, './sub/target.js');
assert.strictEqual(fs.realpathSync(resolved), fs.realpathSync(targetFile));
const resolvedWithoutExt = resolveFrom(tmpDir, './sub/target');
assert.strictEqual(fs.realpathSync(resolvedWithoutExt), fs.realpathSync(targetFile));
const resolvedFromSub = resolveFrom(subDir, './data.json');
assert.strictEqual(fs.realpathSync(resolvedFromSub), fs.realpathSync(jsonFile));
}
// 2. resolveFrom resolves an installed npm package from a specified directory
{
const resolvedPkg = resolveFrom(tmpDir, 'dummy-pkg');
assert.strictEqual(fs.realpathSync(resolvedPkg), fs.realpathSync(pkgIndex));
}
// 3. resolveFrom throws MODULE_NOT_FOUND error when the target module does not exist
{
assert.throws(
() => resolveFrom(tmpDir, './sub/missing-file.js'),
(err) => {
assert.strictEqual(err.code, 'MODULE_NOT_FOUND');
assert.ok(err.message.includes('missing-file.js'));
return true;
}
);
assert.throws(
() => resolveFrom(tmpDir, 'non-existent-package-xyz'),
(err) => {
assert.strictEqual(err.code, 'MODULE_NOT_FOUND');
return true;
}
);
}
// 4. resolveFrom throws TypeError when fromDirectory or moduleId is not a string
{
assert.throws(
() => resolveFrom(null, './sub/target.js'),
{
name: 'TypeError',
message: 'Expected `fromDir` to be of type `string`, got `object`'
}
);
assert.throws(
() => resolveFrom(123, './sub/target.js'),
{
name: 'TypeError',
message: 'Expected `fromDir` to be of type `string`, got `number`'
}
);
assert.throws(
() => resolveFrom(tmpDir, null),
{
name: 'TypeError',
message: 'Expected `moduleId` to be of type `string`, got `object`'
}
);
assert.throws(
() => resolveFrom(tmpDir, 456),
{
name: 'TypeError',
message: 'Expected `moduleId` to be of type `string`, got `number`'
}
);
}
// 5. resolveFrom.silent returns null instead of throwing when the target module does not exist
{
const resultMissingFile = resolveFrom.silent(tmpDir, './sub/missing.js');
assert.strictEqual(resultMissingFile, null);
const resultMissingPkg = resolveFrom.silent(tmpDir, 'missing-package-abc');
assert.strictEqual(resultMissingPkg, null);
}
// 6. resolveFrom.silent returns resolved absolute path when target exists
{
const result = resolveFrom.silent(tmpDir, './sub/target.js');
assert.strictEqual(fs.realpathSync(result), fs.realpathSync(targetFile));
const resultPkg = resolveFrom.silent(tmpDir, 'dummy-pkg');
assert.strictEqual(fs.realpathSync(resultPkg), fs.realpathSync(pkgIndex));
}
// 7. resolveModuleFrom and tryResolveModuleFrom helper functions wrap resolveFrom and resolveFrom.silent
{
const resolved = resolveModuleFrom(tmpDir, './sub/target.js');
assert.strictEqual(fs.realpathSync(resolved), fs.realpathSync(targetFile));
const silentResolved = tryResolveModuleFrom(tmpDir, './sub/target.js');
assert.strictEqual(fs.realpathSync(silentResolved), fs.realpathSync(targetFile));
const silentMissing = tryResolveModuleFrom(tmpDir, './sub/missing.js');
assert.strictEqual(silentMissing, null);
}
console.log('All resolve-from contract tests passed successfully.');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
Seeder de origen
anónimo