샘플
ip-address 10.7.0: AddressError
검증된 샘플 — npm ip-address 10.7.0: AddressError. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: AddressError is an Error subclass with name…
sha256:5bfc3fd916f962e36ddeca147e194c7bef0c2e66533c76e6d4795d89ad4677a7
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-07 |
케이스
HOW- 목표
- verify pkg:npm/ip-address@10.7.0
- 심벌
-
- AddressError
- 생성일
- 2026-09-07T00:28:49Z
컨트랙트
- AddressError is an Error subclass with name property set to 'AddressError'
- AddressError constructor initializes message and optional parseMessage properties
- Address4 constructor throws an instance of AddressError when given an invalid IPv4 address string
- Address6 constructor throws an instance of AddressError with parseMessage highlighting invalid IPv6 syntax
- Address4.fromAddressAndMask throws an instance of AddressError on non-contiguous subnet mask
- safeParseIp helper returns parsed addresses for valid inputs and returns caught AddressError on invalid inputs
파일
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
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/ip-address@10.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ip-address@10.7.0
Demonstrate these symbols/APIs:
- AddressError
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.
{"case":{"caseId":"case:sha256:f31caa37c5416831a50147fc5c45ca45cb10812a3fa2818fae1051447a3a2b93","contract":["AddressError is an Error subclass with name property set to 'AddressError'","AddressError constructor initializes message and optional parseMessage properties","Address4 constructor throws an instance of AddressError when given an invalid IPv4 address string","Address6 constructor throws an instance of AddressError with parseMessage highlighting invalid IPv6 syntax","Address4.fromAddressAndMask throws an instance of AddressError on non-contiguous subnet mask","safeParseIp helper returns parsed addresses for valid inputs and returns caught AddressError on invalid inputs"],"goal":"verify pkg:npm/ip-address@10.7.0","kind":"HOW","packages":["pkg:npm/ip-address@10.7.0"],"schemaVersion":1,"symbols":["AddressError"]},"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/ip-address@10.7.0"],"schemaVersion":1,"subject":"pkg:npm/ip-address@10.7.0","symbols":["AddressError"],"verifierAdapter":"node-typescript@1"}
import { Address4, Address6, AddressError } from 'ip-address';
/**
* Safely parses an IP address (IPv4 or IPv6), returning the parsed instance or capturing AddressError.
*
* @param {string} address - The IP address string to parse.
* @param {'v4' | 'v6' | 'auto'} [version='auto'] - Expected IP version format.
* @returns {{ ok: true, address: Address4 | Address6 } | { ok: false, error: AddressError }}
*/
export function safeParseIp(address, version = 'auto') {
try {
if (version === 'v4') {
return { ok: true, address: new Address4(address) };
}
if (version === 'v6') {
return { ok: true, address: new Address6(address) };
}
try {
return { ok: true, address: new Address4(address) };
} catch {
return { ok: true, address: new Address6(address) };
}
} catch (err) {
if (err instanceof AddressError) {
return { ok: false, error: err };
}
throw err;
}
}
/**
* Creates a new AddressError with a descriptive message and optional parseMessage context.
*
* @param {string} message - Descriptive error message.
* @param {string} [parseMessage] - Detailed parse context message.
* @returns {AddressError}
*/
export function createAddressError(message, parseMessage) {
return new AddressError(message, parseMessage);
}
export { AddressError, Address4, Address6 };
{
"name": "ip-address-error-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ip-address-error-sample",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"ip-address": "10.7.0"
}
},
"node_modules/ip-address": {
"version": "10.7.0",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.0.tgz",
"integrity": "sha512-BGFsyJd5mpXp3rK6jIdADLNgpJUK1jnjzvYF8lK+VyDab9JAmqN0YOKDdP17HlgKb2+ehPgDc8EtnRLbGCAMhA==",
"license": "MIT",
"engines": {
"node": ">= 12"
}
}
}
}
{
"name": "ip-address-error-sample",
"version": "1.0.0",
"type": "module",
"license": "MIT-0",
"dependencies": {
"ip-address": "10.7.0"
},
"scripts": {
"test": "node test/contract.mjs"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/ip-address@10.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/ip-address@10.7.0"
],
"symbols": [
"AddressError"
]
}
import assert from 'node:assert/strict';
import {
AddressError,
Address4,
Address6,
safeParseIp,
createAddressError
} from '../index.mjs';
// Contract 1: AddressError is an Error subclass with name property set to 'AddressError'
{
const err = new AddressError('Invalid address');
assert.equal(err instanceof Error, true);
assert.equal(err instanceof AddressError, true);
assert.equal(err.name, 'AddressError');
assert.equal(err.message, 'Invalid address');
assert.equal(err.parseMessage, undefined);
}
// Contract 2: AddressError constructor initializes message and optional parseMessage properties
{
const parseMarkup = '2001<span class="parse-error">:::</span>1';
const err = createAddressError('Address failed regex: :::', parseMarkup);
assert.equal(err.name, 'AddressError');
assert.equal(err.message, 'Address failed regex: :::');
assert.equal(err.parseMessage, parseMarkup);
}
// Contract 3: Address4 constructor throws an instance of AddressError when given an invalid IPv4 address string
{
const invalidV4Inputs = ['invalid-ip', '256.0.0.1', '1.2.3', '1.2.3.4.5', '1.2.3.999'];
for (const input of invalidV4Inputs) {
assert.throws(
() => new Address4(input),
(err) => {
return err instanceof AddressError && err.name === 'AddressError';
},
`Address4("${input}") must throw AddressError`
);
}
}
// Contract 4: Address6 constructor throws an instance of AddressError with parseMessage highlighting invalid IPv6 syntax
{
const invalidV6Inputs = ['not-an-ipv6', '2001:::1', '12345::1', 'fe80::1::2'];
for (const input of invalidV6Inputs) {
assert.throws(
() => new Address6(input),
(err) => {
return err instanceof AddressError && err.name === 'AddressError';
},
`Address6("${input}") must throw AddressError`
);
}
// Specifically verify parseMessage highlights offending syntax
try {
new Address6('2001:::1');
assert.fail('should have thrown');
} catch (err) {
assert.equal(err instanceof AddressError, true);
assert.equal(err.parseMessage, '2001<span class="parse-error">:::</span>1');
}
}
// Contract 5: Address4.fromAddressAndMask throws an instance of AddressError on non-contiguous subnet mask
{
assert.throws(
() => Address4.fromAddressAndMask('192.168.1.1', '255.0.255.0'),
(err) => {
return err instanceof AddressError && err.message === 'Invalid subnet mask.';
}
);
// Valid contiguous mask succeeds
const valid = Address4.fromAddressAndMask('192.168.1.1', '255.255.255.0');
assert.equal(valid.subnetMask, 24);
}
// Contract 6: safeParseIp helper returns parsed addresses for valid inputs and returns caught AddressError on invalid inputs
{
// Valid IPv4
const v4Valid = safeParseIp('192.168.1.1', 'v4');
assert.equal(v4Valid.ok, true);
assert.equal(v4Valid.address.correctForm(), '192.168.1.1');
// Invalid IPv4
const v4Invalid = safeParseIp('999.999.999.999', 'v4');
assert.equal(v4Invalid.ok, false);
assert.equal(v4Invalid.error instanceof AddressError, true);
assert.equal(v4Invalid.error.name, 'AddressError');
// Valid IPv6
const v6Valid = safeParseIp('2001:db8::1', 'v6');
assert.equal(v6Valid.ok, true);
assert.equal(v6Valid.address.correctForm(), '2001:db8::1');
// Invalid IPv6
const v6Invalid = safeParseIp('invalid-ipv6-string', 'v6');
assert.equal(v6Invalid.ok, false);
assert.equal(v6Invalid.error instanceof AddressError, true);
assert.equal(v6Invalid.error.name, 'AddressError');
// Auto detection valid
const autoV4 = safeParseIp('10.0.0.1');
assert.equal(autoV4.ok, true);
assert.equal(autoV4.address.correctForm(), '10.0.0.1');
const autoV6 = safeParseIp('::1');
assert.equal(autoV6.ok, true);
assert.equal(autoV6.address.correctForm(), '::1');
// Auto detection invalid
const autoInvalid = safeParseIp('completely-invalid-address');
assert.equal(autoInvalid.ok, false);
assert.equal(autoInvalid.error instanceof AddressError, true);
}
console.log('All contract assertions verified successfully.');
오리진 시더
익명