CodeSampleX

Exemplo

golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e: html.CommentNode

Amostra verificada para golang golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e: html.CommentNode. O contrato rodou em go 1.26 · linux debian/x64 · docker…

sha256:4b5f2b599cde069e191e08a2c2ea6e261720fcef539b18c18d3499c24c5fa3d6

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-21

Caso

HOW
Objetivo
verify golang.org/x/net/html.CommentNode in pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e
Pacotes
Símbolos
  • golang.org/x/net/html.CommentNode
Criado
2026-10-21T11:11:27Z

Contrato

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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.0.0-20200324143707-d3edc9973b7e
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e
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"
)

// FindComments parses an HTML fragment or document and returns all comment strings from html.CommentNode nodes.
func FindComments(rawHTML string) ([]string, error) {
	doc, err := html.Parse(strings.NewReader(rawHTML))
	if err != nil {
		return nil, err
	}

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

// NewComment constructs a new html.Node with Type set to html.CommentNode.
func NewComment(text string) *html.Node {
	return &html.Node{
		Type: html.CommentNode,
		Data: text,
	}
}

// RenderHTML serializes an html.Node subtree into HTML markup.
func RenderHTML(n *html.Node) (string, error) {
	var buf bytes.Buffer
	if err := html.Render(&buf, n); err != nil {
		return "", err
	}
	return buf.String(), nil
}
csx.json
{"case":{"caseId":"case:sha256:092b02015f0c1b08d50a55188543681c14ab87e16f55165c7e51932ae210e1e6","contract":["html.Parse extracts nodes of Type html.CommentNode with preserved comment text from HTML input","html.Render serializes an html.Node of Type html.CommentNode into HTML comment markup \u003c!--...--\u003e","html.CommentNode nodes can be programmatically constructed and appended to an HTML DOM tree"],"goal":"verify golang.org/x/net/html.CommentNode in pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e"],"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.0.0-20200324143707-d3edc9973b7e"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e","symbols":["golang.org/x/net/html.CommentNode"],"verifierAdapter":"golang@1"}
go.mod
module example.com/html-commentnode

go 1.22.0

require golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
go.sum
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.CommentNode in pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e"
  ],
  "symbols": [
    "golang.org/x/net/html.CommentNode"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	// 1. Verify html.CommentNode is a distinct NodeType constant.
	if html.CommentNode == html.ErrorNode ||
		html.CommentNode == html.TextNode ||
		html.CommentNode == html.DocumentNode ||
		html.CommentNode == html.ElementNode ||
		html.CommentNode == html.DoctypeNode {
		fmt.Fprintln(os.Stderr, "FAIL: html.CommentNode collides with another html.NodeType")
		os.Exit(1)
	}

	// 2. Verify html.Parse produces nodes with Type == html.CommentNode and preserves comment Data.
	sampleHTML := `<!DOCTYPE html><html><head><!-- header comment --></head><body><div><!-- body comment --><span>text</span><!----></div></body></html>`
	comments, err := htmlcomment.FindComments(sampleHTML)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: FindComments returned error: %v\n", err)
		os.Exit(1)
	}
	expected := []string{" header comment ", " body comment ", ""}
	if len(comments) != len(expected) {
		fmt.Fprintf(os.Stderr, "FAIL: expected %d comments, got %d (%v)\n", len(expected), len(comments), comments)
		os.Exit(1)
	}
	for i, want := range expected {
		if comments[i] != want {
			fmt.Fprintf(os.Stderr, "FAIL: comment[%d] = %q, want %q\n", i, comments[i], want)
			os.Exit(1)
		}
	}

	// 3. Verify constructing an html.CommentNode and rendering it with html.Render outputs <!--...-->.
	commentNode := htmlcomment.NewComment("standalone comment")
	if commentNode.Type != html.CommentNode {
		fmt.Fprintf(os.Stderr, "FAIL: NewComment Type = %v, want %v\n", commentNode.Type, html.CommentNode)
		os.Exit(1)
	}
	rendered, err := htmlcomment.RenderHTML(commentNode)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: RenderHTML failed: %v\n", err)
		os.Exit(1)
	}
	if rendered != "<!--standalone comment-->" {
		fmt.Fprintf(os.Stderr, "FAIL: rendered comment = %q, want %q\n", rendered, "<!--standalone comment-->")
		os.Exit(1)
	}

	// 4. Verify inserting an html.CommentNode into a parsed DOM tree and serializing the document.
	doc, err := html.Parse(strings.NewReader(`<html><head></head><body><p>hello</p></body></html>`))
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: html.Parse failed: %v\n", err)
		os.Exit(1)
	}
	doc.AppendChild(htmlcomment.NewComment("trailing doc comment"))
	fullOut, err := htmlcomment.RenderHTML(doc)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: RenderHTML(doc) failed: %v\n", err)
		os.Exit(1)
	}
	if !strings.HasSuffix(fullOut, "<!--trailing doc comment-->") {
		fmt.Fprintf(os.Stderr, "FAIL: expected trailing comment in rendered output, got: %s\n", fullOut)
		os.Exit(1)
	}

	fmt.Println("PASS")
}

Seeder de origem

anônimo