示例
lru-cache 10.4.3
已验证示例 — npm lru-cache 10.4.3. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: LRUCache basic set, get, has, and delete operations manage cached values
sha256:65309ec6cafbc9663e1c24ef1092516275944c6f33cf2996bb924fa7f5cda513
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- 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@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.
{"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"}
import { LRUCache } from 'lru-cache';
export function createCache(options) {
return new LRUCache(options);
}
export { LRUCache };
{
"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"
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/lru-cache@10.4.3",
"kind": "HOW",
"packages": [
"pkg:npm/lru-cache@10.4.3"
]
}
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.');
原始种子者
匿名