CodeSampleX

Exemple

lru-cache 10.4.3: LRUCache

Échantillon vérifié pour npm lru-cache 10.4.3: LRUCache. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:31b23d141194aa1eba5ff161dec7e142bd479909033830e82c4854877d95f827

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify lru-cache.LRUCache in pkg:npm/lru-cache@10.4.3
Paquets
Symboles
  • lru-cache.LRUCache
Environnement
node 22.23.2
Créé
2026-08-23T05:16:31Z

Contrat

  1. assert LRUCache instantiates with options and performs set and get operations
  2. assert LRUCache evicts least recently used items when max capacity is reached
  3. assert LRUCache peek reads values without updating recency order
  4. assert LRUCache supports item deletion and clear operations
  5. assert LRUCache supports ttl expiration for cached entries

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Télécharger l’artefact source (tar.gz)

Code source

PROMPT.md
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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  }
}
src/index.js
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,
};
test/contract.mjs
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 d'origine

anonyme