CodeSampleX

サンプル

fresh 2.0.0

検証済みサンプル — npm fresh 2.0.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: fresh(reqHeaders, resHeaders) returns false for unconditional…

sha256:a13513787b8f06f4ff588920fa652e8e8d861f2bb13222af32c831056298e691

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

ケース

HOW
ゴール
verify pkg:npm/fresh@2.0.0
パッケージ
作成日
2026-08-20T13:52:02Z

コントラクト

  1. fresh(reqHeaders, resHeaders) returns false for unconditional requests without if-modified-since or if-none-match
  2. fresh(reqHeaders, resHeaders) returns false when Cache-Control header contains no-cache even if ETags match
  3. fresh(reqHeaders, resHeaders) returns true when if-none-match exactly matches the response etag
  4. fresh(reqHeaders, resHeaders) returns true when matching weak ETags like W/"123" and "123"
  5. fresh(reqHeaders, resHeaders) returns true when if-none-match is wildcard *
  6. fresh(reqHeaders, resHeaders) returns true when if-modified-since is at or after response last-modified date
  7. fresh(reqHeaders, resHeaders) prioritizes if-none-match over if-modified-since when both are present

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 pkg:npm/fresh@2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fresh@2.0.0

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:f8aa366ce0acad548bde72db92105d45ed260fe9a6f4c004e3f20cd9b8121604","contract":["fresh(reqHeaders, resHeaders) returns false for unconditional requests without if-modified-since or if-none-match","fresh(reqHeaders, resHeaders) returns false when Cache-Control header contains no-cache even if ETags match","fresh(reqHeaders, resHeaders) returns true when if-none-match exactly matches the response etag","fresh(reqHeaders, resHeaders) returns true when matching weak ETags like W/\"123\" and \"123\"","fresh(reqHeaders, resHeaders) returns true when if-none-match is wildcard *","fresh(reqHeaders, resHeaders) returns true when if-modified-since is at or after response last-modified date","fresh(reqHeaders, resHeaders) prioritizes if-none-match over if-modified-since when both are present"],"goal":"verify pkg:npm/fresh@2.0.0","kind":"HOW","packages":["pkg:npm/fresh@2.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/fresh@2.0.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
index.mjs
import fresh from 'fresh';

export function isResponseFresh(reqHeaders, resHeaders) {
  return fresh(reqHeaders, resHeaders);
}
package-lock.json
{
  "name": "sample-fresh",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fresh",
      "version": "1.0.0",
      "dependencies": {
        "fresh": "2.0.0"
      }
    },
    "node_modules/fresh": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
      "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8"
      }
    }
  }
}
package.json
{
  "name": "sample-fresh",
  "version": "1.0.0",
  "description": "Clean-room verification sample for fresh",
  "type": "module",
  "private": true,
  "dependencies": {
    "fresh": "2.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/fresh@2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fresh@2.0.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fresh from 'fresh';
import { isResponseFresh } from '../index.mjs';

// 1. Unconditional requests return false
assert.equal(fresh({}, {}), false);
assert.equal(isResponseFresh({ host: 'example.com' }, { etag: '"123"' }), false);

// 2. Cache-Control: no-cache returns false even when ETags match
assert.equal(fresh({ 'if-none-match': '"123"', 'cache-control': 'no-cache' }, { etag: '"123"' }), false);
assert.equal(fresh({ 'if-none-match': '"123"', 'cache-control': 'max-age=0, no-cache' }, { etag: '"123"' }), false);

// 3. Exact if-none-match match returns true
assert.equal(fresh({ 'if-none-match': '"123"' }, { etag: '"123"' }), true);
assert.equal(fresh({ 'if-none-match': '"123"' }, { etag: '"456"' }), false);
assert.equal(fresh({ 'if-none-match': '"foo", "bar"' }, { etag: '"bar"' }), true);

// 4. Weak ETag matching returns true
assert.equal(fresh({ 'if-none-match': 'W/"123"' }, { etag: '"123"' }), true);
assert.equal(fresh({ 'if-none-match': '"123"' }, { etag: 'W/"123"' }), true);
assert.equal(fresh({ 'if-none-match': 'W/"123"' }, { etag: 'W/"123"' }), true);

// 5. Wildcard * if-none-match returns true
assert.equal(fresh({ 'if-none-match': '*' }, { etag: '"anything"' }), true);
assert.equal(fresh({ 'if-none-match': '*' }, {}), true);

// 6. if-modified-since comparison
const now = new Date('2026-08-20T12:00:00Z').toUTCString();
const past = new Date('2026-08-20T11:00:00Z').toUTCString();
const future = new Date('2026-08-20T13:00:00Z').toUTCString();
assert.equal(fresh({ 'if-modified-since': now }, { 'last-modified': past }), true);
assert.equal(fresh({ 'if-modified-since': now }, { 'last-modified': now }), true);
assert.equal(fresh({ 'if-modified-since': past }, { 'last-modified': now }), false);

// 7. if-none-match takes precedence over if-modified-since
assert.equal(fresh({ 'if-none-match': '"mismatch"', 'if-modified-since': future }, { etag: '"actual"', 'last-modified': past }), false);
assert.equal(fresh({ 'if-none-match': '"match"', 'if-modified-since': past }, { etag: '"match"', 'last-modified': future }), true);

console.log('All fresh@2.0.0 contract assertions passed.');

オリジンシーダー

匿名