Ejemplo
pathe 2.0.3: basename
Muestra verificada para npm pathe 2.0.3: basename. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: pathe.basename extracts the last…
sha256:9a61e1cea052e0b26db8099b519f01ba33667c51d46190d6b1f131f042ae559c
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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-04 |
Caso
HOW- Objetivo
- verify pathe.basename in pkg:npm/pathe@2.0.3
- Paquetes
- Símbolos
-
- pathe.basename
- Creado
- 2026-09-04T13:16:30Z
Contrato
- pathe.basename extracts the last portion of a POSIX path
- pathe.basename strips a specified file extension or suffix from the filename
- pathe.basename normalizes Windows backslashes and extracts filename from Windows path
- pathe.basename handles trailing slashes by ignoring them and returning directory basename
- pathe.basename returns an empty string for root or empty path inputs
- pathe.basename returns the input unchanged when given a bare filename without path separators
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 pathe.basename in pkg:npm/pathe@2.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/pathe@2.0.3
Demonstrate these symbols/APIs:
- pathe.basename
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:20de455ed2020fa60d7572d724464c7c313b9d4922b700588f51d7f5d9f03f00","contract":["pathe.basename extracts the last portion of a POSIX path","pathe.basename strips a specified file extension or suffix from the filename","pathe.basename normalizes Windows backslashes and extracts filename from Windows path","pathe.basename handles trailing slashes by ignoring them and returning directory basename","pathe.basename returns an empty string for root or empty path inputs","pathe.basename returns the input unchanged when given a bare filename without path separators"],"goal":"verify pathe.basename in pkg:npm/pathe@2.0.3","kind":"HOW","packages":["pkg:npm/pathe@2.0.3"],"schemaVersion":1,"symbols":["pathe.basename"]},"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/pathe@2.0.3"],"schemaVersion":1,"subject":"pkg:npm/pathe@2.0.3","symbols":["pathe.basename"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-pathe-basename",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-pathe-basename",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
},
"node_modules/pathe": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
"license": "MIT"
}
}
}
{
"name": "sample-pathe-basename",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of pathe.basename in pkg:npm/pathe@2.0.3",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"pathe": "2.0.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pathe.basename in pkg:npm/pathe@2.0.3",
"kind": "HOW",
"packages": [
"pkg:npm/pathe@2.0.3"
],
"symbols": [
"pathe.basename"
]
}
const { basename } = require('pathe');
/**
* Returns the last portion of a path, similar to the Unix basename command.
* Trailing directory separators are ignored, and Windows backslashes are normalized to forward slashes.
*
* @param {string} path - The path to evaluate.
* @param {string} [ext] - An optional extension to remove from the result.
* @returns {string} The last portion of the given path.
*/
function getBasename(path, ext) {
return basename(path, ext);
}
/**
* Extracts the filename without the specified extension.
*
* @param {string} path - The path to evaluate.
* @param {string} ext - The extension to strip.
* @returns {string} The filename without extension.
*/
function getFilenameWithoutExtension(path, ext) {
return basename(path, ext);
}
module.exports = {
basename,
getBasename,
getFilenameWithoutExtension
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { basename, getBasename, getFilenameWithoutExtension } = require('../src/index.js');
// 1. pathe.basename extracts the last portion of a POSIX path
assert.strictEqual(basename('/path/to/file.ext'), 'file.ext');
assert.strictEqual(basename('path/to/file.ext'), 'file.ext');
assert.strictEqual(basename('/a/b/c'), 'c');
assert.strictEqual(getBasename('/path/to/file.ext'), 'file.ext');
// 2. pathe.basename strips a specified file extension or suffix from the filename
assert.strictEqual(basename('/path/to/file.ext', '.ext'), 'file');
assert.strictEqual(basename('script.test.js', '.js'), 'script.test');
assert.strictEqual(basename('document.pdf', '.txt'), 'document.pdf');
assert.strictEqual(basename('/path/to/file.ext', 'ext'), 'file.');
assert.strictEqual(getFilenameWithoutExtension('/path/to/file.ext', '.ext'), 'file');
// 3. pathe.basename normalizes Windows backslashes and extracts filename from Windows path
assert.strictEqual(basename('foo\\bar\\file.txt'), 'file.txt');
assert.strictEqual(basename('dir\\subdir\\test.json'), 'test.json');
assert.strictEqual(basename('dir\\subdir\\test.json', '.json'), 'test');
assert.strictEqual(getBasename('foo\\bar\\file.txt'), 'file.txt');
// 4. pathe.basename handles trailing slashes by ignoring them and returning directory basename
assert.strictEqual(basename('/dir/subdir/'), 'subdir');
assert.strictEqual(basename('a/b/c/'), 'c');
assert.strictEqual(basename('dir\\subdir\\'), 'subdir');
assert.strictEqual(getBasename('/dir/subdir/'), 'subdir');
// 5. pathe.basename returns an empty string for root or empty path inputs
assert.strictEqual(basename(''), '');
assert.strictEqual(basename('/'), '');
assert.strictEqual(basename('///'), '');
assert.strictEqual(getBasename(''), '');
// 6. pathe.basename returns the input unchanged when given a bare filename without path separators
assert.strictEqual(basename('file.txt'), 'file.txt');
assert.strictEqual(basename('filename'), 'filename');
assert.strictEqual(getBasename('file.txt'), 'file.txt');
console.log('Contract tests passed successfully.');
Seeder de origen
anónimo