Ejemplo
toad-cache 3.7.4: Fifo
Muestra verificada para npm toad-cache 3.7.4: Fifo. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: require('toad-cache').Fifo ===…
sha256:70499ec27c27b607bbb7223d6935228f3556a5d8b67d5305dcd5cfc57f3645aa
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
- 1
- 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-21 |
Caso
HOW- Objetivo
- verify toad-cache.Fifo in pkg:npm/toad-cache@3.7.4
- Paquetes
- Símbolos
-
- toad-cache.Fifo
- Entorno
- node 22.23.2
- Creado
- 2026-11-21T23:30:57Z
Contrato
- require('toad-cache').Fifo === require('toad-cache').FifoObject and defaults to max=1000, ttl=0, size=0
- new Fifo(max, ttlInMsecs) throws 'Invalid max value' or 'Invalid ttl value' for negative or non-integer inputs and treats max=0 as unlimited
- Fifo evicts the oldest inserted entry when size reaches max even after get() or set() overwrite on that key
- getMany, delete, deleteMany, evict (including no-op when empty), keys, clear, and null-prototype keys like 'toString' maintain accurate size and contents
- With ttlInMsecs > 0, expiresAt returns insertion/update timestamp plus ttl, set() on an existing key refreshes expiry, and get() deletes and returns undefined when Date.now() >= expiry
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.cjs
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 toad-cache.Fifo 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.Fifo
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:55748514f455a4fe385561b72df9937c98b22a9a50953367e737bb74406beb5e","constraints":{"executionContext":"node"},"contract":["require('toad-cache').Fifo === require('toad-cache').FifoObject and defaults to max=1000, ttl=0, size=0","new Fifo(max, ttlInMsecs) throws 'Invalid max value' or 'Invalid ttl value' for negative or non-integer inputs and treats max=0 as unlimited","Fifo evicts the oldest inserted entry when size reaches max even after get() or set() overwrite on that key","getMany, delete, deleteMany, evict (including no-op when empty), keys, clear, and null-prototype keys like 'toString' maintain accurate size and contents","With ttlInMsecs \u003e 0, expiresAt returns insertion/update timestamp plus ttl, set() on an existing key refreshes expiry, and get() deletes and returns undefined when Date.now() \u003e= expiry"],"goal":"verify toad-cache.Fifo in pkg:npm/toad-cache@3.7.4","kind":"HOW","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"symbols":["toad-cache.Fifo"]},"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.Fifo"],"verifierAdapter":"node-typescript@1"}
{
"name": "toad-cache-fifo-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "toad-cache-fifo-sample",
"version": "1.0.0",
"license": "MIT-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-fifo-sample",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"toad-cache": "3.7.4"
}
}
{
"schemaVersion": 1,
"goal": "verify toad-cache.Fifo in pkg:npm/toad-cache@3.7.4",
"kind": "HOW",
"packages": [
"pkg:npm/toad-cache@3.7.4"
],
"symbols": [
"toad-cache.Fifo"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { Fifo } = require('toad-cache');
function createFifoCache(max, ttlInMsecs) {
return new Fifo(max, ttlInMsecs);
}
module.exports = {
createFifoCache,
};
'use strict';
const assert = require('node:assert/strict');
const { Fifo, FifoObject } = require('toad-cache');
const { createFifoCache } = require('../src/index.js');
// 1. Export identity and default constructor values
assert.strictEqual(Fifo, FifoObject);
const defaultCache = createFifoCache();
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
assert.throws(() => new Fifo(-1), /Invalid max value/);
assert.throws(() => new Fifo(1.5), /Invalid max value/);
assert.throws(() => new Fifo('2'), /Invalid max value/);
assert.throws(() => new Fifo(NaN), /Invalid max value/);
assert.throws(() => new Fifo(10, -1), /Invalid ttl value/);
assert.throws(() => new Fifo(10, 0.5), /Invalid ttl value/);
assert.throws(() => new Fifo(10, null), /Invalid ttl value/);
// 3. max = 0 allows unlimited entries; ttl = 0 sets expiry to 0
const unlimited = createFifoCache(0, 0);
unlimited.set('k1', 'v1');
unlimited.set('k2', 'v2');
unlimited.set('k3', 'v3');
assert.strictEqual(unlimited.size, 3);
assert.strictEqual(unlimited.expiresAt('k1'), 0);
assert.strictEqual(unlimited.expiresAt('missing'), undefined);
// 4. Strict FIFO eviction: get() and set() overwrite do not change queue order
const fifo = createFifoCache(2, 0);
fifo.set('a', 1);
fifo.set('b', 2);
assert.strictEqual(fifo.get('a'), 1);
fifo.set('a', 10);
assert.strictEqual(fifo.size, 2);
assert.strictEqual(fifo.get('a'), 10);
// Adding 'c' evicts 'a' (oldest inserted), keeping 'b' and 'c'
fifo.set('c', 3);
assert.strictEqual(fifo.size, 2);
assert.strictEqual(fifo.get('a'), undefined);
assert.deepStrictEqual(fifo.getMany(['a', 'b', 'c']), [undefined, 2, 3]);
assert.deepStrictEqual(fifo.keys(), ['b', 'c']);
// 5. Manual evict(), delete(), deleteMany(), clear(), and prototype-name keys
fifo.evict();
assert.strictEqual(fifo.size, 1);
assert.strictEqual(fifo.get('b'), undefined);
assert.strictEqual(fifo.get('c'), 3);
fifo.set('toString', 'safe-value');
assert.strictEqual(fifo.get('toString'), 'safe-value');
assert.strictEqual(fifo.size, 2);
fifo.delete('missing');
assert.strictEqual(fifo.size, 2);
fifo.deleteMany(['c', 'toString']);
assert.strictEqual(fifo.size, 0);
assert.strictEqual(fifo.first, null);
assert.strictEqual(fifo.last, null);
// evict() on empty cache is a no-op
fifo.evict();
assert.strictEqual(fifo.size, 0);
fifo.set('x', 100);
fifo.set('y', 200);
fifo.clear();
assert.strictEqual(fifo.size, 0);
assert.deepStrictEqual(fifo.keys(), []);
// 6. TTL expiration and expiry refresh on overwrite (deterministic clock)
const realDateNow = Date.now;
let now = 1_700_000_000_000;
Date.now = () => now;
try {
const timed = createFifoCache(3, 500);
timed.set('session', 'alpha');
assert.strictEqual(timed.expiresAt('session'), now + 500);
assert.strictEqual(timed.get('session'), 'alpha');
// Overwriting refreshes expiry without adding a duplicate entry
now += 300;
timed.set('session', 'beta');
assert.strictEqual(timed.size, 1);
assert.strictEqual(timed.expiresAt('session'), now + 500);
// Still valid before refreshed expiry
now += 499;
assert.strictEqual(timed.get('session'), 'beta');
// Expired at exact boundary (item.expiry <= Date.now()) and deleted on read
now += 1;
assert.strictEqual(timed.get('session'), undefined);
assert.strictEqual(timed.size, 0);
assert.strictEqual(timed.expiresAt('session'), undefined);
} finally {
Date.now = realDateNow;
}
console.log('toad-cache.Fifo contract passed');
Seeder de origen
anónimo