Ejemplo
lru-cache 10.4.3: LRUCache
Muestra verificada para npm lru-cache 10.4.3: LRUCache. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: assert LRUCache instantiates…
sha256:31b23d141194aa1eba5ff161dec7e142bd479909033830e82c4854877d95f827
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 2
- Claves de firma que lo compilaron
- 1
Entorno declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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 |
Caso
HOW- Objetivo
- verify lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3
- Paquetes
- Símbolos
-
- lru-cache.LRUCache
- Entorno
- node 22.23.2
- Creado
- 2026-08-23T05:16:31Z
Contrato
- 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
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código fuente
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.');
Seeder de origen
anónimo