CodeSampleX

Ejemplo

yaml 2.9.0: create and modify YAML Document with Document

Muestra verificada para npm yaml 2.9.0: create and modify YAML Document with Document. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:8b0f97db755aed2ecdba1676d2a29fc99842af547fe48cefffc6654c5cb97784

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 node 22.23 windows 11 x64 node 22.23 javascript npm 10

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
create and modify YAML Document with Document
Paquetes
Símbolos
  • Document
Entorno
node 22.23.2
Creado
2026-08-18T19:55:34Z

Contrato

  1. new Document initializes a YAML Document from JavaScript data structures
  2. doc.set and doc.get read and modify top-level document properties
  3. doc.toJS converts the Document to a plain JavaScript object
  4. doc.toString serializes the Document structure to valid YAML string output

Archivos

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

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: create and modify YAML Document with Document
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yaml@2.9.0
Demonstrate these symbols/APIs:
  - Document
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:bc92f63edfc7304176af8388781cb3e0922c51af68cc0802e82474ecdfd7bb3a","constraints":{"executionContext":"node"},"contract":["new Document initializes a YAML Document from JavaScript data structures","doc.set and doc.get read and modify top-level document properties","doc.toJS converts the Document to a plain JavaScript object","doc.toString serializes the Document structure to valid YAML string output"],"goal":"create and modify YAML Document with Document","kind":"HOW","packages":["pkg:npm/yaml@2.9.0"],"schemaVersion":1,"symbols":["Document"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"windows","osVersionBucket":"11","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/yaml@2.9.0"],"schemaVersion":1,"symbols":["Document"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "yaml": "2.9.0"
      }
    },
    "node_modules/yaml": {
      "version": "2.9.0",
      "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
      "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
      "license": "ISC",
      "bin": {
        "yaml": "bin.mjs"
      },
      "engines": {
        "node": ">= 14.6"
      },
      "funding": {
        "url": "https://github.com/sponsors/eemeli"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "yaml": "2.9.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "create and modify YAML Document with Document",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yaml@2.9.0"
  ],
  "symbols": [
    "Document"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const { Document } = require('yaml');

// Contract 1: new Document initializes a YAML Document from JavaScript data structures
const initialData = {
  service: 'order-api',
  replicas: 3,
  environment: 'staging',
  tags: ['ecommerce', 'backend']
};

const doc = new Document(initialData);
assert.equal(doc.contents.items.length, 4);

// Contract 2: doc.set and doc.get read and modify top-level document properties
assert.equal(doc.get('service'), 'order-api');
assert.equal(doc.get('replicas'), 3);

doc.set('replicas', 5);
assert.equal(doc.get('replicas'), 5);

doc.set('region', 'us-east-1');
assert.equal(doc.get('region'), 'us-east-1');

// Contract 3: doc.toJS converts the Document to a plain JavaScript object
const jsResult = doc.toJS();
assert.deepEqual(jsResult, {
  service: 'order-api',
  replicas: 5,
  environment: 'staging',
  tags: ['ecommerce', 'backend'],
  region: 'us-east-1'
});

// Contract 4: doc.toString serializes the Document structure to valid YAML string output
const yamlOutput = doc.toString();
assert.equal(typeof yamlOutput, 'string');
assert.ok(yamlOutput.includes('service: order-api'));
assert.ok(yamlOutput.includes('replicas: 5'));
assert.ok(yamlOutput.includes('- ecommerce'));
assert.ok(yamlOutput.includes('region: us-east-1'));

console.log('Contract verification passed successfully.');

Seeder de origen

anónimo