CodeSampleX

示例

js-yaml 4.3.1

已验证示例 — npm js-yaml 4.3.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: yaml.load parses YAML string with scalars, arrays, and nested mappings into…

sha256:ef6e650d864b6c5772325c8af5827317543f62fd0a78b129d3a24df0f287f856

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

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

案例

HOW
目标
verify pkg:npm/js-yaml@4.3.1
包
创建时间
2026-08-21T08:23:20Z

契约

  1. yaml.load parses YAML string with scalars, arrays, and nested mappings into JavaScript objects
  2. yaml.load handles null, boolean, integer, float, and date types accurately
  3. yaml.load throws YAMLException on invalid YAML syntax
  4. yaml.loadAll parses multiple documents separated by --- in a single string
  5. yaml.dump serializes JavaScript objects into valid YAML format
  6. yaml.dump supports options such as indent and sortKeys
  7. yaml.load with FAILSAFE_SCHEMA parses all scalars as strings without implicit type casting
  8. yaml.load and yaml.dump round-trip preserves object structure and data integrity

文件

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

下载源代码构件 (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/js-yaml@4.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/js-yaml@4.3.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:e2df9d02588b60d01fb15c8ad9ef68626a1cc6d0316e67f4d027ed1667ae020c","contract":["yaml.load parses YAML string with scalars, arrays, and nested mappings into JavaScript objects","yaml.load handles null, boolean, integer, float, and date types accurately","yaml.load throws YAMLException on invalid YAML syntax","yaml.loadAll parses multiple documents separated by --- in a single string","yaml.dump serializes JavaScript objects into valid YAML format","yaml.dump supports options such as indent and sortKeys","yaml.load with FAILSAFE_SCHEMA parses all scalars as strings without implicit type casting","yaml.load and yaml.dump round-trip preserves object structure and data integrity"],"goal":"verify pkg:npm/js-yaml@4.3.1","kind":"HOW","packages":["pkg:npm/js-yaml@4.3.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/js-yaml@4.3.1"],"schemaVersion":1,"subject":"pkg:npm/js-yaml@4.3.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "js-yaml-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "js-yaml-verification",
      "version": "1.0.0",
      "dependencies": {
        "js-yaml": "4.3.1"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/js-yaml": {
      "version": "4.3.1",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz",
      "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==",
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    }
  }
}
package.json
{
  "name": "js-yaml-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for js-yaml",
  "dependencies": {
    "js-yaml": "4.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/js-yaml@4.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/js-yaml@4.3.1"
  ]
}
test/contract.cjs
const assert = require('node:assert');
const yaml = require('js-yaml');

// 1. yaml.load parses YAML string with scalars, arrays, and nested mappings into JavaScript objects
const doc1 = `
title: CodeSampleX
count: 42
items:
  - alpha
  - beta
nested:
  enabled: true
`;
const parsed1 = yaml.load(doc1);
assert.deepStrictEqual(parsed1, {
  title: 'CodeSampleX',
  count: 42,
  items: ['alpha', 'beta'],
  nested: { enabled: true }
});

// 2. yaml.load handles null, boolean, integer, float, and date types accurately
const doc2 = `
nullVal: null
tildeNull: ~
boolTrue: true
boolFalse: false
intVal: 100
floatVal: 3.1415
dateVal: 2026-08-21T00:00:00Z
`;
const parsed2 = yaml.load(doc2);
assert.strictEqual(parsed2.nullVal, null);
assert.strictEqual(parsed2.tildeNull, null);
assert.strictEqual(parsed2.boolTrue, true);
assert.strictEqual(parsed2.boolFalse, false);
assert.strictEqual(parsed2.intVal, 100);
assert.strictEqual(parsed2.floatVal, 3.1415);
assert.ok(parsed2.dateVal instanceof Date);
assert.strictEqual(parsed2.dateVal.toISOString(), '2026-08-21T00:00:00.000Z');

// 3. yaml.load throws YAMLException on invalid YAML syntax
assert.throws(() => {
  yaml.load('foo: [bar: baz');
}, yaml.YAMLException);

// 4. yaml.loadAll parses multiple documents separated by --- in a single string
const multiDoc = `
---
doc: 1
---
doc: 2
`;
const docs = [];
yaml.loadAll(multiDoc, (d) => docs.push(d));
assert.deepStrictEqual(docs, [{ doc: 1 }, { doc: 2 }]);
assert.deepStrictEqual(yaml.loadAll(multiDoc), [{ doc: 1 }, { doc: 2 }]);

// 5. yaml.dump serializes JavaScript objects into valid YAML format
const obj = { name: 'test', values: [1, 2, 3] };
const dumped = yaml.dump(obj);
assert.strictEqual(typeof dumped, 'string');
assert.deepStrictEqual(yaml.load(dumped), obj);

// 6. yaml.dump supports options such as indent and sortKeys
const sortObj = { z: 1, a: 2, m: 3 };
const dumpedSorted = yaml.dump(sortObj, { sortKeys: true, indent: 4 });
assert.strictEqual(dumpedSorted, 'a: 2\nm: 3\nz: 1\n');

// 7. yaml.load with FAILSAFE_SCHEMA parses all scalars as strings without implicit type casting
const failsafeDoc = 'number: 123\nflag: true';
const failsafeParsed = yaml.load(failsafeDoc, { schema: yaml.FAILSAFE_SCHEMA });
assert.strictEqual(failsafeParsed.number, '123');
assert.strictEqual(failsafeParsed.flag, 'true');

// 8. yaml.load and yaml.dump round-trip preserves object structure and data integrity
const complexObj = {
  service: 'api-server',
  port: 8080,
  tags: ['web', 'node'],
  meta: { active: true, version: 1.5 }
};
const roundTrip = yaml.load(yaml.dump(complexObj));
assert.deepStrictEqual(roundTrip, complexObj);

console.log('Contract passed');

原始种子者

匿名