CodeSampleX

Sample

golang.org/x/net v0.47.0: html.ElementNode

Verified sample for golang golang.org/x/net v0.47.0: html.ElementNode. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:0070ea328201b279308155700a260a23bcd7ffb861dc419dad7b6224f54d6e69

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

Verification-run environments

Environment Contract Stages Run
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-10-10

Case

HOW
Goal
verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.47.0
Packages
Symbols
  • golang.org/x/net/html.ElementNode
Environment
go 1.26.6
Created
2026-10-10T18:50:57Z

Contract

  1. html.ElementNode constant distinguishes element nodes from text, document, and comment nodes
  2. html.Parse parses HTML markup into a tree where elements have Type html.ElementNode and Data equal to tag name
  3. Constructing an html.ElementNode with attributes and children renders valid HTML tags via html.Render
  4. Tree traversal inspects Type == html.ElementNode to filter element tags and extract attributes
  5. html.ParseFragment parses snippet in element context and returns nodes with Type html.ElementNode

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

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.ElementNode in pkg:golang/golang.org/x/net@v0.47.0
Kind: HOW

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

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:a349bd01b19b14ebd72477dd3f412b7dfaf0548ce13346f99744f95eaa3d618c","contract":["html.ElementNode constant distinguishes element nodes from text, document, and comment nodes","html.Parse parses HTML markup into a tree where elements have Type html.ElementNode and Data equal to tag name","Constructing an html.ElementNode with attributes and children renders valid HTML tags via html.Render","Tree traversal inspects Type == html.ElementNode to filter element tags and extract attributes","html.ParseFragment parses snippet in element context and returns nodes with Type html.ElementNode"],"goal":"verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.47.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.47.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.ElementNode"]},"contractCommand":["go","run","./test"],"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","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/net@v0.47.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.47.0","symbols":["golang.org/x/net/html.ElementNode"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/net v0.47.0
go.sum
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
sample.go
package sample

import (
	"bytes"
	"fmt"
	"strings"

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

// FindElementsByTag traverses the node tree recursively and returns all nodes with Type == html.ElementNode and matching tag name.
func FindElementsByTag(root *html.Node, tag string) []*html.Node {
	var results []*html.Node
	var traverse func(*html.Node)
	traverse = func(n *html.Node) {
		if n == nil {
			return
		}
		if n.Type == html.ElementNode && strings.EqualFold(n.Data, tag) {
			results = append(results, n)
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			traverse(c)
		}
	}
	traverse(root)
	return results
}

// FindFirstElement traverses the node tree and returns the first node with Type == html.ElementNode.
func FindFirstElement(root *html.Node) (*html.Node, bool) {
	var found *html.Node
	var traverse func(*html.Node)
	traverse = func(n *html.Node) {
		if found != nil || n == nil {
			return
		}
		if n.Type == html.ElementNode {
			found = n
			return
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			traverse(c)
		}
	}
	traverse(root)
	return found, found != nil
}

// CreateElement creates a new html.ElementNode with the given tag, attributes, and text child.
func CreateElement(tag string, dataAtom atom.Atom, attrs []html.Attribute, textContent string) *html.Node {
	elem := &html.Node{
		Type:     html.ElementNode,
		Data:     tag,
		DataAtom: dataAtom,
		Attr:     attrs,
	}
	if textContent != "" {
		elem.AppendChild(&html.Node{
			Type: html.TextNode,
			Data: textContent,
		})
	}
	return elem
}

// RenderNode serializes an html.Node tree into an HTML string.
func RenderNode(n *html.Node) (string, error) {
	var buf bytes.Buffer
	if err := html.Render(&buf, n); err != nil {
		return "", fmt.Errorf("failed to render HTML node: %w", err)
	}
	return buf.String(), nil
}

// ParseHTML parses an HTML string and returns the root document node.
func ParseHTML(htmlStr string) (*html.Node, error) {
	doc, err := html.Parse(strings.NewReader(htmlStr))
	if err != nil {
		return nil, fmt.Errorf("failed to parse HTML: %w", err)
	}
	return doc, nil
}

// ParseFragment parses an HTML snippet in the context of a context element node.
func ParseFragment(contextElem *html.Node, htmlSnippet string) ([]*html.Node, error) {
	nodes, err := html.ParseFragment(strings.NewReader(htmlSnippet), contextElem)
	if err != nil {
		return nil, fmt.Errorf("failed to parse HTML fragment: %w", err)
	}
	return nodes, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.47.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.47.0"
  ],
  "symbols": [
    "golang.org/x/net/html.ElementNode"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	// Assertion 1: html.ElementNode constant distinguishes element nodes from text, document, and comment nodes
	if html.ElementNode == html.TextNode || html.ElementNode == html.DocumentNode || html.ElementNode == html.CommentNode {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: html.ElementNode NodeType is not unique\n")
		os.Exit(1)
	}
	sampleNode := &html.Node{Type: html.ElementNode, Data: "div"}
	if sampleNode.Type != html.ElementNode {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: node Type does not match html.ElementNode\n")
		os.Exit(1)
	}

	// Assertion 2: html.Parse parses HTML markup into a tree where elements have Type html.ElementNode and Data equal to tag name
	htmlInput := `<!DOCTYPE html><html><head><title>Test Page</title></head><body><div id="main" class="box"><p>Hello World</p><button disabled>Click</button></div></body></html>`
	doc, err := sample.ParseHTML(htmlInput)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed to parse HTML: %v\n", err)
		os.Exit(1)
	}

	pNodes := sample.FindElementsByTag(doc, "p")
	if len(pNodes) != 1 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: expected 1 p element, got %d\n", len(pNodes))
		os.Exit(1)
	}
	if pNodes[0].Type != html.ElementNode || pNodes[0].Data != "p" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: p node type or data mismatch: type=%v, data=%v\n", pNodes[0].Type, pNodes[0].Data)
		os.Exit(1)
	}

	buttonNodes := sample.FindElementsByTag(doc, "button")
	if len(buttonNodes) != 1 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: expected 1 button element, got %d\n", len(buttonNodes))
		os.Exit(1)
	}
	if buttonNodes[0].Type != html.ElementNode || buttonNodes[0].Data != "button" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: button node type or data mismatch: type=%v, data=%v\n", buttonNodes[0].Type, buttonNodes[0].Data)
		os.Exit(1)
	}

	// Assertion 3: Constructing an html.ElementNode with attributes and children renders valid HTML tags via html.Render
	cardElem := sample.CreateElement("section", atom.Section, []html.Attribute{
		{Key: "class", Val: "card-container"},
		{Key: "data-role", Val: "widget"},
	}, "")
	headerElem := sample.CreateElement("h2", atom.H2, nil, "Card Title")
	bodyElem := sample.CreateElement("div", atom.Div, []html.Attribute{{Key: "class", Val: "card-body"}}, "Card description text.")
	cardElem.AppendChild(headerElem)
	cardElem.AppendChild(bodyElem)

	rendered, err := sample.RenderNode(cardElem)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed to render element node: %v\n", err)
		os.Exit(1)
	}
	expectedSubstrings := []string{
		`<section class="card-container" data-role="widget">`,
		`<h2>Card Title</h2>`,
		`<div class="card-body">Card description text.</div>`,
		`</section>`,
	}
	for _, sub := range expectedSubstrings {
		if !strings.Contains(rendered, sub) {
			fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed: rendered HTML missing expected substring %q: got %s\n", sub, rendered)
			os.Exit(1)
		}
	}

	// Assertion 4: Tree traversal inspects Type == html.ElementNode to filter element tags and extract attributes
	divNodes := sample.FindElementsByTag(doc, "div")
	if len(divNodes) != 1 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: expected 1 div element, got %d\n", len(divNodes))
		os.Exit(1)
	}
	divElem := divNodes[0]
	if divElem.Type != html.ElementNode || divElem.Data != "div" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: divElem type or tag mismatch\n")
		os.Exit(1)
	}
	var classVal string
	for _, attr := range divElem.Attr {
		if attr.Key == "class" {
			classVal = attr.Val
		}
	}
	if classVal != "box" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: expected class 'box', got %q\n", classVal)
		os.Exit(1)
	}

	// Assertion 5: html.ParseFragment parses snippet in element context and returns nodes with Type html.ElementNode
	contextNode := &html.Node{
		Type:     html.ElementNode,
		Data:     "div",
		DataAtom: atom.Div,
	}
	fragmentNodes, err := sample.ParseFragment(contextNode, `<span class="badge">Badge 1</span><span class="badge">Badge 2</span>`)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed to parse fragment: %v\n", err)
		os.Exit(1)
	}
	if len(fragmentNodes) != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: expected 2 fragment nodes, got %d\n", len(fragmentNodes))
		os.Exit(1)
	}
	for i, fn := range fragmentNodes {
		if fn.Type != html.ElementNode || fn.Data != "span" {
			fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: fragment node %d is not ElementNode span: type=%v, data=%v\n", i, fn.Type, fn.Data)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all golang.org/x/net/html.ElementNode contract assertions passed")
}

Origin Seeder

anonymous