Exemplo
toad-cache 3.7.4: Lru
Amostra verificada para npm toad-cache 3.7.4: Lru. O contrato rodou em node 22 · linux debian/x64 · docker e passou: require('toad-cache').Lru is exported as…
sha256:0133ec9182b709c9486099c2a69c82fd329ace98263430a986f276e3d404d57b
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-11-29 |
Caso
HOW- Objetivo
- verify toad-cache.Lru in pkg:npm/toad-cache@3.7.4
- Pacotes
- Símbolos
-
- toad-cache.Lru
- Ambiente
- node 22.23.2
- Criado
- 2026-11-29T01:20:01Z
Contrato
- require('toad-cache').Lru is exported as an alias of LruObject with defaults max=1000, ttl=0, size=0
- new Lru(max, ttlInMsecs) throws 'Invalid max value' or 'Invalid ttl value' for negative, non-integer, or non-number inputs
- Lru stores and returns falsy values (0, '', false, null) and prototype-name keys like 'toString' while returning undefined for missing keys
- Lru(max) evicts the least-recently-used entry when inserting past max, and both get() and overwriting set() refresh entry recency
- Lru supports getMany(), keys(), evict(), delete(), deleteMany(), clear(), and unlimited capacity when max is 0
- Lru(max, ttlInMsecs) sets expiresAt(key) to Date.now() + ttlInMsecs and lazily deletes and returns undefined once Date.now() >= expiry
Arquivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
Código-fonte
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 toad-cache.Lru in pkg:npm/toad-cache@3.7.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/toad-cache@3.7.4
Demonstrate these symbols/APIs:
- toad-cache.Lru
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:145aaeaa691ea7a2f7f70cd211b041e1a27a562dc10a6e57e1178e8f05654950","constraints":{"executionContext":"node"},"contract":["require('toad-cache').Lru is exported as an alias of LruObject with defaults max=1000, ttl=0, size=0","new Lru(max, ttlInMsecs) throws 'Invalid max value' or 'Invalid ttl value' for negative, non-integer, or non-number inputs","Lru stores and returns falsy values (0, '', false, null) and prototype-name keys like 'toString' while returning undefined for missing keys","Lru(max) evicts the least-recently-used entry when inserting past max, and both get() and overwriting set() refresh entry recency","Lru supports getMany(), keys(), evict(), delete(), deleteMany(), clear(), and unlimited capacity when max is 0","Lru(max, ttlInMsecs) sets expiresAt(key) to Date.now() + ttlInMsecs and lazily deletes and returns undefined once Date.now() \u003e= expiry"],"goal":"verify toad-cache.Lru in pkg:npm/toad-cache@3.7.4","kind":"HOW","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"symbols":["toad-cache.Lru"]},"contractCommand":["node","test/contract.cjs"],"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/toad-cache@3.7.4"],"schemaVersion":1,"subject":"pkg:npm/toad-cache@3.7.4","symbols":["toad-cache.Lru"],"verifierAdapter":"node-typescript@1"}
'use strict';
const { Lru } = require('toad-cache');
function createLruCache(max, ttlInMsecs) {
return new Lru(max, ttlInMsecs);
}
module.exports = {
Lru,
createLruCache,
};
{
"name": "toad-cache-lru-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "toad-cache-lru-sample",
"version": "1.0.0",
"dependencies": {
"toad-cache": "3.7.4"
}
},
"node_modules/toad-cache": {
"version": "3.7.4",
"resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.4.tgz",
"integrity": "sha512-m1TdR/rvT7kgGJZhspNtXdsdYk0fddFpJJFlG5s+UkPFo6lkLoZ3YLOaovPYjq1R75NP5JfeTlSHaOsE09peCg==",
"license": "MIT",
"engines": {
"node": ">=20"
}
}
}
}
{
"name": "toad-cache-lru-sample",
"version": "1.0.0",
"private": true,
"main": "index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"toad-cache": "3.7.4"
}
}
{
"schemaVersion": 1,
"goal": "verify toad-cache.Lru in pkg:npm/toad-cache@3.7.4",
"kind": "HOW",
"packages": [
"pkg:npm/toad-cache@3.7.4"
],
"symbols": [
"toad-cache.Lru"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const assert = require('node:assert/strict');
const { Lru, LruObject } = require('toad-cache');
const { createLruCache } = require('../index.js');
// 1. Export identity and default constructor values
assert.strictEqual(Lru, LruObject);
const defaultCache = createLruCache();
assert.ok(defaultCache instanceof Lru);
assert.strictEqual(defaultCache.max, 1000);
assert.strictEqual(defaultCache.ttl, 0);
assert.strictEqual(defaultCache.size, 0);
assert.strictEqual(defaultCache.first, null);
assert.strictEqual(defaultCache.last, null);
// 2. Constructor parameter validation (non-negative integers required)
assert.throws(() => new Lru(-1), /Invalid max value/);
assert.throws(() => new Lru(1.5), /Invalid max value/);
assert.throws(() => new Lru('10'), /Invalid max value/);
assert.throws(() => new Lru(10, -1), /Invalid ttl value/);
assert.throws(() => new Lru(10, 0.5), /Invalid ttl value/);
assert.throws(() => new Lru(10, '50'), /Invalid ttl value/);
// 3. Basic set/get, falsy values, and prototype-safe keys
const basic = createLruCache(5, 0);
basic.set('zero', 0);
basic.set('empty', '');
basic.set('flag', false);
basic.set('nil', null);
basic.set('toString', 'safe');
assert.strictEqual(basic.size, 5);
assert.strictEqual(basic.get('zero'), 0);
assert.strictEqual(basic.get('empty'), '');
assert.strictEqual(basic.get('flag'), false);
assert.strictEqual(basic.get('nil'), null);
assert.strictEqual(basic.get('toString'), 'safe');
assert.strictEqual(basic.get('missing'), undefined);
assert.strictEqual(basic.expiresAt('zero'), 0);
assert.strictEqual(basic.expiresAt('missing'), undefined);
// 4. LRU eviction order on get() and set() updates
const lru = createLruCache(2, 0);
lru.set('a', 1);
lru.set('b', 2);
assert.strictEqual(lru.size, 2);
assert.strictEqual(lru.first.key, 'a');
assert.strictEqual(lru.last.key, 'b');
// Accessing 'a' promotes it to most-recently-used so 'b' becomes the eviction candidate
assert.strictEqual(lru.get('a'), 1);
assert.strictEqual(lru.first.key, 'b');
assert.strictEqual(lru.last.key, 'a');
// Adding 'c' evicts 'b'
lru.set('c', 3);
assert.strictEqual(lru.size, 2);
assert.strictEqual(lru.get('b'), undefined);
assert.strictEqual(lru.get('a'), 1);
assert.strictEqual(lru.get('c'), 3);
// Replacing an existing key updates its value without growing size and bumps recency
lru.set('a', 10);
assert.strictEqual(lru.size, 2);
assert.strictEqual(lru.last.key, 'a');
assert.strictEqual(lru.get('a'), 10);
// Adding 'd' now evicts 'c' (the least-recently-used entry)
lru.set('d', 4);
assert.strictEqual(lru.size, 2);
assert.strictEqual(lru.get('c'), undefined);
assert.deepStrictEqual(lru.getMany(['a', 'd', 'missing']), [10, 4, undefined]);
// 5. keys(), evict(), delete(), deleteMany(), clear()
const ops = createLruCache(4, 0);
ops.set('k1', 'v1');
ops.set('k2', 'v2');
ops.set('k3', 'v3');
ops.set('k4', 'v4');
assert.deepStrictEqual(ops.keys().sort(), ['k1', 'k2', 'k3', 'k4']);
ops.evict();
assert.strictEqual(ops.get('k1'), undefined);
assert.strictEqual(ops.size, 3);
ops.delete('k3');
assert.strictEqual(ops.get('k3'), undefined);
assert.strictEqual(ops.size, 2);
ops.deleteMany(['k2', 'nonexistent']);
assert.strictEqual(ops.size, 1);
assert.strictEqual(ops.get('k4'), 'v4');
ops.clear();
assert.strictEqual(ops.size, 0);
assert.strictEqual(ops.first, null);
assert.strictEqual(ops.last, null);
assert.deepStrictEqual(ops.keys(), []);
ops.evict(); // no-op on empty cache
assert.strictEqual(ops.size, 0);
// 6. Unlimited capacity when max is 0
const unlimited = createLruCache(0, 0);
unlimited.set('x', 1);
unlimited.set('y', 2);
unlimited.set('z', 3);
assert.strictEqual(unlimited.size, 3);
// 7. TTL expiration and expiresAt() behavior (deterministic clock)
const originalNow = Date.now;
let fakeNow = 1_700_000_000_000;
Date.now = () => fakeNow;
try {
const timed = createLruCache(3, 50);
timed.set('entry', 'val');
assert.strictEqual(timed.expiresAt('entry'), fakeNow + 50);
fakeNow += 49;
assert.strictEqual(timed.get('entry'), 'val');
assert.strictEqual(timed.size, 1);
fakeNow += 1; // now === expiry; item is expired and removed on get()
assert.strictEqual(timed.get('entry'), undefined);
assert.strictEqual(timed.size, 0);
assert.strictEqual(timed.expiresAt('entry'), undefined);
} finally {
Date.now = originalNow;
}
Seeder de origem
anônimo