CodeSampleX

샘플

js-yaml 4.1.0: Schema

검증된 샘플 — npm js-yaml 4.1.0: Schema. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: new yaml.Schema(type) instantiates a custom Schema containing…

sha256:b533e7691f258bb33632b9d30b1c31a8dcda08defc74578051404dd3abc98f92

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

케이스

HOW
목표
verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0
패키지
심벌
  • js-yaml.Schema
환경
node 22.23.2
생성일
2026-08-28T03:32:13Z

컨트랙트

  1. new yaml.Schema(type) instantiates a custom Schema containing the explicit Type
  2. yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type
  3. yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types
  4. yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type
  5. yaml.load with extended Schema deserializes custom explicit tags into instantiated objects
  6. yaml.dump with extended Schema serializes custom objects with custom tag notation
  7. yaml.load with extended Schema resolves custom implicit scalar types automatically
  8. yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions

파일

  • 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 js-yaml.Schema in pkg:npm/js-yaml@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/js-yaml@4.1.0
Demonstrate these symbols/APIs:
  - js-yaml.Schema
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:49e7986e3830f5671e94e65545f4eeb60ad5ba9eae0872ea5f12d5264d5b24c1","constraints":{"executionContext":"node"},"contract":["new yaml.Schema(type) instantiates a custom Schema containing the explicit Type","yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type","yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types","yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type","yaml.load with extended Schema deserializes custom explicit tags into instantiated objects","yaml.dump with extended Schema serializes custom objects with custom tag notation","yaml.load with extended Schema resolves custom implicit scalar types automatically","yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions"],"goal":"verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0","kind":"HOW","packages":["pkg:npm/js-yaml@4.1.0"],"schemaVersion":1,"symbols":["js-yaml.Schema"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/js-yaml@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/js-yaml@4.1.0","symbols":["js-yaml.Schema"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "js-yaml-schema-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "js-yaml-schema-verification",
      "version": "1.0.0",
      "dependencies": {
        "js-yaml": "4.1.0"
      }
    },
    "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.1.0",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
      "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    }
  }
}
package.json
{
  "name": "js-yaml-schema-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for js-yaml.Schema",
  "dependencies": {
    "js-yaml": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/js-yaml@4.1.0"
  ],
  "symbols": [
    "js-yaml.Schema"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert');
const yaml = require('js-yaml');

// Helper classes for custom types
class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}

const PointType = new yaml.Type('!point', {
  kind: 'mapping',
  resolve: function(data) {
    return data !== null && typeof data === 'object' && typeof data.x === 'number' && typeof data.y === 'number';
  },
  construct: function(data) {
    return new Point(data.x, data.y);
  },
  instanceOf: Point,
  represent: function(point) {
    return { x: point.x, y: point.y };
  }
});

const PersonType = new yaml.Type('!person', {
  kind: 'mapping',
  resolve: function(data) {
    return data !== null && typeof data === 'object' && typeof data.name === 'string' && typeof data.age === 'number';
  },
  construct: function(data) {
    return new Person(data.name, data.age);
  },
  instanceOf: Person,
  represent: function(person) {
    return { name: person.name, age: person.age };
  }
});

const HexType = new yaml.Type('!hex', {
  kind: 'scalar',
  resolve: function(data) {
    return typeof data === 'string' && /^0x[0-9a-fA-F]+$/.test(data);
  },
  construct: function(data) {
    return parseInt(data, 16);
  },
  predicate: function(data) {
    return typeof data === 'number';
  },
  represent: function(data) {
    return '0x' + data.toString(16);
  }
});

const RegexType = new yaml.Type('!regex', {
  kind: 'scalar',
  resolve: function(data) {
    return typeof data === 'string' && data.startsWith('/') && data.endsWith('/');
  },
  construct: function(data) {
    return new RegExp(data.slice(1, -1));
  }
});

// 1. new yaml.Schema(type) instantiates a custom Schema containing the explicit Type
const standaloneSchema = new yaml.Schema(PointType);
assert.ok(standaloneSchema instanceof yaml.Schema);
assert.ok(Array.isArray(standaloneSchema.explicit));
assert.ok(standaloneSchema.explicit.includes(PointType));

// 2. yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type
const pointSchema = yaml.DEFAULT_SCHEMA.extend(PointType);
assert.ok(pointSchema instanceof yaml.Schema);
assert.notStrictEqual(pointSchema, yaml.DEFAULT_SCHEMA);

// 3. yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types
const multiSchema = yaml.DEFAULT_SCHEMA.extend([PointType, PersonType, HexType]);
assert.ok(multiSchema instanceof yaml.Schema);

// 4. yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type
const implicitSchema = yaml.DEFAULT_SCHEMA.extend({ implicit: [RegexType] });
assert.ok(implicitSchema instanceof yaml.Schema);
assert.ok(implicitSchema.implicit.includes(RegexType));

// 5. yaml.load with extended Schema deserializes custom explicit tags into instantiated objects
const pointYaml = 'location: !point\n  x: 15\n  y: 30';
const loadedPoint = yaml.load(pointYaml, { schema: pointSchema });
assert.ok(loadedPoint.location instanceof Point);
assert.strictEqual(loadedPoint.location.x, 15);
assert.strictEqual(loadedPoint.location.y, 30);

const multiYaml = `
user: !person
  name: Alice
  age: 28
address: !point
  x: 100
  y: 200
flags: !hex 0x2a
`;
const loadedMulti = yaml.load(multiYaml, { schema: multiSchema });
assert.ok(loadedMulti.user instanceof Person);
assert.strictEqual(loadedMulti.user.name, 'Alice');
assert.strictEqual(loadedMulti.user.age, 28);
assert.ok(loadedMulti.address instanceof Point);
assert.strictEqual(loadedMulti.flags, 42);

// 6. yaml.dump with extended Schema serializes custom objects with custom tag notation
const pointDumped = yaml.dump({ location: new Point(15, 30) }, { schema: pointSchema });
assert.ok(pointDumped.includes('!point'));
const reloaded = yaml.load(pointDumped, { schema: pointSchema });
assert.ok(reloaded.location instanceof Point);
assert.strictEqual(reloaded.location.x, 15);
assert.strictEqual(reloaded.location.y, 30);

// 7. yaml.load with extended Schema resolves custom implicit scalar types automatically
const regexYaml = 'pattern: /abc[0-9]+/';
const loadedRegex = yaml.load(regexYaml, { schema: implicitSchema });
assert.ok(loadedRegex.pattern instanceof RegExp);
assert.ok(loadedRegex.pattern.test('abc1234'));

// 8. yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions
assert.throws(() => {
  yaml.DEFAULT_SCHEMA.extend('not-a-type');
}, yaml.YAMLException);

assert.throws(() => {
  yaml.DEFAULT_SCHEMA.extend([{ invalid: true }]);
}, yaml.YAMLException);

console.log('Contract passed');

오리진 시더

익명