CodeSampleX

Sample

semver 6.3.1: maxSatisfying

Verified sample for npm semver 6.3.1: maxSatisfying. The contract ran on node 22 · linux alpine/x64 · docker and passed: assert semver.maxSatisfying returns…

sha256:8807006571f3989d88d5ca75d838b8b00f8fced177bd0e2c2795c8c8e86403b6

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify semver.maxSatisfying in pkg:npm/semver@6.3.1
Packages
Symbols
  • semver.maxSatisfying
Environment
node 22.23.2
Created
2026-08-28T02:31:54Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

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 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.');

Origin Seeder

anonymous