CodeSampleX

示例

bare-dns 2.1.4

已验证示例 — npm bare-dns 2.1.4. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: package manifest specifies Bare native addon configuration, Apache-2.0…

sha256:17170efe4104817bc48707db11c58217e163fbae1a0a00bce4ca2fbc2aeedde7

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

执行证据

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

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
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-26
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-07

案例

HOW
目标
verify pkg:npm/bare-dns@2.1.4
包
环境
node 22.23.2
创建时间
2026-08-26T14:00:23Z

契约

  1. package manifest specifies Bare native addon configuration, Apache-2.0 license, and exports for root and package subpaths
  2. declares complete TypeScript definitions for DNS lookup, resolveTxt, and DNSResolver class in index.d.ts
  3. implements DNS lookup parameter normalization and resolver delegation in index.js
  4. implements native c-ares DNS resolver and lookup binding in binding.c with CMakeLists.txt build configuration
  5. provides multi-platform precompiled .bare addon binaries across Linux, Darwin, Windows, iOS, and Android targets

文件

  • 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/bare-dns@2.1.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-dns@2.1.4
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:35d7e6e7c4c165cadfad589ef2c27d77d338a8736bb81f0c0e07d49ce580d9e1","constraints":{"executionContext":"node"},"contract":["package manifest specifies Bare native addon configuration, Apache-2.0 license, and exports for root and package subpaths","declares complete TypeScript definitions for DNS lookup, resolveTxt, and DNSResolver class in index.d.ts","implements DNS lookup parameter normalization and resolver delegation in index.js","implements native c-ares DNS resolver and lookup binding in binding.c with CMakeLists.txt build configuration","provides multi-platform precompiled .bare addon binaries across Linux, Darwin, Windows, iOS, and Android targets"],"goal":"verify pkg:npm/bare-dns@2.1.4","kind":"HOW","packages":["pkg:npm/bare-dns@2.1.4"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/bare-dns@2.1.4"],"schemaVersion":1,"subject":"pkg:npm/bare-dns@2.1.4","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-bare-dns",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-dns",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "bare-dns": "2.1.4"
      }
    },
    "node_modules/bare-dns": {
      "version": "2.1.4",
      "resolved": "https://registry.npmjs.org/bare-dns/-/bare-dns-2.1.4.tgz",
      "integrity": "sha512-abwjHmpWqSRNB7V5615QxPH92L71AVzFm/kKTs8VYiNTAi2xVdonpv0BjJ0hwXLwomoW+xsSOPjW6PZPO14asg==",
      "license": "Apache-2.0",
      "engines": {
        "bare": ">=1.7.0"
      }
    }
  }
}
package.json
{
  "name": "sample-bare-dns",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "bare-dns": "2.1.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-dns@2.1.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-dns@2.1.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';

const require = createRequire(import.meta.url);

// 1. Resolve bare-dns package manifest and verify exports and metadata
const pkgPath = require.resolve('bare-dns/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'bare-dns', 'Package name must be bare-dns');
assert.equal(pkg.version, '2.1.4', 'Package version must be 2.1.4');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.equal(pkg.addon, true, 'Package must be marked as addon');
assert.equal(pkg.engines?.bare, '>=1.7.0', 'Package must specify Bare engine >=1.7.0');

assert.ok(pkg.exports, 'Package must define exports');
assert.equal(pkg.exports['.'].types, './index.d.ts', 'Root export must specify index.d.ts types');
assert.equal(pkg.exports['.'].default, './index.js', 'Root export must specify index.js default');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to package.json');

assert.deepEqual(
  pkg.files,
  ['index.js', 'index.d.ts', 'binding.c', 'binding.js', 'CMakeLists.txt', 'lib', 'prebuilds'],
  'Package files array must match expected files'
);

const pkgDir = path.dirname(pkgPath);

// 2. Verify complete TypeScript definitions in index.d.ts
const indexDtsPath = path.join(pkgDir, 'index.d.ts');
assert.ok(fs.existsSync(indexDtsPath), 'index.d.ts must exist');
const indexDts = fs.readFileSync(indexDtsPath, 'utf8');

assert.ok(indexDts.includes('type IPFamily = 4 | 6'), 'index.d.ts must define IPFamily');
assert.ok(indexDts.includes('interface LookupOptions'), 'index.d.ts must define LookupOptions');
assert.ok(indexDts.includes('declare class DNSResolver'), 'index.d.ts must declare DNSResolver class');
assert.ok(indexDts.includes('resolveTxt('), 'DNSResolver must declare resolveTxt');
assert.ok(indexDts.includes('destroy(): void'), 'DNSResolver must declare destroy');
assert.ok(indexDts.includes('export function lookup('), 'index.d.ts must declare lookup function');
assert.ok(indexDts.includes('export function resolveTxt('), 'index.d.ts must declare resolveTxt function');
assert.ok(indexDts.includes('DNSResolver as Resolver'), 'index.d.ts must export DNSResolver as Resolver');
assert.ok(indexDts.includes('export = dns'), 'index.d.ts must export namespace dns');

// 3. Verify JavaScript module implementation in index.js and binding.js
const indexJsPath = path.join(pkgDir, 'index.js');
assert.ok(fs.existsSync(indexJsPath), 'index.js must exist');
const indexJs = fs.readFileSync(indexJsPath, 'utf8');

assert.ok(indexJs.includes("require('./binding')"), 'index.js must require binding');
assert.ok(indexJs.includes('exports.Resolver = class DNSResolver'), 'index.js must define Resolver class');
assert.ok(indexJs.includes('exports.lookup = function lookup'), 'index.js must define lookup function');
assert.ok(indexJs.includes('exports.resolveTxt = function resolveTxt'), 'index.js must define resolveTxt function');
assert.ok(indexJs.includes('static global = new this()'), 'DNSResolver must initialize static global instance');

const bindingJsPath = path.join(pkgDir, 'binding.js');
assert.ok(fs.existsSync(bindingJsPath), 'binding.js must exist');
const bindingJs = fs.readFileSync(bindingJsPath, 'utf8');
assert.ok(bindingJs.includes('require.addon()'), 'binding.js must call require.addon()');

// 4. Verify C binding implementation and CMake build configuration
const bindingCPath = path.join(pkgDir, 'binding.c');
assert.ok(fs.existsSync(bindingCPath), 'binding.c must exist');
const bindingC = fs.readFileSync(bindingCPath, 'utf8');

assert.ok(bindingC.includes('#include <ares.h>'), 'binding.c must include <ares.h>');
assert.ok(bindingC.includes('#include <bare.h>'), 'binding.c must include <bare.h>');
assert.ok(bindingC.includes('#include <js.h>'), 'binding.c must include <js.h>');
assert.ok(bindingC.includes('#include <uv.h>'), 'binding.c must include <uv.h>');
assert.ok(bindingC.includes('bare_dns_lookup'), 'binding.c must define lookup implementation');
assert.ok(bindingC.includes('bare_dns_init_resolver'), 'binding.c must define initResolver implementation');
assert.ok(bindingC.includes('bare_dns_destroy_resolver'), 'binding.c must define destroyResolver implementation');
assert.ok(bindingC.includes('bare_dns_resolve_txt'), 'binding.c must define resolveTxt implementation');
assert.ok(bindingC.includes('BARE_MODULE(bare_dns, bare_dns_exports)'), 'binding.c must export BARE_MODULE bare_dns');

const cmakePath = path.join(pkgDir, 'CMakeLists.txt');
assert.ok(fs.existsSync(cmakePath), 'CMakeLists.txt must exist');
const cmake = fs.readFileSync(cmakePath, 'utf8');
assert.ok(cmake.includes('project(bare_dns C)'), 'CMakeLists.txt must define project bare_dns');
assert.ok(cmake.includes('add_bare_module(bare_dns)'), 'CMakeLists.txt must declare bare module');
assert.ok(cmake.includes('github:c-ares/c-ares'), 'CMakeLists.txt must fetch c-ares dependency');

// 5. Verify prebuilt native binaries across architectures
const prebuildsDir = path.join(pkgDir, 'prebuilds');
assert.ok(fs.existsSync(prebuildsDir), 'prebuilds directory must exist');

const expectedTargets = [
  'android-arm',
  'android-arm64',
  'android-ia32',
  'android-x64',
  'darwin-arm64',
  'darwin-x64',
  'ios-arm64-simulator',
  'ios-arm64',
  'ios-x64-simulator',
  'linux-arm64',
  'linux-x64',
  'win32-arm64',
  'win32-x64'
];

for (const target of expectedTargets) {
  const binaryPath = path.join(prebuildsDir, target, 'bare-dns.bare');
  assert.ok(fs.existsSync(binaryPath), `Prebuild binary must exist for target: ${target}`);
  const stat = fs.statSync(binaryPath);
  assert.ok(stat.size > 0, `Prebuild binary for ${target} must not be empty`);
}

const linuxX64Binary = fs.readFileSync(path.join(prebuildsDir, 'linux-x64', 'bare-dns.bare'));
assert.ok(linuxX64Binary.length > 1000, 'linux-x64 prebuild binary size must exceed 1000 bytes');

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

原始种子者

匿名