CodeSampleX

Exemple

pretty-format 29.7.0

Échantillon vérifié pour npm pretty-format 29.7.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:364c0deaecfdeb229b687a5e22122897d01843ee195a0898c6add3e355cd073f

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 pkg:npm/pretty-format@29.7.0
Paquets
Créé
2026-08-27T21:22:20Z

Contrat

  1. format formats plain objects and arrays with sorted keys and indentation
  2. format supports compact single-line output with min option
  3. format truncates nested objects beyond maxDepth with [Object]
  4. format handles circular object references with [Circular]
  5. format supports custom plugin serializers for domain structures
  6. plugins provides standard built-in serializers including AsymmetricMatcher and ReactElement
  7. DEFAULT_OPTIONS provides default formatting settings and theme

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 pkg:npm/pretty-format@29.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pretty-format@29.7.0

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:82f03703247b796fb1d8f6645e4e8064116dfdc104031423132b3430c39f8e7f","contract":["format formats plain objects and arrays with sorted keys and indentation","format supports compact single-line output with min option","format truncates nested objects beyond maxDepth with [Object]","format handles circular object references with [Circular]","format supports custom plugin serializers for domain structures","plugins provides standard built-in serializers including AsymmetricMatcher and ReactElement","DEFAULT_OPTIONS provides default formatting settings and theme"],"goal":"verify pkg:npm/pretty-format@29.7.0","kind":"HOW","packages":["pkg:npm/pretty-format@29.7.0"],"schemaVersion":1},"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/pretty-format@29.7.0"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@29.7.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pretty-format",
      "version": "1.0.0",
      "dependencies": {
        "pretty-format": "29.7.0"
      }
    },
    "node_modules/@jest/schemas": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz",
      "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==",
      "license": "MIT",
      "dependencies": {
        "@sinclair/typebox": "^0.27.8"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/@sinclair/typebox": {
      "version": "0.27.12",
      "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz",
      "integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==",
      "license": "MIT"
    },
    "node_modules/ansi-styles": {
      "version": "5.2.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
      "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/pretty-format": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",
      "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==",
      "license": "MIT",
      "dependencies": {
        "@jest/schemas": "^29.6.3",
        "ansi-styles": "^5.0.0",
        "react-is": "^18.0.0"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/react-is": {
      "version": "18.3.1",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
      "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-pretty-format",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of pretty-format",
  "main": "src/index.js",
  "dependencies": {
    "pretty-format": "29.7.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/pretty-format@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@29.7.0"
  ]
}
src/index.js
'use strict';

const { format, plugins, DEFAULT_OPTIONS } = require('pretty-format');

/**
 * Formats a value using pretty-format with optional configuration.
 * @param {unknown} value - Value to format.
 * @param {object} [options] - Formatting options.
 * @returns {string}
 */
function formatValue(value, options) {
  return format(value, options);
}

/**
 * Formats a value into a compact single-line string representation.
 * @param {unknown} value - Value to format.
 * @returns {string}
 */
function formatCompact(value) {
  return format(value, { min: true });
}

/**
 * Creates a custom serializer plugin.
 * @param {(val: unknown) => boolean} testFn - Predicate function.
 * @param {(val: unknown, config: object, indentation: string, depth: number, refs: Array<unknown>, printer: Function) => string} serializeFn - Serializer function.
 * @returns {{ test: Function, serialize: Function }}
 */
function createPlugin(testFn, serializeFn) {
  if (typeof testFn !== 'function' || typeof serializeFn !== 'function') {
    throw new TypeError('testFn and serializeFn must be functions');
  }
  return {
    test: testFn,
    serialize: serializeFn
  };
}

module.exports = {
  format,
  formatValue,
  formatCompact,
  createPlugin,
  plugins,
  DEFAULT_OPTIONS
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  format,
  formatValue,
  formatCompact,
  createPlugin,
  plugins,
  DEFAULT_OPTIONS
} = require('../src/index.js');

// 1. format formats plain objects and arrays with sorted keys and indentation
const sampleObj = { z: 10, a: 'hello', arr: [1, 2] };
const formattedObj = formatValue(sampleObj);
assert.strictEqual(
  formattedObj,
  'Object {\n  "a": "hello",\n  "arr": Array [\n    1,\n    2,\n  ],\n  "z": 10,\n}',
  'format must sort object keys alphabetically and indent nested arrays'
);

// 2. format supports compact single-line output with min option
const minFormatted = formatCompact({ a: 1, b: 2 });
assert.strictEqual(
  minFormatted,
  '{"a": 1, "b": 2}',
  'format with min: true must return compact single-line string without newlines'
);

// 3. format truncates nested objects beyond maxDepth with [Object]
const deepObj = { level1: { level2: { level3: 'deep' } } };
const depthFormatted = formatValue(deepObj, { maxDepth: 1 });
assert.strictEqual(
  depthFormatted,
  'Object {\n  "level1": [Object],\n}',
  'format must truncate structures exceeding maxDepth'
);

// 4. format handles circular object references with [Circular]
const circularObj = { name: 'root' };
circularObj.self = circularObj;
const circularFormatted = formatValue(circularObj, { min: true });
assert.strictEqual(
  circularFormatted,
  '{"name": "root", "self": [Circular]}',
  'format must detect and handle circular references'
);

// 5. format supports custom plugin serializers for domain structures
const customPlugin = createPlugin(
  (val) => val != null && typeof val === 'object' && val.__type === 'Money',
  (val) => `${val.currency} ${val.amount.toFixed(2)}`
);
const pluginResult = formatValue(
  { price: { __type: 'Money', currency: 'USD', amount: 49.9 } },
  { plugins: [customPlugin], min: true }
);
assert.strictEqual(
  pluginResult,
  '{"price": USD 49.90}',
  'format must apply custom plugin serializers'
);

// 6. plugins provides standard built-in serializers including AsymmetricMatcher and ReactElement
assert.strictEqual(typeof plugins, 'object', 'plugins must be an object');
assert.strictEqual(typeof plugins.AsymmetricMatcher, 'object', 'plugins.AsymmetricMatcher must be defined');
assert.strictEqual(typeof plugins.DOMCollection, 'object', 'plugins.DOMCollection must be defined');
assert.strictEqual(typeof plugins.DOMElement, 'object', 'plugins.DOMElement must be defined');
assert.strictEqual(typeof plugins.Immutable, 'object', 'plugins.Immutable must be defined');
assert.strictEqual(typeof plugins.ReactElement, 'object', 'plugins.ReactElement must be defined');
assert.strictEqual(typeof plugins.ReactTestComponent, 'object', 'plugins.ReactTestComponent must be defined');
assert.strictEqual(typeof plugins.ReactElement.test, 'function', 'ReactElement plugin must have test function');
assert.strictEqual(typeof plugins.ReactElement.serialize, 'function', 'ReactElement plugin must have serialize function');

// 7. DEFAULT_OPTIONS provides default formatting settings and theme
assert.strictEqual(typeof DEFAULT_OPTIONS, 'object', 'DEFAULT_OPTIONS must be an object');
assert.strictEqual(DEFAULT_OPTIONS.indent, 2, 'DEFAULT_OPTIONS.indent must default to 2');
assert.strictEqual(DEFAULT_OPTIONS.min, false, 'DEFAULT_OPTIONS.min must default to false');
assert.strictEqual(DEFAULT_OPTIONS.callToJSON, true, 'DEFAULT_OPTIONS.callToJSON must default to true');
assert.strictEqual(typeof DEFAULT_OPTIONS.theme, 'object', 'DEFAULT_OPTIONS.theme must be an object');

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

Seeder d'origine

anonyme