CodeSampleX

샘플

golang.org/x/net v0.23.0: html.Node

검증된 샘플 — golang golang.org/x/net v0.23.0: html.Node. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: html.Node struct fields represent node type…

sha256:e49da15dd5db103a14e48bce00ad679e2f854a95c9f616e046e481d950f2501e

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

케이스

HOW
목표
verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.23.0
패키지
심벌
  • golang.org/x/net/html.Node
생성일
2026-09-04T12:45:05Z

컨트랙트

  1. html.Node struct fields represent node type, data, and attributes
  2. html.Node.AppendChild attaches child and sets FirstChild, LastChild, and Parent pointers
  3. html.Node.AppendChild maintains sibling chain when appending multiple children
  4. html.Node.InsertBefore inserts new child before reference node and updates sibling links
  5. html.Node.RemoveChild detaches child and unlinks sibling pointers
  6. html.Parse builds a valid DocumentNode tree with root node and child elements
  7. html.Render serializes Node tree to HTML output matching node structure and attributes

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.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 golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.23.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.23.0
Demonstrate these symbols/APIs:
  - golang.org/x/net/html.Node

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:1d69f7356d79b7792dd671ddec8af435315533bb4602b278589b6a0a84fbcea7","contract":["html.Node struct fields represent node type, data, and attributes","html.Node.AppendChild attaches child and sets FirstChild, LastChild, and Parent pointers","html.Node.AppendChild maintains sibling chain when appending multiple children","html.Node.InsertBefore inserts new child before reference node and updates sibling links","html.Node.RemoveChild detaches child and unlinks sibling pointers","html.Parse builds a valid DocumentNode tree with root node and child elements","html.Render serializes Node tree to HTML output matching node structure and attributes"],"goal":"verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.23.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.23.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.Node"]},"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.23.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.23.0","symbols":["golang.org/x/net/html.Node"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.23.0

require golang.org/x/net v0.23.0
go.sum
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
main.go
package main

import (
	"bytes"
	"fmt"
	"strings"

	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

func main() {
	// 1. Construct an HTML node tree manually
	parent := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Div,
		Data:     "div",
		Attr: []html.Attribute{
			{Key: "id", Val: "content"},
			{Key: "class", Val: "container"},
		},
	}

	child := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.P,
		Data:     "p",
	}

	text := &html.Node{
		Type: html.TextNode,
		Data: "Hello, HTML Node!",
	}

	child.AppendChild(text)
	parent.AppendChild(child)

	var buf bytes.Buffer
	if err := html.Render(&buf, parent); err != nil {
		fmt.Printf("Render failed: %v\n", err)
		return
	}
	fmt.Printf("Rendered HTML:\n%s\n", buf.String())

	// 2. Parse HTML snippet and inspect root node
	raw := `<div class="greeting"><span>Welcome</span></div>`
	doc, err := html.Parse(strings.NewReader(raw))
	if err != nil {
		fmt.Printf("Parse failed: %v\n", err)
		return
	}

	fmt.Printf("Parsed root node type: %v, children: %v\n", doc.Type, doc.FirstChild != nil)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.23.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.23.0"
  ],
  "symbols": [
    "golang.org/x/net/html.Node"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

	"golang.org/x/net/html"
)

func main() {
	// 1. html.Node struct fields represent node type, data, and attributes
	elem := &html.Node{
		Type: html.ElementNode,
		Data: "div",
		Attr: []html.Attribute{
			{Key: "id", Val: "main"},
			{Key: "class", Val: "content"},
		},
	}
	if elem.Type != html.ElementNode || elem.Data != "div" || len(elem.Attr) != 2 {
		fmt.Fprintf(os.Stderr, "Node fields mismatch\n")
		os.Exit(1)
	}
	if elem.Attr[0].Key != "id" || elem.Attr[0].Val != "main" || elem.Attr[1].Key != "class" || elem.Attr[1].Val != "content" {
		fmt.Fprintf(os.Stderr, "Node Attr mismatch\n")
		os.Exit(1)
	}

	// 2. html.Node.AppendChild attaches child and sets FirstChild, LastChild, and Parent pointers
	parent := &html.Node{Type: html.ElementNode, Data: "ul"}
	child1 := &html.Node{Type: html.ElementNode, Data: "li"}
	parent.AppendChild(child1)
	if parent.FirstChild != child1 || parent.LastChild != child1 || child1.Parent != parent {
		fmt.Fprintf(os.Stderr, "AppendChild single child pointers mismatch\n")
		os.Exit(1)
	}
	if child1.PrevSibling != nil || child1.NextSibling != nil {
		fmt.Fprintf(os.Stderr, "Single child should have nil siblings\n")
		os.Exit(1)
	}

	// 3. html.Node.AppendChild maintains sibling chain when appending multiple children
	child2 := &html.Node{Type: html.ElementNode, Data: "li"}
	parent.AppendChild(child2)
	if parent.FirstChild != child1 || parent.LastChild != child2 {
		fmt.Fprintf(os.Stderr, "AppendChild multiple children parent pointers mismatch\n")
		os.Exit(1)
	}
	if child1.NextSibling != child2 || child2.PrevSibling != child1 {
		fmt.Fprintf(os.Stderr, "AppendChild multiple children sibling pointers mismatch\n")
		os.Exit(1)
	}
	if child1.PrevSibling != nil || child2.NextSibling != nil {
		fmt.Fprintf(os.Stderr, "Sibling boundary pointers mismatch\n")
		os.Exit(1)
	}

	// 4. html.Node.InsertBefore inserts new child before reference node and updates sibling links
	childMiddle := &html.Node{Type: html.ElementNode, Data: "li"}
	parent.InsertBefore(childMiddle, child2)
	if child1.NextSibling != childMiddle || childMiddle.PrevSibling != child1 {
		fmt.Fprintf(os.Stderr, "InsertBefore middle prev links mismatch\n")
		os.Exit(1)
	}
	if childMiddle.NextSibling != child2 || child2.PrevSibling != childMiddle {
		fmt.Fprintf(os.Stderr, "InsertBefore middle next links mismatch\n")
		os.Exit(1)
	}
	if childMiddle.Parent != parent {
		fmt.Fprintf(os.Stderr, "InsertBefore parent link mismatch\n")
		os.Exit(1)
	}

	// 5. html.Node.RemoveChild detaches child and unlinks sibling pointers
	parent.RemoveChild(childMiddle)
	if childMiddle.Parent != nil || childMiddle.PrevSibling != nil || childMiddle.NextSibling != nil {
		fmt.Fprintf(os.Stderr, "RemoveChild did not clear detached node pointers\n")
		os.Exit(1)
	}
	if child1.NextSibling != child2 || child2.PrevSibling != child1 {
		fmt.Fprintf(os.Stderr, "RemoveChild did not restore sibling links\n")
		os.Exit(1)
	}

	// 6. html.Parse builds a valid DocumentNode tree with root node and child elements
	rawHTML := `<html><head><title>Test</title></head><body><p>Hello</p></body></html>`
	doc, err := html.Parse(strings.NewReader(rawHTML))
	if err != nil || doc == nil {
		fmt.Fprintf(os.Stderr, "html.Parse failed: %v\n", err)
		os.Exit(1)
	}
	if doc.Type != html.DocumentNode {
		fmt.Fprintf(os.Stderr, "Parsed root is not DocumentNode: got %v\n", doc.Type)
		os.Exit(1)
	}
	if doc.FirstChild == nil || doc.FirstChild.Data != "html" {
		fmt.Fprintf(os.Stderr, "Expected first child to be html node\n")
		os.Exit(1)
	}

	// 7. html.Render serializes Node tree to HTML output matching node structure and attributes
	div := &html.Node{
		Type: html.ElementNode,
		Data: "div",
		Attr: []html.Attribute{
			{Key: "class", Val: "box"},
		},
	}
	span := &html.Node{
		Type: html.ElementNode,
		Data: "span",
	}
	spanText := &html.Node{
		Type: html.TextNode,
		Data: "text",
	}
	span.AppendChild(spanText)
	div.AppendChild(span)

	var buf bytes.Buffer
	if err := html.Render(&buf, div); err != nil {
		fmt.Fprintf(os.Stderr, "html.Render failed: %v\n", err)
		os.Exit(1)
	}
	expected := `<div class="box"><span>text</span></div>`
	if buf.String() != expected {
		fmt.Fprintf(os.Stderr, "Render output mismatch: got %q, want %q\n", buf.String(), expected)
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed.")
}

오리진 시더

익명