CodeSampleX

Exemple

react-router-dom 6.30.4: resolvePath

Échantillon vérifié pour npm react-router-dom 6.30.4: resolvePath. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:6ea6057858dc00d8a695fa806ddbd1ed1d534e652de45ddf5bcca92213e6cf5c

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-01

Cas

HOW
Objectif
verify resolvePath in pkg:npm/react-router-dom@6.30.4
Paquets
Symboles
  • resolvePath
Environnement
node 22.23.2
Créé
2026-09-01T16:03:47Z

Contrat

  1. assert resolvePath resolves relative path against default root pathname
  2. assert resolvePath resolves relative child path against base pathname
  3. assert resolvePath resolves parent relative path with double dots against nested pathname
  4. assert resolvePath preserves absolute path when given absolute pathname
  5. assert resolvePath parses search query and hash fragments into separate path properties
  6. assert resolvePath resolves Path object with pathname, search, and hash properties
  7. assert resolveSubpath helper returns the resolved pathname string

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 resolvePath in pkg:npm/react-router-dom@6.30.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-router-dom@6.30.4
Demonstrate these symbols/APIs:
  - resolvePath

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:1d0f7f3373d3be2eadff582e6f996fbaa9bde60a199e08ca73478f0d500c6daf","contract":["assert resolvePath resolves relative path against default root pathname","assert resolvePath resolves relative child path against base pathname","assert resolvePath resolves parent relative path with double dots against nested pathname","assert resolvePath preserves absolute path when given absolute pathname","assert resolvePath parses search query and hash fragments into separate path properties","assert resolvePath resolves Path object with pathname, search, and hash properties","assert resolveSubpath helper returns the resolved pathname string"],"goal":"verify resolvePath in pkg:npm/react-router-dom@6.30.4","kind":"HOW","packages":["pkg:npm/react-router-dom@6.30.4"],"schemaVersion":1,"symbols":["resolvePath"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react-router-dom@6.30.4"],"schemaVersion":1,"subject":"pkg:npm/react-router-dom@6.30.4","symbols":["resolvePath"],"verifierAdapter":"node-typescript@1"}
index.js
import { resolvePath } from 'react-router-dom';

/**
 * Resolves a destination path or path object relative to a base pathname.
 *
 * @param {string | { pathname?: string, search?: string, hash?: string }} to - The target path or path object.
 * @param {string} [fromPathname="/"] - The base path to resolve against.
 * @returns {{ pathname: string, search: string, hash: string }} The resolved Path object.
 */
export function resolveDestination(to, fromPathname = '/') {
  return resolvePath(to, fromPathname);
}

/**
 * Resolves a relative subpath within a given base route.
 *
 * @param {string} subpath - Relative subpath.
 * @param {string} basePath - Current route pathname.
 * @returns {string} The resolved pathname.
 */
export function resolveSubpath(subpath, basePath) {
  const resolved = resolvePath(subpath, basePath);
  return resolved.pathname;
}

/**
 * Resolves a full URL descriptor with search and hash parameters relative to a base path.
 *
 * @param {string} targetWithParams - Target path containing potential query string and hash.
 * @param {string} basePath - Current base path.
 * @returns {{ pathname: string, search: string, hash: string }} Resolved Path object.
 */
export function resolveTargetWithParams(targetWithParams, basePath) {
  return resolvePath(targetWithParams, basePath);
}

export { resolvePath };
package-lock.json
{
  "name": "sample-react-router-dom-resolve-path",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-router-dom-resolve-path",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-router-dom": "6.30.4"
      }
    },
    "node_modules/@remix-run/router": {
      "version": "1.23.3",
      "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.23.3.tgz",
      "integrity": "sha512-4An71tdz9X8+3sI4Qqqd2LWd9vS39J7sqd9EU4Scw7TJE/qB10Flv/UuqbPVgfQV9XoK8Np6jNquZitnZq5i+Q==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    },
    "node_modules/react": {
      "version": "19.2.8",
      "resolved": "https://registry.npmjs.org/react/-/react-19.2.8.tgz",
      "integrity": "sha512-PWaYA1L/q9u2u7xYQi+Y3L3Yfnie7XyLeaJICV1MGD6LprsBxcAqGjYyr0eY3p+QdsA+x/Irkt4Qif8D63+Sbw==",
      "license": "MIT",
      "peer": true,
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/react-dom": {
      "version": "19.2.8",
      "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.8.tgz",
      "integrity": "sha512-rVprimfGBG3DR+Tq0IQG2DT5PxKth1WIGDmj5yPmlzr4YBe7uyE+Du4oVqTDXZSHGGGXRtTJEGSSePyQCMBglQ==",
      "license": "MIT",
      "peer": true,
      "dependencies": {
        "scheduler": "^0.27.0"
      },
      "peerDependencies": {
        "react": "^19.2.8"
      }
    },
    "node_modules/react-router": {
      "version": "6.30.4",
      "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.30.4.tgz",
      "integrity": "sha512-SVUsDe+DybHM/WmYKIVYhZh1o5Dcuf16yM6WjG02Q9XVFMZIJyHYhwrr6bFBXZkVP6z69kNkMyBCujt8FaFLJA==",
      "license": "MIT",
      "dependencies": {
        "@remix-run/router": "1.23.3"
      },
      "engines": {
        "node": ">=14.0.0"
      },
      "peerDependencies": {
        "react": ">=16.8"
      }
    },
    "node_modules/react-router-dom": {
      "version": "6.30.4",
      "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.30.4.tgz",
      "integrity": "sha512-q4HvNl+mmDdkS0g+MqiBZNteQJCuimWoOyHMy4T/RQLAn9Z29+E91QXRaxOujeMl2HTzRSS0KFPd7lxX3PjV0Q==",
      "license": "MIT",
      "dependencies": {
        "@remix-run/router": "1.23.3",
        "react-router": "6.30.4"
      },
      "engines": {
        "node": ">=14.0.0"
      },
      "peerDependencies": {
        "react": ">=16.8",
        "react-dom": ">=16.8"
      }
    },
    "node_modules/scheduler": {
      "version": "0.27.0",
      "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
      "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==",
      "license": "MIT",
      "peer": true
    }
  }
}
package.json
{
  "name": "sample-react-router-dom-resolve-path",
  "version": "1.0.0",
  "description": "Clean-room sample verifying resolvePath in react-router-dom",
  "type": "module",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "react-router-dom": "6.30.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify resolvePath in pkg:npm/react-router-dom@6.30.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-router-dom@6.30.4"
  ],
  "symbols": [
    "resolvePath"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import { resolvePath } from 'react-router-dom';
import { resolveDestination, resolveSubpath, resolveTargetWithParams } from '../index.js';

// 1. resolvePath resolves relative path against default root pathname
const defaultRoot = resolvePath('about');
assert.strictEqual(defaultRoot.pathname, '/about', 'default fromPathname should be /');
assert.strictEqual(defaultRoot.search, '', 'search query should be empty');
assert.strictEqual(defaultRoot.hash, '', 'hash fragment should be empty');

// 2. resolvePath resolves relative child path against base pathname
const childPath = resolvePath('settings', '/dashboard');
assert.strictEqual(childPath.pathname, '/dashboard/settings', 'relative child path should append to base pathname');
assert.strictEqual(childPath.search, '');
assert.strictEqual(childPath.hash, '');

// 3. resolvePath resolves parent relative path with double dots against nested pathname
const parentPath = resolvePath('../billing', '/dashboard/settings/profile');
assert.strictEqual(parentPath.pathname, '/dashboard/settings/billing', '.. should navigate up one directory level');

// 4. resolvePath preserves absolute path when given absolute pathname
const absolutePath = resolvePath('/login', '/dashboard/settings');
assert.strictEqual(absolutePath.pathname, '/login', 'absolute path should reset to root');

// 5. resolvePath parses search query and hash fragments into separate path properties
const withParams = resolveTargetWithParams('items?sort=asc#section-1', '/store');
assert.strictEqual(withParams.pathname, '/store/items', 'pathname should contain base and subpath');
assert.strictEqual(withParams.search, '?sort=asc', 'search should extract query parameters');
assert.strictEqual(withParams.hash, '#section-1', 'hash should extract anchor fragment');

// 6. resolvePath resolves Path object with pathname, search, and hash properties
const objectInput = resolveDestination({ pathname: 'overview', search: '?view=compact', hash: '#top' }, '/admin');
assert.strictEqual(objectInput.pathname, '/admin/overview', 'Path object pathname should resolve against base');
assert.strictEqual(objectInput.search, '?view=compact', 'Path object search should be preserved');
assert.strictEqual(objectInput.hash, '#top', 'Path object hash should be preserved');

// 7. resolveSubpath helper returns the resolved pathname string
const subpathStr = resolveSubpath('analytics', '/projects/123');
assert.strictEqual(subpathStr, '/projects/123/analytics', 'helper should return resolved pathname string');

console.log('All react-router-dom resolvePath contract assertions passed.');

Seeder d'origine

anonyme