CodeSampleX

Beispiel

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

Verifiziertes Beispiel für golang golang.org/x/net v0.41.0: html.TextNode. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:18b0482dcc3081344ec35a802a476e9d03fdba9125fd793f848b85e6bde80e7c

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-14

Fall

HOW
Ziel
verify golang.org/x/net/html.TextNode in pkg:golang/golang.org/x/net@v0.41.0
Pakete
Symbole
  • golang.org/x/net/html.TextNode
Erstellt
2026-10-14T20:38:00Z

Contract

  1. html.TextNode is a distinct html.NodeType constant
  2. NewTextNode creates an html.Node with Type html.TextNode and the given Data
  3. IsTextNode returns true only for non-nil nodes with Type html.TextNode
  4. CollectText extracts text content from html.TextNode nodes in parsed HTML
  5. html.Render escapes HTML special characters in html.TextNode Data

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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.TextNode 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.TextNode

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:c3077aea6e7dca04d83b8e60e9762f3c94897d2206f06d582584c214526cde59","contract":["html.TextNode is a distinct html.NodeType constant","NewTextNode creates an html.Node with Type html.TextNode and the given Data","IsTextNode returns true only for non-nil nodes with Type html.TextNode","CollectText extracts text content from html.TextNode nodes in parsed HTML","html.Render escapes HTML special characters in html.TextNode Data"],"goal":"verify golang.org/x/net/html.TextNode 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.TextNode"]},"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.TextNode"],"verifierAdapter":"golang@1"}
go.mod
module 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=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.TextNode 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.TextNode"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	// 1. html.TextNode is a distinct html.NodeType constant
	var nt html.NodeType = html.TextNode
	if nt != html.TextNode || nt == html.ElementNode || nt == html.DocumentNode || nt == html.CommentNode {
		fmt.Fprintf(os.Stderr, "unexpected html.TextNode constant value: %v\n", nt)
		os.Exit(1)
	}

	// 2. NewTextNode creates an html.Node with Type html.TextNode and the given Data
	tn := sample.NewTextNode("sample text")
	if tn == nil || tn.Type != html.TextNode || tn.Data != "sample text" {
		fmt.Fprintf(os.Stderr, "NewTextNode failed: %+v\n", tn)
		os.Exit(1)
	}

	// 3. IsTextNode returns true only for non-nil nodes with Type html.TextNode
	if !sample.IsTextNode(tn) {
		fmt.Fprintf(os.Stderr, "IsTextNode returned false for TextNode\n")
		os.Exit(1)
	}
	if sample.IsTextNode(&html.Node{Type: html.ElementNode, Data: "p"}) || sample.IsTextNode(nil) {
		fmt.Fprintf(os.Stderr, "IsTextNode returned true for non-TextNode\n")
		os.Exit(1)
	}

	// 4. CollectText extracts text content from html.TextNode nodes in parsed HTML
	doc, err := html.Parse(strings.NewReader("<article><h1>Title</h1><p>Body <b>bold</b></p></article>"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "html.Parse failed: %v\n", err)
		os.Exit(1)
	}
	if got := sample.CollectText(doc); got != "TitleBody bold" {
		fmt.Fprintf(os.Stderr, "CollectText got %q, want %q\n", got, "TitleBody bold")
		os.Exit(1)
	}

	// 5. html.Render escapes HTML special characters in html.TextNode Data
	escaped, err := sample.RenderTextNode(sample.NewTextNode("<b>a & b</b>"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "RenderTextNode failed: %v\n", err)
		os.Exit(1)
	}
	if want := "&lt;b&gt;a &amp; b&lt;/b&gt;"; escaped != want {
		fmt.Fprintf(os.Stderr, "RenderTextNode got %q, want %q\n", escaped, want)
		os.Exit(1)
	}
}
textnode.go
package sample

import (
	"bytes"
	"strings"

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

// NewTextNode constructs an html.Node with Type set to html.TextNode.
func NewTextNode(text string) *html.Node {
	return &html.Node{
		Type: html.TextNode,
		Data: text,
	}
}

// IsTextNode reports whether n is a non-nil html.Node of type html.TextNode.
func IsTextNode(n *html.Node) bool {
	return n != nil && n.Type == html.TextNode
}

// CollectText traverses the node subtree and concatenates Data from all html.TextNode nodes.
func CollectText(root *html.Node) string {
	if root == nil {
		return ""
	}
	var b strings.Builder
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.TextNode {
			b.WriteString(n.Data)
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(root)
	return b.String()
}

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

Ursprungs-Seeder

anonym