CodeSampleX

Sample

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

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

sha256:f47f81d68efc2a4bc2653d2904cd0f43e43f1a03cd4cae6a0caf3500cadbbbe5

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.EndTagToken in pkg:golang/golang.org/x/net@v0.12.0
Packages
Symbols
  • golang.org/x/net/html.EndTagToken
Created
2026-09-04T07:38:33Z

Contract

  1. html.EndTagToken is a TokenType constant with string representation "EndTag"
  2. html.EndTagToken is distinct from StartTagToken, SelfClosingTagToken, and TextToken
  3. html.NewTokenizer emits html.EndTagToken when encountering closing tags
  4. html.Token with html.EndTagToken serializes to </tag> string representation
  5. Tokenizer.TagName returns tag name and no attributes for html.EndTagToken

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.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.EndTagToken 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.EndTagToken

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:5f726e8b175f8c4d14c9e03b0c6ab60d828d3a95ba4ff9b831896af08dde1d59","contract":["html.EndTagToken is a TokenType constant with string representation \"EndTag\"","html.EndTagToken is distinct from StartTagToken, SelfClosingTagToken, and TextToken","html.NewTokenizer emits html.EndTagToken when encountering closing tags","html.Token with html.EndTagToken serializes to \u003c/tag\u003e string representation","Tokenizer.TagName returns tag name and no attributes for html.EndTagToken"],"goal":"verify golang.org/x/net/html.EndTagToken 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.EndTagToken"]},"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.EndTagToken"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

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=
sample.go
package sample

import (
	"fmt"
	"io"
	"strings"

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

// IsEndTag returns true if the token type is EndTagToken.
func IsEndTag(tt html.TokenType) bool {
	return tt == html.EndTagToken
}

// MakeEndTagToken creates an html.Token configured as an EndTagToken for the specified tag name.
func MakeEndTagToken(name string) html.Token {
	return html.Token{
		Type: html.EndTagToken,
		Data: name,
	}
}

// ExtractEndTags tokenizes the HTML input from reader and returns all end tag names encountered.
func ExtractEndTags(r io.Reader) ([]string, error) {
	z := html.NewTokenizer(r)
	var endTags []string

	for {
		tt := z.Next()
		switch tt {
		case html.ErrorToken:
			err := z.Err()
			if err == io.EOF {
				return endTags, nil
			}
			return nil, fmt.Errorf("tokenizer error: %w", err)
		case html.EndTagToken:
			name, _ := z.TagName()
			endTags = append(endTags, string(name))
		}
	}
}

// ValidateTagPairs checks that every opening tag is properly closed by an EndTagToken.
func ValidateTagPairs(htmlStr string) (bool, error) {
	z := html.NewTokenizer(strings.NewReader(htmlStr))
	var stack []string

	for {
		tt := z.Next()
		switch tt {
		case html.ErrorToken:
			err := z.Err()
			if err == io.EOF {
				return len(stack) == 0, nil
			}
			return false, fmt.Errorf("tokenizer error: %w", err)
		case html.StartTagToken:
			name, _ := z.TagName()
			stack = append(stack, string(name))
		case html.EndTagToken:
			name, _ := z.TagName()
			tagName := string(name)
			if len(stack) == 0 || stack[len(stack)-1] != tagName {
				return false, nil
			}
			stack = stack[:len(stack)-1]
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.EndTagToken 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.EndTagToken"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"reflect"
	"strings"

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

func main() {
	// Assertion 1: html.EndTagToken is a TokenType constant with string representation "EndTag"
	var tt html.TokenType = html.EndTagToken
	if tt.String() != "EndTag" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: expected 'EndTag', got %q\n", tt.String())
		os.Exit(1)
	}
	if !sample.IsEndTag(html.EndTagToken) {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 1 failed: sample.IsEndTag returned false for EndTagToken\n")
		os.Exit(1)
	}

	// Assertion 2: html.EndTagToken is distinct from StartTagToken, SelfClosingTagToken, and TextToken
	if html.EndTagToken == html.StartTagToken {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: EndTagToken equals StartTagToken\n")
		os.Exit(1)
	}
	if html.EndTagToken == html.SelfClosingTagToken {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: EndTagToken equals SelfClosingTagToken\n")
		os.Exit(1)
	}
	if html.EndTagToken == html.TextToken {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: EndTagToken equals TextToken\n")
		os.Exit(1)
	}
	if sample.IsEndTag(html.StartTagToken) || sample.IsEndTag(html.TextToken) {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 2 failed: sample.IsEndTag returned true for non-EndTag\n")
		os.Exit(1)
	}

	// Assertion 3: html.NewTokenizer emits html.EndTagToken when encountering closing tags
	htmlSnippet := `<div class="box"><p>Hello World</p><span>Item</span></div>`
	endTags, err := sample.ExtractEndTags(strings.NewReader(htmlSnippet))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed to extract end tags: %v\n", err)
		os.Exit(1)
	}
	expectedEndTags := []string{"p", "span", "div"}
	if !reflect.DeepEqual(endTags, expectedEndTags) {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 3 failed: expected %v, got %v\n", expectedEndTags, endTags)
		os.Exit(1)
	}

	// Assertion 4: html.Token with html.EndTagToken serializes to </tag> string representation
	endToken := sample.MakeEndTagToken("div")
	if endToken.Type != html.EndTagToken {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: expected token type EndTagToken, got %v\n", endToken.Type)
		os.Exit(1)
	}
	if endToken.String() != "</div>" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: expected '</div>', got %q\n", endToken.String())
		os.Exit(1)
	}

	customEndToken := html.Token{
		Type: html.EndTagToken,
		Data: "section",
	}
	if customEndToken.String() != "</section>" {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 4 failed: expected '</section>', got %q\n", customEndToken.String())
		os.Exit(1)
	}

	// Assertion 5: Tokenizer.TagName returns tag name and no attributes for html.EndTagToken
	z := html.NewTokenizer(strings.NewReader("<main></main>"))
	foundEndTag := false
	for {
		tokenType := z.Next()
		if tokenType == html.ErrorToken {
			break
		}
		if tokenType == html.EndTagToken {
			foundEndTag = true
			name, hasAttr := z.TagName()
			if string(name) != "main" {
				fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: expected tag name 'main', got %q\n", string(name))
				os.Exit(1)
			}
			if hasAttr {
				fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: expected hasAttr=false for EndTagToken\n")
				os.Exit(1)
			}
			raw := string(z.Raw())
			if raw != "</main>" {
				fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: expected raw '</main>', got %q\n", raw)
				os.Exit(1)
			}
		}
	}
	if !foundEndTag {
		fmt.Fprintf(os.Stderr, "FAIL: Assertion 5 failed: EndTagToken was not encountered in tokenizer\n")
		os.Exit(1)
	}

	// Validation helper verification using EndTagToken matching
	valid, err := sample.ValidateTagPairs("<div><p><span>nested</span></p></div>")
	if err != nil || !valid {
		fmt.Fprintf(os.Stderr, "FAIL: ValidateTagPairs failed for valid HTML: valid=%v, err=%v\n", valid, err)
		os.Exit(1)
	}
	invalid, err := sample.ValidateTagPairs("<div><p>mismatched</div></p>")
	if err != nil || invalid {
		fmt.Fprintf(os.Stderr, "FAIL: ValidateTagPairs failed for mismatched tags: invalid=%v, err=%v\n", invalid, err)
		os.Exit(1)
	}

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

Origin Seeder

anonymous