CodeSampleX

샘플

@sinonjs/commons 3.0.1

검증된 샘플 — npm @sinonjs/commons 3.0.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: typeOf returns lowercase type name for JavaScript values…

sha256:05dc1edbde1ad5d98c31d3578a977a17d84210af24a8ef793ea5db3f98066a41

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/%40sinonjs/commons@3.0.1
패키지
환경
node 22.23.2
생성일
2026-08-27T14:32:28Z

컨트랙트

  1. typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects
  2. className returns constructor name for objects and null when constructor is absent or null prototype
  3. functionName returns the identifier name of named and assigned function declarations
  4. every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise
  5. valueToString converts primitives, objects, and nullish values to string representations
  6. prototypes provides safe uncurried methods on array, string, and object prototypes
  7. calledInOrder returns true when spy instances are executed in sequential order
  8. orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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/%40sinonjs/commons@3.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sinonjs/commons@3.0.1

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:fa4d7b0d7c2366b8df5a71d91c44c08c893392557117390f01a72aed8338f34f","contract":["typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects","className returns constructor name for objects and null when constructor is absent or null prototype","functionName returns the identifier name of named and assigned function declarations","every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise","valueToString converts primitives, objects, and nullish values to string representations","prototypes provides safe uncurried methods on array, string, and object prototypes","calledInOrder returns true when spy instances are executed in sequential order","orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId"],"goal":"verify pkg:npm/%40sinonjs/commons@3.0.1","kind":"HOW","packages":["pkg:npm/%40sinonjs/commons@3.0.1"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/%40sinonjs/commons@3.0.1"],"schemaVersion":1,"subject":"pkg:npm/%40sinonjs/commons@3.0.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-sinonjs-commons",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sinonjs-commons",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@sinonjs/commons": "3.0.1"
      }
    },
    "node_modules/@sinonjs/commons": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz",
      "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==",
      "license": "BSD-3-Clause",
      "dependencies": {
        "type-detect": "4.0.8"
      }
    },
    "node_modules/type-detect": {
      "version": "4.0.8",
      "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
      "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    }
  }
}
package.json
{
  "name": "sample-sinonjs-commons",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for @sinonjs/commons",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@sinonjs/commons": "3.0.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40sinonjs/commons@3.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sinonjs/commons@3.0.1"
  ]
}
src/index.js
'use strict';

const commons = require('@sinonjs/commons');

/**
 * Inspects a value using @sinonjs/commons utilities.
 * @param {*} value
 * @returns {object}
 */
function inspectValue(value) {
  return {
    type: commons.typeOf(value),
    className: typeof value === 'object' && value !== null ? commons.className(value) : null,
    stringRepresentation: commons.valueToString(value)
  };
}

/**
 * Validates that all items in a collection satisfy a predicate.
 * @param {Array|Set|Map} collection
 * @param {Function} predicate
 * @returns {boolean}
 */
function validateAll(collection, predicate) {
  return commons.every(collection, predicate);
}

module.exports = {
  commons,
  inspectValue,
  validateAll
};
test/contract.js
'use strict';

const assert = require('assert');
const commons = require('@sinonjs/commons');
const { inspectValue, validateAll } = require('../src/index.js');

// 1. typeOf returns lowercase type name for JavaScript values including primitives, arrays, dates, maps, sets, and objects
{
  assert.strictEqual(commons.typeOf(null), 'null');
  assert.strictEqual(commons.typeOf(undefined), 'undefined');
  assert.strictEqual(commons.typeOf('sample text'), 'string');
  assert.strictEqual(commons.typeOf(42), 'number');
  assert.strictEqual(commons.typeOf(true), 'boolean');
  assert.strictEqual(commons.typeOf([]), 'array');
  assert.strictEqual(commons.typeOf({}), 'object');
  assert.strictEqual(commons.typeOf(new Date()), 'date');
  assert.strictEqual(commons.typeOf(new Map()), 'map');
  assert.strictEqual(commons.typeOf(new Set()), 'set');
  assert.strictEqual(commons.typeOf(/pattern/i), 'regexp');
  assert.strictEqual(commons.typeOf(() => {}), 'function');

  const inspected = inspectValue(new Date());
  assert.strictEqual(inspected.type, 'date');
}

// 2. className returns constructor name for objects and null when constructor is absent or null prototype
{
  assert.strictEqual(commons.className({}), 'Object');
  assert.strictEqual(commons.className([]), 'Array');
  assert.strictEqual(commons.className(new Date()), 'Date');
  assert.strictEqual(commons.className(new Map()), 'Map');
  assert.strictEqual(commons.className(new Set()), 'Set');
  assert.strictEqual(commons.className(Object.create(null)), null);

  class CustomService {}
  assert.strictEqual(commons.className(new CustomService()), 'CustomService');

  const inspected = inspectValue(new CustomService());
  assert.strictEqual(inspected.className, 'CustomService');
}

// 3. functionName returns the identifier name of named and assigned function declarations
{
  function declaredFunction() {}
  assert.strictEqual(commons.functionName(declaredFunction), 'declaredFunction');

  const namedExpression = function computeTotal() {};
  assert.strictEqual(commons.functionName(namedExpression), 'computeTotal');

  const assignedAnonymous = function () {};
  assert.strictEqual(commons.functionName(assignedAnonymous), 'assignedAnonymous');
}

// 4. every returns true when all elements in an array, Set, or Map satisfy predicate and false otherwise
{
  assert.strictEqual(commons.every([2, 4, 6], (x) => x % 2 === 0), true);
  assert.strictEqual(commons.every([2, 3, 6], (x) => x % 2 === 0), false);

  const set = new Set([10, 20, 30]);
  assert.strictEqual(commons.every(set, (x) => x >= 10), true);
  assert.strictEqual(commons.every(set, (x) => x > 15), false);

  const map = new Map([
    ['k1', 100],
    ['k2', 200]
  ]);
  assert.strictEqual(commons.every(map, (val) => val >= 100), true);
  assert.strictEqual(commons.every(map, (val) => val > 150), false);

  assert.strictEqual(validateAll([1, 2, 3], (x) => x > 0), true);
  assert.strictEqual(validateAll([1, -2, 3], (x) => x > 0), false);
}

// 5. valueToString converts primitives, objects, and nullish values to string representations
{
  assert.strictEqual(commons.valueToString('sample string'), 'sample string');
  assert.strictEqual(commons.valueToString(12345), '12345');
  assert.strictEqual(commons.valueToString(true), 'true');
  assert.strictEqual(commons.valueToString(null), 'null');
  assert.strictEqual(commons.valueToString(undefined), 'undefined');
  assert.strictEqual(commons.valueToString([1, 2, 3]), '1,2,3');

  const customObj = {
    toString() {
      return 'custom-string-output';
    }
  };
  assert.strictEqual(commons.valueToString(customObj), 'custom-string-output');

  const inspected = inspectValue(customObj);
  assert.strictEqual(inspected.stringRepresentation, 'custom-string-output');
}

// 6. prototypes provides safe uncurried methods on array, string, and object prototypes
{
  const testArray = [10, 20, 30, 40];
  assert.deepStrictEqual(commons.prototypes.array.slice(testArray, 1, 3), [20, 30]);
  assert.strictEqual(commons.prototypes.array.includes(testArray, 20), true);
  assert.strictEqual(commons.prototypes.array.includes(testArray, 99), false);

  assert.strictEqual(commons.prototypes.string.trim('   padded content   '), 'padded content');
  assert.strictEqual(commons.prototypes.string.startsWith('prefix-suffix', 'prefix'), true);
  assert.strictEqual(commons.prototypes.string.indexOf('abcdef', 'cd'), 2);

  const testObj = { prop: 'value' };
  assert.strictEqual(commons.prototypes.object.hasOwnProperty(testObj, 'prop'), true);
  assert.strictEqual(commons.prototypes.object.hasOwnProperty(testObj, 'missing'), false);
}

// 7. calledInOrder returns true when spy instances are executed in sequential order
{
  let sequence = 0;
  function createTestSpy(id) {
    return {
      id,
      callCount: 0,
      callOrder: [],
      call() {
        this.callCount++;
        this.callOrder.push(++sequence);
      },
      calledBefore(other) {
        if (this.callCount === 0 || other.callCount === 0) return false;
        return this.callOrder[0] < other.callOrder[0];
      }
    };
  }

  const spyFirst = createTestSpy('spyFirst');
  const spySecond = createTestSpy('spySecond');
  const spyThird = createTestSpy('spyThird');

  spyFirst.call();
  spySecond.call();
  spyThird.call();

  assert.strictEqual(commons.calledInOrder([spyFirst, spySecond, spyThird]), true);
  assert.strictEqual(commons.calledInOrder([spySecond, spyFirst, spyThird]), false);
  assert.strictEqual(commons.calledInOrder(spyFirst, spySecond, spyThird), true);
  assert.strictEqual(commons.calledInOrder(spyThird, spySecond, spyFirst), false);
}

// 8. orderByFirstCall sorts an array of spy objects chronologically by their first invocation callId
{
  const proxyA = {
    getCall(index) {
      return index === 0 ? { callId: 300 } : null;
    }
  };
  const proxyB = {
    getCall(index) {
      return index === 0 ? { callId: 100 } : null;
    }
  };
  const proxyC = {
    getCall(index) {
      return index === 0 ? { callId: 200 } : null;
    }
  };

  const sorted = commons.orderByFirstCall([proxyA, proxyB, proxyC]);
  assert.deepStrictEqual(sorted, [proxyB, proxyC, proxyA]);
}

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

오리진 시더

익명