CodeSampleX

샘플

github.com/miekg/dns v1.1.63: Msg.SetQuestion

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

sha256:5867770ff821250d5a48590b9959705c8898176d435beb424577b909166cbf1c

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

케이스

HOW
목표
verify dns.Msg.SetQuestion in pkg:golang/github.com/miekg/dns@v1.1.63
패키지
심벌
  • dns.Msg.SetQuestion
생성일
2026-08-26T04:48:32Z

컨트랙트

  1. dns.Msg.SetQuestion initializes Question section with single DNS question containing normalized FQDN and specified RR type
  2. dns.Msg.SetQuestion sets default query class to ClassINET for standard DNS queries
  3. dns.Msg.SetQuestion supports multiple DNS record types including TypeA, TypeAAAA, TypeTXT, and TypeMX
  4. dns.Msg.SetQuestion replaces existing questions when called repeatedly on the same message

파일

  • PROMPT.md
  • csx.json
  • dns_question.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 dns.Msg.SetQuestion in 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
Demonstrate these symbols/APIs:
  - dns.Msg.SetQuestion
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:8e95009363bc9d03ff2156a98f8ba20dd56c72b48be004a80424b8f55a293f1a","contract":["dns.Msg.SetQuestion initializes Question section with single DNS question containing normalized FQDN and specified RR type","dns.Msg.SetQuestion sets default query class to ClassINET for standard DNS queries","dns.Msg.SetQuestion supports multiple DNS record types including TypeA, TypeAAAA, TypeTXT, and TypeMX","dns.Msg.SetQuestion replaces existing questions when called repeatedly on the same message"],"goal":"verify dns.Msg.SetQuestion in 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"]},"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","symbols":["dns.Msg.SetQuestion"],"verifierAdapter":"golang@1"}
dns_question.go
package dnsquestion

import (
	"fmt"

	"github.com/miekg/dns"
)

// NewDNSQuery creates a new DNS query message with question configured for domain and query type.
func NewDNSQuery(domain string, qtype uint16) *dns.Msg {
	msg := new(dns.Msg)
	msg.SetQuestion(dns.Fqdn(domain), qtype)
	return msg
}

// ResetQuestion changes the question on an existing DNS message.
func ResetQuestion(msg *dns.Msg, domain string, qtype uint16) {
	msg.SetQuestion(dns.Fqdn(domain), qtype)
}

// GetQuestionDetails returns the question name, query type, and query class.
func GetQuestionDetails(msg *dns.Msg) (string, uint16, uint16, error) {
	if len(msg.Question) == 0 {
		return "", 0, 0, fmt.Errorf("message has no questions")
	}
	q := msg.Question[0]
	return q.Name, q.Qtype, q.Qclass, nil
}
go.mod
module example.com/dnsquestion

go 1.26.6

require (
	github.com/miekg/dns v1.1.63
	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 dns.Msg.SetQuestion in pkg:golang/github.com/miekg/dns@v1.1.63",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/miekg/dns@v1.1.63"
  ],
  "symbols": [
    "dns.Msg.SetQuestion"
  ],
  "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/dnsquestion"
	"github.com/miekg/dns"
)

func TestSetQuestionInitializesSingleQuestion(t *testing.T) {
	domain := "example.com"
	msg := dnsquestion.NewDNSQuery(domain, dns.TypeA)

	if len(msg.Question) != 1 {
		t.Fatalf("expected 1 question in msg.Question slice, got %d", len(msg.Question))
	}

	name, qtype, qclass, err := dnsquestion.GetQuestionDetails(msg)
	if err != nil {
		t.Fatalf("unexpected error getting question details: %v", err)
	}

	expectedFQDN := "example.com."
	if name != expectedFQDN {
		t.Errorf("expected question name %q, got %q", expectedFQDN, name)
	}
	if qtype != dns.TypeA {
		t.Errorf("expected Qtype TypeA (%d), got %d", dns.TypeA, qtype)
	}
	if qclass != dns.ClassINET {
		t.Errorf("expected Qclass ClassINET (%d), got %d", dns.ClassINET, qclass)
	}
}

func TestSetQuestionSupportsVariousRecordTypes(t *testing.T) {
	testCases := []struct {
		domain string
		qtype  uint16
	}{
		{"example.org", dns.TypeAAAA},
		{"mail.example.com", dns.TypeMX},
		{"sub.example.net", dns.TypeTXT},
		{"_sip._tcp.example.com", dns.TypeSRV},
	}

	for _, tc := range testCases {
		msg := dnsquestion.NewDNSQuery(tc.domain, tc.qtype)
		name, qtype, qclass, err := dnsquestion.GetQuestionDetails(msg)
		if err != nil {
			t.Fatalf("failed to get question for %s: %v", tc.domain, err)
		}
		expectedName := dns.Fqdn(tc.domain)
		if name != expectedName {
			t.Errorf("expected name %s, got %s", expectedName, name)
		}
		if qtype != tc.qtype {
			t.Errorf("expected qtype %d, got %d", tc.qtype, qtype)
		}
		if qclass != dns.ClassINET {
			t.Errorf("expected qclass ClassINET, got %d", qclass)
		}
	}
}

func TestSetQuestionReplacesExistingQuestion(t *testing.T) {
	msg := dnsquestion.NewDNSQuery("first.example.com", dns.TypeA)
	if len(msg.Question) != 1 || msg.Question[0].Name != "first.example.com." {
		t.Fatalf("initial question setup failed")
	}

	dnsquestion.ResetQuestion(msg, "second.example.com", dns.TypeTXT)
	if len(msg.Question) != 1 {
		t.Fatalf("expected question list to have length 1 after reset, got %d", len(msg.Question))
	}
	if msg.Question[0].Name != "second.example.com." {
		t.Errorf("expected replaced question name 'second.example.com.', got %q", msg.Question[0].Name)
	}
	if msg.Question[0].Qtype != dns.TypeTXT {
		t.Errorf("expected replaced question type TypeTXT (%d), got %d", dns.TypeTXT, msg.Question[0].Qtype)
	}
}

오리진 시더

익명