CodeSampleX

Ejemplo

golang.org/x/net v0.29.0: atom.Body

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

sha256:0c5377be58024c2c1b80a079dfba22649da936649068e1d4499323a23227f6d2

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
2
Claves de firma que lo compilaron
1
Entorno declarado go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-30
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-30

Caso

HOW
Objetivo
verify golang.org/x/net/html/atom.Body in pkg:golang/golang.org/x/net@v0.29.0
Paquetes
Símbolos
  • golang.org/x/net/html/atom.Body
Entorno
go 1.26.6
Creado
2026-08-30T16:33:27Z

Contrato

  1. atom.Body String() returns "body"
  2. atom.Lookup resolves []byte("body") to atom.Body
  3. html.Parse assigns atom.Body as DataAtom for body elements
  4. atom.Body distinguishes body element from other elements in parsed HTML tree

Archivos

  • PROMPT.md
  • atom.go
  • contract_test.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json

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.Body 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/atom.Body
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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

import (
	"strings"

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

// IsBodyAtom checks whether an atom represents the <body> tag.
func IsBodyAtom(a atom.Atom) bool {
	return a == atom.Body
}

// LookupBodyAtom resolves a tag name byte slice to atom.Body.
func LookupBodyAtom(tag []byte) (atom.Atom, bool) {
	a := atom.Lookup(tag)
	return a, a == atom.Body
}

// FindBodyNode finds the first <body> element node in the parsed HTML node tree.
func FindBodyNode(n *html.Node) *html.Node {
	if n == nil {
		return nil
	}
	if n.Type == html.ElementNode && n.DataAtom == atom.Body {
		return n
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if found := FindBodyNode(c); found != nil {
			return found
		}
	}
	return nil
}

// ExtractBodyText parses an HTML document string and extracts inner text from the <body> element.
func ExtractBodyText(htmlStr string) (string, error) {
	doc, err := html.Parse(strings.NewReader(htmlStr))
	if err != nil {
		return "", err
	}

	bodyNode := FindBodyNode(doc)
	if bodyNode == nil {
		return "", nil
	}

	var sb strings.Builder
	var collectText func(*html.Node)
	collectText = func(n *html.Node) {
		if n.Type == html.TextNode {
			sb.WriteString(n.Data)
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			collectText(c)
		}
	}
	collectText(bodyNode)

	return strings.TrimSpace(sb.String()), nil
}
contract_test.go
package sample

import (
	"strings"
	"testing"

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

func TestContractAtomBody(t *testing.T) {
	// 1. Verify atom.Body string representation
	if atom.Body.String() != "body" {
		t.Fatalf("expected atom.Body.String() == \"body\", got %q", atom.Body.String())
	}
	if !IsBodyAtom(atom.Body) {
		t.Fatalf("expected IsBodyAtom(atom.Body) == true")
	}
	if IsBodyAtom(atom.Head) {
		t.Fatalf("expected IsBodyAtom(atom.Head) == false")
	}

	// 2. Verify atom.Lookup resolves byte slice to atom.Body
	lookedUp, isBody := LookupBodyAtom([]byte("body"))
	if !isBody || lookedUp != atom.Body {
		t.Fatalf("expected LookupBodyAtom([]byte(\"body\")) == (atom.Body, true), got (%v, %v)", lookedUp, isBody)
	}

	// 3. Verify html.Parse sets DataAtom to atom.Body for <body> element
	htmlContent := `<!DOCTYPE html><html><head><title>Sample</title></head><body><div class="content"><p>Hello CodeSampleX</p></div></body></html>`
	doc, err := html.Parse(strings.NewReader(htmlContent))
	if err != nil {
		t.Fatalf("html.Parse failed: %v", err)
	}

	body := FindBodyNode(doc)
	if body == nil {
		t.Fatalf("expected FindBodyNode to find body node")
	}
	if body.DataAtom != atom.Body {
		t.Fatalf("expected body.DataAtom == atom.Body, got %v", body.DataAtom)
	}
	if body.Data != "body" {
		t.Fatalf("expected body.Data == \"body\", got %q", body.Data)
	}

	// 4. Verify extracting text from body node
	text, err := ExtractBodyText(htmlContent)
	if err != nil {
		t.Fatalf("ExtractBodyText failed: %v", err)
	}
	if text != "Hello CodeSampleX" {
		t.Fatalf("expected extracted text \"Hello CodeSampleX\", got %q", text)
	}
}
csx.json
{"case":{"caseId":"case:sha256:798ef5491a1f155cf90d830cd751ccb7cb24ec7038fdd3cb3901fd50cd7a418d","contract":["atom.Body String() returns \"body\"","atom.Lookup resolves []byte(\"body\") to atom.Body","html.Parse assigns atom.Body as DataAtom for body elements","atom.Body distinguishes body element from other elements in parsed HTML tree"],"goal":"verify golang.org/x/net/html/atom.Body 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/atom.Body"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","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.29.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.29.0","symbols":["golang.org/x/net/html/atom.Body"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require golang.org/x/net v0.29.0
go.sum
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.Body 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/atom.Body"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}

Seeder de origen

anónimo