CodeSampleX

Ejemplo

fresh 2.0.0

Muestra verificada para npm fresh 2.0.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: fresh(reqHeaders, resHeaders) returns false…

sha256:a13513787b8f06f4ff588920fa652e8e8d861f2bb13222af32c831056298e691

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:npm/fresh@2.0.0
Paquetes
Creado
2026-08-20T13:52:02Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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.');

Seeder de origen

anónimo