Exemple
pretty-format 27.5.1: DEFAULT_OPTIONS
Échantillon vérifié pour npm pretty-format 27.5.1: DEFAULT_OPTIONS. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:0d4ad5f3c1daf824145fdde5a9f602e194be06ea295f15f37bb414695eb1c7d8
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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-05 |
Cas
HOW- Objectif
- verify pretty-format.DEFAULT_OPTIONS in pkg:npm/pretty-format@27.5.1
- Paquets
- Symboles
-
- pretty-format.DEFAULT_OPTIONS
- Créé
- 2026-09-05T23:47:37Z
Contrat
- DEFAULT_OPTIONS exposes baseline formatting configuration with standard defaults
- getDefaultOptions returns a clone matching DEFAULT_OPTIONS
- isValidOptionKey validates option keys against DEFAULT_OPTIONS properties
- formatValue formats objects using default two-space indentation and properties
- formatValue supports custom option overrides including min and indent
- formatValue throws an error when unknown option keys not in DEFAULT_OPTIONS are provided
- formatValue respects the default callToJSON option
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Code source
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 pretty-format.DEFAULT_OPTIONS in pkg:npm/pretty-format@27.5.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/pretty-format@27.5.1
Demonstrate these symbols/APIs:
- pretty-format.DEFAULT_OPTIONS
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.
{"case":{"caseId":"case:sha256:9aff184435abedf605e55d8cf01a304e40a204358394084596a174596bc728f3","contract":["DEFAULT_OPTIONS exposes baseline formatting configuration with standard defaults","getDefaultOptions returns a clone matching DEFAULT_OPTIONS","isValidOptionKey validates option keys against DEFAULT_OPTIONS properties","formatValue formats objects using default two-space indentation and properties","formatValue supports custom option overrides including min and indent","formatValue throws an error when unknown option keys not in DEFAULT_OPTIONS are provided","formatValue respects the default callToJSON option"],"goal":"verify pretty-format.DEFAULT_OPTIONS in pkg:npm/pretty-format@27.5.1","kind":"HOW","packages":["pkg:npm/pretty-format@27.5.1"],"schemaVersion":1,"symbols":["pretty-format.DEFAULT_OPTIONS"]},"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@27.5.1"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@27.5.1","symbols":["pretty-format.DEFAULT_OPTIONS"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-pretty-format-default-options",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-pretty-format-default-options",
"version": "1.0.0",
"dependencies": {
"pretty-format": "27.5.1"
}
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"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": "27.5.1",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz",
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1",
"ansi-styles": "^5.0.0",
"react-is": "^17.0.1"
},
"engines": {
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
}
},
"node_modules/react-is": {
"version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"license": "MIT"
}
}
}
{
"name": "sample-pretty-format-default-options",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of pretty-format.DEFAULT_OPTIONS",
"main": "src/index.js",
"dependencies": {
"pretty-format": "27.5.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pretty-format.DEFAULT_OPTIONS in pkg:npm/pretty-format@27.5.1",
"kind": "HOW",
"packages": [
"pkg:npm/pretty-format@27.5.1"
],
"symbols": [
"pretty-format.DEFAULT_OPTIONS"
]
}
const { DEFAULT_OPTIONS, format } = require('pretty-format');
/**
* Returns a shallow copy of the default formatting options.
* @returns {typeof DEFAULT_OPTIONS}
*/
function getDefaultOptions() {
return { ...DEFAULT_OPTIONS };
}
/**
* Formats a given value using pretty-format with custom options merged over defaults.
* @param {unknown} value - Value to format.
* @param {object} [options] - Optional custom options.
* @returns {string}
*/
function formatValue(value, options) {
return format(value, options);
}
/**
* Checks whether a given configuration key is a recognized option in DEFAULT_OPTIONS.
* @param {string} key - Option key name to validate.
* @returns {boolean}
*/
function isValidOptionKey(key) {
return Object.prototype.hasOwnProperty.call(DEFAULT_OPTIONS, key);
}
module.exports = {
DEFAULT_OPTIONS,
getDefaultOptions,
formatValue,
isValidOptionKey
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
DEFAULT_OPTIONS,
getDefaultOptions,
formatValue,
isValidOptionKey
} = require('../src/index.js');
// 1. DEFAULT_OPTIONS export structure
assert.strictEqual(typeof DEFAULT_OPTIONS, 'object', 'DEFAULT_OPTIONS must be an object');
assert.strictEqual(DEFAULT_OPTIONS.indent, 2, 'DEFAULT_OPTIONS.indent must be 2');
assert.strictEqual(DEFAULT_OPTIONS.callToJSON, true, 'DEFAULT_OPTIONS.callToJSON must be true');
assert.strictEqual(DEFAULT_OPTIONS.escapeString, true, 'DEFAULT_OPTIONS.escapeString must be true');
assert.strictEqual(DEFAULT_OPTIONS.escapeRegex, false, 'DEFAULT_OPTIONS.escapeRegex must be false');
assert.strictEqual(DEFAULT_OPTIONS.highlight, false, 'DEFAULT_OPTIONS.highlight must be false');
assert.strictEqual(DEFAULT_OPTIONS.min, false, 'DEFAULT_OPTIONS.min must be false');
assert.strictEqual(DEFAULT_OPTIONS.maxDepth, Infinity, 'DEFAULT_OPTIONS.maxDepth must be Infinity');
assert.strictEqual(DEFAULT_OPTIONS.compareKeys, undefined, 'DEFAULT_OPTIONS.compareKeys must be undefined');
assert.strictEqual(DEFAULT_OPTIONS.printBasicPrototype, true, 'DEFAULT_OPTIONS.printBasicPrototype must be true');
assert.strictEqual(DEFAULT_OPTIONS.printFunctionName, true, 'DEFAULT_OPTIONS.printFunctionName must be true');
assert.deepStrictEqual(DEFAULT_OPTIONS.plugins, [], 'DEFAULT_OPTIONS.plugins must be an empty array');
assert.deepStrictEqual(DEFAULT_OPTIONS.theme, {
comment: 'gray',
content: 'reset',
prop: 'yellow',
tag: 'cyan',
value: 'green'
}, 'DEFAULT_OPTIONS.theme must have standard default theme keys');
// 2. getDefaultOptions helper returns a valid clone
const clonedDefaults = getDefaultOptions();
assert.deepStrictEqual(clonedDefaults, DEFAULT_OPTIONS);
assert.notStrictEqual(clonedDefaults, DEFAULT_OPTIONS);
// 3. isValidOptionKey uses DEFAULT_OPTIONS to recognize valid options
assert.strictEqual(isValidOptionKey('indent'), true);
assert.strictEqual(isValidOptionKey('callToJSON'), true);
assert.strictEqual(isValidOptionKey('compareKeys'), true);
assert.strictEqual(isValidOptionKey('plugins'), true);
assert.strictEqual(isValidOptionKey('nonExistentOption'), false);
// 4. Default formatting behavior
const testObj = {
active: true,
count: 10,
label: 'sample'
};
const defaultOutput = formatValue(testObj);
assert.strictEqual(
defaultOutput,
'Object {\n "active": true,\n "count": 10,\n "label": "sample",\n}'
);
// 5. Custom option override respects formatting options
const minifiedOutput = formatValue(testObj, { min: true });
assert.strictEqual(minifiedOutput, '{"active": true, "count": 10, "label": "sample"}');
const indent4Output = formatValue({ key: 'val' }, { indent: 4 });
assert.strictEqual(indent4Output, 'Object {\n "key": "val",\n}');
// 6. Unknown options rejection based on DEFAULT_OPTIONS schema
assert.throws(
() => formatValue(testObj, { invalidKey: true }),
/pretty-format: Unknown option "invalidKey"\./
);
// 7. callToJSON behavior
const objWithToJSON = {
secret: 'hide',
toJSON() {
return { visible: true };
}
};
assert.strictEqual(
formatValue(objWithToJSON),
'Object {\n "visible": true,\n}'
);
assert.strictEqual(
formatValue(objWithToJSON, { callToJSON: false }),
'Object {\n "secret": "hide",\n "toJSON": [Function toJSON],\n}'
);
console.log('Contract tests passed successfully.');
Seeder d'origine
anonyme