Ejemplo
golang.org/x/net v0.47.0: html.Attribute
Muestra verificada para golang golang.org/x/net v0.47.0: html.Attribute. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:052c1714164ae4d1d8668ee94ed1fa9d4f7269491c42ed79651dfcd5e8623374
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-10 |
Caso
HOW- Objetivo
- verify golang.org/x/net/html.Attribute in pkg:golang/golang.org/x/net@v0.47.0
- Paquetes
- Símbolos
-
- golang.org/x/net/html.Attribute
- Entorno
- go 1.26.6
- Creado
- 2026-10-10T22:35:36Z
Contrato
- Attribute struct fields Namespace, Key, and Val represent HTML element attributes
- html.Parse extracts element attributes into html.Node.Attr as a slice of html.Attribute
- html.Render serializes html.Node with html.Attribute slice into valid HTML attribute syntax
- Attribute supports namespaced attributes such as xml and xlink
- Attribute values preserve exact strings including whitespace, URLs, and custom data attributes
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
Código fuente
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.Attribute in pkg:golang/golang.org/x/net@v0.47.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/net@v0.47.0
Demonstrate these symbols/APIs:
- golang.org/x/net/html.Attribute
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:c15870b00be5064b249bcf8d5b58a70c6f1923c3cd6feaf5a6f5f1bd4caee322","contract":["Attribute struct fields Namespace, Key, and Val represent HTML element attributes","html.Parse extracts element attributes into html.Node.Attr as a slice of html.Attribute","html.Render serializes html.Node with html.Attribute slice into valid HTML attribute syntax","Attribute supports namespaced attributes such as xml and xlink","Attribute values preserve exact strings including whitespace, URLs, and custom data attributes"],"goal":"verify golang.org/x/net/html.Attribute in pkg:golang/golang.org/x/net@v0.47.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.47.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.Attribute"]},"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.47.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.47.0","symbols":["golang.org/x/net/html.Attribute"],"verifierAdapter":"golang@1"}
module sample
go 1.24.0
require golang.org/x/net v0.47.0
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
package sample
import (
"bytes"
"fmt"
"strings"
"golang.org/x/net/html"
)
// MakeAttribute creates an html.Attribute with optional namespace.
func MakeAttribute(namespace, key, val string) html.Attribute {
return html.Attribute{
Namespace: namespace,
Key: key,
Val: val,
}
}
// GetAttribute finds an attribute by key (ignoring namespace if empty).
func GetAttribute(attrs []html.Attribute, key string) (html.Attribute, bool) {
for _, a := range attrs {
if a.Key == key {
return a, true
}
}
return html.Attribute{}, false
}
// GetNamespacedAttribute finds an attribute matching both namespace and key.
func GetNamespacedAttribute(attrs []html.Attribute, namespace, key string) (html.Attribute, bool) {
for _, a := range attrs {
if a.Namespace == namespace && a.Key == key {
return a, true
}
}
return html.Attribute{}, false
}
// ParseAttributes parses an HTML snippet containing an element and returns its attributes.
func ParseAttributes(snippet string) ([]html.Attribute, error) {
node, err := html.Parse(strings.NewReader(snippet))
if err != nil {
return nil, fmt.Errorf("parse error: %w", err)
}
var found []html.Attribute
var search func(*html.Node)
search = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data != "html" && n.Data != "head" && n.Data != "body" {
found = n.Attr
return
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
search(c)
if found != nil {
return
}
}
}
search(node)
if found == nil {
return nil, fmt.Errorf("no target element node found")
}
return found, nil
}
// RenderAttributes creates an element node with the given tag and attributes, then renders it to HTML.
func RenderAttributes(tag string, attrs []html.Attribute) (string, error) {
node := &html.Node{
Type: html.ElementNode,
Data: tag,
Attr: attrs,
}
var buf bytes.Buffer
if err := html.Render(&buf, node); err != nil {
return "", fmt.Errorf("render error: %w", err)
}
return buf.String(), nil
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/net/html.Attribute in pkg:golang/golang.org/x/net@v0.47.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.47.0"
],
"symbols": [
"golang.org/x/net/html.Attribute"
]
}
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/net/html"
"sample"
)
func main() {
// Assertion 1: Attribute struct fields Namespace, Key, and Val represent HTML element attributes
attr1 := sample.MakeAttribute("", "id", "test-id")
if attr1.Namespace != "" || attr1.Key != "id" || attr1.Val != "test-id" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: %v\n", attr1)
os.Exit(1)
}
// Assertion 2: html.Parse extracts element attributes into html.Node.Attr as a slice of html.Attribute
snippet := `<input type="text" name="query" value="search term" required>`
parsedAttrs, err := sample.ParseAttributes(snippet)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed to parse: %v\n", err)
os.Exit(1)
}
if len(parsedAttrs) != 4 {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: expected 4 attributes, got %d\n", len(parsedAttrs))
os.Exit(1)
}
typeAttr, ok := sample.GetAttribute(parsedAttrs, "type")
if !ok || typeAttr.Val != "text" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: type attr mismatch: %v\n", typeAttr)
os.Exit(1)
}
nameAttr, ok := sample.GetAttribute(parsedAttrs, "name")
if !ok || nameAttr.Val != "query" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: name attr mismatch: %v\n", nameAttr)
os.Exit(1)
}
// Assertion 3: html.Render serializes html.Node with html.Attribute slice into valid HTML attribute syntax
renderAttrs := []html.Attribute{
{Key: "href", Val: "https://example.com/api?a=1&b=2"},
{Key: "title", Val: "Quotes & Ampersands"},
}
rendered, err := sample.RenderAttributes("a", renderAttrs)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed to render: %v\n", err)
os.Exit(1)
}
if !strings.Contains(rendered, `href="https://example.com/api?a=1&b=2"`) || !strings.Contains(rendered, `title="Quotes & Ampersands"`) {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed: rendered mismatch: %s\n", rendered)
os.Exit(1)
}
// Assertion 4: Attribute supports namespaced attributes such as xml and xlink
nsAttrs := []html.Attribute{
sample.MakeAttribute("xml", "lang", "en"),
sample.MakeAttribute("xlink", "href", "#icon-check"),
}
xmlAttr, ok := sample.GetNamespacedAttribute(nsAttrs, "xml", "lang")
if !ok || xmlAttr.Val != "en" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: xml:lang mismatch: %v\n", xmlAttr)
os.Exit(1)
}
xlinkAttr, ok := sample.GetNamespacedAttribute(nsAttrs, "xlink", "href")
if !ok || xlinkAttr.Val != "#icon-check" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: xlink:href mismatch: %v\n", xlinkAttr)
os.Exit(1)
}
// Assertion 5: Attribute values preserve exact strings including whitespace, URLs, and custom data attributes
customSnippet := `<div data-user="alice smith" data-url="https://example.com/profile" data-json='{"active":true}'></div>`
dataAttrs, err := sample.ParseAttributes(customSnippet)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed to parse custom attributes: %v\n", err)
os.Exit(1)
}
userAttr, ok := sample.GetAttribute(dataAttrs, "data-user")
if !ok || userAttr.Val != "alice smith" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: data-user mismatch: %v\n", userAttr)
os.Exit(1)
}
urlAttr, ok := sample.GetAttribute(dataAttrs, "data-url")
if !ok || urlAttr.Val != "https://example.com/profile" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: data-url mismatch: %v\n", urlAttr)
os.Exit(1)
}
jsonAttr, ok := sample.GetAttribute(dataAttrs, "data-json")
if !ok || jsonAttr.Val != `{"active":true}` {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: data-json mismatch: %v\n", jsonAttr)
os.Exit(1)
}
fmt.Println("PASS")
}
Seeder de origen
anónimo