CodeSampleX

サンプル

semver 5.7.2: lte

検証済みサンプル — npm semver 5.7.2: lte. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: semver.lte returns true when the first version is strictly less…

sha256:b8fcb891aad4ac82495234da459086d3217248cae057e3b85dcacc64f537592f

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-27

ケース

HOW
ゴール
verify semver.lte in pkg:npm/semver@5.7.2
パッケージ
シンボル
  • semver.lte
作成日
2026-08-27T20:05:36Z

コントラクト

  1. semver.lte returns true when the first version is strictly less than or equal to the second version
  2. semver.lte returns false when the first version is strictly greater than the second version
  3. semver.lte compares prerelease versions lower than the corresponding normal release version
  4. semver.lte ignores build metadata when evaluating version precedence
  5. semver.lte handles formatted version strings with prefixes, whitespace, and loose options

ファイル

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

ソースアーティファクトをダウンロード (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.lte in pkg:npm/semver@5.7.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/semver@5.7.2
Demonstrate these symbols/APIs:
  - semver.lte

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:2eabd7ad5a8b692ee581687daa768b5d553354305a47b481128c91ce89034bf5","contract":["semver.lte returns true when the first version is strictly less than or equal to the second version","semver.lte returns false when the first version is strictly greater than the second version","semver.lte compares prerelease versions lower than the corresponding normal release version","semver.lte ignores build metadata when evaluating version precedence","semver.lte handles formatted version strings with prefixes, whitespace, and loose options"],"goal":"verify semver.lte in pkg:npm/semver@5.7.2","kind":"HOW","packages":["pkg:npm/semver@5.7.2"],"schemaVersion":1,"symbols":["semver.lte"]},"contractCommand":["node","test/contract.js"],"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/semver@5.7.2"],"schemaVersion":1,"subject":"pkg:npm/semver@5.7.2","symbols":["semver.lte"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-semver-lte",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-semver-lte",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "semver": "5.7.2"
      }
    },
    "node_modules/semver": {
      "version": "5.7.2",
      "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
      "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver"
      }
    }
  }
}
package.json
{
  "name": "sample-semver-lte",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for semver.lte",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "semver": "5.7.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify semver.lte in pkg:npm/semver@5.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/semver@5.7.2"
  ],
  "symbols": [
    "semver.lte"
  ]
}
src/index.js
const semver = require('semver');

/**
 * Checks whether version1 is less than or equal to version2.
 *
 * @param {string} v1 - First semantic version string.
 * @param {string} v2 - Second semantic version string.
 * @param {boolean|object} [options] - Options or loose boolean.
 * @returns {boolean} True if v1 <= v2, false otherwise.
 */
function isVersionAtMost(v1, v2, options) {
  return semver.lte(v1, v2, options);
}

/**
 * Filters a list of version strings to include only those less than or equal to a maximum version.
 *
 * @param {string[]} versions - Array of version strings.
 * @param {string} maxVersion - Upper bound version.
 * @param {boolean|object} [options] - Options or loose boolean.
 * @returns {string[]} Filtered array of version strings.
 */
function filterVersionsAtMost(versions, maxVersion, options) {
  return versions.filter((v) => semver.lte(v, maxVersion, options));
}

module.exports = {
  isVersionAtMost,
  filterVersionsAtMost
};
test/contract.js
const assert = require('node:assert');
const semver = require('semver');
const { isVersionAtMost, filterVersionsAtMost } = require('../src/index.js');

// 1. Basic comparisons: strictly less than and equal versions
assert.strictEqual(semver.lte('1.0.0', '2.0.0'), true, '1.0.0 is less than 2.0.0');
assert.strictEqual(semver.lte('1.2.3', '1.2.4'), true, '1.2.3 is less than 1.2.4');
assert.strictEqual(semver.lte('1.2.3', '1.2.3'), true, '1.2.3 is equal to 1.2.3');
assert.strictEqual(semver.lte('2.0.0', '1.9.9'), false, '2.0.0 is not less than or equal to 1.9.9');
assert.strictEqual(semver.lte('1.2.4', '1.2.3'), false, '1.2.4 is not less than or equal to 1.2.3');

// Helper function tests
assert.strictEqual(isVersionAtMost('1.0.0', '2.0.0'), true, 'isVersionAtMost returns true when v1 < v2');
assert.strictEqual(isVersionAtMost('1.0.0', '1.0.0'), true, 'isVersionAtMost returns true when v1 == v2');
assert.strictEqual(isVersionAtMost('2.0.0', '1.0.0'), false, 'isVersionAtMost returns false when v1 > v2');

// 2. Prerelease comparison: prereleases are lower than corresponding releases
assert.strictEqual(semver.lte('1.0.0-alpha', '1.0.0'), true, 'prerelease is lower than release');
assert.strictEqual(semver.lte('1.0.0', '1.0.0-alpha'), false, 'release is not lower than or equal to prerelease');
assert.strictEqual(semver.lte('1.0.0-alpha.1', '1.0.0-alpha.2'), true, 'alpha.1 is lower than alpha.2');
assert.strictEqual(semver.lte('1.0.0-alpha.2', '1.0.0-beta.1'), true, 'alpha is lower than beta');
assert.strictEqual(semver.lte('1.0.0-alpha', '1.0.0-alpha'), true, 'identical prereleases are equal');

// 3. Build metadata: build metadata is ignored for precedence
assert.strictEqual(semver.lte('1.0.0+build.1', '1.0.0+build.2'), true, 'build metadata ignored, treated as equal');
assert.strictEqual(semver.lte('1.0.0+build.2', '1.0.0+build.1'), true, 'build metadata ignored, treated as equal');

// 4. Formatting: v prefixes and whitespace handling
assert.strictEqual(semver.lte('v1.2.3', '1.2.3'), true, 'leading v prefix handled');
assert.strictEqual(semver.lte('  1.2.3  ', '  1.2.4  '), true, 'whitespace trimmed');
assert.strictEqual(semver.lte('=1.2.3', 'v1.2.4', { loose: true }), true, 'loose mode supports leading equal signs');

// 5. Array filtering helper
const versions = ['0.9.0', '1.0.0', '1.2.0', '2.0.0', '2.1.0'];
const filtered = filterVersionsAtMost(versions, '1.2.0');
assert.deepStrictEqual(filtered, ['0.9.0', '1.0.0', '1.2.0'], 'filters versions up to 1.2.0');

console.log('Contract tests passed successfully.');

オリジンシーダー

匿名