CodeSampleX

Beispiel

argparse 2.0.1

Verifiziertes Beispiel für npm argparse 2.0.1. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: ArgumentParser parses positional and…

sha256:08e1549f386de08d293b61b68457dad04c254fccf9c41d6e78ce94a04496dfad

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-23

Fall

HOW
Ziel
verify pkg:npm/argparse@2.0.1
Pakete
Erstellt
2026-08-23T13:46:18Z

Contract

  1. ArgumentParser parses positional and optional arguments with default values and type conversion
  2. ArgumentParser supports flag actions including store_true, store_false, append, and count
  3. ArgumentParser supports nargs to capture multiple values into an array
  4. ArgumentParser accepts custom type conversion functions
  5. ArgumentParser format_help and format_usage return formatted CLI documentation
  6. BooleanOptionalAction handles --flag and --no-flag switches setting boolean values
  7. add_subparsers defines subcommands with subcommand-specific arguments and options
  8. add_mutually_exclusive_group ensures mutually exclusive flags are configured and parsed

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/argparse@2.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/argparse@2.0.1

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:56672d57e812a3ba60ab2385fa82ac39649628a99812893266da210d01116083","contract":["ArgumentParser parses positional and optional arguments with default values and type conversion","ArgumentParser supports flag actions including store_true, store_false, append, and count","ArgumentParser supports nargs to capture multiple values into an array","ArgumentParser accepts custom type conversion functions","ArgumentParser format_help and format_usage return formatted CLI documentation","BooleanOptionalAction handles --flag and --no-flag switches setting boolean values","add_subparsers defines subcommands with subcommand-specific arguments and options","add_mutually_exclusive_group ensures mutually exclusive flags are configured and parsed"],"goal":"verify pkg:npm/argparse@2.0.1","kind":"HOW","packages":["pkg:npm/argparse@2.0.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/argparse@2.0.1"],"schemaVersion":1,"subject":"pkg:npm/argparse@2.0.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "argparse-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "argparse-verification",
      "version": "1.0.0",
      "dependencies": {
        "argparse": "2.0.1"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    }
  }
}
package.json
{
  "name": "argparse-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for argparse",
  "dependencies": {
    "argparse": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/argparse@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/argparse@2.0.1"
  ]
}
test/contract.cjs
const assert = require('node:assert');
const { ArgumentParser, BooleanOptionalAction } = require('argparse');

// 1. ArgumentParser parses positional and optional arguments with default values and type conversion
const parser1 = new ArgumentParser({ description: 'Basic CLI parser' });
parser1.add_argument('target');
parser1.add_argument('-p', '--port', { type: 'int', default: 8080 });
parser1.add_argument('-r', '--ratio', { type: 'float', default: 1.0 });

const parsed1 = parser1.parse_args(['server', '--port', '3000', '--ratio', '0.75']);
assert.strictEqual(parsed1.target, 'server');
assert.strictEqual(parsed1.port, 3000);
assert.strictEqual(parsed1.ratio, 0.75);

const defaultParsed1 = parser1.parse_args(['client']);
assert.strictEqual(defaultParsed1.target, 'client');
assert.strictEqual(defaultParsed1.port, 8080);
assert.strictEqual(defaultParsed1.ratio, 1.0);

// 2. ArgumentParser supports flag actions including store_true, store_false, append, and count
const parser2 = new ArgumentParser();
parser2.add_argument('-v', '--verbose', { action: 'store_true' });
parser2.add_argument('-q', '--quiet', { action: 'store_false' });
parser2.add_argument('-i', '--include', { action: 'append' });
parser2.add_argument('-l', { action: 'count', dest: 'level', default: 0 });

const parsed2 = parser2.parse_args(['-v', '-i', 'src', '-i', 'lib', '-lll']);
assert.strictEqual(parsed2.verbose, true);
assert.strictEqual(parsed2.quiet, true);
assert.deepStrictEqual(parsed2.include, ['src', 'lib']);
assert.strictEqual(parsed2.level, 3);

// 3. ArgumentParser supports nargs to capture multiple values into an array
const parser3 = new ArgumentParser();
parser3.add_argument('--coords', { nargs: 2, type: 'float' });
parser3.add_argument('--files', { nargs: '+' });

const parsed3 = parser3.parse_args(['--coords', '12.5', '45.0', '--files', 'a.txt', 'b.txt']);
assert.deepStrictEqual(parsed3.coords, [12.5, 45.0]);
assert.deepStrictEqual(parsed3.files, ['a.txt', 'b.txt']);

// 4. ArgumentParser accepts custom type conversion functions
const parser4 = new ArgumentParser();
parser4.add_argument('--hex', { type: (val) => parseInt(val, 16) });
parser4.add_argument('--upper', { type: (val) => val.toUpperCase() });

const parsed4 = parser4.parse_args(['--hex', 'ff', '--upper', 'hello']);
assert.strictEqual(parsed4.hex, 255);
assert.strictEqual(parsed4.upper, 'HELLO');

// 5. ArgumentParser format_help and format_usage return formatted CLI documentation
const parser5 = new ArgumentParser({ prog: 'mycli', description: 'Sample CLI tool' });
parser5.add_argument('--config', { help: 'Path to configuration file' });
parser5.add_argument('command', { help: 'Command to run' });

const usageText = parser5.format_usage();
assert.ok(usageText.includes('usage: mycli'));
const helpText = parser5.format_help();
assert.ok(helpText.includes('Sample CLI tool'));
assert.ok(helpText.includes('Path to configuration file'));
assert.ok(helpText.includes('Command to run'));

// 6. BooleanOptionalAction handles --flag and --no-flag switches setting boolean values
const parser6 = new ArgumentParser();
parser6.add_argument('--color', { action: BooleanOptionalAction, default: null });

assert.strictEqual(parser6.parse_args(['--color']).color, true);
assert.strictEqual(parser6.parse_args(['--no-color']).color, false);
assert.strictEqual(parser6.parse_args([]).color, null);

// 7. add_subparsers defines subcommands with subcommand-specific arguments and options
const parser7 = new ArgumentParser({ prog: 'cli' });
const subparsers = parser7.add_subparsers({ dest: 'subcommand', help: 'sub-command help' });

const buildSub = subparsers.add_parser('build', { help: 'build help' });
buildSub.add_argument('--release', { action: 'store_true' });

const testSub = subparsers.add_parser('test', { help: 'test help' });
testSub.add_argument('--filter', { default: '*' });

const parsed7Build = parser7.parse_args(['build', '--release']);
assert.strictEqual(parsed7Build.subcommand, 'build');
assert.strictEqual(parsed7Build.release, true);

const parsed7Test = parser7.parse_args(['test', '--filter', 'unit']);
assert.strictEqual(parsed7Test.subcommand, 'test');
assert.strictEqual(parsed7Test.filter, 'unit');

// 8. add_mutually_exclusive_group ensures mutually exclusive flags are configured and parsed
const parser8 = new ArgumentParser();
const exclusiveGroup = parser8.add_mutually_exclusive_group();
exclusiveGroup.add_argument('--json', { action: 'store_true' });
exclusiveGroup.add_argument('--yaml', { action: 'store_true' });

const parsed8Json = parser8.parse_args(['--json']);
assert.strictEqual(parsed8Json.json, true);
assert.strictEqual(parsed8Json.yaml, false);

const parsed8Yaml = parser8.parse_args(['--yaml']);
assert.strictEqual(parsed8Yaml.json, false);
assert.strictEqual(parsed8Yaml.yaml, true);

console.log('Contract passed');

Ursprungs-Seeder

anonym