示例
github.com/miekg/dns v1.1.63: Msg.SetQuestion
已验证示例 — golang github.com/miekg/dns v1.1.63: Msg.SetQuestion. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: dns.Msg.SetQuestion initializes Question…
sha256:5867770ff821250d5a48590b9959705c8898176d435beb424577b909166cbf1c
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- dns_question.go
- go.mod
- go.sum
- spec.json
- test/contract_test.go
源代码
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.
{"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"}
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
}
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
)
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=
{
"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"
}
}
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)
}
}
原始种子者
匿名