CodeSampleX

샘플

@jest/diff-sequences 30.4.0: default

검증된 샘플 — npm @jest/diff-sequences 30.4.0: default. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: validateLength throws TypeError when aLength…

sha256:71820bc012179516292b9e06e6f4069b393cbb10f8c4f0d7275e66b77f35db77

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0
패키지
심벌
  • @jest/diff-sequences.default
환경
node 22.23.2
생성일
2026-09-04T10:34:08Z

컨트랙트

  1. validateLength throws TypeError when aLength or bLength is not a number
  2. validateLength throws RangeError when aLength or bLength is negative or not a safe integer
  3. validateCallback throws TypeError when isCommon or foundSubsequence is not a function
  4. diffSequence does not invoke foundSubsequence when sequences have zero length or have no items in common
  5. diffSequence invokes foundSubsequence with full length at index 0 when sequences are identical
  6. diffSequence finds longest common subsequence chunks for partially matching sequences
  7. diffSequence correctly identifies common subsequences in string sequences to compute shortest edit scripts
  8. diffSequence supports custom comparison functions like Object.is for arbitrary element types

파일

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

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

소스

.npmrc
audit=false
fund=false
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 @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jest/diff-sequences@30.4.0
Demonstrate these symbols/APIs:
  - @jest/diff-sequences.default

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:c016b1774f1043c0a7a5321c46981950424031df2600be0fc91c59bb72acdaf0","contract":["validateLength throws TypeError when aLength or bLength is not a number","validateLength throws RangeError when aLength or bLength is negative or not a safe integer","validateCallback throws TypeError when isCommon or foundSubsequence is not a function","diffSequence does not invoke foundSubsequence when sequences have zero length or have no items in common","diffSequence invokes foundSubsequence with full length at index 0 when sequences are identical","diffSequence finds longest common subsequence chunks for partially matching sequences","diffSequence correctly identifies common subsequences in string sequences to compute shortest edit scripts","diffSequence supports custom comparison functions like Object.is for arbitrary element types"],"goal":"verify @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0","kind":"HOW","packages":["pkg:npm/%40jest/diff-sequences@30.4.0"],"schemaVersion":1,"symbols":["@jest/diff-sequences.default"]},"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/%40jest/diff-sequences@30.4.0"],"schemaVersion":1,"subject":"pkg:npm/%40jest/diff-sequences@30.4.0","symbols":["@jest/diff-sequences.default"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const jestDiffSequences = require('@jest/diff-sequences');
const diffSequence = jestDiffSequences.default || jestDiffSequences;

/**
 * Compare items in two sequences to find a longest common subsequence.
 * @param {number} aLength
 * @param {number} bLength
 * @param {(aIndex: number, bIndex: number) => boolean} isCommon
 * @param {(nCommon: number, aCommon: number, bCommon: number) => void} foundSubsequence
 */
function diff(aLength, bLength, isCommon, foundSubsequence) {
  return diffSequence(aLength, bLength, isCommon, foundSubsequence);
}

/**
 * Count the total number of common items between two arrays.
 * @param {Array} a
 * @param {Array} b
 * @param {(x: any, y: any) => boolean} [comparator]
 * @returns {number}
 */
function countCommonItems(a, b, comparator = (x, y) => x === y) {
  let count = 0;
  diffSequence(
    a.length,
    b.length,
    (aIndex, bIndex) => comparator(a[aIndex], b[bIndex]),
    (nCommon) => {
      count += nCommon;
    }
  );
  return count;
}

/**
 * Find the items in the longest common subsequence between two arrays.
 * @param {Array} a
 * @param {Array} b
 * @param {(x: any, y: any) => boolean} [comparator]
 * @returns {Array}
 */
function findCommonItems(a, b, comparator = Object.is) {
  const common = [];
  diffSequence(
    a.length,
    b.length,
    (aIndex, bIndex) => comparator(a[aIndex], b[bIndex]),
    (nCommon, aCommon) => {
      for (; nCommon !== 0; nCommon -= 1, aCommon += 1) {
        common.push(a[aCommon]);
      }
    }
  );
  return common;
}

/**
 * Find differences between strings as diff items [operation, text]
 * -1 for deletion from a, 1 for insertion from b, 0 for common text.
 * @param {string} a
 * @param {string} b
 * @returns {Array<[number, string]>}
 */
function findDiffItems(a, b) {
  const isCommon = (aIndex, bIndex) => a[aIndex] === b[bIndex];
  let aIndex = 0;
  let bIndex = 0;
  const result = [];

  diffSequence(
    a.length,
    b.length,
    isCommon,
    (nCommon, aCommon, bCommon) => {
      if (aIndex !== aCommon) {
        result.push([-1, a.slice(aIndex, aCommon)]);
      }
      if (bIndex !== bCommon) {
        result.push([1, b.slice(bIndex, bCommon)]);
      }
      aIndex = aCommon + nCommon;
      bIndex = bCommon + nCommon;
      result.push([0, a.slice(aCommon, aIndex)]);
    }
  );

  if (aIndex !== a.length) {
    result.push([-1, a.slice(aIndex)]);
  }
  if (bIndex !== b.length) {
    result.push([1, b.slice(bIndex)]);
  }

  return result;
}

module.exports = {
  diff,
  diffSequence,
  countCommonItems,
  findCommonItems,
  findDiffItems,
};
package-lock.json
{
  "name": "sample-jest-diff-sequences",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-diff-sequences",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jest/diff-sequences": "30.4.0"
      }
    },
    "node_modules/@jest/diff-sequences": {
      "version": "30.4.0",
      "resolved": "https://registry.npmjs.org/@jest/diff-sequences/-/diff-sequences-30.4.0.tgz",
      "integrity": "sha512-zOpzlfUs45l6u7jm39qr87JCHUDsaeCtvL+kQe/Vn9jSnRB4/5IPXISm0h9I1vZW/o00Kn4UTJ2MOlhnUGwv3g==",
      "license": "MIT",
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-jest-diff-sequences",
  "version": "1.0.0",
  "private": true,
  "description": "verify @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@jest/diff-sequences": "30.4.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jest/diff-sequences@30.4.0"
  ],
  "symbols": [
    "@jest/diff-sequences.default"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import diffSequenceDefault from '@jest/diff-sequences';
import {
  diff,
  diffSequence,
  countCommonItems,
  findCommonItems,
  findDiffItems,
} from '../index.js';

// Verify default import from package matches diffSequence
assert.strictEqual(typeof diffSequenceDefault, 'function', 'Default export must be a function');
assert.strictEqual(typeof diffSequence, 'function', 'diffSequence must be a function');
assert.strictEqual(typeof diff, 'function', 'diff helper must be a function');

// Contract 1: validateLength throws TypeError when aLength or bLength is not a number
assert.throws(
  () => diffSequence('0', 0, () => true, () => {}),
  (err) => {
    assert(err instanceof TypeError);
    assert.match(err.message, /aLength typeof string is not a number/);
    return true;
  }
);
assert.throws(
  () => diffSequence(0, '0', () => true, () => {}),
  (err) => {
    assert(err instanceof TypeError);
    assert.match(err.message, /bLength typeof string is not a number/);
    return true;
  }
);

// Contract 2: validateLength throws RangeError when aLength or bLength is negative or not a safe integer
assert.throws(
  () => diffSequence(-1, 0, () => true, () => {}),
  (err) => {
    assert(err instanceof RangeError);
    assert.match(err.message, /aLength value -1 is a negative integer/);
    return true;
  }
);
assert.throws(
  () => diffSequence(0, -3, () => true, () => {}),
  (err) => {
    assert(err instanceof RangeError);
    assert.match(err.message, /bLength value -3 is a negative integer/);
    return true;
  }
);
assert.throws(
  () => diffSequence(1.5, 0, () => true, () => {}),
  (err) => {
    assert(err instanceof RangeError);
    assert.match(err.message, /aLength value 1\.5 is not a safe integer/);
    return true;
  }
);

// Contract 3: validateCallback throws TypeError when isCommon or foundSubsequence is not a function
assert.throws(
  () => diffSequence(0, 0, null, () => {}),
  (err) => {
    assert(err instanceof TypeError);
    assert.match(err.message, /isCommon typeof object is not a function/);
    return true;
  }
);
assert.throws(
  () => diffSequence(0, 0, () => true, 'invalid'),
  (err) => {
    assert(err instanceof TypeError);
    assert.match(err.message, /foundSubsequence typeof string is not a function/);
    return true;
  }
);

// Contract 4: diffSequence does not invoke foundSubsequence when sequences have zero length or have no items in common
let calledWhenEmpty = false;
diffSequence(0, 0, () => true, () => { calledWhenEmpty = true; });
assert.strictEqual(calledWhenEmpty, false, 'foundSubsequence must not be called for empty sequences');

let calledWhenDisjoint = false;
const aDisjoint = ['x', 'y'];
const bDisjoint = ['1', '2'];
diffSequence(
  aDisjoint.length,
  bDisjoint.length,
  (aIdx, bIdx) => aDisjoint[aIdx] === bDisjoint[bIdx],
  () => { calledWhenDisjoint = true; }
);
assert.strictEqual(calledWhenDisjoint, false, 'foundSubsequence must not be called when there are no common items');

// Contract 5: diffSequence invokes foundSubsequence with full length at index 0 when sequences are identical
const identicalA = ['apple', 'banana', 'cherry'];
const identicalB = ['apple', 'banana', 'cherry'];
const identicalCalls = [];
diffSequence(
  identicalA.length,
  identicalB.length,
  (i, j) => identicalA[i] === identicalB[j],
  (nCommon, aCommon, bCommon) => {
    identicalCalls.push({ nCommon, aCommon, bCommon });
  }
);
assert.strictEqual(identicalCalls.length, 1, 'Exactly one callback invocation expected for identical sequences');
assert.deepStrictEqual(identicalCalls[0], { nCommon: 3, aCommon: 0, bCommon: 0 });

// Contract 6: diffSequence finds longest common subsequence chunks for partially matching sequences
const aSeq = ['a', 'b', 'c', 'a', 'b', 'b', 'a'];
const bSeq = ['c', 'b', 'a', 'b', 'a', 'c'];
const subseqCalls = [];
diffSequence(
  aSeq.length,
  bSeq.length,
  (i, j) => aSeq[i] === bSeq[j],
  (nCommon, aCommon, bCommon) => {
    subseqCalls.push({ nCommon, aCommon, bCommon });
  }
);
assert.strictEqual(subseqCalls.length, 3);
assert.deepStrictEqual(subseqCalls[0], { nCommon: 1, aCommon: 2, bCommon: 0 });
assert.deepStrictEqual(subseqCalls[1], { nCommon: 1, aCommon: 4, bCommon: 1 });
assert.deepStrictEqual(subseqCalls[2], { nCommon: 2, aCommon: 5, bCommon: 3 });

assert.strictEqual(countCommonItems(aSeq, bSeq), 4);
assert.deepStrictEqual(findCommonItems(aSeq, bSeq), ['c', 'b', 'b', 'a']);

// Contract 7: diffSequence correctly identifies common subsequences in string sequences to compute shortest edit scripts
const diffResult = findDiffItems('kitten', 'sitting');
assert.deepStrictEqual(diffResult, [
  [-1, 'k'],
  [1, 's'],
  [0, 'itt'],
  [-1, 'e'],
  [1, 'i'],
  [0, 'n'],
  [1, 'g'],
]);

// Contract 8: diffSequence supports custom comparison functions like Object.is for arbitrary element types
const aObj = [NaN, 0, -0];
const bObj = [NaN, -0, 0];
const commonObj = findCommonItems(aObj, bObj, Object.is);
assert.strictEqual(commonObj.length, 2);
assert.ok(Number.isNaN(commonObj[0]));
assert.strictEqual(Object.is(commonObj[1], -0) || Object.is(commonObj[1], 0), true);

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

오리진 시더

익명