CodeSampleX

Ejemplo

golang.org/x/net v0.41.0: atom.Atom

Muestra verificada para golang golang.org/x/net v0.41.0: atom.Atom. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:e200d707e3ddad494e184fe2603af6c2bccdf81ed3afffb8bda0b3eb7d9b15d9

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-15

Caso

HOW
Objetivo
verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.41.0
Paquetes
Símbolos
  • golang.org/x/net/html/atom.Atom
Creado
2026-10-15T02:18:25Z

Contrato

  1. atom.Atom zero value atom.Atom(0) maps to empty string ""
  2. atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name
  3. atom.Lookup resolves valid HTML tag byte slices to non-zero atom.Atom and returns atom.Atom(0) for unknown or uppercase tags
  4. html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags
  5. atom.Atom supports direct integer equality comparison between element DataAtom and atom constants

Archivos

  • PROMPT.md
  • atom_sample.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
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/atom.Atom in pkg:golang/golang.org/x/net@v0.41.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.41.0
Demonstrate these symbols/APIs:
  - golang.org/x/net/html/atom.Atom

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.
atom_sample.go
package sample

import (
	"strings"

	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

// IsValidAtom returns true when the atom has a non-zero integer code.
func IsValidAtom(a atom.Atom) bool {
	return a != 0
}

// AtomString returns the lowercase name of the atom.
func AtomString(a atom.Atom) string {
	return a.String()
}

// LookupTagAtom resolves a lowercase tag byte slice into an atom.Atom.
func LookupTagAtom(tag []byte) atom.Atom {
	return atom.Lookup(tag)
}

// NodeHasAtom checks if an html.Node has the specified DataAtom.
func NodeHasAtom(n *html.Node, expected atom.Atom) bool {
	if n == nil {
		return false
	}
	return n.DataAtom == expected
}

// FindElementByAtom traverses the HTML node tree and returns the first ElementNode with the given atom.Atom.
func FindElementByAtom(root *html.Node, target atom.Atom) *html.Node {
	if root == nil {
		return nil
	}
	if root.Type == html.ElementNode && root.DataAtom == target {
		return root
	}
	for child := root.FirstChild; child != nil; child = child.NextSibling {
		if found := FindElementByAtom(child, target); found != nil {
			return found
		}
	}
	return nil
}

// ParseHTMLDoc parses an HTML fragment or document into an html.Node tree.
func ParseHTMLDoc(src string) (*html.Node, error) {
	return html.Parse(strings.NewReader(src))
}
csx.json
{"case":{"caseId":"case:sha256:9758fbe8cef66865e29bbdddd1c48d35ba8355b461fbc3e6fbf7bd1c8ec31503","contract":["atom.Atom zero value atom.Atom(0) maps to empty string \"\"","atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name","atom.Lookup resolves valid HTML tag byte slices to non-zero atom.Atom and returns atom.Atom(0) for unknown or uppercase tags","html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags","atom.Atom supports direct integer equality comparison between element DataAtom and atom constants"],"goal":"verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.41.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.41.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html/atom.Atom"]},"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.41.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.41.0","symbols":["golang.org/x/net/html/atom.Atom"],"verifierAdapter":"golang@1"}
go.mod
module example.com/atomsample

go 1.23.0

require golang.org/x/net v0.41.0
go.sum
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.41.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.41.0"
  ],
  "symbols": [
    "golang.org/x/net/html/atom.Atom"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	sample "example.com/atomsample"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

func main() {
	// 1. Zero value atom.Atom(0) maps to empty string ""
	var zeroAtom atom.Atom
	if zeroAtom != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected zero atom to equal 0, got %v\n", zeroAtom)
		os.Exit(1)
	}
	if zeroAtom.String() != "" {
		fmt.Fprintf(os.Stderr, "FAIL: expected zeroAtom.String() == \"\", got %q\n", zeroAtom.String())
		os.Exit(1)
	}
	if sample.IsValidAtom(zeroAtom) {
		fmt.Fprintf(os.Stderr, "FAIL: expected IsValidAtom(0) == false\n")
		os.Exit(1)
	}

	// 2. Known atom.Atom constants have non-zero integer codes whose String() returns their lowercase name
	knownAtoms := []struct {
		code atom.Atom
		name string
	}{
		{atom.Div, "div"},
		{atom.Span, "span"},
		{atom.A, "a"},
		{atom.P, "p"},
		{atom.Body, "body"},
		{atom.Table, "table"},
		{atom.Input, "input"},
	}
	for _, tc := range knownAtoms {
		if tc.code == 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected non-zero atom for %s\n", tc.name)
			os.Exit(1)
		}
		if tc.code.String() != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected %s.String() == %q, got %q\n", tc.name, tc.name, tc.code.String())
			os.Exit(1)
		}
		if sample.AtomString(tc.code) != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected AtomString(%s) == %q, got %q\n", tc.name, tc.name, sample.AtomString(tc.code))
			os.Exit(1)
		}
		if !sample.IsValidAtom(tc.code) {
			fmt.Fprintf(os.Stderr, "FAIL: expected IsValidAtom(%s) == true\n", tc.name)
			os.Exit(1)
		}
	}

	// 3. atom.Lookup resolves valid lowercase HTML tag byte slices to non-zero atom.Atom and returns 0 for unknown or uppercase tags
	if got := sample.LookupTagAtom([]byte("div")); got != atom.Div {
		fmt.Fprintf(os.Stderr, "FAIL: LookupTagAtom(\"div\") expected atom.Div, got %v\n", got)
		os.Exit(1)
	}
	if got := sample.LookupTagAtom([]byte("DIV")); got != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: LookupTagAtom(\"DIV\") expected 0, got %v\n", got)
		os.Exit(1)
	}
	if got := sample.LookupTagAtom([]byte("x-custom-tag")); got != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: LookupTagAtom(\"x-custom-tag\") expected 0, got %v\n", got)
		os.Exit(1)
	}
	if got := sample.LookupTagAtom([]byte("")); got != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: LookupTagAtom(\"\") expected 0, got %v\n", got)
		os.Exit(1)
	}

	// 4. html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags
	doc, err := sample.ParseHTMLDoc(`<!DOCTYPE html><html><body><div id="main"><span class="label">Hello</span><x-custom>Item</x-custom></div></body></html>`)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ParseHTMLDoc error: %v\n", err)
		os.Exit(1)
	}

	divNode := sample.FindElementByAtom(doc, atom.Div)
	if divNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: FindElementByAtom(atom.Div) returned nil\n")
		os.Exit(1)
	}
	if divNode.DataAtom != atom.Div || divNode.Data != "div" {
		fmt.Fprintf(os.Stderr, "FAIL: unexpected divNode DataAtom=%v Data=%q\n", divNode.DataAtom, divNode.Data)
		os.Exit(1)
	}

	spanNode := sample.FindElementByAtom(divNode, atom.Span)
	if spanNode == nil || spanNode.DataAtom != atom.Span {
		fmt.Fprintf(os.Stderr, "FAIL: FindElementByAtom(atom.Span) failed\n")
		os.Exit(1)
	}

	var customNode *html.Node
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.ElementNode && n.Data == "x-custom" {
			customNode = n
			return
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(doc)
	if customNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: custom element x-custom not found\n")
		os.Exit(1)
	}
	if customNode.DataAtom != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected customNode.DataAtom == 0, got %v\n", customNode.DataAtom)
		os.Exit(1)
	}

	// 5. Direct integer equality comparison between element DataAtom and atom constants
	if !sample.NodeHasAtom(divNode, atom.Div) {
		fmt.Fprintf(os.Stderr, "FAIL: NodeHasAtom(divNode, atom.Div) returned false\n")
		os.Exit(1)
	}
	if sample.NodeHasAtom(divNode, atom.Span) {
		fmt.Fprintf(os.Stderr, "FAIL: NodeHasAtom(divNode, atom.Span) returned true\n")
		os.Exit(1)
	}

	fmt.Println("PASS: golang.org/x/net/html/atom.Atom contract passed")
}

Seeder de origen

anónimo