示例
lru-cache 5.1.1
已验证示例 — npm lru-cache 5.1.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: LRUCache get and set store and retrieve key-value pairs while respecting…
sha256:33f47a04a5ae9b9d961ce0a162da870061652a08dbe1a0d76c4ecc3e2e425ad1
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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@5.1.1
- 创建时间
- 2026-08-21T13:48:28Z
契约
- 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
文件
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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.
{"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"}
import LRU from "lru-cache";
export function createCache(options) {
return new LRU(options);
}
{
"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"
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/lru-cache@5.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/lru-cache@5.1.1"
]
}
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.");
原始种子者
匿名