CodeSampleX

샘플

github.com/miekg/dns v1.1.63

검증된 샘플 — golang github.com/miekg/dns v1.1.63. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: dns.Msg.SetQuestion constructs standard DNS query…

sha256:87155f93cfe91ba4949994767053ea25ce7c66b5ca50abebdd2cf48ee2bfb84e

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-23

케이스

HOW
목표
verify pkg:golang/github.com/miekg/dns@v1.1.63
패키지
생성일
2026-08-23T17:11:07Z

컨트랙트

  1. dns.Msg.SetQuestion constructs standard DNS query question with FQDN and query type
  2. dns.Msg.Pack encodes DNS message into RFC 1035 binary wire format
  3. dns.Msg.Unpack decodes RFC 1035 binary wire format back into DNS message structure
  4. dns.NewRR parses zone file format resource records into typed RR structures including A, TXT, and MX

파일

  • PROMPT.md
  • csx.json
  • dns_sample.go
  • go.mod
  • go.sum
  • spec.json
  • test/contract_test.go

소스 아티팩트 내려받기 (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:golang/github.com/miekg/dns@v1.1.63
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/miekg/dns@v1.1.63
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:0b2a014d4a07de7ee422aef5457b11a1dfb275083d3a043d19d9d8d9183a07de","contract":["dns.Msg.SetQuestion constructs standard DNS query question with FQDN and query type","dns.Msg.Pack encodes DNS message into RFC 1035 binary wire format","dns.Msg.Unpack decodes RFC 1035 binary wire format back into DNS message structure","dns.NewRR parses zone file format resource records into typed RR structures including A, TXT, and MX"],"goal":"verify pkg:golang/github.com/miekg/dns@v1.1.63","kind":"HOW","packages":["pkg:golang/github.com/miekg/dns@v1.1.63"],"schemaVersion":1,"symbols":["dns.Msg.SetQuestion","dns.Msg.Pack","dns.Msg.Unpack","dns.NewRR"]},"contractCommand":["go","test","-v","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/miekg/dns@v1.1.63"],"schemaVersion":1,"subject":"pkg:golang/github.com/miekg/dns@v1.1.63","verifierAdapter":"golang@1"}
dns_sample.go
package dnssample

import (
	"fmt"
	"net"

	"github.com/miekg/dns"
)

// BuildQuery creates a DNS query message for the specified domain and record type.
func BuildQuery(domain string, qtype uint16, recursionDesired bool) *dns.Msg {
	m := new(dns.Msg)
	m.SetQuestion(dns.Fqdn(domain), qtype)
	m.RecursionDesired = recursionDesired
	return m
}

// PackAndUnpack serializes a DNS message to wire format and deserializes it back.
func PackAndUnpack(msg *dns.Msg) (*dns.Msg, []byte, error) {
	wire, err := msg.Pack()
	if err != nil {
		return nil, nil, fmt.Errorf("pack failed: %w", err)
	}

	unpacked := new(dns.Msg)
	if err := unpacked.Unpack(wire); err != nil {
		return nil, nil, fmt.Errorf("unpack failed: %w", err)
	}

	return unpacked, wire, nil
}

// BuildResponse creates a response message answering an A query for domain with given IP and TTL.
func BuildResponse(query *dns.Msg, ip string, ttl uint32) (*dns.Msg, error) {
	resp := new(dns.Msg)
	resp.SetReply(query)
	resp.Authoritative = true

	qName := query.Question[0].Name
	rrStr := fmt.Sprintf("%s %d IN A %s", qName, ttl, ip)
	rr, err := dns.NewRR(rrStr)
	if err != nil {
		return nil, fmt.Errorf("failed to parse A record: %w", err)
	}

	resp.Answer = append(resp.Answer, rr)
	return resp, nil
}

// ParseResourceRecord parses an RFC 1035 zone file formatted RR string.
func ParseResourceRecord(recordStr string) (dns.RR, error) {
	rr, err := dns.NewRR(recordStr)
	if err != nil {
		return nil, fmt.Errorf("failed to parse RR: %w", err)
	}
	return rr, nil
}

// ParseIPv4Extract returns the net.IP from an A resource record.
func ParseIPv4Extract(rr dns.RR) (net.IP, error) {
	aRecord, ok := rr.(*dns.A)
	if !ok {
		return nil, fmt.Errorf("record is not an A record: %T", rr)
	}
	return aRecord.A, nil
}
go.mod
module example.com/dnssample

go 1.26.6

require (
	github.com/miekg/dns v1.1.63 // indirect
	golang.org/x/mod v0.18.0 // indirect
	golang.org/x/net v0.31.0 // indirect
	golang.org/x/sync v0.7.0 // indirect
	golang.org/x/sys v0.27.0 // indirect
	golang.org/x/tools v0.22.0 // indirect
)
go.sum
github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/miekg/dns@v1.1.63",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/miekg/dns@v1.1.63"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract_test.go
package test

import (
	"testing"

	"example.com/dnssample"
	"github.com/miekg/dns"
)

func TestDNSQueryBuildAndWireSerialization(t *testing.T) {
	domain := "example.com"
	query := dnssample.BuildQuery(domain, dns.TypeA, true)

	if len(query.Question) != 1 {
		t.Fatalf("expected 1 question, got %d", len(query.Question))
	}
	if query.Question[0].Name != "example.com." {
		t.Fatalf("expected FQDN 'example.com.', got '%s'", query.Question[0].Name)
	}
	if query.Question[0].Qtype != dns.TypeA {
		t.Fatalf("expected Qtype TypeA, got %d", query.Question[0].Qtype)
	}
	if query.Question[0].Qclass != dns.ClassINET {
		t.Fatalf("expected Qclass ClassINET, got %d", query.Question[0].Qclass)
	}
	if !query.RecursionDesired {
		t.Fatalf("expected RecursionDesired to be true")
	}

	unpacked, wire, err := dnssample.PackAndUnpack(query)
	if err != nil {
		t.Fatalf("PackAndUnpack failed: %v", err)
	}
	if len(wire) == 0 {
		t.Fatalf("expected non-empty wire bytes")
	}
	if unpacked.Id != query.Id {
		t.Fatalf("unpacked Id %d does not match original %d", unpacked.Id, query.Id)
	}
	if unpacked.Question[0].Name != "example.com." {
		t.Fatalf("unpacked question name mismatch: %s", unpacked.Question[0].Name)
	}
	if unpacked.Question[0].Qtype != dns.TypeA {
		t.Fatalf("unpacked question type mismatch: %d", unpacked.Question[0].Qtype)
	}
}

func TestDNSResponseAndResourceRecordParsing(t *testing.T) {
	query := dnssample.BuildQuery("example.com", dns.TypeA, true)
	expectedIP := "93.184.216.34"
	var expectedTTL uint32 = 300

	resp, err := dnssample.BuildResponse(query, expectedIP, expectedTTL)
	if err != nil {
		t.Fatalf("BuildResponse failed: %v", err)
	}

	if !resp.Response {
		t.Fatalf("expected Response flag to be true")
	}
	if !resp.Authoritative {
		t.Fatalf("expected Authoritative flag to be true")
	}
	if len(resp.Answer) != 1 {
		t.Fatalf("expected 1 answer RR, got %d", len(resp.Answer))
	}

	ip, err := dnssample.ParseIPv4Extract(resp.Answer[0])
	if err != nil {
		t.Fatalf("ParseIPv4Extract failed: %v", err)
	}
	if ip.String() != expectedIP {
		t.Fatalf("expected IP %s, got %s", expectedIP, ip.String())
	}

	unpackedResp, _, err := dnssample.PackAndUnpack(resp)
	if err != nil {
		t.Fatalf("PackAndUnpack response failed: %v", err)
	}
	if len(unpackedResp.Answer) != 1 {
		t.Fatalf("expected 1 answer in unpacked response, got %d", len(unpackedResp.Answer))
	}
	unpackedIP, err := dnssample.ParseIPv4Extract(unpackedResp.Answer[0])
	if err != nil {
		t.Fatalf("failed extracting IP from unpacked answer: %v", err)
	}
	if unpackedIP.String() != expectedIP {
		t.Fatalf("expected unpacked IP %s, got %s", expectedIP, unpackedIP.String())
	}
}

func TestParseMultipleResourceRecordTypes(t *testing.T) {
	txtStr := "example.com. 3600 IN TXT \"v=spf1 include:_spf.example.com ~all\""
	rrTxt, err := dnssample.ParseResourceRecord(txtStr)
	if err != nil {
		t.Fatalf("failed parsing TXT record: %v", err)
	}
	txtRecord, ok := rrTxt.(*dns.TXT)
	if !ok {
		t.Fatalf("expected *dns.TXT, got %T", rrTxt)
	}
	if len(txtRecord.Txt) != 1 || txtRecord.Txt[0] != "v=spf1 include:_spf.example.com ~all" {
		t.Fatalf("unexpected TXT content: %v", txtRecord.Txt)
	}

	mxStr := "example.com. 3600 IN MX 10 mail.example.com."
	rrMx, err := dnssample.ParseResourceRecord(mxStr)
	if err != nil {
		t.Fatalf("failed parsing MX record: %v", err)
	}
	mxRecord, ok := rrMx.(*dns.MX)
	if !ok {
		t.Fatalf("expected *dns.MX, got %T", rrMx)
	}
	if mxRecord.Preference != 10 || mxRecord.Mx != "mail.example.com." {
		t.Fatalf("unexpected MX values: pref=%d mx=%s", mxRecord.Preference, mxRecord.Mx)
	}

	invalidStr := "not-a-valid-dns-rr-format"
	_, err = dnssample.ParseResourceRecord(invalidStr)
	if err == nil {
		t.Fatalf("expected error parsing invalid RR string, got nil")
	}
}

오리진 시더

익명