CodeSampleX

Beispiel

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

Verifiziertes Beispiel für golang golang.org/x/net v0.41.0: html.Node. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:a65697420d1aa01520aa447289b5289f8d2040a89f92883602d6bfb757e09b32

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-14

Fall

HOW
Ziel
verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.41.0
Pakete
Symbole
  • golang.org/x/net/html.Node
Erstellt
2026-10-14T18:27:45Z

Contract

  1. html.Parse parses HTML documents into a DocumentNode tree maintaining hierarchical Parent, FirstChild, LastChild, PrevSibling, and NextSibling pointer links.
  2. html.Node represents HTML elements, text, and comments with accurate NodeType, DataAtom, Data, and slice of Attribute key-value pairs.
  3. html.Node DOM manipulation methods (InsertBefore, AppendChild, RemoveChild) update child lists and bidirectional sibling links.
  4. html.Render serializes an html.Node subtree back to standard HTML matching in-memory DOM mutations.
  5. html.ParseFragment parses HTML fragments within a specified context html.Node, returning isolated root nodes.

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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.41.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.41.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:f827b41a69b31e27f018a7178df8f240a711a170727a9dfd10843bb42d0736c2","contract":["html.Parse parses HTML documents into a DocumentNode tree maintaining hierarchical Parent, FirstChild, LastChild, PrevSibling, and NextSibling pointer links.","html.Node represents HTML elements, text, and comments with accurate NodeType, DataAtom, Data, and slice of Attribute key-value pairs.","html.Node DOM manipulation methods (InsertBefore, AppendChild, RemoveChild) update child lists and bidirectional sibling links.","html.Render serializes an html.Node subtree back to standard HTML matching in-memory DOM mutations.","html.ParseFragment parses HTML fragments within a specified context html.Node, returning isolated root nodes."],"goal":"verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.41.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.41.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.41.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.41.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.41.0
go.sum
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
main.go
package main

import (
	"bytes"
	"fmt"
	"strings"

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

func main() {
	raw := `<!DOCTYPE html><html><head><title>Page</title></head><body><div id="main"><p>First</p></div></body></html>`
	doc, err := html.Parse(strings.NewReader(raw))
	if err != nil {
		panic(err)
	}

	var div *html.Node
	var findDiv func(*html.Node)
	findDiv = func(n *html.Node) {
		if n.Type == html.ElementNode && n.DataAtom == atom.Div {
			div = n
			return
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			findDiv(c)
			if div != nil {
				return
			}
		}
	}
	findDiv(doc)

	secondP := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.P,
		Data:     "p",
		Attr:     []html.Attribute{{Key: "class", Val: "note"}},
	}
	secondP.AppendChild(&html.Node{
		Type: html.TextNode,
		Data: "Second",
	})
	div.AppendChild(secondP)

	var buf bytes.Buffer
	if err := html.Render(&buf, div); err != nil {
		panic(err)
	}
	fmt.Println(buf.String())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.Node in pkg:golang/golang.org/x/net@v0.41.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.41.0"
  ],
  "symbols": [
    "golang.org/x/net/html.Node"
  ]
}
test/contract.go
package main

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

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

func findElement(n *html.Node, tag string) *html.Node {
	if n == nil {
		return nil
	}
	if n.Type == html.ElementNode && n.Data == tag {
		return n
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if found := findElement(c, tag); found != nil {
			return found
		}
	}
	return nil
}

func main() {
	// 1. html.Parse builds a DocumentNode tree with accurate Parent, FirstChild, LastChild, PrevSibling, and NextSibling links
	rawHTML := `<!DOCTYPE html><html><head><title>Title</title></head><body><div id="container" class="box"><p>Alpha</p><p>Beta</p></div></body></html>`
	doc, err := html.Parse(strings.NewReader(rawHTML))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Contract 1 failed: html.Parse error: %v\n", err)
		os.Exit(1)
	}
	if doc.Type != html.DocumentNode {
		fmt.Fprintf(os.Stderr, "Contract 1 failed: expected DocumentNode, got %v\n", doc.Type)
		os.Exit(1)
	}
	doctype := doc.FirstChild
	if doctype == nil || doctype.Type != html.DoctypeNode || doctype.Data != "html" {
		fmt.Fprintf(os.Stderr, "Contract 1 failed: expected html DoctypeNode as first child\n")
		os.Exit(1)
	}
	htmlElem := doctype.NextSibling
	if htmlElem == nil || htmlElem.Type != html.ElementNode || htmlElem.Data != "html" || htmlElem.Parent != doc {
		fmt.Fprintf(os.Stderr, "Contract 1 failed: unexpected html element or parent link\n")
		os.Exit(1)
	}
	headElem := htmlElem.FirstChild
	bodyElem := htmlElem.LastChild
	if headElem == nil || bodyElem == nil || headElem.NextSibling != bodyElem || bodyElem.PrevSibling != headElem {
		fmt.Fprintf(os.Stderr, "Contract 1 failed: head and body sibling links broken\n")
		os.Exit(1)
	}

	// 2. html.Node stores element Type, DataAtom, Data, and Attribute key-value pairs accurately
	divNode := findElement(doc, "div")
	if divNode == nil || divNode.DataAtom != atom.Div || len(divNode.Attr) != 2 {
		fmt.Fprintf(os.Stderr, "Contract 2 failed: div node or attributes not parsed properly\n")
		os.Exit(1)
	}
	if divNode.Attr[0].Key != "id" || divNode.Attr[0].Val != "container" || divNode.Attr[1].Key != "class" || divNode.Attr[1].Val != "box" {
		fmt.Fprintf(os.Stderr, "Contract 2 failed: unexpected div attributes: %+v\n", divNode.Attr)
		os.Exit(1)
	}
	firstP := divNode.FirstChild
	lastP := divNode.LastChild
	if firstP == nil || firstP.FirstChild == nil || firstP.FirstChild.Type != html.TextNode || firstP.FirstChild.Data != "Alpha" {
		fmt.Fprintf(os.Stderr, "Contract 2 failed: unexpected first paragraph text node\n")
		os.Exit(1)
	}

	// 3. html.Node manipulation methods (InsertBefore, AppendChild, RemoveChild) update tree pointers consistently
	midP := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.P,
		Data:     "p",
		Attr:     []html.Attribute{{Key: "id", Val: "mid"}},
	}
	midP.AppendChild(&html.Node{
		Type: html.TextNode,
		Data: "Middle",
	})
	divNode.InsertBefore(midP, lastP)
	if midP.Parent != divNode || midP.PrevSibling != firstP || midP.NextSibling != lastP || firstP.NextSibling != midP || lastP.PrevSibling != midP {
		fmt.Fprintf(os.Stderr, "Contract 3 failed: InsertBefore did not link siblings properly\n")
		os.Exit(1)
	}

	tailSpan := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Span,
		Data:     "span",
	}
	tailSpan.AppendChild(&html.Node{
		Type: html.TextNode,
		Data: "Tail",
	})
	divNode.AppendChild(tailSpan)
	if divNode.LastChild != tailSpan || tailSpan.PrevSibling != lastP || lastP.NextSibling != tailSpan {
		fmt.Fprintf(os.Stderr, "Contract 3 failed: AppendChild did not update LastChild links\n")
		os.Exit(1)
	}

	divNode.RemoveChild(midP)
	if midP.Parent != nil || midP.PrevSibling != nil || midP.NextSibling != nil || firstP.NextSibling != lastP || lastP.PrevSibling != firstP {
		fmt.Fprintf(os.Stderr, "Contract 3 failed: RemoveChild did not detach node or repair sibling links\n")
		os.Exit(1)
	}

	// 4. html.Render serializes an html.Node subtree reflecting in-memory DOM modifications
	var buf bytes.Buffer
	if err := html.Render(&buf, divNode); err != nil {
		fmt.Fprintf(os.Stderr, "Contract 4 failed: html.Render error: %v\n", err)
		os.Exit(1)
	}
	expectedRendered := `<div id="container" class="box"><p>Alpha</p><p>Beta</p><span>Tail</span></div>`
	if buf.String() != expectedRendered {
		fmt.Fprintf(os.Stderr, "Contract 4 failed: expected %q, got %q\n", expectedRendered, buf.String())
		os.Exit(1)
	}

	// 5. html.ParseFragment parses HTML fragments in the context of a parent html.Node
	ctxNode := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Tbody,
		Data:     "tbody",
	}
	parts, err := html.ParseFragment(strings.NewReader(`<tr><td>Cell</td></tr><!--end-->`), ctxNode)
	if err != nil || len(parts) != 2 {
		fmt.Fprintf(os.Stderr, "Contract 5 failed: html.ParseFragment err=%v, len=%d\n", err, len(parts))
		os.Exit(1)
	}
	if parts[0].Type != html.ElementNode || parts[0].Data != "tr" || parts[1].Type != html.CommentNode || parts[1].Data != "end" {
		fmt.Fprintf(os.Stderr, "Contract 5 failed: unexpected fragment node types\n")
		os.Exit(1)
	}

	fmt.Println("PASS")
}

Ursprungs-Seeder

anonym