CodeSampleX

Ejemplo

has-symbols 1.1.0: hasNativeSymbols, hasSymbols

Muestra verificada para npm has-symbols 1.1.0: hasNativeSymbols, hasSymbols. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:335a6888833cc5b1c69510a9b3f0ad1b28ab0a11f7ad15641e47e61ca669612b

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 windows 11 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

Caso

HOW
Objetivo
verify pkg:npm/has-symbols@1.1.0
Paquetes
Símbolos
  • hasNativeSymbols
  • hasSymbols
Creado
2026-08-18T17:57:24Z

Contrato

  1. hasNativeSymbols() returns true in modern JavaScript runtimes with native Symbol support
  2. hasSymbols() from has-symbols/shams.js returns true when Symbol and Object.getOwnPropertySymbols are supported
  3. native symbols created with Symbol() produce distinct symbol primitives non-enumerable in Object.keys
  4. Object.getOwnPropertySymbols retrieves symbol properties assigned to objects
  5. wrapper functions checkNativeSymbols and checkSymbolsOrShams match direct library calls

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/has-symbols@1.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/has-symbols@1.1.0
Demonstrate these symbols/APIs:
  - hasNativeSymbols
  - hasSymbols

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:1d7aeeae14d2d313ec4165ca97c8dd9bcd89bbd3e57e64a7f5e1ef19fc8d8e5a","contract":["hasNativeSymbols() returns true in modern JavaScript runtimes with native Symbol support","hasSymbols() from has-symbols/shams.js returns true when Symbol and Object.getOwnPropertySymbols are supported","native symbols created with Symbol() produce distinct symbol primitives non-enumerable in Object.keys","Object.getOwnPropertySymbols retrieves symbol properties assigned to objects","wrapper functions checkNativeSymbols and checkSymbolsOrShams match direct library calls"],"goal":"verify pkg:npm/has-symbols@1.1.0","kind":"HOW","packages":["pkg:npm/has-symbols@1.1.0"],"schemaVersion":1,"symbols":["hasNativeSymbols","hasSymbols"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/has-symbols@1.1.0"],"schemaVersion":1,"symbols":["hasNativeSymbols","hasSymbols"],"verifierAdapter":"node-typescript@1"}
index.mjs
import hasNativeSymbols from 'has-symbols';
import hasSymbolsShams from 'has-symbols/shams.js';

/**
 * Checks whether the current JavaScript environment has native Symbol support.
 * @returns {boolean}
 */
export function checkNativeSymbols() {
  return hasNativeSymbols();
}

/**
 * Checks whether the current JavaScript environment supports Symbols (either native or shams).
 * @returns {boolean}
 */
export function checkSymbolsOrShams() {
  return hasSymbolsShams();
}
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "has-symbols": "1.1.0"
      }
    },
    "node_modules/has-symbols": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
      "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "has-symbols": "1.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/has-symbols@1.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/has-symbols@1.1.0"
  ],
  "symbols": [
    "hasNativeSymbols",
    "hasSymbols"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import hasNativeSymbols from 'has-symbols';
import hasSymbolsShams from 'has-symbols/shams.js';
import { checkNativeSymbols, checkSymbolsOrShams } from '../index.mjs';

// Case 1: hasNativeSymbols returns boolean
{
  const result = hasNativeSymbols();
  assert.equal(typeof result, 'boolean', 'hasNativeSymbols() must return a boolean');
  assert.equal(result, true, 'hasNativeSymbols() should return true in Node.js environment');
}

// Case 2: hasSymbolsShams returns boolean
{
  const result = hasSymbolsShams();
  assert.equal(typeof result, 'boolean', 'hasSymbolsShams() must return a boolean');
  assert.equal(result, true, 'hasSymbolsShams() should return true in Node.js environment');
}

// Case 3: native symbol characteristics validated when supported
{
  if (hasNativeSymbols()) {
    const sym1 = Symbol('test');
    const sym2 = Symbol('test');
    assert.equal(typeof sym1, 'symbol', 'typeof Symbol() must be "symbol"');
    assert.notEqual(sym1, sym2, 'distinct symbols with same description must not be equal');
    assert.equal(typeof Symbol.iterator, 'symbol', 'Symbol.iterator must be a symbol');
  }
}

// Case 4: symbol property isolation on objects
{
  if (hasSymbolsShams()) {
    const symKey = Symbol('contract_key');
    const targetObj = { standardKey: 'visible' };
    targetObj[symKey] = 'symbol_value';

    // Standard reflection ignores symbol keys
    assert.deepEqual(Object.keys(targetObj), ['standardKey'], 'Object.keys should exclude symbol keys');
    
    // Symbol reflection retrieves symbol keys
    const symbols = Object.getOwnPropertySymbols(targetObj);
    assert.equal(symbols.length, 1, 'Object.getOwnPropertySymbols should find 1 symbol key');
    assert.equal(symbols[0], symKey, 'retrieved symbol must match assigned symbol');
    assert.equal(targetObj[symbols[0]], 'symbol_value', 'value via symbol key must match');
  }
}

// Case 5: wrapper functions in index.mjs match direct library exports
{
  assert.equal(checkNativeSymbols(), hasNativeSymbols(), 'checkNativeSymbols should match hasNativeSymbols()');
  assert.equal(checkSymbolsOrShams(), hasSymbolsShams(), 'checkSymbolsOrShams should match hasSymbolsShams()');
}

console.log('PASS: all has-symbols contract assertions passed');

Seeder de origen

anónimo