CodeSampleX

サンプル

pathe 2.0.3: resolve

検証済みサンプル — npm pathe 2.0.3: resolve. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: pathe.resolve resolves multiple path segments into a…

sha256:52a9f5b4160a1ec69563512e658e53ba187df95789245d25ad58a482df5f607e

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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);
});

オリジンシーダー

匿名