CodeSampleX

Sample

golang.org/x/net v0.23.0: html.CommentNode

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

sha256:96fd0e4f42154eb2ced32634686276bd09173363318306be7b9acf7b2df381c5

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.CommentNode in pkg:golang/golang.org/x/net@v0.23.0
Packages
Symbols
  • golang.org/x/net/html.CommentNode
Created
2026-09-04T14:57:26Z

Contract

  1. html.Parse extracts nodes of Type html.CommentNode with preserved comment text from HTML input
  2. html.Render correctly serializes an html.CommentNode into HTML comment markup <!-- text -->
  3. html.CommentNode can be programmatically constructed and inserted into an HTML DOM tree

Files

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

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

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.
comment.go
package htmlcomment

import (
	"bytes"
	"strings"

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

// ExtractComments parses an HTML string and returns all comment node data found in the document tree.
func ExtractComments(htmlContent string) ([]string, error) {
	doc, err := html.Parse(strings.NewReader(htmlContent))
	if err != nil {
		return nil, err
	}

	var comments []string
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.CommentNode {
			comments = append(comments, n.Data)
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(doc)
	return comments, nil
}

// CreateCommentNode creates a new standalone html.Node of Type html.CommentNode with the given text.
func CreateCommentNode(commentText string) *html.Node {
	return &html.Node{
		Type: html.CommentNode,
		Data: commentText,
	}
}

// RenderNode renders an html.Node tree to an HTML string.
func RenderNode(n *html.Node) (string, error) {
	var buf bytes.Buffer
	if err := html.Render(&buf, n); err != nil {
		return "", err
	}
	return buf.String(), nil
}

// PrependComment inserts a comment node as the very first child of target node.
func PrependComment(target *html.Node, commentText string) {
	commentNode := CreateCommentNode(commentText)
	if target.FirstChild != nil {
		target.InsertBefore(commentNode, target.FirstChild)
	} else {
		target.AppendChild(commentNode)
	}
}
csx.json
{"case":{"caseId":"case:sha256:6caabc95edc0fc5665c04f248d35138cce59a36a46730ec0ab38bf7776ae998e","contract":["html.Parse extracts nodes of Type html.CommentNode with preserved comment text from HTML input","html.Render correctly serializes an html.CommentNode into HTML comment markup \u003c!-- text --\u003e","html.CommentNode can be programmatically constructed and inserted into an HTML DOM tree"],"goal":"verify golang.org/x/net/html.CommentNode in pkg:golang/golang.org/x/net@v0.23.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.23.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.CommentNode"]},"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.23.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.23.0","symbols":["golang.org/x/net/html.CommentNode"],"verifierAdapter":"golang@1"}
go.mod
module example.com/html-comment-sample

go 1.22.0

require golang.org/x/net v0.23.0
go.sum
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.CommentNode in pkg:golang/golang.org/x/net@v0.23.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.23.0"
  ],
  "symbols": [
    "golang.org/x/net/html.CommentNode"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	htmlcomment "example.com/html-comment-sample"
	"golang.org/x/net/html"
)

func main() {
	// Assertion 1: Verify html.CommentNode type identity and distinctness from other node types
	if html.CommentNode == html.ElementNode || html.CommentNode == html.TextNode || html.CommentNode == html.DocumentNode {
		fmt.Fprintf(os.Stderr, "FAIL: html.CommentNode must have a distinct NodeType value\n")
		os.Exit(1)
	}

	// Assertion 2: html.Parse extracts nodes of Type html.CommentNode with preserved comment text from HTML input
	htmlInput := `<!DOCTYPE html><html><head><!-- metadata comment --></head><body><!-- main section --><div>Hello <!-- inline comment -->World</div><!----></body></html>`
	comments, err := htmlcomment.ExtractComments(htmlInput)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: ExtractComments failed: %v\n", err)
		os.Exit(1)
	}
	expectedComments := []string{
		" metadata comment ",
		" main section ",
		" inline comment ",
		"",
	}
	if len(comments) != len(expectedComments) {
		fmt.Fprintf(os.Stderr, "FAIL: expected %d comments, got %d: %v\n", len(expectedComments), len(comments), comments)
		os.Exit(1)
	}
	for i, expected := range expectedComments {
		if comments[i] != expected {
			fmt.Fprintf(os.Stderr, "FAIL: comment [%d] expected %q, got %q\n", i, expected, comments[i])
			os.Exit(1)
		}
	}

	// Assertion 3: html.Render correctly serializes an html.CommentNode into HTML comment markup <!-- text -->
	node := htmlcomment.CreateCommentNode("sample comment content")
	if node.Type != html.CommentNode {
		fmt.Fprintf(os.Stderr, "FAIL: created node has Type %v, expected html.CommentNode (%v)\n", node.Type, html.CommentNode)
		os.Exit(1)
	}
	if node.Data != "sample comment content" {
		fmt.Fprintf(os.Stderr, "FAIL: created node has Data %q, expected %q\n", node.Data, "sample comment content")
		os.Exit(1)
	}

	rendered, err := htmlcomment.RenderNode(node)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: RenderNode failed: %v\n", err)
		os.Exit(1)
	}
	if rendered != "<!--sample comment content-->" {
		fmt.Fprintf(os.Stderr, "FAIL: rendered comment mismatch: expected %q, got %q\n", "<!--sample comment content-->", rendered)
		os.Exit(1)
	}

	// Assertion 4: html.CommentNode can be programmatically constructed and inserted into an HTML DOM tree
	doc, err := html.Parse(strings.NewReader(`<html><head></head><body><p>Paragraph</p></body></html>`))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: parsing base html failed: %v\n", err)
		os.Exit(1)
	}

	// Find the body element and prepend a comment
	var body *html.Node
	var findBody func(*html.Node)
	findBody = func(n *html.Node) {
		if n.Type == html.ElementNode && n.Data == "body" {
			body = n
			return
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			findBody(c)
		}
	}
	findBody(doc)
	if body == nil {
		fmt.Fprintf(os.Stderr, "FAIL: body node not found in parsed document\n")
		os.Exit(1)
	}

	htmlcomment.PrependComment(body, "injected-comment")
	renderedDoc, err := htmlcomment.RenderNode(doc)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: RenderNode for doc failed: %v\n", err)
		os.Exit(1)
	}
	if !strings.Contains(renderedDoc, "<!--injected-comment-->") {
		fmt.Fprintf(os.Stderr, "FAIL: rendered document missing injected comment: %s\n", renderedDoc)
		os.Exit(1)
	}

	// Verify the inserted node in the AST is indeed an html.CommentNode
	if body.FirstChild == nil || body.FirstChild.Type != html.CommentNode || body.FirstChild.Data != "injected-comment" {
		fmt.Fprintf(os.Stderr, "FAIL: body.FirstChild is not the expected html.CommentNode\n")
		os.Exit(1)
	}

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

Origin Seeder

anonymous