CodeSampleX

Пример

netmask 2.1.2: long2ip

Проверенный пример — npm netmask 2.1.2: long2ip. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: require('netmask').long2ip is exported…

sha256:3617405abd36dbc6697c1e92dee99da9dc8ffe53e193f5b900c3c83503b51f51

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-11-27

Кейс

HOW
Цель
verify netmask.long2ip in pkg:npm/netmask@2.1.2
Пакеты
Символы
  • netmask.long2ip
Окружение
node 22.23.2
Создан
2026-11-27T01:03:33Z

Контракт

  1. require('netmask').long2ip is exported as a function in CommonJS
  2. netmask.long2ip converts 32-bit unsigned integers to dotted-quad IPv4 strings (0 -> '0.0.0.0', 0x0a141e28 -> '10.20.30.40', 0x7f000001 -> '127.0.0.1', 0xc0a80101 -> '192.168.1.1', 0xffffffff -> '255.255.255.255')
  3. netmask.long2ip applies 32-bit bitwise coercion without throwing on signed negative (-1 -> '255.255.255.255') and overflow (0x100000000 -> '0.0.0.0') inputs
  4. netmask.long2ip(netmask.ip2long('192.168.1.1')) round-trips to '192.168.1.1'

Файлы

  • 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 netmask.long2ip in pkg:npm/netmask@2.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/netmask@2.1.2
Demonstrate these symbols/APIs:
  - netmask.long2ip
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:e990b22ea28c9ff93faa57716ac3485673fc65b7091d071f3c434fe92ebc9dd2","constraints":{"executionContext":"node"},"contract":["require('netmask').long2ip is exported as a function in CommonJS","netmask.long2ip converts 32-bit unsigned integers to dotted-quad IPv4 strings (0 -\u003e '0.0.0.0', 0x0a141e28 -\u003e '10.20.30.40', 0x7f000001 -\u003e '127.0.0.1', 0xc0a80101 -\u003e '192.168.1.1', 0xffffffff -\u003e '255.255.255.255')","netmask.long2ip applies 32-bit bitwise coercion without throwing on signed negative (-1 -\u003e '255.255.255.255') and overflow (0x100000000 -\u003e '0.0.0.0') inputs","netmask.long2ip(netmask.ip2long('192.168.1.1')) round-trips to '192.168.1.1'"],"goal":"verify netmask.long2ip in pkg:npm/netmask@2.1.2","kind":"HOW","packages":["pkg:npm/netmask@2.1.2"],"schemaVersion":1,"symbols":["netmask.long2ip"]},"contractCommand":["node","test/contract.js"],"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/netmask@2.1.2"],"schemaVersion":1,"subject":"pkg:npm/netmask@2.1.2","symbols":["netmask.long2ip"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "netmask-long2ip-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "netmask-long2ip-sample",
      "version": "1.0.0",
      "dependencies": {
        "netmask": "2.1.2"
      }
    },
    "node_modules/netmask": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.1.2.tgz",
      "integrity": "sha512-In/qjEgPWP3EEKRBrATKSHRCcempKN/gUl97rrB1mTreVQfvPGthTJVwNXwbQHtIzzLf1bYyh8M50xpeYk0r6Q==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4.0"
      }
    }
  }
}
package.json
{
  "name": "netmask-long2ip-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Verify netmask.long2ip in netmask 2.1.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "netmask": "2.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify netmask.long2ip in pkg:npm/netmask@2.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/netmask@2.1.2"
  ],
  "symbols": [
    "netmask.long2ip"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const { long2ip } = require('netmask');

function formatIpv4(value) {
  return long2ip(value);
}

module.exports = { formatIpv4, long2ip };
test/contract.js
'use strict';

const assert = require('node:assert/strict');
const netmask = require('netmask');
const { formatIpv4 } = require('../src/index.js');

assert.equal(typeof netmask.long2ip, 'function');

// Standard unsigned 32-bit integer conversions
assert.equal(netmask.long2ip(0), '0.0.0.0');
assert.equal(netmask.long2ip(0x0a141e28), '10.20.30.40');
assert.equal(netmask.long2ip(0x7f000001), '127.0.0.1');
assert.equal(netmask.long2ip(0xc0a80101), '192.168.1.1');
assert.equal(netmask.long2ip(0xffffffff), '255.255.255.255');

// Wrapper exports and preserves long2ip output
assert.equal(formatIpv4(2130706433), '127.0.0.1');

// Bitwise 32-bit coercion for signed negative and >32-bit integers (does not throw)
assert.equal(netmask.long2ip(-1), '255.255.255.255');
assert.equal(netmask.long2ip(0x100000000), '0.0.0.0');

// Round-trip consistency with ip2long
assert.equal(netmask.long2ip(netmask.ip2long('192.168.1.1')), '192.168.1.1');

console.log('PASS: netmask.long2ip contract verified');

Исходный сидер

аноним