CodeSampleX

Ejemplo

@vitest/utils 2.1.9

Muestra verificada para npm @vitest/utils 2.1.9. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: getType distinguishes JavaScript types…

sha256:130d5deb423affaa2e91c42cb790191de80aa8a93ca5f2b472700930ec0af1ec

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 10

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@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

Caso

HOW
Objetivo
verify pkg:npm/%40vitest/utils@2.1.9
Paquetes
Entorno
node 22.23.2
Creado
2026-08-26T14:50:16Z

Contrato

  1. getType distinguishes JavaScript types including primitives, collections, and built-ins
  2. deepClone creates an independent deep copy of nested objects and arrays
  3. deepMerge deeply merges source object properties into target object
  4. createDefer creates a Promise with attached resolve and reject methods
  5. slash normalizes Windows backslash paths to Unix forward slashes
  6. toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays
  7. isObject identifies object structures while returning false for arrays, functions, and primitives
  8. isPrimitive identifies JavaScript primitive values and rejects object structures
  9. parseRegexp parses stringified regular expressions into RegExp instances
  10. nanoid generates random identifier strings with default and custom lengths

Archivos

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

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/%40vitest/utils@2.1.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/utils@2.1.9
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:777f35b5e6c6c4bf38c68b44c3642047ea3f43bb831603c3f3b34da135048ea8","constraints":{"executionContext":"node"},"contract":["getType distinguishes JavaScript types including primitives, collections, and built-ins","deepClone creates an independent deep copy of nested objects and arrays","deepMerge deeply merges source object properties into target object","createDefer creates a Promise with attached resolve and reject methods","slash normalizes Windows backslash paths to Unix forward slashes","toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays","isObject identifies object structures while returning false for arrays, functions, and primitives","isPrimitive identifies JavaScript primitive values and rejects object structures","parseRegexp parses stringified regular expressions into RegExp instances","nanoid generates random identifier strings with default and custom lengths"],"goal":"verify pkg:npm/%40vitest/utils@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/utils@2.1.9"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40vitest/utils@2.1.9"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/utils@2.1.9","verifierAdapter":"node-typescript@1"}
index.mjs
import {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  parseRegexp,
  nanoid,
  stringify
} from '@vitest/utils';

export {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  parseRegexp,
  nanoid,
  stringify
};

export function cloneAndMerge(target, source) {
  const clonedTarget = deepClone(target);
  return deepMerge(clonedTarget, source);
}

export function createResolvedDefer(value) {
  const deferred = createDefer();
  deferred.resolve(value);
  return deferred;
}
package-lock.json
{
  "name": "sample-vitest-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-utils",
      "version": "1.0.0",
      "dependencies": {
        "@vitest/utils": "2.1.9"
      }
    },
    "node_modules/@vitest/pretty-format": {
      "version": "2.1.9",
      "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.9.tgz",
      "integrity": "sha512-KhRIdGV2U9HOUzxfiHmY8IFHTdqtOhIzCpd8WRdJiE7D/HUcZVD0EgQCVjm+Q9gkUXWgBvMmTtZgIG48wq7sOQ==",
      "license": "MIT",
      "dependencies": {
        "tinyrainbow": "^1.2.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/@vitest/utils": {
      "version": "2.1.9",
      "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz",
      "integrity": "sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==",
      "license": "MIT",
      "dependencies": {
        "@vitest/pretty-format": "2.1.9",
        "loupe": "^3.1.2",
        "tinyrainbow": "^1.2.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/loupe": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",
      "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",
      "license": "MIT"
    },
    "node_modules/tinyrainbow": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz",
      "integrity": "sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-utils",
  "version": "1.0.0",
  "description": "Clean-room verification sample for @vitest/utils",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@vitest/utils": "2.1.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40vitest/utils@2.1.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/utils@2.1.9"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  parseRegexp,
  nanoid,
  stringify
} from '@vitest/utils';
import { cloneAndMerge, createResolvedDefer } from '../index.mjs';

// 1. getType distinguishes JavaScript types including primitives, collections, and built-ins
{
  assert.equal(getType(null), 'Null');
  assert.equal(getType(undefined), 'Undefined');
  assert.equal(getType(123), 'Number');
  assert.equal(getType('test'), 'String');
  assert.equal(getType(true), 'Boolean');
  assert.equal(getType(Symbol('sym')), 'Symbol');
  assert.equal(getType(10n), 'BigInt');
  assert.equal(getType([]), 'Array');
  assert.equal(getType({}), 'Object');
  assert.equal(getType(/abc/), 'RegExp');
  assert.equal(getType(new Set()), 'Set');
  assert.equal(getType(new Map()), 'Map');
  assert.equal(getType(Promise.resolve()), 'Promise');
  assert.equal(getType(new Date()), 'Date');
}

// 2. deepClone creates an independent deep copy of nested objects and arrays
{
  const original = {
    num: 1,
    nested: { str: 'alpha' },
    arr: [1, { val: 2 }],
  };
  const copy = deepClone(original);
  assert.deepEqual(copy, original);
  assert.notEqual(copy, original);
  assert.notEqual(copy.nested, original.nested);
  assert.notEqual(copy.arr, original.arr);
  assert.notEqual(copy.arr[1], original.arr[1]);
}

// 3. deepMerge deeply merges source object properties into target object
{
  const target = { a: 1, nested: { b: 2, c: 3 } };
  const source = { nested: { c: 4, d: 5 }, e: 6 };
  const merged = deepMerge(target, source);
  assert.equal(merged, target);
  assert.deepEqual(target, {
    a: 1,
    nested: { b: 2, c: 4, d: 5 },
    e: 6,
  });
  assert.deepEqual(source, { nested: { c: 4, d: 5 }, e: 6 });

  // Test helper function cloneAndMerge
  const originalObj = { x: 10, inner: { y: 20 } };
  const patch = { inner: { z: 30 } };
  const mergedCopy = cloneAndMerge(originalObj, patch);
  assert.deepEqual(mergedCopy, { x: 10, inner: { y: 20, z: 30 } });
  assert.equal(originalObj.inner.z, undefined);
}

// 4. createDefer creates a Promise with attached resolve and reject methods
{
  const deferred = createDefer();
  assert.ok(deferred instanceof Promise);
  assert.equal(typeof deferred.resolve, 'function');
  assert.equal(typeof deferred.reject, 'function');

  deferred.resolve('completed');
  const result = await deferred;
  assert.equal(result, 'completed');

  // Test helper function createResolvedDefer
  const helperDefer = createResolvedDefer('fast-resolved');
  const helperResult = await helperDefer;
  assert.equal(helperResult, 'fast-resolved');
}

// 5. slash normalizes Windows backslash paths to Unix forward slashes
{
  assert.equal(slash('foo\\bar\\baz.js'), 'foo/bar/baz.js');
  assert.equal(slash('nested\\dir\\sub\\index.js'), 'nested/dir/sub/index.js');
  assert.equal(slash('already/forward/slash'), 'already/forward/slash');
}

// 6. toArray converts nullish values to empty arrays and wraps non-array values in single-element arrays
{
  assert.deepEqual(toArray(null), []);
  assert.deepEqual(toArray(undefined), []);
  assert.deepEqual(toArray('single'), ['single']);
  assert.deepEqual(toArray(42), [42]);
  const arr = [1, 2, 3];
  assert.equal(toArray(arr), arr);
}

// 7. isObject identifies object structures while returning false for arrays, functions, and primitives
{
  assert.equal(isObject({}), true);
  assert.equal(isObject(Object.create(null)), true);
  assert.equal(isObject(new Map()), true);
  assert.equal(isObject(new Set()), true);
  assert.equal(isObject([]), false);
  assert.equal(isObject(() => {}), false);
  assert.equal(isObject(null), false);
  assert.equal(isObject(undefined), false);
  assert.equal(isObject('string'), false);
  assert.equal(isObject(123), false);
}

// 8. isPrimitive identifies JavaScript primitive values and rejects object structures
{
  assert.equal(isPrimitive('str'), true);
  assert.equal(isPrimitive(123), true);
  assert.equal(isPrimitive(true), true);
  assert.equal(isPrimitive(null), true);
  assert.equal(isPrimitive(undefined), true);
  assert.equal(isPrimitive(Symbol('s')), true);
  assert.equal(isPrimitive(10n), true);
  assert.equal(isPrimitive({}), false);
  assert.equal(isPrimitive([]), false);
  assert.equal(isPrimitive(() => {}), false);
}

// 9. parseRegexp parses stringified regular expressions into RegExp instances
{
  const parsed = parseRegexp('/^test[0-9]+$/gi');
  assert.ok(parsed instanceof RegExp);
  assert.equal(parsed.source, '^test[0-9]+$');
  assert.equal(parsed.flags, 'gi');
  assert.ok(parsed.test('TEST123'));
  assert.ok(!parsed.test('other'));
}

// 10. nanoid generates random identifier strings with default and custom lengths
{
  const id1 = nanoid();
  const id2 = nanoid();
  assert.equal(typeof id1, 'string');
  assert.equal(id1.length, 21);
  assert.notEqual(id1, id2);

  const customId = nanoid(10);
  assert.equal(typeof customId, 'string');
  assert.equal(customId.length, 10);
}

console.log('All @vitest/utils contract assertions passed.');

Seeder de origen

anónimo