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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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)
	}
}

オリジンシーダー

匿名