Ejemplo
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7: html.Attribute
Muestra verificada para golang golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7: html.Attribute. El contrato se ejecutó en go 1.26 · linux debian/x64 …
sha256:d6f97ddc30ab74f240a1d7dba3065f25aace337400f42debb6eff53fecfe9750
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
linux 24 · ubuntu · glibc 2.39 x64 go
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-16 |
Caso
HOW- Objetivo
- verify golang.org/x/net/html.Attribute in pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7
- Símbolos
-
- golang.org/x/net/html.Attribute
- Creado
- 2026-10-16T05:30:16Z
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.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.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:771d0cee984f52f54beb36b34881c96bd4b24752cb40833ca4a312c04d8214e5","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.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.Attribute"]},"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.Attribute"],"verifierAdapter":"golang@1"}
module example.com/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=
package sample
import (
"bytes"
"fmt"
"strings"
"golang.org/x/net/html"
)
// MakeAttribute creates an html.Attribute with an 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.
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.0.0-20190813141303-74dc4d7220e7",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/net@v0.0.0-20190813141303-74dc4d7220e7"
],
"symbols": [
"golang.org/x/net/html.Attribute"
]
}
package main
import (
"fmt"
"os"
"strings"
"example.com/sample"
"golang.org/x/net/html"
)
func main() {
// Assertion 1: Attribute struct fields Namespace, Key, and Val represent HTML element attributes
attr1 := sample.MakeAttribute("", "id", "item-id")
if attr1.Namespace != "" || attr1.Key != "id" || attr1.Val != "item-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-label="primary button" data-url="https://example.com/item" 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)
}
labelAttr, ok := sample.GetAttribute(dataAttrs, "data-label")
if !ok || labelAttr.Val != "primary button" {
fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: data-label mismatch: %v\n", labelAttr)
os.Exit(1)
}
urlAttr, ok := sample.GetAttribute(dataAttrs, "data-url")
if !ok || urlAttr.Val != "https://example.com/item" {
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