CodeSampleX

Пример

pathe 2.0.3: resolve

Проверенный пример — npm pathe 2.0.3: resolve. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: pathe.resolve resolves multiple path…

sha256:52a9f5b4160a1ec69563512e658e53ba187df95789245d25ad58a482df5f607e

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify pathe.resolve in pkg:npm/pathe@2.0.3
Пакеты
Символы
  • pathe.resolve
Создан
2026-08-26T10:49:51Z

Контракт

  1. pathe.resolve resolves multiple path segments into a normalized POSIX path string
  2. pathe.resolve resolves relative path segments and parent directory navigation (..)
  3. pathe.resolve processes paths from right to left until an absolute path is constructed
  4. pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory
  5. pathe.resolve normalizes redundant slashes and relative dot segments
  6. pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments
  7. pathe.resolve ignores empty string segments between non-empty path arguments

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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 pathe.resolve 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.resolve

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:3a2a6c2f7d37c0c0bd325a20386fd774557a8d1794c233fd1ba96e117a194392","contract":["pathe.resolve resolves multiple path segments into a normalized POSIX path string","pathe.resolve resolves relative path segments and parent directory navigation (..)","pathe.resolve processes paths from right to left until an absolute path is constructed","pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory","pathe.resolve normalizes redundant slashes and relative dot segments","pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments","pathe.resolve ignores empty string segments between non-empty path arguments"],"goal":"verify pathe.resolve in pkg:npm/pathe@2.0.3","kind":"HOW","packages":["pkg:npm/pathe@2.0.3"],"schemaVersion":1,"symbols":["pathe.resolve"]},"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.resolve"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-pathe-resolve",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pathe-resolve",
      "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"
    }
  }
}
package.json
{
  "name": "sample-pathe-resolve",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for pathe.resolve in pathe@2.0.3",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "pathe": "2.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pathe.resolve in pkg:npm/pathe@2.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pathe@2.0.3"
  ],
  "symbols": [
    "pathe.resolve"
  ]
}
src/index.js
const pathe = require('pathe');
const { resolve, normalize } = pathe;

/**
 * Resolves a sequence of paths or path segments into an absolute POSIX path.
 *
 * @param {...string} paths - Path segments to resolve.
 * @returns {string} Normalized absolute POSIX path.
 */
function resolvePath(...paths) {
  return resolve(...paths);
}

/**
 * Resolves path segments relative to a specified base directory.
 *
 * @param {string} base - Base directory path.
 * @param {...string} segments - Additional segments to resolve against the base.
 * @returns {string} Resolved POSIX path.
 */
function resolveRelative(base, ...segments) {
  return resolve(base, ...segments);
}

module.exports = {
  pathe,
  resolve,
  normalize,
  resolvePath,
  resolveRelative
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { pathe, resolve, normalize, resolvePath, resolveRelative } = require('../src/index.js');

async function runTests() {
  const cwd = normalize(process.cwd());

  // 1. pathe.resolve resolves multiple path segments into a normalized POSIX path string
  assert.equal(typeof pathe.resolve, 'function', 'pathe.resolve must be a function');
  assert.equal(typeof resolve, 'function', 'resolve must be a function');
  assert.equal(resolve('/a', 'b', 'c'), '/a/b/c', 'resolve should join and normalize path segments');
  assert.equal(resolvePath('/foo', 'bar', 'baz'), '/foo/bar/baz', 'resolvePath helper should resolve segments');

  // 2. pathe.resolve resolves relative path segments and parent directory navigation (..)
  assert.equal(resolve('/foo/bar', '../baz'), '/foo/baz', 'resolve should handle .. navigation');
  assert.equal(resolve('/a/b/c', 'd', '../e'), '/a/b/c/e', 'resolve should traverse relative parent correctly');
  assert.equal(resolveRelative('/base/dir', './sub', '../other'), '/base/dir/other', 'resolveRelative helper should resolve ..');

  // 3. pathe.resolve processes paths from right to left until an absolute path is constructed
  assert.equal(resolve('/first/path', '/second/path'), '/second/path', 'Rightmost absolute path takes precedence');
  assert.equal(resolve('/root', 'sub1', '/target', 'file.txt'), '/target/file.txt', 'Absolute segment overrides earlier segments');

  // 4. pathe.resolve strips trailing slashes from resolved paths unless resolving to root directory
  assert.equal(resolve('/foo/bar/'), '/foo/bar', 'Trailing slash should be removed for non-root paths');
  assert.equal(resolve('/'), '/', 'Root slash must be preserved');

  // 5. pathe.resolve normalizes redundant slashes and relative dot segments
  assert.equal(resolve('/foo//bar///baz'), '/foo/bar/baz', 'Redundant slashes should be normalized');
  assert.equal(resolve('/foo/./bar/../baz'), '/foo/baz', 'Dot segments should be resolved');

  // 6. pathe.resolve defaults to the current working directory in POSIX format when given empty or no arguments
  assert.equal(resolve(''), cwd, 'Empty string should resolve to normalized current working directory');
  assert.equal(resolve(), cwd, 'No arguments should resolve to normalized current working directory');

  // 7. pathe.resolve ignores empty string segments between non-empty path arguments
  assert.equal(resolve('/foo', '', 'bar'), '/foo/bar', 'Empty string segments should be ignored');
  assert.equal(resolve('/foo', '', '', 'bar'), '/foo/bar', 'Multiple empty string segments should be ignored');

  console.log('All contract assertions for pathe.resolve passed successfully.');
}

runTests().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Исходный сидер

аноним