CodeSampleX

Exemplo

bare-semver 1.1.0: parse, compare and validate semantic versions and ranges with bare-semver

Amostra verificada para npm bare-semver 1.1.0: parse, compare and validate semantic versions and ranges with bare-semver. O contrato rodou em node 22 · linux…

sha256:f322af6da5f050ad6721686d4294b7f839f06092aee9f3822217e530cf347a9c

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
parse, compare and validate semantic versions and ranges with bare-semver
Pacotes
Símbolos
  • bare-semver.Range
  • bare-semver.Version
  • bare-semver.satisfies
Criado
2026-08-27T13:10:04Z

Contrato

  1. Version.parse parses semantic version strings into major, minor, patch, prerelease, and build components
  2. Version.compare and Version.prototype.compare correctly order semantic versions according to precedence rules
  3. Version.prototype.toString serializes Version instances back to standard semantic version format
  4. Range.parse parses caret, tilde, comparator expressions, and union ranges into Range instances
  5. Range.prototype.test checks whether Version instances satisfy the range constraints
  6. satisfies tests whether semantic version strings or Version instances satisfy range expressions
  7. Version.parse throws SemVerError with INVALID_VERSION for malformed version strings

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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: parse, compare and validate semantic versions and ranges with bare-semver
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-semver@1.1.0
Demonstrate these symbols/APIs:
  - bare-semver.Range
  - bare-semver.Version
  - bare-semver.satisfies

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:3f34050a532bca7e41fa6edddbced99953d3571900ebf93abaa0c61e32ca6acd","contract":["Version.parse parses semantic version strings into major, minor, patch, prerelease, and build components","Version.compare and Version.prototype.compare correctly order semantic versions according to precedence rules","Version.prototype.toString serializes Version instances back to standard semantic version format","Range.parse parses caret, tilde, comparator expressions, and union ranges into Range instances","Range.prototype.test checks whether Version instances satisfy the range constraints","satisfies tests whether semantic version strings or Version instances satisfy range expressions","Version.parse throws SemVerError with INVALID_VERSION for malformed version strings"],"goal":"parse, compare and validate semantic versions and ranges with bare-semver","kind":"HOW","packages":["pkg:npm/bare-semver@1.1.0"],"schemaVersion":1,"symbols":["bare-semver.Range","bare-semver.Version","bare-semver.satisfies"]},"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/bare-semver@1.1.0"],"schemaVersion":1,"subject":"pkg:npm/bare-semver@1.1.0","symbols":["bare-semver.Range","bare-semver.Version","bare-semver.satisfies"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "bare-semver-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "bare-semver-sample",
      "version": "1.0.0",
      "dependencies": {
        "bare-semver": "1.1.0"
      }
    },
    "node_modules/bare-semver": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.1.0.tgz",
      "integrity": "sha512-1Hw5qJ7hXdVt3uPUqjeFTuxyvBUJauvz5A1I2jk8gzjZMHp04n//6nV9MDbG9CMw78JHY2lGV0w6s//LrASm2w==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "bare-semver-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for bare-semver",
  "dependencies": {
    "bare-semver": "1.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "parse, compare and validate semantic versions and ranges with bare-semver",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-semver@1.1.0"
  ],
  "symbols": [
    "bare-semver.Range",
    "bare-semver.Version",
    "bare-semver.satisfies"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import semver from 'bare-semver';

// 1. Version.parse parses semantic version strings into major, minor, patch, prerelease, and build components
const v1 = semver.Version.parse('1.2.3-alpha.1+build.42');
assert.strictEqual(v1.major, 1);
assert.strictEqual(v1.minor, 2);
assert.strictEqual(v1.patch, 3);
assert.deepStrictEqual(v1.prerelease, ['alpha', '1']);
assert.deepStrictEqual(v1.build, ['build', '42']);
assert.strictEqual(v1.toString(), '1.2.3-alpha.1+build.42');

// 2. Version.compare and Version.prototype.compare correctly order semantic versions according to precedence rules
const vA = semver.Version.parse('1.0.0-alpha');
const vB = semver.Version.parse('1.0.0');
const vC = semver.Version.parse('1.2.3');
const vD = semver.Version.parse('1.2.4');

assert.strictEqual(semver.Version.compare(vA, vB), -1);
assert.strictEqual(semver.Version.compare(vB, vA), 1);
assert.strictEqual(semver.Version.compare(vC, vD), -1);
assert.strictEqual(semver.Version.compare(vD, vC), 1);
assert.strictEqual(semver.Version.compare(vC, vC), 0);
assert.strictEqual(vC.compare(vD), -1);
assert.strictEqual(vD.compare(vC), 1);

// 3. Version.prototype.toString serializes Version instances back to standard semantic version format
const created = new semver.Version(2, 5, 1, { prerelease: ['beta', '2'], build: ['exp', 'sha'] });
assert.strictEqual(created.toString(), '2.5.1-beta.2+exp.sha');

// 4. Range.parse parses caret, tilde, comparator expressions, and union ranges into Range instances
const caretRange = semver.Range.parse('^1.2.3');
const tildeRange = semver.Range.parse('~1.2.3');
const unionRange = semver.Range.parse('>=1.0.0 <2.0.0 || >=3.0.0');
assert.ok(caretRange instanceof semver.Range);
assert.ok(tildeRange instanceof semver.Range);
assert.ok(unionRange instanceof semver.Range);

// 5. Range.prototype.test checks whether Version instances satisfy the range constraints
assert.strictEqual(caretRange.test(semver.Version.parse('1.2.3')), true);
assert.strictEqual(caretRange.test(semver.Version.parse('1.9.0')), true);
assert.strictEqual(caretRange.test(semver.Version.parse('2.0.0')), false);
assert.strictEqual(tildeRange.test(semver.Version.parse('1.2.9')), true);
assert.strictEqual(tildeRange.test(semver.Version.parse('1.3.0')), false);
assert.strictEqual(unionRange.test(semver.Version.parse('1.5.0')), true);
assert.strictEqual(unionRange.test(semver.Version.parse('2.5.0')), false);
assert.strictEqual(unionRange.test(semver.Version.parse('3.1.0')), true);

// 6. satisfies tests whether semantic version strings or Version instances satisfy range expressions
assert.strictEqual(semver.satisfies('1.2.3', '>=1.0.0 <2.0.0'), true);
assert.strictEqual(semver.satisfies('2.0.0', '>=1.0.0 <2.0.0'), false);
assert.strictEqual(semver.satisfies('1.2.3', '^1.2.0'), true);
assert.strictEqual(semver.satisfies('1.3.0', '~1.2.3'), false);
assert.strictEqual(semver.satisfies(vC, '^1.0.0'), true);

// 7. Version.parse throws SemVerError with INVALID_VERSION for malformed version strings
assert.throws(() => {
  semver.Version.parse('invalid.version.string');
}, (err) => {
  return err.name === 'SemVerError' && err.code === 'INVALID_VERSION';
});

console.log('Contract passed');

Seeder de origem

anônimo