CodeSampleX

示例

fresh 2.0.0

已验证示例 — npm fresh 2.0.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: fresh(reqHeaders, resHeaders) returns false for unconditional requests…

sha256:a13513787b8f06f4ff588920fa652e8e8d861f2bb13222af32c831056298e691

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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.');

原始种子者

匿名