Sample
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7: html.ParseFragment
Verified sample for golang golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7: html.ParseFragment. The contract ran on go 1.26 · linux debian/x64 · docker…
sha256:4aebd0d6f2ce7e694bf56fd690c3e193e7b9a742f63d3a0538c8b992ab666dab
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-10-16 |
Case
HOW- Goal
- verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7
- Symbols
-
- golang.org/x/net/html.ParseFragment
- Created
- 2026-10-16T07:54:07Z
Contract
- html.ParseFragment with nil context parses a fragment into a root html element containing head and body
- html.ParseFragment with a body element context parses child elements directly without outer html/body wrappers
- html.ParseFragment with a table element context wraps tr elements inside an implicit tbody element
- html.ParseFragment with a select element context parses option elements and preserves their attributes
Files
- PROMPT.md
- csx.json
- fragment.go
- go.mod
- go.sum
- spec.json
- test/contract.go
Source
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.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7
Demonstrate these symbols/APIs:
- golang.org/x/net/html.ParseFragment
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:e04490f18cd2da1b75dbe2bdef2a4c5101babfdd30b495619584d031a6b15be2","contract":["html.ParseFragment with nil context parses a fragment into a root html element containing head and body","html.ParseFragment with a body element context parses child elements directly without outer html/body wrappers","html.ParseFragment with a table element context wraps tr elements inside an implicit tbody element","html.ParseFragment with a select element context parses option elements and preserves their attributes"],"goal":"verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7"],"schemaVersion":1,"symbols":["golang.org/x/net/html.ParseFragment"]},"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.0.0-20190813141303-74dc4d7220e7"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7","symbols":["golang.org/x/net/html.ParseFragment"],"verifierAdapter":"golang@1"}
package sample
import (
"io"
"strings"
"golang.org/x/net/html"
)
// ParseFragment parses an HTML fragment from an io.Reader using the provided context node.
func ParseFragment(r io.Reader, context *html.Node) ([]*html.Node, error) {
return html.ParseFragment(r, context)
}
// ParseFragmentString parses an HTML string fragment using the provided context node.
func ParseFragmentString(fragment string, context *html.Node) ([]*html.Node, error) {
return html.ParseFragment(strings.NewReader(fragment), context)
}
// FindFirstElement traverses the node slice depth-first and returns the first element matching tag.
func FindFirstElement(nodes []*html.Node, tag string) *html.Node {
for _, n := range nodes {
if found := findElement(n, tag); found != nil {
return found
}
}
return nil
}
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
}
// GetAttr looks up an attribute value on an html.Node.
func GetAttr(n *html.Node, key string) (string, bool) {
if n == nil {
return "", false
}
for _, a := range n.Attr {
if a.Key == key {
return a.Val, true
}
}
return "", false
}
module sample
go 1.21
require golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
{
"schemaVersion": 1,
"goal": "verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7"
],
"symbols": [
"golang.org/x/net/html.ParseFragment"
]
}
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
"sample"
)
func main() {
// 1. ParseFragment with nil context returns a root html element containing head and body
nodes1, err := sample.ParseFragmentString("<p>Hello Fragment</p>", nil)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if len(nodes1) != 1 || nodes1[0].Type != html.ElementNode || nodes1[0].Data != "html" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected single html element root\n")
os.Exit(1)
}
if sample.FindFirstElement(nodes1, "head") == nil || sample.FindFirstElement(nodes1, "body") == nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected head and body elements\n")
os.Exit(1)
}
pNode := sample.FindFirstElement(nodes1, "p")
if pNode == nil || pNode.FirstChild == nil || pNode.FirstChild.Data != "Hello Fragment" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected p element with text\n")
os.Exit(1)
}
// 2. ParseFragment with a body context parses child elements directly without html/body wrapper
bodyCtx := &html.Node{
Type: html.ElementNode,
Data: "body",
DataAtom: atom.Body,
}
nodes2, err := sample.ParseFragmentString("<h1>Title</h1><em>Note</em>", bodyCtx)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if len(nodes2) != 2 || nodes2[0].Data != "h1" || nodes2[1].Data != "em" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected h1 and em top-level nodes\n")
os.Exit(1)
}
// 3. ParseFragment with a table context wraps tr elements inside an implicit tbody element
tableCtx := &html.Node{
Type: html.ElementNode,
Data: "table",
DataAtom: atom.Table,
}
nodes3, err := sample.ParseFragmentString("<tr><td>Cell</td></tr>", tableCtx)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if len(nodes3) != 1 || nodes3[0].Data != "tbody" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected implicit tbody root\n")
os.Exit(1)
}
tdNode := sample.FindFirstElement(nodes3, "td")
if tdNode == nil || tdNode.FirstChild == nil || tdNode.FirstChild.Data != "Cell" {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected td element with Cell text\n")
os.Exit(1)
}
// 4. ParseFragment with a select context parses option nodes and preserves attributes
selectCtx := &html.Node{
Type: html.ElementNode,
Data: "select",
DataAtom: atom.Select,
}
nodes4, err := sample.ParseFragment(strings.NewReader(`<option value="a">Alpha</option><option value="b" selected>Beta</option>`), selectCtx)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if len(nodes4) != 2 || nodes4[0].Data != "option" || nodes4[1].Data != "option" {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected 2 option nodes\n")
os.Exit(1)
}
valA, okA := sample.GetAttr(nodes4[0], "value")
_, okSelected := sample.GetAttr(nodes4[1], "selected")
if !okA || valA != "a" || !okSelected {
fmt.Fprintf(os.Stderr, "assertion 4 failed: option attributes not preserved\n")
os.Exit(1)
}
}
Origin Seeder
anonymous