CodeSampleX

Ejemplo

optionator 0.9.4

Muestra verificada para npm optionator 0.9.4. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: optionator parses command-line arguments…

sha256:12490a59f8cca7e6a4c9ae78e65d71a2ca868671a6aa7e5ec8612e158513edef

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Caso

HOW
Objetivo
verify pkg:npm/optionator@0.9.4
Paquetes
Entorno
node 22.23.2
Creado
2026-08-20T22:48:50Z

Contrato

  1. optionator parses command-line arguments and applies default values
  2. optionator generates formatted help text containing option definitions
  3. optionator parseArgv handles process.argv style array

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 pkg:npm/optionator@0.9.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/optionator@0.9.4
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:5c9b096718e85d330faafa46f9552d84b2469bd4f1247adfcf7e844e662971d3","constraints":{"executionContext":"node"},"contract":["optionator parses command-line arguments and applies default values","optionator generates formatted help text containing option definitions","optionator parseArgv handles process.argv style array"],"goal":"verify pkg:npm/optionator@0.9.4","kind":"HOW","packages":["pkg:npm/optionator@0.9.4"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/optionator@0.9.4"],"schemaVersion":1,"subject":"pkg:npm/optionator@0.9.4","verifierAdapter":"node-typescript@1"}
index.js
const optionator = require('optionator');

function createParser(customOptions = {}) {
  return optionator({
    prepend: 'Usage: cli [options]',
    append: 'Version: 1.0.0',
    options: [
      {
        option: 'help',
        alias: 'h',
        type: 'Boolean',
        description: 'displays help'
      },
      {
        option: 'port',
        alias: 'p',
        type: 'Int',
        description: 'port number to listen on',
        default: '8080'
      },
      {
        option: 'verbose',
        alias: 'v',
        type: 'Boolean',
        description: 'enable verbose logging'
      },
      ...(customOptions.options || [])
    ]
  });
}

function parseCommandLine(args, customOptions) {
  const parser = createParser(customOptions);
  return parser.parse(args);
}

function getHelpText(customOptions) {
  const parser = createParser(customOptions);
  return parser.generateHelp();
}

module.exports = {
  createParser,
  parseCommandLine,
  getHelpText
};
package-lock.json
{
  "name": "verify-optionator",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-optionator",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "optionator": "0.9.4"
      }
    },
    "node_modules/deep-is": {
      "version": "0.1.4",
      "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
      "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==",
      "license": "MIT"
    },
    "node_modules/fast-levenshtein": {
      "version": "2.0.6",
      "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
      "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==",
      "license": "MIT"
    },
    "node_modules/levn": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
      "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==",
      "license": "MIT",
      "dependencies": {
        "prelude-ls": "^1.2.1",
        "type-check": "~0.4.0"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/optionator": {
      "version": "0.9.4",
      "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz",
      "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==",
      "license": "MIT",
      "dependencies": {
        "deep-is": "^0.1.3",
        "fast-levenshtein": "^2.0.6",
        "levn": "^0.4.1",
        "prelude-ls": "^1.2.1",
        "type-check": "^0.4.0",
        "word-wrap": "^1.2.5"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/prelude-ls": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
      "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/type-check": {
      "version": "0.4.0",
      "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
      "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==",
      "license": "MIT",
      "dependencies": {
        "prelude-ls": "^1.2.1"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/word-wrap": {
      "version": "1.2.5",
      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",
      "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "verify-optionator",
  "version": "1.0.0",
  "description": "Verification sample for optionator",
  "main": "index.js",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "optionator": "0.9.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/optionator@0.9.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/optionator@0.9.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert');
const { createParser, parseCommandLine, getHelpText } = require('../index.js');

// Contract 1: optionator parses command-line arguments and applies default values
const defaultParsed = parseCommandLine('');
assert.strictEqual(defaultParsed.port, 8080, 'Default port should be 8080');
assert.strictEqual(defaultParsed.verbose, undefined, 'Verbose should be undefined when not set');

const parsed = parseCommandLine('--port 3000 -v');
assert.strictEqual(parsed.port, 3000, 'Port option should be parsed as integer 3000');
assert.strictEqual(parsed.verbose, true, 'Verbose alias -v should parse as true');

// Contract 2: optionator generates formatted help text containing option definitions
const helpText = getHelpText();
assert.ok(typeof helpText === 'string', 'Help text should be a string');
assert.ok(helpText.includes('Usage: cli [options]'), 'Help text should include prepend usage');
assert.ok(helpText.includes('-h, --help'), 'Help text should list help flag');
assert.ok(helpText.includes('-p, --port Int'), 'Help text should list port option with type Int');
assert.ok(helpText.includes('-v, --verbose'), 'Help text should list verbose option');
assert.ok(helpText.includes('Version: 1.0.0'), 'Help text should include append version');

// Contract 3: optionator parseArgv handles process.argv style array
const parser = createParser();
const argvParsed = parser.parseArgv(['node', 'script.js', '--port', '9000']);
assert.strictEqual(argvParsed.port, 9000, 'parseArgv should extract port 9000');

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

Seeder de origen

anónimo