CodeSampleX

Sample

golang.org/x/net v0.12.0: html.StartTagToken

Verified sample for golang golang.org/x/net v0.12.0: html.StartTagToken. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:cccaec26deed07337dc4af868df31d9902e7de857e267867dad4ab55e07d3874

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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-04

Case

HOW
Goal
verify golang.org/x/net/html.StartTagToken in pkg:golang/golang.org/x/net@v0.12.0
Packages
Symbols
  • golang.org/x/net/html.StartTagToken
Created
2026-09-04T09:19:19Z

Contract

  1. When tokenizing HTML containing start tags, html.NewTokenizer yields TokenType html.StartTagToken for each opening tag.
  2. For each StartTagToken, Token.Data contains the tag name and Token.Attr contains key-value pairs of attributes.
  3. Tokenizer.TagName returns tag name and hasAttr, while TagAttr iterates over attributes without Token allocations.
  4. Token.String returns reconstructed HTML start tag with attributes.
  5. Valueless boolean attributes are parsed with empty Val in Token.Attr.
  6. html.StartTagToken.String returns 'StartTag'.

Files

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

Download the source artifact (tar.gz)

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

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

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:f82ffe3627d4aad8066c64139a111b0301e3deaf79fd4ae798d6dacfa07ee1eb","contract":["When tokenizing HTML containing start tags, html.NewTokenizer yields TokenType html.StartTagToken for each opening tag.","For each StartTagToken, Token.Data contains the tag name and Token.Attr contains key-value pairs of attributes.","Tokenizer.TagName returns tag name and hasAttr, while TagAttr iterates over attributes without Token allocations.","Token.String returns reconstructed HTML start tag with attributes.","Valueless boolean attributes are parsed with empty Val in Token.Attr.","html.StartTagToken.String returns 'StartTag'."],"goal":"verify golang.org/x/net/html.StartTagToken in pkg:golang/golang.org/x/net@v0.12.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.12.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.StartTagToken"]},"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.12.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.12.0","symbols":["golang.org/x/net/html.StartTagToken"],"verifierAdapter":"golang@1"}
go.mod
module example.com/net-html-start-tag-token

go 1.20

require golang.org/x/net v0.12.0
go.sum
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
main.go
package main

import (
	"fmt"
	"io"
	"os"
	"strings"

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

// TagInfo represents a parsed HTML start tag and its attributes.
type TagInfo struct {
	Name       string
	Attributes map[string]string
}

// ExtractStartTags parses HTML input and returns all start tags with their attributes.
func ExtractStartTags(input string) ([]TagInfo, error) {
	z := html.NewTokenizer(strings.NewReader(input))
	var tags []TagInfo

	for {
		tt := z.Next()
		if tt == html.ErrorToken {
			if z.Err() == io.EOF {
				break
			}
			return nil, z.Err()
		}

		if tt == html.StartTagToken {
			tok := z.Token()
			attrs := make(map[string]string, len(tok.Attr))
			for _, attr := range tok.Attr {
				attrs[attr.Key] = attr.Val
			}
			tags = append(tags, TagInfo{
				Name:       tok.Data,
				Attributes: attrs,
			})
		}
	}

	return tags, nil
}

func main() {
	snippet := `<div id="content" class="main"><a href="https://example.com" target="_blank">Link</a></div>`
	tags, err := ExtractStartTags(snippet)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error extracting start tags: %v\n", err)
		os.Exit(1)
	}

	for _, tag := range tags {
		fmt.Printf("StartTag: %s, Attributes: %v\n", tag.Name, tag.Attributes)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.StartTagToken in pkg:golang/golang.org/x/net@v0.12.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.12.0"
  ],
  "symbols": [
    "golang.org/x/net/html.StartTagToken"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"io"
	"os"
	"strings"

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

func main() {
	// Assertion 1: Tokenizer yields StartTagToken for opening tags in HTML
	{
		input := `<html><body><div id="main"><span>Hello</span></div></body></html>`
		z := html.NewTokenizer(strings.NewReader(input))

		var startTagNames []string
		for {
			tt := z.Next()
			if tt == html.ErrorToken {
				if z.Err() == io.EOF {
					break
				}
				fmt.Fprintf(os.Stderr, "unexpected error during tokenization: %v\n", z.Err())
				os.Exit(1)
			}
			if tt == html.StartTagToken {
				tok := z.Token()
				if tok.Type != html.StartTagToken {
					fmt.Fprintf(os.Stderr, "expected tok.Type == html.StartTagToken, got %v\n", tok.Type)
					os.Exit(1)
				}
				startTagNames = append(startTagNames, tok.Data)
			}
		}

		expectedTags := []string{"html", "body", "div", "span"}
		if len(startTagNames) != len(expectedTags) {
			fmt.Fprintf(os.Stderr, "expected %d start tags, got %d (%v)\n", len(expectedTags), len(startTagNames), startTagNames)
			os.Exit(1)
		}
		for i, expected := range expectedTags {
			if startTagNames[i] != expected {
				fmt.Fprintf(os.Stderr, "expected tag[%d] to be %q, got %q\n", i, expected, startTagNames[i])
				os.Exit(1)
			}
		}
	}

	// Assertion 2: For each StartTagToken, Token.Data contains tag name and Token.Attr contains key-value pairs
	{
		input := `<a href="https://example.com" target="_blank" rel="noopener">Link</a>`
		z := html.NewTokenizer(strings.NewReader(input))

		tt := z.Next()
		if tt != html.StartTagToken {
			fmt.Fprintf(os.Stderr, "expected StartTagToken, got %v\n", tt)
			os.Exit(1)
		}

		tok := z.Token()
		if tok.Data != "a" {
			fmt.Fprintf(os.Stderr, "expected tag name 'a', got %q\n", tok.Data)
			os.Exit(1)
		}

		if len(tok.Attr) != 3 {
			fmt.Fprintf(os.Stderr, "expected 3 attributes, got %d\n", len(tok.Attr))
			os.Exit(1)
		}

		attrMap := make(map[string]string)
		for _, a := range tok.Attr {
			attrMap[a.Key] = a.Val
		}

		if attrMap["href"] != "https://example.com" {
			fmt.Fprintf(os.Stderr, "expected href 'https://example.com', got %q\n", attrMap["href"])
			os.Exit(1)
		}
		if attrMap["target"] != "_blank" {
			fmt.Fprintf(os.Stderr, "expected target '_blank', got %q\n", attrMap["target"])
			os.Exit(1)
		}
		if attrMap["rel"] != "noopener" {
			fmt.Fprintf(os.Stderr, "expected rel 'noopener', got %q\n", attrMap["rel"])
			os.Exit(1)
		}
	}

	// Assertion 3: Tokenizer.TagName returns tag name and hasAttr, while TagAttr iterates over attributes
	{
		input := `<section id="sec1" role="region">Content</section>`
		z := html.NewTokenizer(strings.NewReader(input))

		tt := z.Next()
		if tt != html.StartTagToken {
			fmt.Fprintf(os.Stderr, "expected StartTagToken, got %v\n", tt)
			os.Exit(1)
		}

		name, hasAttr := z.TagName()
		if string(name) != "section" {
			fmt.Fprintf(os.Stderr, "expected TagName 'section', got %q\n", string(name))
			os.Exit(1)
		}
		if !hasAttr {
			fmt.Fprintf(os.Stderr, "expected hasAttr true, got false\n")
			os.Exit(1)
		}

		k1, v1, more1 := z.TagAttr()
		if string(k1) != "id" || string(v1) != "sec1" || !more1 {
			fmt.Fprintf(os.Stderr, "attr 1 mismatch: key=%q, val=%q, more=%v\n", string(k1), string(v1), more1)
			os.Exit(1)
		}

		k2, v2, more2 := z.TagAttr()
		if string(k2) != "role" || string(v2) != "region" || more2 {
			fmt.Fprintf(os.Stderr, "attr 2 mismatch: key=%q, val=%q, more=%v\n", string(k2), string(v2), more2)
			os.Exit(1)
		}
	}

	// Assertion 4: Token.String returns reconstructed HTML start tag with attributes
	{
		input := `<button type="submit" class="btn primary">Submit</button>`
		z := html.NewTokenizer(strings.NewReader(input))

		tt := z.Next()
		if tt != html.StartTagToken {
			fmt.Fprintf(os.Stderr, "expected StartTagToken, got %v\n", tt)
			os.Exit(1)
		}

		tok := z.Token()
		expectedStr := `<button type="submit" class="btn primary">`
		if tok.String() != expectedStr {
			fmt.Fprintf(os.Stderr, "expected tok.String() %q, got %q\n", expectedStr, tok.String())
			os.Exit(1)
		}
	}

	// Assertion 5: Valueless boolean attributes are parsed with empty Val
	{
		input := `<input type="checkbox" checked disabled>`
		z := html.NewTokenizer(strings.NewReader(input))

		tt := z.Next()
		if tt != html.StartTagToken {
			fmt.Fprintf(os.Stderr, "expected StartTagToken, got %v\n", tt)
			os.Exit(1)
		}

		tok := z.Token()
		attrMap := make(map[string]string)
		for _, a := range tok.Attr {
			attrMap[a.Key] = a.Val
		}

		if val, exists := attrMap["checked"]; !exists || val != "" {
			fmt.Fprintf(os.Stderr, "expected checked to exist with empty val, got exists=%v, val=%q\n", exists, val)
			os.Exit(1)
		}
		if val, exists := attrMap["disabled"]; !exists || val != "" {
			fmt.Fprintf(os.Stderr, "expected disabled to exist with empty val, got exists=%v, val=%q\n", exists, val)
			os.Exit(1)
		}
	}

	// Assertion 6: html.StartTagToken.String returns "StartTag"
	{
		if html.StartTagToken.String() != "StartTag" {
			fmt.Fprintf(os.Stderr, "expected StartTagToken.String() == 'StartTag', got %q\n", html.StartTagToken.String())
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all golang.org/x/net/html.StartTagToken contract assertions passed")
}

Origin Seeder

anonymous