CodeSampleX

Exemple

golang.org/x/net v0.61.0: atom.H3

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

sha256:b537b7e8a9a88a21499859d1e0e20d62ebd063db26088c23b238a4ee3517d745

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

Cas

HOW
Objectif
verify golang.org/x/net/html/atom.H3 in pkg:golang/golang.org/x/net@v0.61.0
Paquets
Symboles
  • golang.org/x/net/html/atom.H3
Créé
2026-10-12T04:20:56Z

Contrat

  1. atom.H3 is non-zero and its String method returns "h3"
  2. atom.Lookup returns atom.H3 for byte slice "h3"
  3. html.Parse parses <h3> element with DataAtom equal to atom.H3

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • 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.H3 in pkg:golang/golang.org/x/net@v0.61.0
Kind: HOW

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

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.
csx.json
{"case":{"caseId":"case:sha256:93c88f29e41d98d625458276dc0cb7cd1bd16e11f09a491ddb6cf9b80e3504b4","contract":["atom.H3 is non-zero and its String method returns \"h3\"","atom.Lookup returns atom.H3 for byte slice \"h3\"","html.Parse parses \u003ch3\u003e element with DataAtom equal to atom.H3"],"goal":"verify golang.org/x/net/html/atom.H3 in pkg:golang/golang.org/x/net@v0.61.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.61.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html/atom.H3"]},"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.61.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.61.0","symbols":["golang.org/x/net/html/atom.H3"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/net v0.61.0
go.sum
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
main.go
package main

import (
	"fmt"
	"strings"

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

func main() {
	rawHTML := "<div><h3>Heading 3 Text</h3><p>Paragraph</p></div>"
	doc, err := html.Parse(strings.NewReader(rawHTML))
	if err != nil {
		panic(err)
	}

	var foundH3 bool
	var traverse func(*html.Node)
	traverse = func(n *html.Node) {
		if n.Type == html.ElementNode && n.DataAtom == atom.H3 {
			foundH3 = true
			if n.FirstChild != nil {
				fmt.Printf("Found <%s>: %s\n", n.DataAtom.String(), n.FirstChild.Data)
			}
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			traverse(c)
		}
	}
	traverse(doc)

	if !foundH3 {
		panic("expected to find <h3> element")
	}

	lookupAtom := atom.Lookup([]byte("h3"))
	fmt.Printf("Lookup 'h3' matches atom.H3: %t\n", lookupAtom == atom.H3)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.H3 in pkg:golang/golang.org/x/net@v0.61.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.61.0"
  ],
  "symbols": [
    "golang.org/x/net/html/atom.H3"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runContractTests() error {
	// Assertion 1: atom.H3 is non-zero and its String method returns "h3"
	if atom.H3 == 0 {
		return fmt.Errorf("expected atom.H3 to be non-zero, got 0")
	}
	if got := atom.H3.String(); got != "h3" {
		return fmt.Errorf("expected atom.H3.String() to be %q, got %q", "h3", got)
	}

	// Assertion 2: atom.Lookup returns atom.H3 for byte slice "h3"
	if got := atom.Lookup([]byte("h3")); got != atom.H3 {
		return fmt.Errorf("expected atom.Lookup([]byte(\"h3\")) to be atom.H3 (%d), got %d", atom.H3, got)
	}

	// Assertion 3: html.Parse parses <h3> element with DataAtom equal to atom.H3
	doc, err := html.Parse(strings.NewReader("<html><body><H3>Section Heading</H3></body></html>"))
	if err != nil {
		return fmt.Errorf("html.Parse failed: %w", err)
	}

	var foundH3 bool
	var traverse func(*html.Node)
	traverse = func(n *html.Node) {
		if n.Type == html.ElementNode && n.DataAtom == atom.H3 {
			foundH3 = true
			if n.Data != "h3" {
				// Note: HTML parser canonicalizes tag names to lower case
				err = fmt.Errorf("expected Data to be %q, got %q", "h3", n.Data)
			}
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			traverse(c)
		}
	}
	traverse(doc)

	if err != nil {
		return err
	}
	if !foundH3 {
		return fmt.Errorf("failed to find ElementNode with DataAtom == atom.H3")
	}

	return nil
}

Seeder d'origine

anonyme