CodeSampleX

샘플

lru-cache 10.4.3

검증된 샘플 — npm lru-cache 10.4.3. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: LRUCache basic set, get, has, and delete operations manage cached…

sha256:65309ec6cafbc9663e1c24ef1092516275944c6f33cf2996bb924fa7f5cda513

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21
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-07

케이스

HOW
목표
verify pkg:npm/lru-cache@10.4.3
패키지
생성일
2026-08-21T13:46:37Z

컨트랙트

  1. LRUCache basic set, get, has, and delete operations manage cached values
  2. LRUCache evicts the least recently used item when cache capacity max is exceeded
  3. LRUCache expires cached entries after ttl duration
  4. LRUCache enforces maxSize using sizeCalculation and evicts entries exceeding size limit
  5. LRUCache peek retrieves value without altering LRU order
  6. LRUCache supports iteration over keys, values, and entries and clear resets cache size

파일

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

소스 아티팩트 내려받기 (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/lru-cache@10.4.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/lru-cache@10.4.3

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:bcc8101e276003eae935e76b83d0bc4144997111fe65736a0a754906f9d9919d","contract":["LRUCache basic set, get, has, and delete operations manage cached values","LRUCache evicts the least recently used item when cache capacity max is exceeded","LRUCache expires cached entries after ttl duration","LRUCache enforces maxSize using sizeCalculation and evicts entries exceeding size limit","LRUCache peek retrieves value without altering LRU order","LRUCache supports iteration over keys, values, and entries and clear resets cache size"],"goal":"verify pkg:npm/lru-cache@10.4.3","kind":"HOW","packages":["pkg:npm/lru-cache@10.4.3"],"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/lru-cache@10.4.3"],"schemaVersion":1,"subject":"pkg:npm/lru-cache@10.4.3","verifierAdapter":"node-typescript@1"}
index.mjs
import { LRUCache } from 'lru-cache';

export function createCache(options) {
  return new LRUCache(options);
}

export { LRUCache };
package-lock.json
{
  "name": "sample-lru-cache",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-lru-cache",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "lru-cache": "10.4.3"
      }
    },
    "node_modules/lru-cache": {
      "version": "10.4.3",
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
      "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-lru-cache",
  "version": "1.0.0",
  "description": "Clean-room verification sample for lru-cache",
  "type": "module",
  "private": true,
  "dependencies": {
    "lru-cache": "10.4.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/lru-cache@10.4.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/lru-cache@10.4.3"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { LRUCache, createCache } from '../index.mjs';

// 1. Basic set, get, has, and delete operations
{
  const cache = createCache({ max: 5 });
  cache.set('a', 1);
  cache.set('b', 2);
  assert.equal(cache.get('a'), 1);
  assert.equal(cache.get('b'), 2);
  assert.equal(cache.has('a'), true);
  assert.equal(cache.has('missing'), false);
  assert.equal(cache.delete('a'), true);
  assert.equal(cache.has('a'), false);
  assert.equal(cache.get('a'), undefined);
}

// 2. LRU eviction when exceeding max items
{
  const cache = new LRUCache({ max: 2 });
  cache.set('a', 1);
  cache.set('b', 2);
  assert.equal(cache.get('a'), 1); // access 'a' so 'b' is least recently used
  cache.set('c', 3);
  assert.equal(cache.has('b'), false);
  assert.equal(cache.has('a'), true);
  assert.equal(cache.has('c'), true);
  assert.equal(cache.size, 2);
}

// 3. TTL expiration of cached entries
{
  const cache = new LRUCache({ max: 5, ttl: 50 });
  cache.set('temp', 'val');
  assert.equal(cache.get('temp'), 'val');
  await new Promise((resolve) => setTimeout(resolve, 80));
  assert.equal(cache.get('temp'), undefined);
  assert.equal(cache.has('temp'), false);
}

// 4. maxSize and sizeCalculation eviction
{
  const cache = new LRUCache({
    maxSize: 10,
    sizeCalculation: (value) => value.length,
  });
  cache.set('k1', 'abcd');
  cache.set('k2', 'efgh');
  assert.equal(cache.calculatedSize, 8);
  cache.set('k3', 'ijkl');
  assert.equal(cache.has('k1'), false);
  assert.equal(cache.has('k2'), true);
  assert.equal(cache.has('k3'), true);
  assert.equal(cache.calculatedSize, 8);
}

// 5. peek retrieves value without updating LRU order
{
  const cache = new LRUCache({ max: 2 });
  cache.set('x', 10);
  cache.set('y', 20);
  assert.equal(cache.peek('x'), 10);
  cache.set('z', 30);
  assert.equal(cache.has('x'), false);
  assert.equal(cache.has('y'), true);
  assert.equal(cache.has('z'), true);
}

// 6. Iteration over keys, values, and entries
{
  const cache = new LRUCache({ max: 5 });
  cache.set('1', 'one');
  cache.set('2', 'two');
  assert.deepEqual([...cache.keys()], ['2', '1']);
  assert.deepEqual([...cache.values()], ['two', 'one']);
  assert.deepEqual([...cache.entries()], [['2', 'two'], ['1', 'one']]);
  cache.clear();
  assert.equal(cache.size, 0);
}

console.log('All LRUCache@10.4.3 contract assertions passed.');

오리진 시더

익명