CodeSampleX

Exemple

npm-run-path 4.0.1: env

Échantillon vérifié pour npm npm-run-path 4.0.1: env. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:321840afb791a40f5e41f3a319748fe3a51227b2ddfa8ea4f4437fb5060a7971

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-04

Cas

HOW
Objectif
verify npm-run-path.env in pkg:npm/npm-run-path@4.0.1
Paquets
Symboles
  • npm-run-path.env
Environnement
node 22.23.2
Créé
2026-09-04T03:20:21Z

Contrat

  1. npmRunPath.env returns an environment object containing augmented PATH
  2. npmRunPath.env does not mutate the provided input environment object
  3. npmRunPath.env preserves custom non-PATH environment variables
  4. npmRunPath.env prepends node_modules/.bin based on custom cwd to PATH
  5. npmRunPath.env appends directory of custom execPath to PATH
  6. npmRunPath.env operates with default parameters without throwing

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 npm-run-path.env in pkg:npm/npm-run-path@4.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/npm-run-path@4.0.1
Demonstrate these symbols/APIs:
  - npm-run-path.env
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:9b5bdc27cd8a117d68139b914924ca223f774d33207dfb63431620b310cf5db2","constraints":{"executionContext":"node"},"contract":["npmRunPath.env returns an environment object containing augmented PATH","npmRunPath.env does not mutate the provided input environment object","npmRunPath.env preserves custom non-PATH environment variables","npmRunPath.env prepends node_modules/.bin based on custom cwd to PATH","npmRunPath.env appends directory of custom execPath to PATH","npmRunPath.env operates with default parameters without throwing"],"goal":"verify npm-run-path.env in pkg:npm/npm-run-path@4.0.1","kind":"HOW","packages":["pkg:npm/npm-run-path@4.0.1"],"schemaVersion":1,"symbols":["npm-run-path.env"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/npm-run-path@4.0.1"],"schemaVersion":1,"subject":"pkg:npm/npm-run-path@4.0.1","symbols":["npm-run-path.env"],"verifierAdapter":"node-typescript@1"}
index.js
const npmRunPath = require('npm-run-path');

function getAugmentedEnv(options) {
  return npmRunPath.env(options);
}

module.exports = {
  getAugmentedEnv,
  npmRunPath,
};
package-lock.json
{
  "name": "sample-npm-run-path-env",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-npm-run-path-env",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "npm-run-path": "4.0.1"
      }
    },
    "node_modules/npm-run-path": {
      "version": "4.0.1",
      "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
      "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==",
      "license": "MIT",
      "dependencies": {
        "path-key": "^3.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/path-key": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
      "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-npm-run-path-env",
  "version": "1.0.0",
  "description": "Verify npm-run-path.env behavior",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "npm-run-path": "4.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify npm-run-path.env in pkg:npm/npm-run-path@4.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/npm-run-path@4.0.1"
  ],
  "symbols": [
    "npm-run-path.env"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import path from 'node:path';
import npmRunPath from 'npm-run-path';
import { getAugmentedEnv } from '../index.js';

// 1. npmRunPath.env returns an environment object containing augmented PATH
const defaultEnv = npmRunPath.env();
assert.strictEqual(typeof defaultEnv, 'object', 'npmRunPath.env() must return an object');
assert(defaultEnv !== null, 'npmRunPath.env() must not return null');
assert('PATH' in defaultEnv || 'Path' in defaultEnv, 'augmented environment must have a PATH key');
const pathKey = 'PATH' in defaultEnv ? 'PATH' : 'Path';
assert(typeof defaultEnv[pathKey] === 'string', 'PATH key in environment must be a string');
assert(defaultEnv[pathKey].includes('node_modules' + path.sep + '.bin'), 'augmented PATH must include node_modules/.bin');

const helperEnv = getAugmentedEnv();
assert.strictEqual(typeof helperEnv, 'object', 'getAugmentedEnv helper must return an object');
assert(typeof helperEnv[pathKey] === 'string', 'helper PATH must be a string');

// 2. npmRunPath.env does not mutate the provided input environment object
const originalEnv = {
  PATH: 'base-test-path',
  CUSTOM_APP_VAR: 'csx_env_test_value'
};
const cwdFake = path.resolve('virtual-project', 'child');
const execFake = path.resolve('virtual-bin', 'node');
const resultEnv = npmRunPath.env({
  env: originalEnv,
  cwd: cwdFake,
  execPath: execFake
});
assert.strictEqual(originalEnv.PATH, 'base-test-path', 'originalEnv.PATH must not be modified');
assert.strictEqual(originalEnv.CUSTOM_APP_VAR, 'csx_env_test_value', 'originalEnv custom variables must not be modified');
assert.notStrictEqual(resultEnv, originalEnv, 'resultEnv must be a new object reference');

// 3. npmRunPath.env preserves custom non-PATH environment variables
assert.strictEqual(resultEnv.CUSTOM_APP_VAR, 'csx_env_test_value', 'custom environment variables must be preserved in result');

// 4. npmRunPath.env prepends node_modules/.bin based on custom cwd to PATH
const augmentedPath = resultEnv[pathKey];
const pathEntries = augmentedPath.split(path.delimiter);
assert(pathEntries.includes(path.join(cwdFake, 'node_modules/.bin')), 'must include child node_modules/.bin');
assert(pathEntries.includes(path.join(path.dirname(cwdFake), 'node_modules/.bin')), 'must include parent node_modules/.bin');
assert(pathEntries.includes('base-test-path'), 'must retain existing base PATH at the end');

// 5. npmRunPath.env appends directory of custom execPath to PATH
assert(pathEntries.includes(path.dirname(execFake)), 'must include dirname of custom execPath');

// 6. npmRunPath.env operates with default parameters without throwing
assert.doesNotThrow(() => {
  const env = npmRunPath.env({});
  assert.strictEqual(typeof env, 'object');
}, 'calling npmRunPath.env({}) must succeed');

console.log('All contract assertions passed.');

Seeder d'origine

anonyme