CodeSampleX

Sample

http-cache-semantics 4.2.0: revalidatedPolicy

Verified sample for npm http-cache-semantics 4.2.0: revalidatedPolicy. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:56c83a50497ee1a3a2c7da46aa777e25ed4daf1e0904f4a3bb49e0a83672f3d4

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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-05

Case

HOW
Goal
verify http-cache-semantics.revalidatedPolicy in pkg:npm/http-cache-semantics@4.2.0
Packages
Symbols
  • http-cache-semantics.revalidatedPolicy
Environment
node 22.23.2
Created
2026-09-05T23:09:52Z

Contract

  1. revalidatedPolicy returns matches=true and modified=false when 304 response validator matches stored response
  2. revalidatedPolicy updates stored response headers with headers provided in the 304 response
  3. revalidatedPolicy returns matches=false and modified=true when response status is 200 indicating modified resource
  4. revalidatedPolicy throws Error when response headers or request headers are missing

Files

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

Download the source artifact (tar.gz)

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 http-cache-semantics.revalidatedPolicy in pkg:npm/http-cache-semantics@4.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/http-cache-semantics@4.2.0
Demonstrate these symbols/APIs:
  - http-cache-semantics.revalidatedPolicy

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:f505829e2e4bcee9f83f2d6527cbf013e847cac0a23a444beb723549d56bec4c","constraints":{"executionContext":"node"},"contract":["revalidatedPolicy returns matches=true and modified=false when 304 response validator matches stored response","revalidatedPolicy updates stored response headers with headers provided in the 304 response","revalidatedPolicy returns matches=false and modified=true when response status is 200 indicating modified resource","revalidatedPolicy throws Error when response headers or request headers are missing"],"goal":"verify http-cache-semantics.revalidatedPolicy in pkg:npm/http-cache-semantics@4.2.0","kind":"HOW","packages":["pkg:npm/http-cache-semantics@4.2.0"],"schemaVersion":1,"symbols":["http-cache-semantics.revalidatedPolicy"]},"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/http-cache-semantics@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/http-cache-semantics@4.2.0","symbols":["http-cache-semantics.revalidatedPolicy"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-http-cache-semantics",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-http-cache-semantics",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "http-cache-semantics": "4.2.0"
      }
    },
    "node_modules/http-cache-semantics": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.2.0.tgz",
      "integrity": "sha512-dTxcvPXqPvXBQpq5dUr6mEMJX4oIEFv6bwom3FDwKRDsuIjjJGANqhBuoAn9c1RQJIdAKav33ED65E2ys+87QQ==",
      "license": "BSD-2-Clause"
    }
  }
}
package.json
{
  "name": "sample-http-cache-semantics",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for http-cache-semantics@4.2.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "http-cache-semantics": "4.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify http-cache-semantics.revalidatedPolicy in pkg:npm/http-cache-semantics@4.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/http-cache-semantics@4.2.0"
  ],
  "symbols": [
    "http-cache-semantics.revalidatedPolicy"
  ]
}
src/index.js
'use strict';

const CachePolicy = require('http-cache-semantics');

/**
 * Creates a new CachePolicy instance.
 *
 * @param {object} req - HTTP request representation.
 * @param {object} res - HTTP response representation.
 * @param {object} [options] - Cache policy options.
 * @returns {CachePolicy} The created cache policy.
 */
function createPolicy(req, res, options) {
  return new CachePolicy(req, res, options);
}

/**
 * Revalidates a cached response policy using a revalidation request and server response.
 *
 * @param {CachePolicy} policy - Current CachePolicy instance.
 * @param {object} revalReq - HTTP request sent to revalidate.
 * @param {object} revalRes - HTTP response received from the revalidation request.
 * @returns {{ policy: CachePolicy, modified: boolean, matches: boolean }} Revalidation outcome.
 */
function revalidate(policy, revalReq, revalRes) {
  return policy.revalidatedPolicy(revalReq, revalRes);
}

module.exports = {
  CachePolicy,
  createPolicy,
  revalidate,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { CachePolicy, createPolicy, revalidate } = require('../src/index.js');

async function testAll() {
  // 1. Export verification
  assert.equal(typeof CachePolicy, 'function', 'CachePolicy should be a constructor function');
  assert.equal(typeof createPolicy, 'function', 'createPolicy should be a function');
  assert.equal(typeof revalidate, 'function', 'revalidate should be a function');

  // 2. Initial cached response setup
  const req = {
    url: '/api/item',
    method: 'GET',
    headers: { host: 'example.com' },
  };
  const res = {
    status: 200,
    headers: {
      'cache-control': 'public, max-age=60',
      'etag': '"entity-v1"',
      'last-modified': 'Sat, 05 Sep 2026 12:00:00 GMT',
    },
  };
  const policy = createPolicy(req, res);
  assert.equal(policy.storable(), true, 'initial policy should be storable');

  // 3. Revalidation with matching 304 Not Modified
  const revalReq = {
    url: '/api/item',
    method: 'GET',
    headers: {
      host: 'example.com',
      'if-none-match': '"entity-v1"',
    },
  };
  const revalRes304 = {
    status: 304,
    headers: {
      'cache-control': 'public, max-age=300',
      'etag': '"entity-v1"',
    },
  };

  const res304 = revalidate(policy, revalReq, revalRes304);
  assert.equal(res304.matches, true, 'matches should be true when 304 validator matches');
  assert.equal(res304.modified, false, 'modified should be false when 304 Not Modified received');
  assert.ok(res304.policy instanceof CachePolicy, 'revalidated policy should be a CachePolicy instance');
  assert.equal(
    res304.policy.responseHeaders()['cache-control'],
    'public, max-age=300',
    'revalidated policy should update response headers from 304 response'
  );

  // 4. Revalidation with 200 OK (modified content)
  const revalRes200 = {
    status: 200,
    headers: {
      'cache-control': 'public, max-age=180',
      'etag': '"entity-v2"',
    },
  };

  const res200 = revalidate(policy, revalReq, revalRes200);
  assert.equal(res200.matches, false, 'matches should be false when response status is 200');
  assert.equal(res200.modified, true, 'modified should be true when response status is 200');
  assert.ok(res200.policy instanceof CachePolicy, 'revalidated policy should be a CachePolicy instance');

  // 5. Missing headers error handling
  assert.throws(
    () => revalidate(policy, revalReq, { status: 200 }),
    /Response headers missing/,
    'revalidatedPolicy should throw Error when response headers are missing'
  );

  assert.throws(
    () => revalidate(policy, { url: '/api/item' }, revalRes304),
    /Request headers missing/,
    'revalidatedPolicy should throw Error when request headers are missing'
  );

  console.log('All http-cache-semantics revalidatedPolicy contract assertions passed.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

Origin Seeder

anonymous