CodeSampleX

Beispiel

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

Verifiziertes Beispiel für golang golang.org/x/net v0.41.0: atom.Atom. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:e200d707e3ddad494e184fe2603af6c2bccdf81ed3afffb8bda0b3eb7d9b15d9

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.41.0
Pakete
Symbole
  • golang.org/x/net/html/atom.Atom
Erstellt
2026-10-15T02:18:25Z

Contract

  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

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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")
}

Ursprungs-Seeder

anonym