CodeSampleX

Sample

@vitest/utils 4.1.11

Verified sample for npm @vitest/utils 4.1.11. The contract ran on node 22 · linux alpine/x64 · docker and passed: getType distinguishes JavaScript types…

sha256:4433b67746e766a48200b447afe623b7478c14477acc55f5e53ee79999f6c580

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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-28

Case

HOW
Goal
verify pkg:npm/%40vitest/utils@4.1.11
Packages
Created
2026-08-28T06:25:19Z

Contract

  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. cleanUrl strips query strings and hash fragments from URLs
  10. nanoid generates random identifier strings with default and custom lengths
  11. getSafeTimers provides access to unmocked native timer methods
  12. delay returns a promise that resolves after the specified duration
  13. diff computes differences between two values
  14. stringify serializes values into readable formatted strings
  15. processError processes error objects into structured test error representations
  16. unique removes duplicate primitive elements from an array

Files

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

Download the source artifact (tar.gz)

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

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/utils@4.1.11

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:193c5c4e635e4a467a112c98d19acab32c1c6950b2e14954faefb317bb1bec19","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","cleanUrl strips query strings and hash fragments from URLs","nanoid generates random identifier strings with default and custom lengths","getSafeTimers provides access to unmocked native timer methods","delay returns a promise that resolves after the specified duration","diff computes differences between two values","stringify serializes values into readable formatted strings","processError processes error objects into structured test error representations","unique removes duplicate primitive elements from an array"],"goal":"verify pkg:npm/%40vitest/utils@4.1.11","kind":"HOW","packages":["pkg:npm/%40vitest/utils@4.1.11"],"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/%40vitest/utils@4.1.11"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/utils@4.1.11","verifierAdapter":"node-typescript@1"}
index.mjs
import {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  cleanUrl,
  nanoid,
  unique
} from '@vitest/utils/helpers';
import { diff } from '@vitest/utils/diff';
import { stringify, format } from '@vitest/utils/display';
import { delay, getSafeTimers } from '@vitest/utils/timers';
import { processError } from '@vitest/utils/error';

export {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  cleanUrl,
  nanoid,
  unique,
  diff,
  stringify,
  format,
  delay,
  getSafeTimers,
  processError
};

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": "4.1.11"
      }
    },
    "node_modules/@vitest/pretty-format": {
      "version": "4.1.11",
      "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.11.tgz",
      "integrity": "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==",
      "license": "MIT",
      "dependencies": {
        "tinyrainbow": "^3.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/@vitest/utils": {
      "version": "4.1.11",
      "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.11.tgz",
      "integrity": "sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ==",
      "license": "MIT",
      "dependencies": {
        "@vitest/pretty-format": "4.1.11",
        "convert-source-map": "^2.0.0",
        "tinyrainbow": "^3.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/convert-source-map": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
      "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
      "license": "MIT"
    },
    "node_modules/tinyrainbow": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.1.tgz",
      "integrity": "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==",
      "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": "4.1.11"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40vitest/utils@4.1.11",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/utils@4.1.11"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  getType,
  deepMerge,
  deepClone,
  createDefer,
  slash,
  toArray,
  isObject,
  isPrimitive,
  notNullish,
  cleanUrl,
  nanoid,
  unique
} from '@vitest/utils/helpers';
import { diff } from '@vitest/utils/diff';
import { stringify, format } from '@vitest/utils/display';
import { delay, getSafeTimers } from '@vitest/utils/timers';
import { processError } from '@vitest/utils/error';
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. cleanUrl strips query strings and hash fragments from URLs
{
  assert.equal(cleanUrl('https://example.com/path?foo=bar#section'), 'https://example.com/path');
  assert.equal(cleanUrl('file:///path/to/file.js?v=1'), 'file:///path/to/file.js');
}

// 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);
}

// 11. getSafeTimers provides access to unmocked native timer methods
{
  const timers = getSafeTimers();
  assert.equal(typeof timers.setTimeout, 'function');
  assert.equal(typeof timers.clearTimeout, 'function');
  assert.equal(typeof timers.setInterval, 'function');
  assert.equal(typeof timers.clearInterval, 'function');
}

// 12. delay returns a promise that resolves after the specified duration
{
  const start = Date.now();
  await delay(10);
  const elapsed = Date.now() - start;
  assert.ok(elapsed >= 5);
}

// 13. diff computes differences between two values
{
  const diffResult = diff('hello\nworld', 'hello\nearth');
  assert.equal(typeof diffResult, 'string');
  assert.ok(diffResult.includes('world') || diffResult.includes('earth'));
}

// 14. stringify serializes values into readable formatted strings
{
  const str = stringify({ a: 1, b: 'two' });
  assert.equal(typeof str, 'string');
  assert.ok(str.includes('"a": 1'));
  assert.ok(str.includes('"b": "two"'));
}

// 15. processError processes error objects into structured test error representations
{
  const rawErr = new Error('test failure');
  const processed = processError(rawErr);
  assert.equal(processed.name, 'Error');
  assert.equal(processed.message, 'test failure');
  assert.ok(typeof processed.stack === 'string');
}

// 16. unique removes duplicate primitive elements from an array
{
  const list = [1, 2, 2, 3, 1, 4];
  const uniq = unique(list);
  assert.deepEqual(uniq, [1, 2, 3, 4]);
}

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

Origin Seeder

anonymous