CodeSampleX

샘플

semver 6.3.1: maxSatisfying

검증된 샘플 — npm semver 6.3.1: maxSatisfying. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert semver.maxSatisfying returns the highest version…

sha256:8807006571f3989d88d5ca75d838b8b00f8fced177bd0e2c2795c8c8e86403b6

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-28

케이스

HOW
목표
verify semver.maxSatisfying in pkg:npm/semver@6.3.1
패키지
심벌
  • semver.maxSatisfying
환경
node 22.23.2
생성일
2026-08-28T02:31:54Z

컨트랙트

  1. assert semver.maxSatisfying returns the highest version in an array satisfying a caret range
  2. assert semver.maxSatisfying returns the highest version matching a bounded comparison range
  3. assert semver.maxSatisfying returns null when no version satisfies the specified range
  4. assert semver.maxSatisfying returns null for an empty array of versions
  5. assert semver.maxSatisfying respects the includePrerelease option to match prerelease versions
  6. assert semver.maxSatisfying respects the loose option for loose version string formats

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 semver.maxSatisfying in pkg:npm/semver@6.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/semver@6.3.1
Demonstrate these symbols/APIs:
  - semver.maxSatisfying
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:96c0f1a505fbad0f8b71e44a6ea7d669004518616050c09ddf89b98a28568844","constraints":{"executionContext":"node"},"contract":["assert semver.maxSatisfying returns the highest version in an array satisfying a caret range","assert semver.maxSatisfying returns the highest version matching a bounded comparison range","assert semver.maxSatisfying returns null when no version satisfies the specified range","assert semver.maxSatisfying returns null for an empty array of versions","assert semver.maxSatisfying respects the includePrerelease option to match prerelease versions","assert semver.maxSatisfying respects the loose option for loose version string formats"],"goal":"verify semver.maxSatisfying in pkg:npm/semver@6.3.1","kind":"HOW","packages":["pkg:npm/semver@6.3.1"],"schemaVersion":1,"symbols":["semver.maxSatisfying"]},"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/semver@6.3.1"],"schemaVersion":1,"subject":"pkg:npm/semver@6.3.1","symbols":["semver.maxSatisfying"],"verifierAdapter":"node-typescript@1"}
index.js
const semver = require('semver');

/**
 * Finds the maximum satisfying version from a list of versions against a range.
 *
 * @param {string[]} versions - Array of version strings.
 * @param {string} range - Semver range string.
 * @param {object} [options] - Options object (e.g., includePrerelease, loose).
 * @returns {string|null} The highest satisfying version string, or null if none match.
 */
function findMaxSatisfying(versions, range, options) {
  return semver.maxSatisfying(versions, range, options);
}

module.exports = {
  findMaxSatisfying,
  semver,
};
package-lock.json
{
  "name": "sample-semver-max-satisfying",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-semver-max-satisfying",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "semver": "6.3.1"
      }
    },
    "node_modules/semver": {
      "version": "6.3.1",
      "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
      "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      }
    }
  }
}
package.json
{
  "name": "sample-semver-max-satisfying",
  "version": "1.0.0",
  "description": "Clean-room sample verifying semver.maxSatisfying functionality",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "semver": "6.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify semver.maxSatisfying in pkg:npm/semver@6.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/semver@6.3.1"
  ],
  "symbols": [
    "semver.maxSatisfying"
  ],
  "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 semver from 'semver';
import { findMaxSatisfying } from '../index.js';

// 1. Returns the highest version in an array satisfying a caret range
const versions1 = ['1.2.0', '1.2.3', '1.3.0', '2.0.0', '1.2.9'];
const max1 = findMaxSatisfying(versions1, '^1.2.0');
assert.strictEqual(max1, '1.3.0', 'semver.maxSatisfying must return the highest version satisfying ^1.2.0');

const directMax1 = semver.maxSatisfying(versions1, '^1.2.0');
assert.strictEqual(directMax1, '1.3.0', 'semver.maxSatisfying direct call must return 1.3.0');

// 2. Returns the highest version matching a bounded comparison range
const versions2 = ['1.0.0', '1.4.9', '1.5.0', '1.8.2', '2.0.1'];
const max2 = findMaxSatisfying(versions2, '>=1.0.0 <1.5.0');
assert.strictEqual(max2, '1.4.9', 'semver.maxSatisfying must return highest within range >=1.0.0 <1.5.0');

// 3. Returns null when no version satisfies the specified range
const versions3 = ['1.0.0', '1.2.0', '1.3.0'];
const max3 = findMaxSatisfying(versions3, '^2.0.0');
assert.strictEqual(max3, null, 'semver.maxSatisfying must return null when no version matches');

// 4. Returns null for an empty array of versions
const max4 = findMaxSatisfying([], '^1.0.0');
assert.strictEqual(max4, null, 'semver.maxSatisfying must return null for an empty versions array');

// 5. Respects the includePrerelease option to match prerelease versions
const versions5 = ['1.2.0', '1.2.4-alpha.1', '1.2.4-beta.0'];
const maxNoPrerelease = findMaxSatisfying(versions5, '^1.2.3');
assert.strictEqual(maxNoPrerelease, null, 'semver.maxSatisfying without includePrerelease must return null for prereleases');

const maxWithPrerelease = findMaxSatisfying(versions5, '^1.2.3', { includePrerelease: true });
assert.strictEqual(maxWithPrerelease, '1.2.4-beta.0', 'semver.maxSatisfying with includePrerelease must return the highest matching prerelease');

// 6. Respects the loose option for loose version string formats
const looseVersions = ['v1.2.0', 'v1.3.0', '2.0.0'];
const maxLoose = findMaxSatisfying(looseVersions, '^1.0.0', { loose: true });
assert.strictEqual(maxLoose, 'v1.3.0', 'semver.maxSatisfying with loose option must parse loose version strings');

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

오리진 시더

익명