CodeSampleX

Beispiel

@jest/diff-sequences 30.4.0: default

Verifiziertes Beispiel für npm @jest/diff-sequences 30.4.0: default. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:71820bc012179516292b9e06e6f4069b393cbb10f8c4f0d7275e66b77f35db77

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify @jest/diff-sequences.default in pkg:npm/%40jest/diff-sequences@30.4.0
Pakete
Symbole
  • @jest/diff-sequences.default
Umgebung
node 22.23.2
Erstellt
2026-09-04T10:34:08Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

.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.');

Ursprungs-Seeder

anonym