示例
lru-cache 10.4.3: LRUCache
已验证示例 — npm lru-cache 10.4.3: LRUCache. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: assert LRUCache instantiates with options and performs set and…
sha256:31b23d141194aa1eba5ff161dec7e142bd479909033830e82c4854877d95f827
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-23 |
| 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 lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3
- 符号
-
- lru-cache.LRUCache
- 环境
- node 22.23.2
- 创建时间
- 2026-08-23T05:16:31Z
契约
- assert LRUCache instantiates with options and performs set and get operations
- assert LRUCache evicts least recently used items when max capacity is reached
- assert LRUCache peek reads values without updating recency order
- assert LRUCache supports item deletion and clear operations
- assert LRUCache supports ttl expiration for cached entries
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/lru-cache@10.4.3
Demonstrate these symbols/APIs:
- lru-cache.LRUCache
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:819931733a12c835847bd0bfe51248ac0cdffe8dc13a96403713298a29e3c887","constraints":{"executionContext":"node"},"contract":["assert LRUCache instantiates with options and performs set and get operations","assert LRUCache evicts least recently used items when max capacity is reached","assert LRUCache peek reads values without updating recency order","assert LRUCache supports item deletion and clear operations","assert LRUCache supports ttl expiration for cached entries"],"goal":"verify lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3","kind":"HOW","packages":["pkg:npm/lru-cache@10.4.3"],"schemaVersion":1,"symbols":["lru-cache.LRUCache"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/lru-cache@10.4.3"],"schemaVersion":1,"subject":"pkg:npm/lru-cache@10.4.3","symbols":["lru-cache.LRUCache"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-lru-cache-lrucache",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-lru-cache-lrucache",
"version": "1.0.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-lrucache",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of lru-cache LRUCache",
"main": "src/index.js",
"dependencies": {
"lru-cache": "10.4.3"
}
}
{
"schemaVersion": 1,
"goal": "verify lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3",
"kind": "HOW",
"packages": [
"pkg:npm/lru-cache@10.4.3"
],
"symbols": [
"lru-cache.LRUCache"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const { LRUCache } = require('lru-cache');
/**
* Create a new LRUCache instance with given options.
* @param {object} options
* @returns {LRUCache}
*/
function createCache(options = {}) {
return new LRUCache(options);
}
module.exports = {
LRUCache,
createCache,
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { LRUCache, createCache } = require('../src/index.js');
// 1. assert LRUCache instantiates with options and performs set and get operations
{
const cache = createCache({ max: 10 });
assert.ok(cache instanceof LRUCache, 'cache should be an instance of LRUCache');
cache.set('key1', 'value1');
assert.equal(cache.get('key1'), 'value1', 'get should retrieve the stored value');
assert.equal(cache.has('key1'), true, 'has should return true for stored key');
assert.equal(cache.size, 1, 'size should reflect number of stored items');
}
// 2. assert LRUCache evicts least recently used items when max capacity is reached
{
const cache = new LRUCache({ max: 2 });
cache.set('a', 1);
cache.set('b', 2);
cache.get('a'); // 'a' accessed, so 'b' becomes least recently used
cache.set('c', 3); // causes 'b' to be evicted
assert.equal(cache.get('a'), 1, 'key a should remain in cache');
assert.equal(cache.get('c'), 3, 'key c should be stored in cache');
assert.equal(cache.has('b'), false, 'key b should be evicted');
assert.equal(cache.get('b'), undefined, 'get on evicted key b should return undefined');
assert.equal(cache.size, 2, 'cache size should not exceed max');
}
// 3. assert LRUCache peek reads values without updating recency order
{
const cache = new LRUCache({ max: 2 });
cache.set('a', 1);
cache.set('b', 2);
// peek 'a' does not refresh 'a' recency, so 'a' remains older than 'b'
const peekVal = cache.peek('a');
assert.equal(peekVal, 1, 'peek should return the value');
cache.set('c', 3); // 'a' is evicted because it was not refreshed by peek
assert.equal(cache.has('a'), false, 'key a should have been evicted');
assert.equal(cache.has('b'), true, 'key b should remain in cache');
assert.equal(cache.has('c'), true, 'key c should remain in cache');
}
// 4. assert LRUCache supports item deletion and clear operations
{
const cache = new LRUCache({ max: 5 });
cache.set('x', 10);
cache.set('y', 20);
assert.equal(cache.size, 2);
const deleted = cache.delete('x');
assert.equal(deleted, true, 'delete should return true for deleted key');
assert.equal(cache.has('x'), false, 'has should return false after delete');
assert.equal(cache.size, 1);
cache.clear();
assert.equal(cache.size, 0, 'size should be 0 after clear');
assert.equal(cache.has('y'), false, 'all keys should be removed after clear');
}
// 5. assert LRUCache supports ttl expiration for cached entries
{
const cache = new LRUCache({ max: 5, ttl: 50 });
cache.set('temp', 'temporary-val');
assert.equal(cache.get('temp'), 'temporary-val', 'value should be available immediately');
// Wait for TTL expiration
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(cache.get('temp'), undefined, 'expired item should return undefined');
assert.equal(cache.has('temp'), false, 'has should return false for expired item');
}
console.log('All LRUCache contract assertions passed successfully.');
原始种子者
匿名