샘플
golang.org/x/net v0.29.0: html.Parse
검증된 샘플 — golang golang.org/x/net v0.29.0: html.Parse. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: html.Parse parses an HTML document into a…
sha256:4615c2c1f7fae1131aeb0622a74e563871fcee8ce173b6925ceb012fa545ffc4
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-03 |
케이스
HOW- 목표
- verify golang.org/x/net/html.Parse in pkg:golang/golang.org/x/net@v0.29.0
- 심벌
-
- golang.org/x/net/html.Parse
- 생성일
- 2026-09-03T05:10:23Z
컨트랙트
- html.Parse parses an HTML document into a DocumentNode with standard html, head, and body hierarchy
- html.Parse constructs ElementNode with expected tag Data, namespace, and Attribute key-value pairs
- html.Parse constructs TextNode containing inner text and CommentNode containing comments
- html.Parse handles fragment-like or unclosed HTML input by synthesizing a valid document tree without error
- html.Parse preserves sibling and parent pointers across all traversed child nodes
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.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 golang.org/x/net/html.Parse in pkg:golang/golang.org/x/net@v0.29.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/net@v0.29.0
Demonstrate these symbols/APIs:
- golang.org/x/net/html.Parse
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:b9c6c8ee828eea62c8a081465b5e5ae1f6d7144fd01d5caf7c30d4bcecf9dc1e","contract":["html.Parse parses an HTML document into a DocumentNode with standard html, head, and body hierarchy","html.Parse constructs ElementNode with expected tag Data, namespace, and Attribute key-value pairs","html.Parse constructs TextNode containing inner text and CommentNode containing comments","html.Parse handles fragment-like or unclosed HTML input by synthesizing a valid document tree without error","html.Parse preserves sibling and parent pointers across all traversed child nodes"],"goal":"verify golang.org/x/net/html.Parse in pkg:golang/golang.org/x/net@v0.29.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.29.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.Parse"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/net@v0.29.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.29.0","symbols":["golang.org/x/net/html.Parse"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require golang.org/x/net v0.29.0
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
package main
import (
"fmt"
"log"
"strings"
"golang.org/x/net/html"
)
func main() {
htmlContent := `<!DOCTYPE html>
<html>
<head>
<title>CodeSampleX Demonstration</title>
</head>
<body>
<header>
<h1>Welcome to HTML Parsing</h1>
</header>
<main>
<p class="summary" id="lead">Parsing HTML documents into a DOM tree in Go.</p>
</main>
</body>
</html>`
doc, err := html.Parse(strings.NewReader(htmlContent))
if err != nil {
log.Fatalf("failed to parse HTML: %v", err)
}
fmt.Println("HTML parsed successfully into document tree.")
var findNode func(*html.Node, string) *html.Node
findNode = func(n *html.Node, tag string) *html.Node {
if n.Type == html.ElementNode && n.Data == tag {
return n
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
if res := findNode(c, tag); res != nil {
return res
}
}
return nil
}
titleNode := findNode(doc, "title")
if titleNode != nil && titleNode.FirstChild != nil {
fmt.Printf("Document Title: %s\n", titleNode.FirstChild.Data)
}
pNode := findNode(doc, "p")
if pNode != nil {
for _, attr := range pNode.Attr {
fmt.Printf("Attribute %s=%q\n", attr.Key, attr.Val)
}
if pNode.FirstChild != nil {
fmt.Printf("Paragraph text: %s\n", pNode.FirstChild.Data)
}
}
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/net/html.Parse in pkg:golang/golang.org/x/net@v0.29.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.29.0"
],
"symbols": [
"golang.org/x/net/html.Parse"
]
}
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/net/html"
)
func main() {
// 1. html.Parse parses an HTML document into a DocumentNode with standard html, head, and body hierarchy
docHTML := `<!DOCTYPE html><html><head><title>Contract Test</title></head><body><h1>Heading</h1></body></html>`
doc, err := html.Parse(strings.NewReader(docHTML))
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: html.Parse returned error: %v\n", err)
os.Exit(1)
}
if doc == nil || doc.Type != html.DocumentNode {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected DocumentNode root\n")
os.Exit(1)
}
var htmlNode, headNode, bodyNode *html.Node
for c := doc.FirstChild; c != nil; c = c.NextSibling {
if c.Type == html.ElementNode && c.Data == "html" {
htmlNode = c
break
}
}
if htmlNode == nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: html element not found\n")
os.Exit(1)
}
for c := htmlNode.FirstChild; c != nil; c = c.NextSibling {
if c.Type == html.ElementNode && c.Data == "head" {
headNode = c
} else if c.Type == html.ElementNode && c.Data == "body" {
bodyNode = c
}
}
if headNode == nil || bodyNode == nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: head or body element missing\n")
os.Exit(1)
}
// 2. html.Parse constructs ElementNode with expected tag Data, namespace, and Attribute key-value pairs
attrHTML := `<div id="main-card" class="card primary" data-count="42"><span>item</span></div>`
attrDoc, err := html.Parse(strings.NewReader(attrHTML))
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: html.Parse returned error: %v\n", err)
os.Exit(1)
}
divNode := findFirstByTag(attrDoc, "div")
if divNode == nil || divNode.Type != html.ElementNode {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: div element not found\n")
os.Exit(1)
}
attrMap := make(map[string]string)
for _, attr := range divNode.Attr {
attrMap[attr.Key] = attr.Val
}
if attrMap["id"] != "main-card" || attrMap["class"] != "card primary" || attrMap["data-count"] != "42" {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: attributes mismatch: got %+v\n", attrMap)
os.Exit(1)
}
// 3. html.Parse constructs TextNode containing inner text and CommentNode containing comments
textCommentHTML := `<div><!-- initial comment -->Sample Text Content<!-- closing comment --></div>`
tcDoc, err := html.Parse(strings.NewReader(textCommentHTML))
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: html.Parse returned error: %v\n", err)
os.Exit(1)
}
tcDiv := findFirstByTag(tcDoc, "div")
if tcDiv == nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: div element not found\n")
os.Exit(1)
}
var commentCount, textCount int
var capturedText string
for c := tcDiv.FirstChild; c != nil; c = c.NextSibling {
if c.Type == html.CommentNode {
commentCount++
} else if c.Type == html.TextNode {
textCount++
capturedText = c.Data
}
}
if commentCount != 2 || textCount != 1 || capturedText != "Sample Text Content" {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: comments=%d (want 2), texts=%d (want 1), text=%q\n", commentCount, textCount, capturedText)
os.Exit(1)
}
// 4. html.Parse handles fragment-like or unclosed HTML input by synthesizing a valid document tree without error
unclosedHTML := `<section><p>Unclosed paragraph<span>Nested text`
unclosedDoc, err := html.Parse(strings.NewReader(unclosedHTML))
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: html.Parse returned unexpected error: %v\n", err)
os.Exit(1)
}
pElement := findFirstByTag(unclosedDoc, "p")
spanElement := findFirstByTag(unclosedDoc, "span")
if pElement == nil || spanElement == nil {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: unclosed elements were not properly parsed\n")
os.Exit(1)
}
// 5. html.Parse preserves sibling and parent pointers across all traversed child nodes
if err := verifyPointers(doc); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: doc pointer check failed: %v\n", err)
os.Exit(1)
}
if err := verifyPointers(attrDoc); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: attrDoc pointer check failed: %v\n", err)
os.Exit(1)
}
if err := verifyPointers(unclosedDoc); err != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: unclosedDoc pointer check failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
func findFirstByTag(n *html.Node, tag string) *html.Node {
if n.Type == html.ElementNode && n.Data == tag {
return n
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
if res := findFirstByTag(c, tag); res != nil {
return res
}
}
return nil
}
func verifyPointers(n *html.Node) error {
var lastChild *html.Node
for c := n.FirstChild; c != nil; c = c.NextSibling {
if c.Parent != n {
return fmt.Errorf("child node %p has parent %p, expected %p", c, c.Parent, n)
}
if c.NextSibling != nil && c.NextSibling.PrevSibling != c {
return fmt.Errorf("node %p next sibling's prev sibling mismatch", c)
}
if c.PrevSibling != nil && c.PrevSibling.NextSibling != c {
return fmt.Errorf("node %p prev sibling's next sibling mismatch", c)
}
lastChild = c
if err := verifyPointers(c); err != nil {
return err
}
}
if n.FirstChild != nil && n.LastChild != lastChild {
return fmt.Errorf("node %p LastChild mismatch: got %p, expected %p", n, n.LastChild, lastChild)
}
return nil
}
오리진 시더
익명