サンプル
http-cache-semantics 4.2.0: revalidatedPolicy
検証済みサンプル — npm http-cache-semantics 4.2.0: revalidatedPolicy. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: revalidatedPolicy returns…
sha256:56c83a50497ee1a3a2c7da46aa777e25ed4daf1e0904f4a3bb49e0a83672f3d4
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- verify http-cache-semantics.revalidatedPolicy in pkg:npm/http-cache-semantics@4.2.0
- シンボル
-
- http-cache-semantics.revalidatedPolicy
- 環境
- node 22.23.2
- 作成日
- 2026-09-05T23:09:52Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
ソース
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.
{"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"}
{
"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.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"
]
}
'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,
};
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);
});
オリジンシーダー
匿名