CodeSampleX

샘플

lru-cache 5.1.1

검증된 샘플 — npm lru-cache 5.1.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: LRUCache get and set store and retrieve key-value pairs while…

sha256:33f47a04a5ae9b9d961ce0a162da870061652a08dbe1a0d76c4ecc3e2e425ad1

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
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

케이스

HOW
목표
verify pkg:npm/lru-cache@5.1.1
패키지
생성일
2026-08-21T13:48:28Z

컨트랙트

  1. LRUCache get and set store and retrieve key-value pairs while respecting maximum capacity by evicting least recently used entries
  2. LRUCache peek inspects cached values without updating the recency order
  3. LRUCache has and del verify existence and delete individual entries from the cache
  4. LRUCache forEach and rforEach iterate entries in most-recently-used and least-recently-used order
  5. LRUCache keys and values return arrays of keys and values in order from newest to oldest
  6. LRUCache dump and load serialize the cache state and restore entries into a separate cache instance
  7. LRUCache dispose callback is triggered when an entry is evicted due to capacity or deleted
  8. LRUCache reset removes all entries and resets cache length and itemCount to 0

파일

  • 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@5.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/lru-cache@5.1.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:558b001db97565e3e2b614aba841cd60010bd2bea8bd45a016a2b0f191534611","contract":["LRUCache get and set store and retrieve key-value pairs while respecting maximum capacity by evicting least recently used entries","LRUCache peek inspects cached values without updating the recency order","LRUCache has and del verify existence and delete individual entries from the cache","LRUCache forEach and rforEach iterate entries in most-recently-used and least-recently-used order","LRUCache keys and values return arrays of keys and values in order from newest to oldest","LRUCache dump and load serialize the cache state and restore entries into a separate cache instance","LRUCache dispose callback is triggered when an entry is evicted due to capacity or deleted","LRUCache reset removes all entries and resets cache length and itemCount to 0"],"goal":"verify pkg:npm/lru-cache@5.1.1","kind":"HOW","packages":["pkg:npm/lru-cache@5.1.1"],"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@5.1.1"],"schemaVersion":1,"subject":"pkg:npm/lru-cache@5.1.1","verifierAdapter":"node-typescript@1"}
index.mjs
import LRU from "lru-cache";

export function createCache(options) {
  return new LRU(options);
}
package-lock.json
{
  "name": "sample-lru-cache",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-lru-cache",
      "version": "1.0.0",
      "dependencies": {
        "lru-cache": "5.1.1"
      }
    },
    "node_modules/lru-cache": {
      "version": "5.1.1",
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
      "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
      "license": "ISC",
      "dependencies": {
        "yallist": "^3.0.2"
      }
    },
    "node_modules/yallist": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
      "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
      "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": "5.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/lru-cache@5.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/lru-cache@5.1.1"
  ]
}
test/contract.mjs
import assert from "node:assert/strict";
import LRU from "lru-cache";
import { createCache } from "../index.mjs";

// 1. LRUCache get and set store and retrieve key-value pairs while respecting maximum capacity by evicting least recently used entries
{
  const cache = createCache({ max: 3 });
  cache.set("a", 1);
  cache.set("b", 2);
  cache.set("c", 3);

  assert.equal(cache.get("a"), 1);
  assert.equal(cache.get("b"), 2);
  assert.equal(cache.get("c"), 3);
  assert.equal(cache.itemCount, 3);

  // Access "a" so "b" becomes least recently used: c -> a -> b (LRU is b)
  cache.get("a");
  cache.set("d", 4);
  assert.equal(cache.get("b"), undefined);
  assert.equal(cache.get("a"), 1);
  assert.equal(cache.get("c"), 3);
  assert.equal(cache.get("d"), 4);
  assert.equal(cache.itemCount, 3);
}

// 2. LRUCache peek inspects cached values without updating the recency order
{
  const cache = new LRU({ max: 2 });
  cache.set("first", "val1");
  cache.set("second", "val2");

  // Peek "first" without making it most recent
  assert.equal(cache.peek("first"), "val1");

  // Adding "third" should evict "first" because peek did not refresh "first"
  cache.set("third", "val3");
  assert.equal(cache.get("first"), undefined);
  assert.equal(cache.get("second"), "val2");
  assert.equal(cache.get("third"), "val3");
}

// 3. LRUCache has and del verify existence and delete individual entries from the cache
{
  const cache = new LRU({ max: 5 });
  cache.set("k1", "v1");
  cache.set("k2", "v2");

  assert.equal(cache.has("k1"), true);
  assert.equal(cache.has("k3"), false);

  cache.del("k1");
  assert.equal(cache.has("k1"), false);
  assert.equal(cache.get("k1"), undefined);
  assert.equal(cache.itemCount, 1);
}

// 4. LRUCache forEach and rforEach iterate entries in most-recently-used and least-recently-used order
{
  const cache = new LRU({ max: 5 });
  cache.set("x", 10);
  cache.set("y", 20);
  cache.set("z", 30);
  // Order newest to oldest: z, y, x

  const forward = [];
  cache.forEach((val, key) => {
    forward.push({ key, val });
  });
  assert.deepEqual(forward, [
    { key: "z", val: 30 },
    { key: "y", val: 20 },
    { key: "x", val: 10 }
  ]);

  const reverse = [];
  cache.rforEach((val, key) => {
    reverse.push({ key, val });
  });
  assert.deepEqual(reverse, [
    { key: "x", val: 10 },
    { key: "y", val: 20 },
    { key: "z", val: 30 }
  ]);
}

// 5. LRUCache keys and values return arrays of keys and values in order from newest to oldest
{
  const cache = new LRU({ max: 3 });
  cache.set("alpha", 1);
  cache.set("beta", 2);
  cache.set("gamma", 3);

  // Access alpha to make it newest: beta -> gamma -> alpha
  cache.get("alpha");

  assert.deepEqual(cache.keys(), ["alpha", "gamma", "beta"]);
  assert.deepEqual(cache.values(), [1, 3, 2]);
}

// 6. LRUCache dump and load serialize the cache state and restore entries into a separate cache instance
{
  const original = new LRU({ max: 3 });
  original.set("p", 100);
  original.set("q", 200);

  const serialized = original.dump();
  assert.equal(Array.isArray(serialized), true);
  assert.equal(serialized.length, 2);

  const restored = new LRU({ max: 3 });
  restored.load(serialized);

  assert.equal(restored.get("p"), 100);
  assert.equal(restored.get("q"), 200);
  assert.deepEqual(restored.keys(), original.keys());
}

// 7. LRUCache dispose callback is triggered when an entry is evicted due to capacity or deleted
{
  const disposed = [];
  const cache = new LRU({
    max: 2,
    dispose: (key, val) => {
      disposed.push({ key, val });
    }
  });

  cache.set("e1", "val1");
  cache.set("e2", "val2");
  cache.set("e3", "val3"); // e1 is evicted

  assert.deepEqual(disposed, [{ key: "e1", val: "val1" }]);

  cache.del("e2");
  assert.deepEqual(disposed, [
    { key: "e1", val: "val1" },
    { key: "e2", val: "val2" }
  ]);
}

// 8. LRUCache reset removes all entries and resets cache length and itemCount to 0
{
  const cache = new LRU({ max: 5 });
  cache.set("item1", "v1");
  cache.set("item2", "v2");
  assert.equal(cache.itemCount, 2);

  cache.reset();
  assert.equal(cache.itemCount, 0);
  assert.equal(cache.length, 0);
  assert.equal(cache.get("item1"), undefined);
  assert.equal(cache.get("item2"), undefined);
  assert.deepEqual(cache.keys(), []);
}

console.log("All LRUCache@5.1.1 contract tests passed.");

오리진 시더

익명