CodeSampleX

Exemple

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

Échantillon vérifié pour golang golang.org/x/net v0.47.0: atom.Atom. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:bb4f0964e178884d8ed7820f2cb42541aa489f6286b1785f3dc6cc27b9efda79

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-11

Cas

HOW
Objectif
verify golang.org/x/net/html/atom.Atom in pkg:golang/golang.org/x/net@v0.47.0
Paquets
Symboles
  • golang.org/x/net/html/atom.Atom
Créé
2026-10-11T06:28:02Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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.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/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"
)

// IsKnownAtom checks if the atom is a non-zero known atom.
func IsKnownAtom(a atom.Atom) bool {
	return a != 0
}

// AtomName returns the string representation of an atom.
func AtomName(a atom.Atom) string {
	return a.String()
}

// ResolveAtom resolves a byte slice to an Atom using atom.Lookup.
func ResolveAtom(tag []byte) atom.Atom {
	return atom.Lookup(tag)
}

// MatchDataAtom checks if an HTML node's DataAtom matches the expected atom.
func MatchDataAtom(n *html.Node, expected atom.Atom) bool {
	if n == nil {
		return false
	}
	return n.DataAtom == expected
}

// FindFirstByAtom finds the first descendant ElementNode matching the given atom.
func FindFirstByAtom(n *html.Node, target atom.Atom) *html.Node {
	if n == nil {
		return nil
	}
	if n.Type == html.ElementNode && n.DataAtom == target {
		return n
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if found := FindFirstByAtom(c, target); found != nil {
			return found
		}
	}
	return nil
}

// ParseHTML parses an HTML document and returns the root Node.
func ParseHTML(htmlContent string) (*html.Node, error) {
	return html.Parse(strings.NewReader(htmlContent))
}
csx.json
{"case":{"caseId":"case:sha256:30bd424c836d5e8abd4f6d4dc1645294834084a12a0df9a29ea446111a30f54d","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.47.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.47.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.47.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.47.0","symbols":["golang.org/x/net/html/atom.Atom"],"verifierAdapter":"golang@1"}
go.mod
module example.com/atomsample

go 1.26.6

require golang.org/x/net v0.47.0
go.sum
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.Atom 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/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() {
	// Assertion 1: atom.Atom zero value maps to empty string ""
	var zeroAtom atom.Atom
	if zeroAtom != 0 {
		fmt.Fprintf(os.Stderr, "FAIL: expected zero atom to be 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.IsKnownAtom(zeroAtom) {
		fmt.Fprintf(os.Stderr, "FAIL: sample.IsKnownAtom(zeroAtom) returned true for zero atom\n")
		os.Exit(1)
	}

	// Assertion 2: atom.Atom constants have non-zero integer codes whose String() returns their lowercase tag or attribute name
	atoms := []struct {
		a    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 atoms {
		if tc.a == 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected non-zero atom for %s\n", tc.name)
			os.Exit(1)
		}
		if tc.a.String() != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom %s.String() == %q, got %q\n", tc.name, tc.name, tc.a.String())
			os.Exit(1)
		}
		if sample.AtomName(tc.a) != tc.name {
			fmt.Fprintf(os.Stderr, "FAIL: expected sample.AtomName(%s) == %q, got %q\n", tc.name, tc.name, sample.AtomName(tc.a))
			os.Exit(1)
		}
		if !sample.IsKnownAtom(tc.a) {
			fmt.Fprintf(os.Stderr, "FAIL: expected sample.IsKnownAtom(%s) == true\n", tc.name)
			os.Exit(1)
		}
	}

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

	// Assertion 4: html.Parse assigns atom.Atom to html.Node.DataAtom for known HTML tags and zero for custom tags
	rawHTML := `<!DOCTYPE html><html><body><div id="wrapper"><span class="highlight">Text</span><custom-widget>Custom</custom-widget></div></body></html>`
	doc, err := sample.ParseHTML(rawHTML)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ParseHTML failed: %v\n", err)
		os.Exit(1)
	}

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

	spanNode := sample.FindFirstByAtom(divNode, atom.Span)
	if spanNode == nil {
		fmt.Fprintf(os.Stderr, "FAIL: FindFirstByAtom(atom.Span) returned nil\n")
		os.Exit(1)
	}
	if spanNode.DataAtom != atom.Span {
		fmt.Fprintf(os.Stderr, "FAIL: expected spanNode.DataAtom == atom.Span, got %v\n", spanNode.DataAtom)
		os.Exit(1)
	}

	// Check custom tag has DataAtom == 0
	var customNode *html.Node
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.ElementNode && n.Data == "custom-widget" {
			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-widget node 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)
	}

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

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

Seeder d'origine

anonyme