샘플
which 2.0.2: sync
검증된 샘플 — npm which 2.0.2: sync. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: which.sync resolves the path to an executable from a custom…
sha256:e900d51b6145e11f69e755489fbfb845057b7db355a3628b87929a5ff8021425
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-23 |
케이스
HOW- 목표
- verify which.sync in pkg:npm/which@2.0.2
- 패키지
- 심벌
-
- which.sync
- 생성일
- 2026-08-23T04:23:24Z
컨트랙트
- 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
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
소스
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 });
}
오리진 시더
익명