CodeSampleX

サンプル

golang.org/x/net v0.41.0: html.NodeType

検証済みサンプル — golang golang.org/x/net v0.41.0: html.NodeType. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: html.NodeType constants identify…

sha256:177eea55e32b5ffd62934c410217c35ef5a55432eaa9f70a5ba50eb295ff44d9

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-10-15

ケース

HOW
ゴール
verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.41.0
パッケージ
シンボル
  • golang.org/x/net/html.NodeType
作成日
2026-10-15T01:10:48Z

コントラクト

  1. html.NodeType constants identify distinct DOM node kinds including ErrorNode, TextNode, DocumentNode, ElementNode, CommentNode, DoctypeNode, and RawNode
  2. html.Parse assigns the appropriate html.NodeType to each node in the parsed tree
  3. Manually constructed html.Node instances preserve their html.NodeType across tree attachment

ファイル

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

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

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:61bfae9121fca47bb0d3a1168a505f7d8c9cc4104f299d267c76fbcd4778e785","contract":["html.NodeType constants identify distinct DOM node kinds including ErrorNode, TextNode, DocumentNode, ElementNode, CommentNode, DoctypeNode, and RawNode","html.Parse assigns the appropriate html.NodeType to each node in the parsed tree","Manually constructed html.Node instances preserve their html.NodeType across tree attachment"],"goal":"verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.41.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.41.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.NodeType"]},"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.41.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.41.0","symbols":["golang.org/x/net/html.NodeType"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.24.0

require golang.org/x/net v0.41.0
go.sum
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
main.go
package main

import (
	"fmt"
	"log"
	"strings"

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

// DescribeNodeType returns the label corresponding to an html.NodeType.
func DescribeNodeType(nt html.NodeType) string {
	switch nt {
	case html.ErrorNode:
		return "ErrorNode"
	case html.TextNode:
		return "TextNode"
	case html.DocumentNode:
		return "DocumentNode"
	case html.ElementNode:
		return "ElementNode"
	case html.CommentNode:
		return "CommentNode"
	case html.DoctypeNode:
		return "DoctypeNode"
	case html.RawNode:
		return "RawNode"
	default:
		return fmt.Sprintf("NodeType(%d)", nt)
	}
}

// TallyNodeTypes walks an HTML node tree and counts occurrences of each html.NodeType.
func TallyNodeTypes(root *html.Node) map[html.NodeType]int {
	counts := make(map[html.NodeType]int)
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n == nil {
			return
		}
		counts[n.Type]++
		for child := n.FirstChild; child != nil; child = child.NextSibling {
			walk(child)
		}
	}
	walk(root)
	return counts
}

func main() {
	markup := `<!DOCTYPE html><html><!-- header comment --><body><p>Hello</p></body></html>`
	doc, err := html.Parse(strings.NewReader(markup))
	if err != nil {
		log.Fatalf("parse failed: %v", err)
	}

	counts := TallyNodeTypes(doc)
	fmt.Printf("Root: %s\n", DescribeNodeType(doc.Type))
	for nt, c := range counts {
		fmt.Printf("  %s: %d\n", DescribeNodeType(nt), c)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.NodeType in pkg:golang/golang.org/x/net@v0.41.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.41.0"
  ],
  "symbols": [
    "golang.org/x/net/html.NodeType"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	// Assertion 1: html.NodeType constants identify distinct DOM node kinds (ErrorNode, TextNode, DocumentNode, ElementNode, CommentNode, DoctypeNode, RawNode)
	expectedValues := map[html.NodeType]uint32{
		html.ErrorNode:    0,
		html.TextNode:     1,
		html.DocumentNode: 2,
		html.ElementNode:  3,
		html.CommentNode:  4,
		html.DoctypeNode:  5,
		html.RawNode:      6,
	}
	for nt, want := range expectedValues {
		if uint32(nt) != want {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected NodeType %d to equal %d, got %d\n", nt, want, uint32(nt))
			os.Exit(1)
		}
	}

	allTypes := []html.NodeType{
		html.ErrorNode,
		html.TextNode,
		html.DocumentNode,
		html.ElementNode,
		html.CommentNode,
		html.DoctypeNode,
		html.RawNode,
	}
	seen := make(map[html.NodeType]bool)
	for _, t := range allTypes {
		if seen[t] {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: duplicate NodeType %v\n", t)
			os.Exit(1)
		}
		seen[t] = true
	}

	// Assertion 2: html.Parse assigns the appropriate html.NodeType to each node in the parsed tree
	rawHTML := `<!DOCTYPE html><html><!-- note --><body><div>Sample</div></body></html>`
	doc, err := html.Parse(strings.NewReader(rawHTML))
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: html.Parse failed: %v\n", err)
		os.Exit(1)
	}
	if doc.Type != html.DocumentNode {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected DocumentNode at root, got %v\n", doc.Type)
		os.Exit(1)
	}

	counts := make(map[html.NodeType]int)
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n == nil {
			return
		}
		counts[n.Type]++
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(doc)

	if counts[html.DocumentNode] != 1 {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 1 DocumentNode, got %d\n", counts[html.DocumentNode])
		os.Exit(1)
	}
	if counts[html.DoctypeNode] != 1 {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 1 DoctypeNode, got %d\n", counts[html.DoctypeNode])
		os.Exit(1)
	}
	if counts[html.CommentNode] != 1 {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 1 CommentNode, got %d\n", counts[html.CommentNode])
		os.Exit(1)
	}
	if counts[html.ElementNode] < 4 {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected at least 4 ElementNodes, got %d\n", counts[html.ElementNode])
		os.Exit(1)
	}
	if counts[html.TextNode] != 1 {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected 1 TextNode, got %d\n", counts[html.TextNode])
		os.Exit(1)
	}

	// Assertion 3: Manually constructed html.Node instances preserve their html.NodeType across tree attachment
	parent := &html.Node{Type: html.ElementNode, Data: "section"}
	comment := &html.Node{Type: html.CommentNode, Data: "inline"}
	text := &html.Node{Type: html.TextNode, Data: "body"}
	parent.AppendChild(comment)
	parent.AppendChild(text)

	if parent.Type != html.ElementNode || parent.FirstChild.Type != html.CommentNode || parent.LastChild.Type != html.TextNode {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected node types after AppendChild\n")
		os.Exit(1)
	}

	fmt.Println("Contract passed.")
}

オリジンシーダー

匿名