CodeSampleX

Ejemplo

std-env 4.2.0: isFastly

Muestra verificada para npm std-env 4.2.0: isFastly. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: std-env.isFastly exports a boolean…

sha256:c92db2d81d3f8c216960ee12671b4ae01eeb69a363bead324733895c52f1d77e

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 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

Caso

HOW
Objetivo
verify std-env.isFastly in pkg:npm/std-env@4.2.0
Paquetes
Símbolos
  • std-env.isFastly
Creado
2026-09-06T19:15:30Z

Contrato

  1. std-env.isFastly exports a boolean indicating whether the execution context is the Fastly runtime
  2. std-env.isFastly evaluates to false in standard Node.js runtime environments
  3. std-env.isFastly consistently reflects the presence of the fastly global property in globalThis
  4. std-env.isFastly evaluates to true and detects fastly runtime when fastly global is present at module evaluation
  5. std-env.isFastly distinguishes Fastly from Node.js where isNode evaluates to true and isFastly evaluates to false

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 std-env.isFastly in pkg:npm/std-env@4.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/std-env@4.2.0
Demonstrate these symbols/APIs:
  - std-env.isFastly

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:0293641c23ed6ba178e5f298bc70744f26ffa868d3a9f42e1a2ba924e65f8851","contract":["std-env.isFastly exports a boolean indicating whether the execution context is the Fastly runtime","std-env.isFastly evaluates to false in standard Node.js runtime environments","std-env.isFastly consistently reflects the presence of the fastly global property in globalThis","std-env.isFastly evaluates to true and detects fastly runtime when fastly global is present at module evaluation","std-env.isFastly distinguishes Fastly from Node.js where isNode evaluates to true and isFastly evaluates to false"],"goal":"verify std-env.isFastly in pkg:npm/std-env@4.2.0","kind":"HOW","packages":["pkg:npm/std-env@4.2.0"],"schemaVersion":1,"symbols":["std-env.isFastly"]},"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/std-env@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/std-env@4.2.0","symbols":["std-env.isFastly"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { isFastly, runtime, isNode, isBun, isDeno } from 'std-env';

export { isFastly, runtime, isNode, isBun, isDeno };
export default isFastly;
package-lock.json
{
  "name": "sample-std-env-is-fastly",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-std-env-is-fastly",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "std-env": "4.2.0"
      }
    },
    "node_modules/std-env": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.2.0.tgz",
      "integrity": "sha512-oCUKSupKTHX53EyjDtuZQ64pjLJ6yYCtpmEw0goYxtjG9KpbRe8KAsl2tBUGU9DyMcJ0RwJ8GqJAFzMXcXW1Rw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-std-env-is-fastly",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "std-env": "4.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify std-env.isFastly in pkg:npm/std-env@4.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/std-env@4.2.0"
  ],
  "symbols": [
    "std-env.isFastly"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as stdEnv from 'std-env';
import { isFastly, runtime, isNode, isBun, isDeno } from '../index.mjs';

// 1. std-env.isFastly exports a boolean indicating whether the execution context is the Fastly runtime
{
  assert.equal(typeof isFastly, 'boolean', 'isFastly must be a boolean');
  assert.equal(typeof stdEnv.isFastly, 'boolean', 'std-env.isFastly must be a boolean');
}

// 2. std-env.isFastly evaluates to false in standard Node.js runtime environments
{
  assert.equal(isFastly, false, 'isFastly must be false in standard Node.js environment');
  assert.equal(stdEnv.isFastly, false, 'std-env.isFastly must be false in standard Node.js environment');
}

// 3. std-env.isFastly consistently reflects the presence of the fastly global property in globalThis
{
  const hasFastlyGlobal = 'fastly' in globalThis;
  assert.equal(hasFastlyGlobal, false, 'fastly global should not be present in standard Node.js');
  assert.equal(isFastly, hasFastlyGlobal, 'isFastly should match presence of fastly in globalThis');
  assert.equal(stdEnv.isFastly, hasFastlyGlobal, 'std-env.isFastly should match presence of fastly in globalThis');
}

// 4. std-env.isFastly evaluates to true and detects fastly runtime when fastly global is present at module evaluation
{
  try {
    globalThis.fastly = {};
    const resolved = import.meta.resolve('std-env');
    const mockedModule = await import(`${resolved}?mock=fastly-test`);
    assert.equal(mockedModule.isFastly, true, 'isFastly should evaluate to true when fastly is in globalThis');
    assert.equal(mockedModule.runtime, 'fastly', 'runtime should evaluate to "fastly" when fastly is in globalThis');
  } finally {
    delete globalThis.fastly;
  }
}

// 5. std-env.isFastly distinguishes Fastly from Node.js where isNode evaluates to true and isFastly evaluates to false
{
  assert.equal(stdEnv.isNode, true, 'isNode must be true in Node.js runtime');
  assert.equal(stdEnv.isFastly, false, 'isFastly must be false in Node.js runtime');
  assert.notEqual(stdEnv.isNode, stdEnv.isFastly, 'isNode and isFastly must not both be true in Node.js runtime');
  assert.equal(stdEnv.runtime, 'node', 'std-env.runtime must be "node" in Node.js runtime');
}

console.log('All std-env.isFastly contract assertions passed successfully.');

Seeder de origen

anónimo