CodeSampleX

示例

lru-cache 6.0.0

已验证示例 — npm lru-cache 6.0.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: cache.set(key, value) and cache.get(key) store and retrieve values

sha256:4889208dd521d04e712cd35ec4b50e62c5f5f738754494631e6701226e613c9a

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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@6.0.0
包
创建时间
2026-08-21T13:50:43Z

契约

  1. cache.set(key, value) and cache.get(key) store and retrieve values
  2. cache.has(key) returns true for existing keys and false for missing keys
  3. cache.del(key) removes the key and reduces itemCount
  4. cache evicts the least recently used item when max capacity is exceeded
  5. cache.get(key) updates recency so the accessed item is not evicted next
  6. cache.reset() clears all cached entries and resets itemCount to 0
  7. cache.keys() and cache.values() return active keys and values in recency order

文件

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

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

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:47e1a2affbbb295cb66ba426707a9aaee4bcd3db7fed3b64b5c386801487e487","contract":["cache.set(key, value) and cache.get(key) store and retrieve values","cache.has(key) returns true for existing keys and false for missing keys","cache.del(key) removes the key and reduces itemCount","cache evicts the least recently used item when max capacity is exceeded","cache.get(key) updates recency so the accessed item is not evicted next","cache.reset() clears all cached entries and resets itemCount to 0","cache.keys() and cache.values() return active keys and values in recency order"],"goal":"verify pkg:npm/lru-cache@6.0.0","kind":"HOW","packages":["pkg:npm/lru-cache@6.0.0"],"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@6.0.0"],"schemaVersion":1,"subject":"pkg:npm/lru-cache@6.0.0","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": "6.0.0"
      }
    },
    "node_modules/lru-cache": {
      "version": "6.0.0",
      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
      "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
      "license": "ISC",
      "dependencies": {
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/yallist": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
      "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
      "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": "6.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/lru-cache@6.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/lru-cache@6.0.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import LRU from 'lru-cache';
import { createCache } from '../index.mjs';

// 1. cache.set(key, value) and cache.get(key) store and retrieve values
const cache = createCache({ max: 3 });
cache.set('a', 'alpha');
cache.set('b', 'beta');
assert.equal(cache.get('a'), 'alpha');
assert.equal(cache.get('b'), 'beta');
assert.equal(cache.get('c'), undefined);

// 2. cache.has(key) returns true for existing keys and false for missing keys
assert.equal(cache.has('a'), true);
assert.equal(cache.has('b'), true);
assert.equal(cache.has('missing'), false);

// 3. cache.del(key) removes the key and reduces itemCount
assert.equal(cache.itemCount, 2);
cache.del('b');
assert.equal(cache.has('b'), false);
assert.equal(cache.get('b'), undefined);
assert.equal(cache.itemCount, 1);

// 4. cache evicts the least recently used item when max capacity is exceeded
const smallCache = new LRU({ max: 2 });
smallCache.set('x', 1);
smallCache.set('y', 2);
smallCache.set('z', 3);
assert.equal(smallCache.has('x'), false);
assert.equal(smallCache.get('y'), 2);
assert.equal(smallCache.get('z'), 3);
assert.equal(smallCache.itemCount, 2);

// 5. cache.get(key) updates recency so the accessed item is not evicted next
const lruCache = new LRU({ max: 2 });
lruCache.set('first', '1');
lruCache.set('second', '2');
lruCache.get('first');
lruCache.set('third', '3');
assert.equal(lruCache.has('second'), false);
assert.equal(lruCache.has('first'), true);
assert.equal(lruCache.has('third'), true);

// 6. cache.reset() clears all cached entries and resets itemCount to 0
lruCache.reset();
assert.equal(lruCache.itemCount, 0);
assert.equal(lruCache.has('first'), false);
assert.equal(lruCache.has('third'), false);

// 7. cache.keys() and cache.values() return active keys and values in recency order
const iterCache = new LRU({ max: 3 });
iterCache.set('k1', 'v1');
iterCache.set('k2', 'v2');
iterCache.set('k3', 'v3');
assert.deepEqual(Array.from(iterCache.keys()), ['k3', 'k2', 'k1']);
assert.deepEqual(Array.from(iterCache.values()), ['v3', 'v2', 'v1']);

console.log('All lru-cache@6.0.0 contract assertions passed.');

原始种子者

匿名