CodeSampleX

示例

crelt 1.0.7

已验证示例 — npm crelt 1.0.7. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: crelt creates DOM elements with tag name and attributes

sha256:2902cc1bf29dd63c3581db82b693179d589b8a0b16753ca116abd0c63c5860c5

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

执行证据

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

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

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-15

案例

HOW
目标
verify pkg:npm/crelt@1.0.7
包
创建时间
2026-09-15T05:14:34Z

契约

  1. crelt creates DOM elements with tag name and attributes
  2. crelt wraps existing DOM elements when passed as first argument
  3. crelt appends string children as text nodes
  4. crelt appends element and node children
  5. crelt handles nested arrays of children flattening them recursively
  6. crelt ignores null and undefined children
  7. crelt throws RangeError for unsupported child node types

文件

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

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

Use EXACTLY these public packages and versions:
  - pkg:npm/crelt@1.0.7

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:f3e046d0d45a0614977073cebfd46498b5660b76c94958c6314b0823b3ef0579","contract":["crelt creates DOM elements with tag name and attributes","crelt wraps existing DOM elements when passed as first argument","crelt appends string children as text nodes","crelt appends element and node children","crelt handles nested arrays of children flattening them recursively","crelt ignores null and undefined children","crelt throws RangeError for unsupported child node types"],"goal":"verify pkg:npm/crelt@1.0.7","kind":"HOW","packages":["pkg:npm/crelt@1.0.7"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/crelt@1.0.7"],"schemaVersion":1,"subject":"pkg:npm/crelt@1.0.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "crelt-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "crelt-sample",
      "version": "1.0.0",
      "dependencies": {
        "crelt": "1.0.7"
      }
    },
    "node_modules/crelt": {
      "version": "1.0.7",
      "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz",
      "integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "crelt-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for crelt",
  "dependencies": {
    "crelt": "1.0.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/crelt@1.0.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/crelt@1.0.7"
  ]
}
test/contract.mjs
import assert from 'node:assert';

// Minimal DOM mock for Node.js environment
class MockElement {
  constructor(tagName) {
    this.tagName = tagName.toUpperCase();
    this.nodeType = 1;
    this.attributes = {};
    this.childNodes = [];
  }

  setAttribute(name, value) {
    this.attributes[name] = String(value);
  }

  getAttribute(name) {
    return Object.prototype.hasOwnProperty.call(this.attributes, name) ? this.attributes[name] : null;
  }

  appendChild(child) {
    this.childNodes.push(child);
    return child;
  }
}

class MockTextNode {
  constructor(text) {
    this.nodeValue = String(text);
    this.nodeType = 3;
  }
}

globalThis.document = {
  createElement(tag) {
    return new MockElement(tag);
  },
  createTextNode(text) {
    return new MockTextNode(text);
  }
};

import crelt from 'crelt';

// 1. crelt creates DOM elements with tag name and attributes
const el1 = crelt('div', { id: 'test-id', class: 'container', tabIndex: 0 });
assert.strictEqual(el1.tagName, 'DIV');
assert.strictEqual(el1.getAttribute('id'), 'test-id');
assert.strictEqual(el1.getAttribute('class'), 'container');
assert.strictEqual(el1.tabIndex, 0);

// 2. crelt wraps existing DOM elements when passed as first argument
const existing = globalThis.document.createElement('section');
const el2 = crelt(existing, { 'data-mode': 'active' });
assert.strictEqual(el2, existing);
assert.strictEqual(el2.tagName, 'SECTION');
assert.strictEqual(el2.getAttribute('data-mode'), 'active');

// 3. crelt appends string children as text nodes
const el3 = crelt('p', null, 'hello', ' ', 'world');
assert.strictEqual(el3.childNodes.length, 3);
assert.strictEqual(el3.childNodes[0].nodeType, 3);
assert.strictEqual(el3.childNodes[0].nodeValue, 'hello');
assert.strictEqual(el3.childNodes[1].nodeValue, ' ');
assert.strictEqual(el3.childNodes[2].nodeValue, 'world');

// 4. crelt appends element and node children
const childSpan = crelt('span', null, 'inner');
const el4 = crelt('div', null, childSpan);
assert.strictEqual(el4.childNodes.length, 1);
assert.strictEqual(el4.childNodes[0], childSpan);
assert.strictEqual(el4.childNodes[0].childNodes[0].nodeValue, 'inner');

// 5. crelt handles nested arrays of children flattening them recursively
const el5 = crelt('ul', null, [
  crelt('li', null, 'item 1'),
  [crelt('li', null, 'item 2'), [crelt('li', null, 'item 3')]]
]);
assert.strictEqual(el5.childNodes.length, 3);
assert.strictEqual(el5.childNodes[0].childNodes[0].nodeValue, 'item 1');
assert.strictEqual(el5.childNodes[1].childNodes[0].nodeValue, 'item 2');
assert.strictEqual(el5.childNodes[2].childNodes[0].nodeValue, 'item 3');

// 6. crelt ignores null and undefined children
const el6 = crelt('div', null, null, 'valid', undefined);
assert.strictEqual(el6.childNodes.length, 1);
assert.strictEqual(el6.childNodes[0].nodeValue, 'valid');

// 7. crelt throws RangeError for unsupported child node types
assert.throws(
  () => {
    crelt('div', null, 42);
  },
  (err) => {
    return err instanceof RangeError && err.message.includes('Unsupported child node: 42');
  }
);

assert.throws(
  () => {
    crelt('div', null, { some: 'object' });
  },
  (err) => {
    return err instanceof RangeError && err.message.includes('Unsupported child node:');
  }
);

console.log('Contract passed');

原始种子者

匿名