CodeSampleX

Sample

golang.org/x/net v0.51.0: html.NodeType

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

sha256:46031dd6f7dc513975274db3de87c7aec86562bc52286e97232854c7790b46d9

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 linux 24 · ubuntu · glibc 2.39 x64 go

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-09-03

Case

HOW
Goal
verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.51.0
Packages
Symbols
  • golang.org/x/net/html.NodeType
Created
2026-09-03T15:53:17Z

Contract

  1. NodeType constants match expected enum values and their String() method returns valid type names
  2. NodeType.String() for an undefined or out-of-range value returns formatted string NodeType(val)
  3. html.Parse assigns DocumentNode to the root node and DoctypeNode to the doctype declaration
  4. html.Parse assigns ElementNode to HTML tags and TextNode to character data content
  5. html.Parse assigns CommentNode to HTML comment declarations

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

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

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:acda987e5b458ae4927228f9a7f57c84409ec149334648ea9cf755c017fb482b","contract":["NodeType constants match expected enum values and their String() method returns valid type names","NodeType.String() for an undefined or out-of-range value returns formatted string NodeType(val)","html.Parse assigns DocumentNode to the root node and DoctypeNode to the doctype declaration","html.Parse assigns ElementNode to HTML tags and TextNode to character data content","html.Parse assigns CommentNode to HTML comment declarations"],"goal":"verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.51.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.51.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.NodeType"]},"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.51.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.51.0","symbols":["golang.org/x/net/html.NodeType"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require golang.org/x/net v0.51.0
go.sum
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
sample.go
package sample

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

// NodeTypeName returns the string representation of a given NodeType.
func NodeTypeName(t html.NodeType) string {
	return t.String()
}

// ClassifyNode returns the NodeType of the provided html.Node.
func ClassifyNode(n *html.Node) html.NodeType {
	if n == nil {
		return html.ErrorNode
	}
	return n.Type
}

// CountNodeTypes recursively traverses an HTML node tree and counts occurrences of each NodeType.
func CountNodeTypes(n *html.Node) map[html.NodeType]int {
	counts := make(map[html.NodeType]int)
	var walk func(*html.Node)
	walk = func(curr *html.Node) {
		if curr == nil {
			return
		}
		counts[curr.Type]++
		for c := curr.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(n)
	return counts
}

// FindNodesByType returns all nodes in the subtree rooted at n that match the given NodeType.
func FindNodesByType(n *html.Node, target html.NodeType) []*html.Node {
	var result []*html.Node
	var walk func(*html.Node)
	walk = func(curr *html.Node) {
		if curr == nil {
			return
		}
		if curr.Type == target {
			result = append(result, curr)
		}
		for c := curr.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(n)
	return result
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.51.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.51.0"
  ],
  "symbols": [
    "golang.org/x/net/html.NodeType"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	"sample"

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

func main() {
	// Assertion 1: NodeType constants match expected enum values and their String() method returns valid type names
	{
		type testCase struct {
			nodeType html.NodeType
			expected uint32
			name     string
		}
		cases := []testCase{
			{html.ErrorNode, 0, "ErrorNode"},
			{html.TextNode, 1, "TextNode"},
			{html.DocumentNode, 2, "DocumentNode"},
			{html.ElementNode, 3, "ElementNode"},
			{html.CommentNode, 4, "CommentNode"},
			{html.DoctypeNode, 5, "DoctypeNode"},
			{html.RawNode, 6, "RawNode"},
		}

		for _, tc := range cases {
			if uint32(tc.nodeType) != tc.expected {
				fmt.Fprintf(os.Stderr, "FAIL: expected %s value to be %d, got %d\n", tc.name, tc.expected, uint32(tc.nodeType))
				os.Exit(1)
			}
			if tc.nodeType.String() != tc.name {
				fmt.Fprintf(os.Stderr, "FAIL: expected %s.String() == %q, got %q\n", tc.name, tc.name, tc.nodeType.String())
				os.Exit(1)
			}
			if sample.NodeTypeName(tc.nodeType) != tc.name {
				fmt.Fprintf(os.Stderr, "FAIL: expected sample.NodeTypeName(%s) == %q, got %q\n", tc.name, tc.name, sample.NodeTypeName(tc.nodeType))
				os.Exit(1)
			}
		}
	}

	// Assertion 2: NodeType.String() for an undefined or out-of-range value returns formatted string NodeType(val)
	{
		outOfRange := html.NodeType(99)
		expected := "NodeType(99)"
		if outOfRange.String() != expected {
			fmt.Fprintf(os.Stderr, "FAIL: expected out-of-range String() to be %q, got %q\n", expected, outOfRange.String())
			os.Exit(1)
		}
	}

	// Parsing HTML document for structural NodeType verification
	htmlContent := `<!DOCTYPE html><html><head><title>Sample</title></head><body><!-- test comment --><p>Hello World</p></body></html>`
	doc, err := html.Parse(strings.NewReader(htmlContent))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: html.Parse failed: %v\n", err)
		os.Exit(1)
	}

	// Assertion 3: html.Parse assigns DocumentNode to the root node and DoctypeNode to the doctype declaration
	{
		if doc.Type != html.DocumentNode {
			fmt.Fprintf(os.Stderr, "FAIL: expected root node type DocumentNode, got %v\n", doc.Type)
			os.Exit(1)
		}
		if sample.ClassifyNode(doc) != html.DocumentNode {
			fmt.Fprintf(os.Stderr, "FAIL: sample.ClassifyNode(doc) != DocumentNode\n")
			os.Exit(1)
		}

		doctypeNodes := sample.FindNodesByType(doc, html.DoctypeNode)
		if len(doctypeNodes) != 1 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 1 DoctypeNode, found %d\n", len(doctypeNodes))
			os.Exit(1)
		}
		if doctypeNodes[0].Data != "html" {
			fmt.Fprintf(os.Stderr, "FAIL: expected doctype data 'html', got %q\n", doctypeNodes[0].Data)
			os.Exit(1)
		}
	}

	// Assertion 4: html.Parse assigns ElementNode to HTML tags and TextNode to character data content
	{
		elementNodes := sample.FindNodesByType(doc, html.ElementNode)
		if len(elementNodes) < 4 { // html, head, title, body, p
			fmt.Fprintf(os.Stderr, "FAIL: expected at least 4 ElementNodes, found %d\n", len(elementNodes))
			os.Exit(1)
		}

		textNodes := sample.FindNodesByType(doc, html.TextNode)
		foundHello := false
		for _, tn := range textNodes {
			if tn.Type != html.TextNode {
				fmt.Fprintf(os.Stderr, "FAIL: found node with non-TextNode in textNodes slice\n")
				os.Exit(1)
			}
			if strings.TrimSpace(tn.Data) == "Hello World" {
				foundHello = true
			}
		}
		if !foundHello {
			fmt.Fprintf(os.Stderr, "FAIL: expected to find TextNode with content 'Hello World'\n")
			os.Exit(1)
		}
	}

	// Assertion 5: html.Parse assigns CommentNode to HTML comment declarations
	{
		commentNodes := sample.FindNodesByType(doc, html.CommentNode)
		if len(commentNodes) != 1 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 1 CommentNode, found %d\n", len(commentNodes))
			os.Exit(1)
		}
		if strings.TrimSpace(commentNodes[0].Data) != "test comment" {
			fmt.Fprintf(os.Stderr, "FAIL: expected comment data 'test comment', got %q\n", commentNodes[0].Data)
			os.Exit(1)
		}
	}

	// Verify node counts
	counts := sample.CountNodeTypes(doc)
	if counts[html.DocumentNode] != 1 || counts[html.DoctypeNode] != 1 || counts[html.CommentNode] != 1 {
		fmt.Fprintf(os.Stderr, "FAIL: unexpected node type counts: %+v\n", counts)
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/net/html.NodeType contract verified")
}

Origin Seeder

anonymous