Beispiel
which 2.0.2: sync
Verifiziertes Beispiel für npm which 2.0.2: sync. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: which.sync resolves the path to an…
sha256:e900d51b6145e11f69e755489fbfb845057b7db355a3628b87929a5ff8021425
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-23 |
Fall
HOW- Ziel
- verify which.sync in pkg:npm/which@2.0.2
- Pakete
- Symbole
-
- which.sync
- Erstellt
- 2026-08-23T04:23:24Z
Contract
- which.sync resolves the path to an executable from a custom search path
- which.sync throws an ENOENT error when the executable is not found
- which.sync with nothrow option returns null when the executable is not found
- which.sync with all option returns an array of all matching executable paths
- which.sync respects custom path delimiter with colon option
- which.sync directly resolves executable paths containing directory slashes
- findExecutableSync and tryFindExecutableSync helper functions correctly wrap which.sync behavior
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Quelltext
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 which.sync in pkg:npm/which@2.0.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/which@2.0.2
Demonstrate these symbols/APIs:
- which.sync
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:ccd41ccf7d3f37b27bb0bc9046c7fbe00693a1920b0a56ba28e117fa0b4a38be","contract":["which.sync resolves the path to an executable from a custom search path","which.sync throws an ENOENT error when the executable is not found","which.sync with nothrow option returns null when the executable is not found","which.sync with all option returns an array of all matching executable paths","which.sync respects custom path delimiter with colon option","which.sync directly resolves executable paths containing directory slashes","findExecutableSync and tryFindExecutableSync helper functions correctly wrap which.sync behavior"],"goal":"verify which.sync in pkg:npm/which@2.0.2","kind":"HOW","packages":["pkg:npm/which@2.0.2"],"schemaVersion":1,"symbols":["which.sync"]},"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/which@2.0.2"],"schemaVersion":1,"subject":"pkg:npm/which@2.0.2","symbols":["which.sync"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-which-sync",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-which-sync",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"which": "2.0.2"
}
},
"node_modules/isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
"license": "ISC"
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"license": "ISC",
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"node-which": "bin/node-which"
},
"engines": {
"node": ">= 8"
}
}
}
}
{
"name": "sample-which-sync",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of which.sync in which@2.0.2",
"main": "src/index.mjs",
"type": "module",
"license": "MIT-0",
"dependencies": {
"which": "2.0.2"
}
}
{
"schemaVersion": 1,
"goal": "verify which.sync in pkg:npm/which@2.0.2",
"kind": "HOW",
"packages": [
"pkg:npm/which@2.0.2"
],
"symbols": [
"which.sync"
]
}
import which from "which";
/**
* Synchronously finds the first matching executable path in the search path or PATH.
*
* @param {string} cmd - Command name or executable file path.
* @param {object} [options={}] - Search options.
* @returns {string} Absolute or relative path to the resolved executable.
*/
export function findExecutableSync(cmd, options = {}) {
return which.sync(cmd, options);
}
/**
* Synchronously finds all matching executable paths in the search path or PATH.
*
* @param {string} cmd - Command name or executable file path.
* @param {object} [options={}] - Search options.
* @returns {string[]} Array of matching executable paths.
*/
export function findAllExecutablesSync(cmd, options = {}) {
return which.sync(cmd, { ...options, all: true });
}
/**
* Safely checks if an executable exists, returning its path or null if not found.
*
* @param {string} cmd - Command name or executable file path.
* @param {object} [options={}] - Search options.
* @returns {string|null} Resolved executable path or null if not found.
*/
export function tryFindExecutableSync(cmd, options = {}) {
return which.sync(cmd, { ...options, nothrow: true });
}
export { which };
export default which;
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import which, {
findExecutableSync,
findAllExecutablesSync,
tryFindExecutableSync,
} from "../src/index.mjs";
const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), "csx-which-contract-"));
const binA = path.join(tmpBase, "binA");
const binB = path.join(tmpBase, "binB");
try {
fs.mkdirSync(binA, { recursive: true });
fs.mkdirSync(binB, { recursive: true });
const exeA = path.join(binA, "tool-alpha");
const exeB = path.join(binB, "tool-alpha");
const exeOnlyB = path.join(binB, "tool-beta");
fs.writeFileSync(exeA, "#!/bin/sh\necho alpha-a\n", { mode: 0o755 });
fs.writeFileSync(exeB, "#!/bin/sh\necho alpha-b\n", { mode: 0o755 });
fs.writeFileSync(exeOnlyB, "#!/bin/sh\necho beta-b\n", { mode: 0o755 });
// 1. which.sync resolves the path to an executable from a custom search path
{
const resolved = which.sync("tool-alpha", { path: binA });
assert.strictEqual(resolved, exeA, "which.sync should find tool-alpha in binA");
const resolvedBeta = which.sync("tool-beta", { path: `${binA}:${binB}` });
assert.strictEqual(resolvedBeta, exeOnlyB, "which.sync should find tool-beta in binB");
}
// 2. which.sync throws an ENOENT error when the executable is not found
{
assert.throws(
() => which.sync("non-existent-binary-12345", { path: binA }),
(err) => {
assert.strictEqual(err.code, "ENOENT", "Error code must be ENOENT");
assert.ok(err.message.includes("not found: non-existent-binary-12345"), "Error message should mention binary name");
return true;
}
);
}
// 3. which.sync with nothrow option returns null when the executable is not found
{
const result = which.sync("non-existent-binary-12345", { path: binA, nothrow: true });
assert.strictEqual(result, null, "which.sync with nothrow should return null when binary is missing");
}
// 4. which.sync with all option returns an array of all matching executable paths
{
const allMatches = which.sync("tool-alpha", { path: `${binA}:${binB}`, all: true });
assert.ok(Array.isArray(allMatches), "Result must be an array");
assert.strictEqual(allMatches.length, 2, "Both executable locations should be found");
assert.strictEqual(allMatches[0], exeA);
assert.strictEqual(allMatches[1], exeB);
const allBeta = which.sync("tool-beta", { path: `${binA}:${binB}`, all: true });
assert.deepStrictEqual(allBeta, [exeOnlyB]);
}
// 5. which.sync respects custom path delimiter with colon option
{
const resolved = which.sync("tool-beta", {
path: `${binA}|${binB}`,
colon: "|",
});
assert.strictEqual(resolved, exeOnlyB, "which.sync should parse custom colon delimiter");
}
// 6. which.sync directly resolves executable paths containing directory slashes
{
const resolvedDirect = which.sync(exeA);
assert.strictEqual(resolvedDirect, exeA, "Direct path with slashes should resolve to executable");
assert.throws(
() => which.sync(path.join(binA, "nonexistent-file")),
(err) => {
assert.strictEqual(err.code, "ENOENT");
return true;
}
);
}
// 7. findExecutableSync and tryFindExecutableSync helper functions correctly wrap which.sync behavior
{
const found = findExecutableSync("tool-alpha", { path: binA });
assert.strictEqual(found, exeA);
const all = findAllExecutablesSync("tool-alpha", { path: `${binA}:${binB}` });
assert.deepStrictEqual(all, [exeA, exeB]);
const safeNull = tryFindExecutableSync("non-existent", { path: binA });
assert.strictEqual(safeNull, null);
}
console.log("All which.sync contract assertions passed successfully.");
} finally {
fs.rmSync(tmpBase, { recursive: true, force: true });
}
Ursprungs-Seeder
anonym