Exemplo
golang.org/x/net v0.29.0: html.ParseFragment, html.Render
Amostra verificada para golang golang.org/x/net v0.29.0: html.ParseFragment, html.Render. O contrato rodou em go 1.26 · linux alpine/x64 · docker e passou.
sha256:c00e983a99d189e6fe281f344a3a8c5d2263d056275c6f7ad407323150425766
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-27 |
Caso
HOW- Objetivo
- verify golang.org/x/net/html.Render and ParseFragment in pkg:golang/golang.org/x/net@v0.29.0
- Pacotes
- Símbolos
-
- golang.org/x/net/html.ParseFragment
- golang.org/x/net/html.Render
- Criado
- 2026-08-27T13:18:58Z
Contrato
- html.ParseFragment parses HTML fragment string in context node into slice of nodes
- html.ParseFragment handles multiple sibling elements and text nodes
- html.Render serializes HTML node tree to writer output
- html.Render correctly escapes special characters in text nodes
- html.ParseFragment and html.Render roundtrip preserve element structure and attributes
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código-fonte
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.Render and ParseFragment in pkg:golang/golang.org/x/net@v0.29.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/net@v0.29.0
Demonstrate these symbols/APIs:
- golang.org/x/net/html.ParseFragment
- golang.org/x/net/html.Render
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:3ef1faa38146a15e1f21189a3e63340b3a8ce79fcfd7e58ee35a2c16ae8625b0","contract":["html.ParseFragment parses HTML fragment string in context node into slice of nodes","html.ParseFragment handles multiple sibling elements and text nodes","html.Render serializes HTML node tree to writer output","html.Render correctly escapes special characters in text nodes","html.ParseFragment and html.Render roundtrip preserve element structure and attributes"],"goal":"verify golang.org/x/net/html.Render and ParseFragment in pkg:golang/golang.org/x/net@v0.29.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.29.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.ParseFragment","golang.org/x/net/html.Render"]},"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.29.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.29.0","symbols":["golang.org/x/net/html.ParseFragment","golang.org/x/net/html.Render"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.22
require golang.org/x/net v0.29.0
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
package main
import (
"bytes"
"fmt"
"log"
"strings"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
func main() {
// Parse an HTML fragment in the context of a body element
fragmentHTML := `<div class="card"><h1 class="title">Item</h1><p>Description & details</p></div>`
contextNode := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Body,
Data: "body",
}
nodes, err := html.ParseFragment(strings.NewReader(fragmentHTML), contextNode)
if err != nil {
log.Fatalf("ParseFragment failed: %v", err)
}
fmt.Printf("Parsed %d top-level node(s)\n", len(nodes))
// Render the parsed node tree back to an HTML string
var buf bytes.Buffer
for _, n := range nodes {
if err := html.Render(&buf, n); err != nil {
log.Fatalf("Render failed: %v", err)
}
}
renderedHTML := buf.String()
fmt.Printf("Rendered HTML:\n%s\n", renderedHTML)
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/net/html.Render and ParseFragment in pkg:golang/golang.org/x/net@v0.29.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.29.0"
],
"symbols": [
"golang.org/x/net/html.ParseFragment",
"golang.org/x/net/html.Render"
]
}
package main
import (
"bytes"
"fmt"
"os"
"strings"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
func main() {
bodyContext := &html.Node{
Type: html.ElementNode,
DataAtom: atom.Body,
Data: "body",
}
// 1. html.ParseFragment parses HTML fragment string in context node into slice of nodes
{
input := `<div id="box" class="highlight"><p>Hello World</p></div>`
nodes, err := html.ParseFragment(strings.NewReader(input), bodyContext)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: ParseFragment returned error: %v\n", err)
os.Exit(1)
}
if len(nodes) != 1 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected 1 node, got %d\n", len(nodes))
os.Exit(1)
}
div := nodes[0]
if div.Type != html.ElementNode || div.Data != "div" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected ElementNode 'div', got type=%v, data=%q\n", div.Type, div.Data)
os.Exit(1)
}
var idVal, classVal string
for _, attr := range div.Attr {
if attr.Key == "id" {
idVal = attr.Val
}
if attr.Key == "class" {
classVal = attr.Val
}
}
if idVal != "box" || classVal != "highlight" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected id='box' and class='highlight', got id=%q, class=%q\n", idVal, classVal)
os.Exit(1)
}
p := div.FirstChild
if p == nil || p.Type != html.ElementNode || p.Data != "p" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected child ElementNode 'p', got %+v\n", p)
os.Exit(1)
}
if p.FirstChild == nil || p.FirstChild.Type != html.TextNode || p.FirstChild.Data != "Hello World" {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected text child 'Hello World', got %+v\n", p.FirstChild)
os.Exit(1)
}
}
// 2. html.ParseFragment handles multiple sibling elements and text nodes
{
input := `<span>First</span> and <span>Second</span>`
nodes, err := html.ParseFragment(strings.NewReader(input), bodyContext)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: ParseFragment error: %v\n", err)
os.Exit(1)
}
if len(nodes) != 3 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 3 nodes, got %d\n", len(nodes))
os.Exit(1)
}
if nodes[0].Type != html.ElementNode || nodes[0].Data != "span" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected node 0 to be span element\n")
os.Exit(1)
}
if nodes[1].Type != html.TextNode || nodes[1].Data != " and " {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected node 1 to be text ' and ', got %q\n", nodes[1].Data)
os.Exit(1)
}
if nodes[2].Type != html.ElementNode || nodes[2].Data != "span" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected node 2 to be span element\n")
os.Exit(1)
}
}
// 3. html.Render serializes HTML node tree to writer output
{
aNode := &html.Node{
Type: html.ElementNode,
DataAtom: atom.A,
Data: "a",
Attr: []html.Attribute{
{Key: "href", Val: "https://example.com"},
},
}
textNode := &html.Node{
Type: html.TextNode,
Data: "Link",
}
aNode.AppendChild(textNode)
var buf bytes.Buffer
if err := html.Render(&buf, aNode); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Render error: %v\n", err)
os.Exit(1)
}
expected := `<a href="https://example.com">Link</a>`
if buf.String() != expected {
fmt.Fprintf(os.Stderr, "assertion 3 failed: expected %q, got %q\n", expected, buf.String())
os.Exit(1)
}
}
// 4. html.Render correctly escapes special characters in text nodes
{
pNode := &html.Node{
Type: html.ElementNode,
DataAtom: atom.P,
Data: "p",
}
textNode := &html.Node{
Type: html.TextNode,
Data: `5 < 10 & 10 > 5`,
}
pNode.AppendChild(textNode)
var buf bytes.Buffer
if err := html.Render(&buf, pNode); err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: Render error: %v\n", err)
os.Exit(1)
}
expected := `<p>5 < 10 & 10 > 5</p>`
if buf.String() != expected {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected %q, got %q\n", expected, buf.String())
os.Exit(1)
}
}
// 5. html.ParseFragment and html.Render roundtrip preserve element structure and attributes
{
originalHTML := `<section id="sec1"><ul class="list"><li>Item 1</li><li>Item 2</li></ul></section>`
nodes, err := html.ParseFragment(strings.NewReader(originalHTML), bodyContext)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: ParseFragment error: %v\n", err)
os.Exit(1)
}
var buf bytes.Buffer
for _, n := range nodes {
if err := html.Render(&buf, n); err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Render error: %v\n", err)
os.Exit(1)
}
}
if buf.String() != originalHTML {
fmt.Fprintf(os.Stderr, "assertion 5 failed: roundtrip mismatch: expected %q, got %q\n", originalHTML, buf.String())
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
Seeder de origem
anônimo