CodeSampleX

示例

builder-util-runtime 9.7.0

已验证示例 — npm builder-util-runtime 9.7.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: CancellationToken tracks cancelled state and propagates…

sha256:f9aa9a26272d7edfe8e39dff390cda41e4f976ca348dd6f9f90a1b0fcbc54c93

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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/builder-util-runtime@9.7.0
包
创建时间
2026-08-23T13:43:53Z

契约

  1. CancellationToken tracks cancelled state and propagates cancellation from parent tokens to child tokens
  2. CancellationToken.createPromise resolves successfully or rejects with CancellationError when cancelled
  3. parseXml parses XML hierarchy, attributes, and CDATA blocks into navigable XElement trees
  4. UUID v5 generates deterministic RFC 4122 v5 UUIDs from namespace and name inputs
  5. deepAssign recursively merges object properties and deduplicates arrays while ignoring prototype pollution keys
  6. parseDn and mapToObject parse RFC 2253 distinguished name strings into key-value maps and plain objects
  7. objectToArgs and asArray helper utilities transform parameters safely
  8. MemoLazy lazily computes and memoizes values based on selector cache invalidation

文件

  • 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/builder-util-runtime@9.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/builder-util-runtime@9.7.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:d63f34a45e66d20e494a9afa0f5411925e90465daa0ba0959046885aac1ced32","contract":["CancellationToken tracks cancelled state and propagates cancellation from parent tokens to child tokens","CancellationToken.createPromise resolves successfully or rejects with CancellationError when cancelled","parseXml parses XML hierarchy, attributes, and CDATA blocks into navigable XElement trees","UUID v5 generates deterministic RFC 4122 v5 UUIDs from namespace and name inputs","deepAssign recursively merges object properties and deduplicates arrays while ignoring prototype pollution keys","parseDn and mapToObject parse RFC 2253 distinguished name strings into key-value maps and plain objects","objectToArgs and asArray helper utilities transform parameters safely","MemoLazy lazily computes and memoizes values based on selector cache invalidation"],"goal":"verify pkg:npm/builder-util-runtime@9.7.0","kind":"HOW","packages":["pkg:npm/builder-util-runtime@9.7.0"],"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/builder-util-runtime@9.7.0"],"schemaVersion":1,"subject":"pkg:npm/builder-util-runtime@9.7.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-builder-util-runtime",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-builder-util-runtime",
      "version": "1.0.0",
      "dependencies": {
        "builder-util-runtime": "9.7.0"
      }
    },
    "node_modules/builder-util-runtime": {
      "version": "9.7.0",
      "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.7.0.tgz",
      "integrity": "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "sax": "^1.2.4"
      },
      "engines": {
        "node": ">=12.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/sax": {
      "version": "1.6.1",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
      "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=11.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-builder-util-runtime",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "builder-util-runtime": "9.7.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/builder-util-runtime@9.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/builder-util-runtime@9.7.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  CancellationToken,
  CancellationError,
  parseXml,
  XElement,
  UUID,
  deepAssign,
  asArray,
  objectToArgs,
  MemoLazy,
  parseDn,
  mapToObject,
} from 'builder-util-runtime';

// 1. CancellationToken tracks cancelled state and propagates cancellation from parent tokens to child tokens
{
  const parent = new CancellationToken();
  const child = new CancellationToken(parent);

  assert.equal(parent.cancelled, false);
  assert.equal(child.cancelled, false);

  let childCancelledFired = false;
  child.onCancel(() => {
    childCancelledFired = true;
  });

  parent.cancel();
  assert.equal(parent.cancelled, true);
  assert.equal(child.cancelled, true);
  assert.equal(childCancelledFired, true);

  let immediateCalled = false;
  child.onCancel(() => {
    immediateCalled = true;
  });
  assert.equal(immediateCalled, true);
}

// 2. CancellationToken.createPromise resolves successfully or rejects with CancellationError when cancelled
{
  const token = new CancellationToken();
  let cancelCleanupCalled = false;

  const promise = token.createPromise((resolve, _reject, onCancel) => {
    const timer = setTimeout(() => resolve('done'), 500);
    onCancel(() => {
      clearTimeout(timer);
      cancelCleanupCalled = true;
    });
  });

  token.cancel();
  await assert.rejects(promise, (err) => {
    assert.ok(err instanceof CancellationError);
    assert.equal(err.message, 'cancelled');
    return true;
  });
  assert.equal(cancelCleanupCalled, true);

  const alreadyCancelledToken = new CancellationToken();
  alreadyCancelledToken.cancel();
  await assert.rejects(
    alreadyCancelledToken.createPromise((resolve) => resolve('success')),
    CancellationError
  );
}

// 3. parseXml parses XML hierarchy, attributes, and CDATA blocks into navigable XElement trees
{
  const xmlData = `
    <root id="123" type="sample">
      <title>Test Project</title>
      <description><![CDATA[Some <cdata> content & symbols]]></description>
      <items>
        <item code="A">First</item>
        <item code="B">Second</item>
      </items>
    </root>
  `;

  const root = parseXml(xmlData);
  assert.ok(root instanceof XElement);
  assert.equal(root.name, 'root');
  assert.equal(root.attribute('id'), '123');
  assert.equal(root.attribute('type'), 'sample');

  assert.throws(() => root.attribute('missing'), {
    code: 'ERR_XML_MISSED_ATTRIBUTE',
  });

  const title = root.element('title');
  assert.equal(title.value, 'Test Project');

  const desc = root.element('description');
  assert.equal(desc.value, 'Some <cdata> content & symbols');
  assert.equal(desc.isCData, true);

  const items = root.element('items');
  const itemList = items.getElements('item');
  assert.equal(itemList.length, 2);
  assert.equal(itemList[0].attribute('code'), 'A');
  assert.equal(itemList[0].value, 'First');
  assert.equal(itemList[1].attribute('code'), 'B');
  assert.equal(itemList[1].value, 'Second');

  assert.equal(root.elementValueOrEmpty('nonexistent'), '');
  assert.throws(() => root.element('nonexistent'), {
    code: 'ERR_XML_MISSED_ELEMENT',
  });
}

// 4. UUID v5 generates deterministic RFC 4122 v5 UUIDs from namespace and name inputs
{
  const namespace = UUID.parse('6ba7b810-9dad-11d1-80b4-00c04fd430c8');
  const generated1 = UUID.v5('example.com', namespace);
  const generated2 = UUID.v5('example.com', namespace);

  assert.equal(generated1.toString(), generated2.toString());
  assert.equal(typeof generated1.toString(), 'string');

  const checkResult = UUID.check(generated1.toString());
  assert.ok(checkResult !== false);
  assert.equal(checkResult.version, 5);
  assert.equal(checkResult.variant, 'rfc4122');
  assert.equal(checkResult.format, 'ascii');
}

// 5. deepAssign recursively merges object properties and deduplicates arrays while ignoring prototype pollution keys
{
  const target = {
    a: 1,
    nested: { x: 'original', y: 10 },
    arr: [1, 2],
  };

  const source1 = {
    nested: { y: 20, z: true },
    arr: [2, 3],
  };

  const source2 = {
    b: 'added',
    arr: [3, 4],
  };

  const result = deepAssign(target, source1, source2);
  assert.equal(result, target);
  assert.deepEqual(result, {
    a: 1,
    nested: { x: 'original', y: 20, z: true },
    arr: [1, 2, 3, 4],
    b: 'added',
  });

  const polluted = JSON.parse('{"__proto__": {"polluted": true}}');
  deepAssign({}, polluted);
  assert.equal(({}).polluted, undefined);
}

// 6. parseDn and mapToObject parse RFC 2253 distinguished name strings into key-value maps and plain objects
{
  const dnMap = parseDn('CN="Sample Developer", OU=Engineering, O=Example, C=US');
  assert.equal(dnMap.get('CN'), 'Sample Developer');
  assert.equal(dnMap.get('OU'), 'Engineering');
  assert.equal(dnMap.get('O'), 'Example');
  assert.equal(dnMap.get('C'), 'US');

  const dnObj = mapToObject(dnMap);
  assert.deepEqual(dnObj, {
    CN: 'Sample Developer',
    OU: 'Engineering',
    O: 'Example',
    C: 'US',
  });
}

// 7. objectToArgs and asArray helper utilities transform parameters safely
{
  assert.deepEqual(asArray(null), []);
  assert.deepEqual(asArray(undefined), []);
  assert.deepEqual(asArray('single'), ['single']);
  assert.deepEqual(asArray(['a', 'b']), ['a', 'b']);

  const args = objectToArgs({
    arch: 'x64',
    target: 'zip',
    empty: null,
  });
  assert.deepEqual(args, ['--arch', 'x64', '--target', 'zip']);
}

// 8. MemoLazy lazily computes and memoizes values based on selector cache invalidation
{
  let creatorCalls = 0;
  let currentConfig = 'v1';
  const lazy = new MemoLazy(
    () => currentConfig,
    (cfg) => {
      creatorCalls++;
      return { version: cfg, parsed: true };
    }
  );

  assert.equal(lazy.hasValue, false);
  assert.equal(creatorCalls, 0);

  const val1 = lazy.value;
  assert.equal(creatorCalls, 1);
  assert.equal(lazy.hasValue, true);
  assert.deepEqual(val1, { version: 'v1', parsed: true });

  const val2 = lazy.value;
  assert.equal(creatorCalls, 1);
  assert.equal(val1, val2);

  currentConfig = 'v2';
  const val3 = lazy.value;
  assert.equal(creatorCalls, 2);
  assert.deepEqual(val3, { version: 'v2', parsed: true });
}

原始种子者

匿名