Sample
http-cache-semantics 4.2.0: stale
Verified sample for npm http-cache-semantics 4.2.0: stale. The contract ran on node 22 · linux debian/x64 · docker and passed.
sha256:0fd61ab36cb50efacd3bfca6b64a13ace3da820fd576b9c192d7b6206f2262d3
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-06 |
Case
HOW- Goal
- verify http-cache-semantics.stale in pkg:npm/http-cache-semantics@4.2.0
- Packages
- Symbols
-
- http-cache-semantics.stale
- Environment
- node 22.23.2
- Created
- 2026-09-06T02:55:58Z
Contract
- stale returns false when response has unexpired max-age and zero age
- stale returns true when response has max-age set to zero
- stale returns true when response age header exceeds max-age
- stale returns false when response age header is below max-age
- stale transitions from false to true when cache resident time exceeds max-age
- stale returns true when response contains no-cache directive
- stale returns true when response contains no-store directive
- stale returns true in shared cache when s-maxage is exceeded even if max-age is unexpired
- stale returns false in private cache when s-maxage is exceeded but max-age is unexpired
- stale returns true when response Expires header is in the past
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Source
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.stale 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.stale
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:65bb070a17fe1b6b168dd7c5f532a9ef7e7b270b3027a9b1421ee8d1980fcffe","contract":["stale returns false when response has unexpired max-age and zero age","stale returns true when response has max-age set to zero","stale returns true when response age header exceeds max-age","stale returns false when response age header is below max-age","stale transitions from false to true when cache resident time exceeds max-age","stale returns true when response contains no-cache directive","stale returns true when response contains no-store directive","stale returns true in shared cache when s-maxage is exceeded even if max-age is unexpired","stale returns false in private cache when s-maxage is exceeded but max-age is unexpired","stale returns true when response Expires header is in the past"],"goal":"verify http-cache-semantics.stale 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.stale"]},"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.stale"],"verifierAdapter":"node-typescript@1"}
{
"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"
}
}
}
{
"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"
}
}
{
"schemaVersion": 1,
"goal": "verify http-cache-semantics.stale in pkg:npm/http-cache-semantics@4.2.0",
"kind": "HOW",
"packages": [
"pkg:npm/http-cache-semantics@4.2.0"
],
"symbols": [
"http-cache-semantics.stale"
]
}
'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);
}
/**
* Determines whether a cached response is stale.
*
* @param {CachePolicy} policy - CachePolicy instance.
* @returns {boolean} True if the cached response is past its expiration.
*/
function isStale(policy) {
return policy.stale();
}
module.exports = {
CachePolicy,
createPolicy,
isStale,
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { CachePolicy, createPolicy, isStale } = require('../src/index.js');
async function testAll() {
// Export and symbol 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 isStale, 'function', 'isStale should be a function');
assert.equal(typeof CachePolicy.prototype.stale, 'function', 'CachePolicy.prototype.stale must be a function');
const baseReq = {
url: '/api/resource',
method: 'GET',
headers: { host: 'example.com' },
};
// 1. stale returns false when response has unexpired max-age and zero age
{
const res = {
status: 200,
headers: {
'cache-control': 'public, max-age=3600',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), false);
assert.equal(isStale(policy), false);
}
// 2. stale returns true when response has max-age set to zero
{
const res = {
status: 200,
headers: {
'cache-control': 'public, max-age=0',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 3. stale returns true when response age header exceeds max-age
{
const res = {
status: 200,
headers: {
'cache-control': 'public, max-age=60',
age: '120',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 4. stale returns false when response age header is below max-age
{
const res = {
status: 200,
headers: {
'cache-control': 'public, max-age=120',
age: '30',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), false);
assert.equal(isStale(policy), false);
}
// 5. stale transitions from false to true when cache resident time exceeds max-age
{
const res = {
status: 200,
headers: {
'cache-control': 'public, max-age=10',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), false);
assert.equal(isStale(policy), false);
const initialNow = policy.now();
policy.now = () => initialNow + 15000;
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 6. stale returns true when response contains no-cache directive
{
const res = {
status: 200,
headers: {
'cache-control': 'no-cache',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 7. stale returns true when response contains no-store directive
{
const res = {
status: 200,
headers: {
'cache-control': 'no-store',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 8. stale returns true in shared cache when s-maxage is exceeded even if max-age is unexpired
{
const res = {
status: 200,
headers: {
'cache-control': 'public, s-maxage=10, max-age=3600',
age: '25',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
// 9. stale returns false in private cache when s-maxage is exceeded but max-age is unexpired
{
const res = {
status: 200,
headers: {
'cache-control': 'public, s-maxage=10, max-age=3600',
age: '25',
},
};
const policy = createPolicy(baseReq, res, { shared: false });
assert.equal(policy.stale(), false);
assert.equal(isStale(policy), false);
}
// 10. stale returns true when response Expires header is in the past
{
const res = {
status: 200,
headers: {
expires: 'Mon, 01 Jan 1990 00:00:00 GMT',
},
};
const policy = createPolicy(baseReq, res);
assert.equal(policy.stale(), true);
assert.equal(isStale(policy), true);
}
console.log('All http-cache-semantics stale contract assertions passed.');
}
testAll().catch((err) => {
console.error('Contract test failure:', err);
process.exit(1);
});
Origin Seeder
anonymous