Ejemplo
toad-cache 3.7.4: HitStatisticsRecord
Muestra verificada para npm toad-cache 3.7.4: HitStatisticsRecord. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.
sha256:9ef29f25556ee033d781a8ad0ed972e6473aa612c0904b7d14193cc07f968c56
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-23 |
Caso
HOW- Objetivo
- verify toad-cache.HitStatisticsRecord in pkg:npm/toad-cache@3.7.4
- Paquetes
- Símbolos
-
- toad-cache.HitStatisticsRecord
- Entorno
- node 22.23.2
- Creado
- 2026-11-23T15:51:08Z
Contrato
- new HitStatisticsRecord() initializes an empty records map and getStatistics() returns the live records object
- initForCache(cacheId, timestamp) creates a zeroed 10-field statistics bucket and replaces prior timestamps for that cacheId on re-initialization
- resetForCache(cacheId) is a no-op for unknown cacheIds and zeroes all timestamp buckets for an existing cacheId without altering other caches
- sharing a HitStatisticsRecord across multiple LruObjectHitStatistics instances isolates per-cache counters under one getStatistics() map and supports per-cache resetForCache
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.cjs
- 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.HitStatisticsRecord 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.HitStatisticsRecord
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:95f071e592a17cff8059866c5b1a5a8d89613482fc23d447838151907fa1dfee","constraints":{"executionContext":"node"},"contract":["new HitStatisticsRecord() initializes an empty records map and getStatistics() returns the live records object","initForCache(cacheId, timestamp) creates a zeroed 10-field statistics bucket and replaces prior timestamps for that cacheId on re-initialization","resetForCache(cacheId) is a no-op for unknown cacheIds and zeroes all timestamp buckets for an existing cacheId without altering other caches","sharing a HitStatisticsRecord across multiple LruObjectHitStatistics instances isolates per-cache counters under one getStatistics() map and supports per-cache resetForCache"],"goal":"verify toad-cache.HitStatisticsRecord in pkg:npm/toad-cache@3.7.4","kind":"HOW","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"symbols":["toad-cache.HitStatisticsRecord"]},"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.HitStatisticsRecord"],"verifierAdapter":"node-typescript@1"}
{
"name": "toad-cache-hit-statistics-record-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "toad-cache-hit-statistics-record-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-hit-statistics-record-sample",
"version": "1.0.0",
"private": true,
"description": "Minimal sample verifying toad-cache HitStatisticsRecord initialization, shared cache statistics aggregation, and per-cache reset",
"main": "src/index.cjs",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"toad-cache": "3.7.4"
}
}
{
"schemaVersion": 1,
"goal": "verify toad-cache.HitStatisticsRecord in pkg:npm/toad-cache@3.7.4",
"kind": "HOW",
"packages": [
"pkg:npm/toad-cache@3.7.4"
],
"symbols": [
"toad-cache.HitStatisticsRecord"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { HitStatisticsRecord, LruObjectHitStatistics } = require('toad-cache');
function createSharedStatisticsRecord() {
return new HitStatisticsRecord();
}
function createTrackedCache(cacheId, sharedRecord, options = {}) {
const {
max = 100,
ttlInMsecs = 0,
statisticTtlInHours = 24,
} = options;
return new LruObjectHitStatistics(
max,
ttlInMsecs,
cacheId,
sharedRecord,
statisticTtlInHours,
);
}
module.exports = {
HitStatisticsRecord,
createSharedStatisticsRecord,
createTrackedCache,
};
'use strict';
const assert = require('node:assert/strict');
const {
HitStatisticsRecord,
createSharedStatisticsRecord,
createTrackedCache,
} = require('../src/index.cjs');
const ZERO_STATS = {
cacheSize: 0,
hits: 0,
falsyHits: 0,
emptyHits: 0,
misses: 0,
expirations: 0,
evictions: 0,
invalidateOne: 0,
invalidateAll: 0,
sets: 0,
};
// 1. Fresh HitStatisticsRecord starts empty and getStatistics() returns live records
const directRecord = new HitStatisticsRecord();
assert.deepEqual(directRecord.records, {});
assert.equal(directRecord.getStatistics(), directRecord.records);
// 2. initForCache creates a zeroed bucket and replaces prior timestamps on re-init
directRecord.initForCache('alpha', '2026-01-01');
assert.deepEqual(directRecord.getStatistics(), {
alpha: {
'2026-01-01': ZERO_STATS,
},
});
directRecord.records.alpha['2026-01-01'].hits = 4;
directRecord.initForCache('alpha', '2026-01-02');
assert.deepEqual(directRecord.getStatistics(), {
alpha: {
'2026-01-02': ZERO_STATS,
},
});
// 3. resetForCache is a safe no-op for unknown cacheIds
directRecord.resetForCache('nonexistent');
assert.equal('nonexistent' in directRecord.getStatistics(), false);
// 4. resetForCache zeroes all timestamp buckets for the target cacheId only
directRecord.initForCache('beta', '2026-01-02');
directRecord.records.alpha['2026-01-02'].hits = 3;
directRecord.records.alpha['2026-01-02'].misses = 2;
directRecord.records.alpha['2026-01-03'] = { ...ZERO_STATS, sets: 5 };
directRecord.records.beta['2026-01-02'].hits = 7;
directRecord.resetForCache('alpha');
assert.deepEqual(directRecord.getStatistics().alpha, {
'2026-01-02': ZERO_STATS,
'2026-01-03': ZERO_STATS,
});
assert.equal(directRecord.getStatistics().beta['2026-01-02'].hits, 7);
// 5. Shared HitStatisticsRecord across multiple LruObjectHitStatistics caches
const sharedRecord = createSharedStatisticsRecord();
const cacheA = createTrackedCache('cache-a', sharedRecord, { max: 2, ttlInMsecs: 0 });
const cacheB = createTrackedCache('cache-b', sharedRecord, { max: 5, ttlInMsecs: 0 });
assert.equal(cacheA.getStatistics(), sharedRecord.getStatistics());
assert.equal(cacheB.getStatistics(), sharedRecord.getStatistics());
cacheA.set('k1', 'v1');
cacheA.set('k2', '');
cacheA.set('k3', 0); // triggers eviction of k1 (max = 2)
assert.equal(cacheA.get('k2'), ''); // hit + falsyHit + emptyHit
assert.equal(cacheA.get('k3'), 0); // hit + falsyHit
assert.equal(cacheA.get('missing'), undefined); // miss
cacheA.delete('k3'); // invalidateOne
cacheA.clear(); // invalidateAll
cacheB.set('item', 'ok');
assert.equal(cacheB.get('item'), 'ok');
const stats = sharedRecord.getStatistics();
const [stampA] = Object.keys(stats['cache-a']);
const [stampB] = Object.keys(stats['cache-b']);
assert.ok(stampA, 'expected timestamp key for cache-a');
assert.ok(stampB, 'expected timestamp key for cache-b');
assert.deepEqual(stats['cache-a'][stampA], {
cacheSize: 0,
hits: 2,
falsyHits: 2,
emptyHits: 1,
misses: 1,
expirations: 0,
evictions: 1,
invalidateOne: 1,
invalidateAll: 1,
sets: 3,
});
assert.deepEqual(stats['cache-b'][stampB], {
...ZERO_STATS,
cacheSize: 1,
hits: 1,
sets: 1,
});
// Resetting cache-a clears its counters while leaving cache-b intact
sharedRecord.resetForCache('cache-a');
assert.deepEqual(sharedRecord.getStatistics()['cache-a'][stampA], ZERO_STATS);
assert.equal(sharedRecord.getStatistics()['cache-b'][stampB].hits, 1);
assert.equal(sharedRecord.getStatistics()['cache-b'][stampB].sets, 1);
console.log('PASS: toad-cache.HitStatisticsRecord contract verified');
Seeder de origen
anónimo