CodeSampleX

Exemple

kleur 4.1.5: bgGreen

Échantillon vérifié pour npm kleur 4.1.5: bgGreen. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:7c5c59ae59a9c70df35bc33c7a558740597dbdc90eab63a0c07d08617a0936e4

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify kleur.bgGreen in pkg:npm/kleur@4.1.5
Paquets
Symboles
  • kleur.bgGreen
Créé
2026-08-27T12:03:21Z

Contrat

  1. kleur.bgGreen wraps a string in ANSI background green escape codes \u001b[42m and \u001b[49m
  2. kleur.bgGreen returns a chainable formatter when called with no arguments
  3. kleur.bgGreen coerces numeric and non-string inputs into styled strings
  4. kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes
  5. setting kleur.enabled to false disables styling and returns the input as plain text

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 kleur.bgGreen in pkg:npm/kleur@4.1.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/kleur@4.1.5
Demonstrate these symbols/APIs:
  - kleur.bgGreen

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:c9978dd71308004585136282f83a9590ab1f45c81b1658457f2818d51683528b","contract":["kleur.bgGreen wraps a string in ANSI background green escape codes \\u001b[42m and \\u001b[49m","kleur.bgGreen returns a chainable formatter when called with no arguments","kleur.bgGreen coerces numeric and non-string inputs into styled strings","kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes","setting kleur.enabled to false disables styling and returns the input as plain text"],"goal":"verify kleur.bgGreen in pkg:npm/kleur@4.1.5","kind":"HOW","packages":["pkg:npm/kleur@4.1.5"],"schemaVersion":1,"symbols":["kleur.bgGreen"]},"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/kleur@4.1.5"],"schemaVersion":1,"subject":"pkg:npm/kleur@4.1.5","symbols":["kleur.bgGreen"],"verifierAdapter":"node-typescript@1"}
index.js
import kleur from 'kleur';

/**
 * Formats text with green background ANSI styling.
 * @param {string|number|boolean} text
 * @returns {string}
 */
export function formatSuccessBadge(text) {
  return kleur.bgGreen().white().bold(` ${text} `);
}

/**
 * Applies green background directly using kleur.bgGreen.
 * @param {string|number|boolean} text
 * @returns {string}
 */
export function applyBgGreen(text) {
  return kleur.bgGreen(text);
}

export { kleur };
package-lock.json
{
  "name": "verify-kleur-bggreen",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-kleur-bggreen",
      "version": "1.0.0",
      "dependencies": {
        "kleur": "4.1.5"
      }
    },
    "node_modules/kleur": {
      "version": "4.1.5",
      "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz",
      "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    }
  }
}
package.json
{
  "name": "verify-kleur-bggreen",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for kleur.bgGreen in kleur@4.1.5",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "kleur": "4.1.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify kleur.bgGreen in pkg:npm/kleur@4.1.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/kleur@4.1.5"
  ],
  "symbols": [
    "kleur.bgGreen"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { kleur, applyBgGreen, formatSuccessBadge } from '../index.js';

// Ensure predictable styling behavior in non-interactive / CI environments
kleur.enabled = true;

// Contract 1: kleur.bgGreen wraps a string in ANSI background green escape codes (\u001b[42m and \u001b[49m).
const basic = kleur.bgGreen('SUCCESS');
assert.equal(basic, '\u001b[42mSUCCESS\u001b[49m');
assert.equal(applyBgGreen('PASS'), '\u001b[42mPASS\u001b[49m');

// Contract 2: kleur.bgGreen returns a chainable formatter when called with no arguments.
const chained = kleur.bgGreen().bold('HIGHLIGHT');
assert.equal(chained, '\u001b[42m\u001b[1mHIGHLIGHT\u001b[49m\u001b[22m');

const badge = formatSuccessBadge('OK');
assert.equal(badge, '\u001b[42m\u001b[37m\u001b[1m OK \u001b[49m\u001b[39m\u001b[22m');

// Contract 3: kleur.bgGreen coerces numeric and non-string inputs into styled strings.
const num = kleur.bgGreen(200);
assert.equal(num, '\u001b[42m200\u001b[49m');

// Contract 4: kleur.bgGreen handles empty strings by wrapping them in open and close ANSI codes.
const empty = kleur.bgGreen('');
assert.equal(empty, '\u001b[42m\u001b[49m');

// Contract 5: setting kleur.enabled to false disables styling and returns the input as plain text.
kleur.enabled = false;
assert.equal(kleur.bgGreen('NO_COLOR'), 'NO_COLOR');
assert.equal(applyBgGreen('PLAIN'), 'PLAIN');
assert.equal(formatSuccessBadge('DISABLED'), ' DISABLED ');

// Restore enabled state
kleur.enabled = true;

console.log('All kleur.bgGreen contract tests passed.');

Seeder d'origine

anonyme