Exemple
golang.org/x/net v0.24.0: html.ElementNode
Échantillon vérifié pour golang golang.org/x/net v0.24.0: html.ElementNode. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi …
sha256:b6f09fe572bc30d7991374f783a842c9e7a74d158e1c1bc784e017c1bbc14d1f
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.24.0
- Paquets
- Symboles
-
- golang.org/x/net/html.ElementNode
- Environnement
- go 1.26.6
- Créé
- 2026-09-04T13:26:10Z
Contrat
- html.ElementNode is a NodeType distinguishing HTML element nodes from document and text nodes
- html.Parse parses HTML string into a DOM tree containing ElementNode with expected tag names
- html.ElementNode contains Attr slice representing HTML attributes with Key and Val
- html.ElementNode supports tree mutation via AppendChild and RemoveChild maintaining parent and sibling pointers
- html.Render serializes a tree of ElementNode nodes back into valid HTML output
- html.ParseFragment parses HTML fragment using an ElementNode context node
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Code 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.ElementNode in pkg:golang/golang.org/x/net@v0.24.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/net@v0.24.0
Demonstrate these symbols/APIs:
- golang.org/x/net/html.ElementNode
Required runtime conditions:
- ecosystem: golang
- language: go
- packageManager: go@1.26.6
- runtime: go@1.26.6
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:750bc650a262e0ea7058ada44434a795c3bc8971e8d1e77ddcda2bf569caccff","contract":["html.ElementNode is a NodeType distinguishing HTML element nodes from document and text nodes","html.Parse parses HTML string into a DOM tree containing ElementNode with expected tag names","html.ElementNode contains Attr slice representing HTML attributes with Key and Val","html.ElementNode supports tree mutation via AppendChild and RemoveChild maintaining parent and sibling pointers","html.Render serializes a tree of ElementNode nodes back into valid HTML output","html.ParseFragment parses HTML fragment using an ElementNode context node"],"goal":"verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.24.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.24.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.ElementNode"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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.24.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.24.0","symbols":["golang.org/x/net/html.ElementNode"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.24.0
require golang.org/x/net v0.24.0
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
package main
import (
"bytes"
"fmt"
"strings"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
func main() {
rawHTML := `<div class="container" id="main"><p>CodeSampleX Demo</p></div>`
doc, err := html.Parse(strings.NewReader(rawHTML))
if err != nil {
panic(err)
}
var visit func(*html.Node)
visit = func(n *html.Node) {
if n.Type == html.ElementNode {
fmt.Printf("Element: <%s>\n", n.Data)
for _, attr := range n.Attr {
fmt.Printf(" Attr: %s=%s\n", attr.Key, attr.Val)
}
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
visit(c)
}
}
visit(doc)
// Create and append an ElementNode programmatically
newElem := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Span,
Data: "span",
Attr: []html.Attribute{
{Key: "class", Val: "badge"},
},
}
doc.AppendChild(newElem)
var buf bytes.Buffer
if err := html.Render(&buf, doc); err != nil {
panic(err)
}
fmt.Printf("Rendered HTML:\n%s\n", buf.String())
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/net/html.ElementNode in pkg:golang/golang.org/x/net@v0.24.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.24.0"
],
"symbols": [
"golang.org/x/net/html.ElementNode"
],
"runtimeConditions": {
"ecosystem": "golang",
"language": "go",
"packageManager": "go@1.26.6",
"runtime": "go@1.26.6"
}
}
package main
import (
"bytes"
"fmt"
"os"
"strings"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
func main() {
// 1. html.ElementNode is a NodeType distinguishing HTML element nodes from document and text nodes
if html.ElementNode == html.DocumentNode {
fmt.Fprintf(os.Stderr, "Contract 1 failed: ElementNode must not equal DocumentNode\n")
os.Exit(1)
}
if html.ElementNode == html.TextNode {
fmt.Fprintf(os.Stderr, "Contract 1 failed: ElementNode must not equal TextNode\n")
os.Exit(1)
}
if html.ElementNode == html.CommentNode {
fmt.Fprintf(os.Stderr, "Contract 1 failed: ElementNode must not equal CommentNode\n")
os.Exit(1)
}
// 2. html.Parse parses HTML string into a DOM tree containing ElementNode with expected tag names
rawHTML := `<!DOCTYPE html><html><head><title>Test</title></head><body><div id="content"><p>Hello</p></div></body></html>`
doc, err := html.Parse(strings.NewReader(rawHTML))
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 2 failed: html.Parse error: %v\n", err)
os.Exit(1)
}
if doc == nil || doc.Type != html.DocumentNode {
fmt.Fprintf(os.Stderr, "Contract 2 failed: root node must be DocumentNode\n")
os.Exit(1)
}
var elementTags []string
var findElements func(*html.Node)
findElements = func(n *html.Node) {
if n.Type == html.ElementNode {
elementTags = append(elementTags, n.Data)
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
findElements(c)
}
}
findElements(doc)
expectedTags := []string{"html", "head", "title", "body", "div", "p"}
if len(elementTags) != len(expectedTags) {
fmt.Fprintf(os.Stderr, "Contract 2 failed: element tags length mismatch: got %v, want %v\n", elementTags, expectedTags)
os.Exit(1)
}
for i, tag := range expectedTags {
if elementTags[i] != tag {
fmt.Fprintf(os.Stderr, "Contract 2 failed: tag at %d mismatch: got %s, want %s\n", i, elementTags[i], tag)
os.Exit(1)
}
}
// 3. html.ElementNode contains Attr slice representing HTML attributes with Key and Val
var divNode *html.Node
var findDiv func(*html.Node)
findDiv = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == "div" {
divNode = n
return
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
findDiv(c)
}
}
findDiv(doc)
if divNode == nil {
fmt.Fprintf(os.Stderr, "Contract 3 failed: div ElementNode not found\n")
os.Exit(1)
}
if len(divNode.Attr) != 1 || divNode.Attr[0].Key != "id" || divNode.Attr[0].Val != "content" {
fmt.Fprintf(os.Stderr, "Contract 3 failed: div Attr mismatch: got %+v\n", divNode.Attr)
os.Exit(1)
}
// 4. html.ElementNode supports tree mutation via AppendChild and RemoveChild maintaining parent and sibling pointers
parent := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Ul,
Data: "ul",
}
child1 := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Li,
Data: "li",
}
child2 := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Li,
Data: "li",
}
parent.AppendChild(child1)
parent.AppendChild(child2)
if parent.FirstChild != child1 || parent.LastChild != child2 {
fmt.Fprintf(os.Stderr, "Contract 4 failed: AppendChild pointers mismatch\n")
os.Exit(1)
}
if child1.Parent != parent || child2.Parent != parent {
fmt.Fprintf(os.Stderr, "Contract 4 failed: child Parent pointer mismatch\n")
os.Exit(1)
}
if child1.NextSibling != child2 || child2.PrevSibling != child1 {
fmt.Fprintf(os.Stderr, "Contract 4 failed: sibling pointers mismatch\n")
os.Exit(1)
}
parent.RemoveChild(child1)
if parent.FirstChild != child2 || child1.Parent != nil || child1.NextSibling != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed: RemoveChild pointers mismatch\n")
os.Exit(1)
}
// 5. html.Render serializes a tree of ElementNode nodes back into valid HTML output
var renderBuf bytes.Buffer
if err := html.Render(&renderBuf, parent); err != nil {
fmt.Fprintf(os.Stderr, "Contract 5 failed: html.Render error: %v\n", err)
os.Exit(1)
}
expectedRendered := "<ul><li></li></ul>"
if renderBuf.String() != expectedRendered {
fmt.Fprintf(os.Stderr, "Contract 5 failed: html.Render mismatch: got %q, want %q\n", renderBuf.String(), expectedRendered)
os.Exit(1)
}
// 6. html.ParseFragment parses HTML fragment using an ElementNode context node
contextNode := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Div,
Data: "div",
}
fragHTML := `<span class="frag">fragment text</span>`
nodes, err := html.ParseFragment(strings.NewReader(fragHTML), contextNode)
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 6 failed: html.ParseFragment error: %v\n", err)
os.Exit(1)
}
if len(nodes) != 1 {
fmt.Fprintf(os.Stderr, "Contract 6 failed: nodes length mismatch: got %d, want 1\n", len(nodes))
os.Exit(1)
}
fragElem := nodes[0]
if fragElem.Type != html.ElementNode || fragElem.Data != "span" {
fmt.Fprintf(os.Stderr, "Contract 6 failed: fragElem mismatch: Type=%v, Data=%s\n", fragElem.Type, fragElem.Data)
os.Exit(1)
}
if len(fragElem.Attr) != 1 || fragElem.Attr[0].Key != "class" || fragElem.Attr[0].Val != "frag" {
fmt.Fprintf(os.Stderr, "Contract 6 failed: fragElem Attr mismatch: %+v\n", fragElem.Attr)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
Seeder d'origine
anonyme