CodeSampleX

Пример

golang.org/x/net v0.24.0: atom.H5

Проверенный пример — golang golang.org/x/net v0.24.0: atom.H5. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:682c5249f74e0048f6394e40b3185fb8a844c6bb67fc5c35633db2ff92f3b239

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-09-05

Кейс

HOW
Цель
verify golang.org/x/net/html/atom.H5 in pkg:golang/golang.org/x/net@v0.24.0
Пакеты
Символы
  • golang.org/x/net/html/atom.H5
Создан
2026-09-05T10:20:15Z

Контракт

  1. atom.H5 is a non-zero Atom constant whose String() method returns "h5"
  2. atom.Lookup on byte slice "h5" returns atom.H5
  3. atom.String on byte slice "h5" returns "h5"
  4. atom.H5 is distinct from other heading atoms such as atom.H1, atom.H2, atom.H3, atom.H4, and atom.H6
  5. html.Parse on HTML containing <h5> tag yields an ElementNode with DataAtom equal to atom.H5
  6. explicitly created html.Node with DataAtom atom.H5 and Data "h5" renders as an <h5> element

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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.H5 in pkg:golang/golang.org/x/net@v0.24.0
Kind: HOW

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

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:a7bf6ce8ee0c0a55a82f3f4a0522f504c61503f7cd610b960a021940938a4891","contract":["atom.H5 is a non-zero Atom constant whose String() method returns \"h5\"","atom.Lookup on byte slice \"h5\" returns atom.H5","atom.String on byte slice \"h5\" returns \"h5\"","atom.H5 is distinct from other heading atoms such as atom.H1, atom.H2, atom.H3, atom.H4, and atom.H6","html.Parse on HTML containing \u003ch5\u003e tag yields an ElementNode with DataAtom equal to atom.H5","explicitly created html.Node with DataAtom atom.H5 and Data \"h5\" renders as an \u003ch5\u003e element"],"goal":"verify golang.org/x/net/html/atom.H5 in pkg:golang/golang.org/x/net@v0.24.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.24.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html/atom.H5"]},"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.24.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.24.0","symbols":["golang.org/x/net/html/atom.H5"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

require golang.org/x/net v0.24.0
go.sum
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
main.go
package main

import (
	"bytes"
	"fmt"
	"strings"

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

// IsH5Element reports whether n is an HTML <h5> element.
func IsH5Element(n *html.Node) bool {
	return n != nil && n.Type == html.ElementNode && n.DataAtom == atom.H5
}

// CreateH5Element constructs a new <h5> DOM element containing text.
func CreateH5Element(text string) *html.Node {
	h5 := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.H5,
		Data:     atom.H5.String(),
	}
	if text != "" {
		h5.AppendChild(&html.Node{
			Type: html.TextNode,
			Data: text,
		})
	}
	return h5
}

// FindFirstH5 searches the node tree for the first <h5> element.
func FindFirstH5(n *html.Node) *html.Node {
	if IsH5Element(n) {
		return n
	}
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if found := FindFirstH5(c); found != nil {
			return found
		}
	}
	return nil
}

func main() {
	// Demonstrating atom.H5 constant and string representation
	fmt.Printf("atom.H5 integer value: %d, string: %q\n", atom.H5, atom.H5.String())

	// Resolving atom from byte slice
	resolved := atom.Lookup([]byte("h5"))
	fmt.Printf("Lookup(\"h5\"): %d (matches atom.H5: %t)\n", resolved, resolved == atom.H5)

	// Creating an explicit <h5> element using atom.H5
	node := CreateH5Element("Sample Heading 5")
	var buf bytes.Buffer
	if err := html.Render(&buf, node); err != nil {
		panic(err)
	}
	fmt.Printf("Rendered element: %s\n", buf.String())

	// Parsing HTML document and identifying <h5> by DataAtom
	doc, err := html.Parse(strings.NewReader("<html><body><h5>Document Subheading</h5></body></html>"))
	if err != nil {
		panic(err)
	}
	found := FindFirstH5(doc)
	if found != nil {
		fmt.Printf("Found <h5> in parsed document with DataAtom == atom.H5\n")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html/atom.H5 in pkg:golang/golang.org/x/net@v0.24.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.24.0"
  ],
  "symbols": [
    "golang.org/x/net/html/atom.H5"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

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

func main() {
	// 1. atom.H5 is a non-zero Atom constant whose String() method returns "h5"
	{
		if atom.H5 == 0 {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom.H5 to be non-zero, got 0\n")
			os.Exit(1)
		}
		if atom.H5.String() != "h5" {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom.H5.String() to be \"h5\", got %q\n", atom.H5.String())
			os.Exit(1)
		}
	}

	// 2. atom.Lookup on byte slice "h5" returns atom.H5
	{
		lookupResult := atom.Lookup([]byte("h5"))
		if lookupResult != atom.H5 {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom.Lookup([]byte(\"h5\")) to be atom.H5, got %v\n", lookupResult)
			os.Exit(1)
		}
	}

	// 3. atom.String on byte slice "h5" returns "h5"
	{
		strResult := atom.String([]byte("h5"))
		if strResult != "h5" {
			fmt.Fprintf(os.Stderr, "FAIL: expected atom.String([]byte(\"h5\")) to be \"h5\", got %q\n", strResult)
			os.Exit(1)
		}
	}

	// 4. atom.H5 is distinct from other heading atoms such as atom.H1, atom.H2, atom.H3, atom.H4, and atom.H6
	{
		otherHeadings := []struct {
			name string
			a    atom.Atom
		}{
			{"H1", atom.H1},
			{"H2", atom.H2},
			{"H3", atom.H3},
			{"H4", atom.H4},
			{"H6", atom.H6},
		}
		for _, oh := range otherHeadings {
			if atom.H5 == oh.a {
				fmt.Fprintf(os.Stderr, "FAIL: atom.H5 unexpectedly matches atom.%s\n", oh.name)
				os.Exit(1)
			}
		}
	}

	// 5. html.Parse on HTML containing <h5> tag yields an ElementNode with DataAtom equal to atom.H5
	{
		doc, err := html.Parse(strings.NewReader("<!DOCTYPE html><html><body><h5>Title 5</h5></body></html>"))
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: html.Parse failed: %v\n", err)
			os.Exit(1)
		}

		var h5Node *html.Node
		var walk func(*html.Node)
		walk = func(n *html.Node) {
			if n.Type == html.ElementNode && n.DataAtom == atom.H5 {
				h5Node = n
				return
			}
			for c := n.FirstChild; c != nil; c = c.NextSibling {
				walk(c)
			}
		}
		walk(doc)

		if h5Node == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected to find node with DataAtom == atom.H5 in parsed document\n")
			os.Exit(1)
		}
		if h5Node.Data != "h5" {
			fmt.Fprintf(os.Stderr, "FAIL: expected h5Node.Data to be \"h5\", got %q\n", h5Node.Data)
			os.Exit(1)
		}
	}

	// 6. explicitly created html.Node with DataAtom atom.H5 and Data "h5" renders as an <h5> element
	{
		node := &html.Node{
			Type:     html.ElementNode,
			DataAtom: atom.H5,
			Data:     atom.H5.String(),
		}
		node.AppendChild(&html.Node{
			Type: html.TextNode,
			Data: "Contract Header 5",
		})

		var buf bytes.Buffer
		if err := html.Render(&buf, node); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: html.Render failed: %v\n", err)
			os.Exit(1)
		}
		expected := "<h5>Contract Header 5</h5>"
		if buf.String() != expected {
			fmt.Fprintf(os.Stderr, "FAIL: expected rendered output %q, got %q\n", expected, buf.String())
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all contract assertions passed")
}

Исходный сидер

аноним