CodeSampleX

샘플

json-schema-traverse 1.0.0

검증된 샘플 — npm json-schema-traverse 1.0.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: traverse invokes callback for each subschema with…

sha256:7ad08f1064928ecf1639c998c4ce09578a86fe14b49467f9e3b5b1e58cec94f7

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
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-23

케이스

HOW
목표
verify pkg:npm/json-schema-traverse@1.0.0
패키지
생성일
2026-08-23T06:02:44Z

컨트랙트

  1. traverse invokes callback for each subschema with jsonPtr, parentKeyword, and schema context across standard keywords
  2. traverse visits custom keywords when allKeys option is enabled
  3. traverse executes pre and post callbacks in correct order during schema traversal

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js

소스 아티팩트 내려받기 (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/json-schema-traverse@1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-schema-traverse@1.0.0

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:9b552d07c668bda11c511216ffec6e41f8172ae35b857303637d1d09b3125388","contract":["traverse invokes callback for each subschema with jsonPtr, parentKeyword, and schema context across standard keywords","traverse visits custom keywords when allKeys option is enabled","traverse executes pre and post callbacks in correct order during schema traversal"],"goal":"verify pkg:npm/json-schema-traverse@1.0.0","kind":"HOW","packages":["pkg:npm/json-schema-traverse@1.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/json-schema-traverse@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/json-schema-traverse@1.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-schema-traverse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-schema-traverse",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "json-schema-traverse": "1.0.0"
      }
    },
    "node_modules/json-schema-traverse": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
      "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-json-schema-traverse",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for json-schema-traverse",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "json-schema-traverse": "1.0.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/json-schema-traverse@1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-schema-traverse@1.0.0"
  ]
}
src/index.js
const traverse = require('json-schema-traverse');

function traverseSchema(schema, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }
  return traverse(schema, options, cb);
}

module.exports = {
  traverse,
  traverseSchema
};
test/contract.js
const assert = require('node:assert');
const traverse = require('json-schema-traverse');
const { traverseSchema } = require('../src/index.js');

// 1. Traverse invokes callback for each subschema with jsonPtr, parentKeyword, and schema context across standard keywords
const standardSchema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    tags: {
      type: 'array',
      items: { type: 'string' }
    }
  },
  definitions: {
    customDef: { type: 'number' }
  }
};

const visitedStandard = [];
traverse(standardSchema, (subschema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) => {
  visitedStandard.push({
    jsonPtr,
    parentKeyword,
    keyIndex,
    subschemaType: subschema.type,
    isRoot: rootSchema === standardSchema
  });
});

assert.strictEqual(visitedStandard.length, 5, 'Should visit root and 4 subschemas');
assert.strictEqual(visitedStandard[0].jsonPtr, '', 'Root jsonPtr should be empty string');
assert.strictEqual(visitedStandard[0].isRoot, true, 'Root schema reference should match');

assert.strictEqual(visitedStandard[1].jsonPtr, '/properties/name');
assert.strictEqual(visitedStandard[1].parentKeyword, 'properties');
assert.strictEqual(visitedStandard[1].keyIndex, 'name');
assert.strictEqual(visitedStandard[1].subschemaType, 'string');

assert.strictEqual(visitedStandard[2].jsonPtr, '/properties/tags');
assert.strictEqual(visitedStandard[2].parentKeyword, 'properties');
assert.strictEqual(visitedStandard[2].keyIndex, 'tags');

assert.strictEqual(visitedStandard[3].jsonPtr, '/properties/tags/items');
assert.strictEqual(visitedStandard[3].parentKeyword, 'items');
assert.strictEqual(visitedStandard[3].subschemaType, 'string');

assert.strictEqual(visitedStandard[4].jsonPtr, '/definitions/customDef');
assert.strictEqual(visitedStandard[4].parentKeyword, 'definitions');
assert.strictEqual(visitedStandard[4].keyIndex, 'customDef');
assert.strictEqual(visitedStandard[4].subschemaType, 'number');

// Test wrapper function helper
const helperVisited = [];
traverseSchema(standardSchema, (subschema, jsonPtr) => {
  helperVisited.push(jsonPtr);
});
assert.deepStrictEqual(helperVisited, visitedStandard.map(v => v.jsonPtr), 'traverseSchema helper should produce same traversal');

// 2. Traverse visits custom keywords when allKeys option is enabled
const customKeywordsSchema = {
  customObject: {
    type: 'string',
    nestedCustom: { type: 'boolean' }
  }
};

const defaultKeysVisited = [];
traverse(customKeywordsSchema, (subschema, jsonPtr) => {
  defaultKeysVisited.push(jsonPtr);
});
assert.strictEqual(defaultKeysVisited.length, 1, 'Without allKeys, custom keyword objects should not be traversed as subschemas');

const allKeysVisited = [];
traverse(customKeywordsSchema, { allKeys: true }, (subschema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) => {
  allKeysVisited.push({ jsonPtr, parentKeyword, keyIndex });
});
assert.strictEqual(allKeysVisited.length, 3, 'With allKeys: true, all custom keyword objects should be traversed');
assert.strictEqual(allKeysVisited[0].jsonPtr, '');
assert.strictEqual(allKeysVisited[1].jsonPtr, '/customObject');
assert.strictEqual(allKeysVisited[1].parentKeyword, 'customObject');
assert.strictEqual(allKeysVisited[2].jsonPtr, '/customObject/nestedCustom');
assert.strictEqual(allKeysVisited[2].parentKeyword, 'nestedCustom');

// 3. Traverse executes pre and post callbacks in correct order during schema traversal
const lifecycleEvents = [];
traverse(standardSchema, {
  cb: {
    pre: (schema, jsonPtr) => lifecycleEvents.push(`pre:${jsonPtr}`),
    post: (schema, jsonPtr) => lifecycleEvents.push(`post:${jsonPtr}`)
  }
});

assert.strictEqual(lifecycleEvents[0], 'pre:', 'Root pre hook should run first');
assert.strictEqual(lifecycleEvents[lifecycleEvents.length - 1], 'post:', 'Root post hook should run last');
assert.strictEqual(lifecycleEvents.includes('pre:/properties/name'), true, 'Should include pre hook for /properties/name');
assert.strictEqual(lifecycleEvents.includes('post:/properties/name'), true, 'Should include post hook for /properties/name');

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

오리진 시더

익명