CodeSampleX

Beispiel

golang.org/x/net v0.47.0: html.DoctypeNode

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

sha256:863b19bc16e02b49786400959ab706f7734e7899a2be19cc94c562a15dca2eb5

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-10

Fall

HOW
Ziel
verify golang.org/x/net/html.DoctypeNode in pkg:golang/golang.org/x/net@v0.47.0
Pakete
Symbole
  • golang.org/x/net/html.DoctypeNode
Erstellt
2026-10-10T23:17:25Z

Contract

  1. html.DoctypeNode is a NodeType constant
  2. html.DoctypeNode is distinct from other NodeType values
  3. html.Parse parses DOCTYPE declaration as an html.DoctypeNode
  4. html.Parse extracts system and public attributes on html.DoctypeNode
  5. html.Render outputs valid DOCTYPE markup for an html.DoctypeNode

Dateien

  • PROMPT.md
  • csx.json
  • doctype.go
  • go.mod
  • go.sum
  • spec.json
  • test/contract.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.DoctypeNode in pkg:golang/golang.org/x/net@v0.47.0
Kind: HOW

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

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:dfd49c90be85180deddacb7f37790463bafef017a940b106698c1e1fae8a4649","contract":["html.DoctypeNode is a NodeType constant","html.DoctypeNode is distinct from other NodeType values","html.Parse parses DOCTYPE declaration as an html.DoctypeNode","html.Parse extracts system and public attributes on html.DoctypeNode","html.Render outputs valid DOCTYPE markup for an html.DoctypeNode"],"goal":"verify golang.org/x/net/html.DoctypeNode in pkg:golang/golang.org/x/net@v0.47.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.47.0"],"schemaVersion":1,"symbols":["golang.org/x/net/html.DoctypeNode"]},"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.47.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.47.0","symbols":["golang.org/x/net/html.DoctypeNode"],"verifierAdapter":"golang@1"}
doctype.go
package sample

import (
	"bytes"

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

// FindDoctype traverses the direct children of the given document node
// and returns the first node with Type == html.DoctypeNode, or nil if none is found.
func FindDoctype(doc *html.Node) *html.Node {
	if doc == nil {
		return nil
	}
	for c := doc.FirstChild; c != nil; c = c.NextSibling {
		if c.Type == html.DoctypeNode {
			return c
		}
	}
	return nil
}

// IsDoctype returns true if the node is non-nil and its Type is html.DoctypeNode.
func IsDoctype(n *html.Node) bool {
	return n != nil && n.Type == html.DoctypeNode
}

// NewDoctype constructs a new html.Node representing a DOCTYPE declaration.
func NewDoctype(name, publicID, systemID string) *html.Node {
	n := &html.Node{
		Type: html.DoctypeNode,
		Data: name,
	}
	if publicID != "" {
		n.Attr = append(n.Attr, html.Attribute{Key: "public", Val: publicID})
	}
	if systemID != "" {
		n.Attr = append(n.Attr, html.Attribute{Key: "system", Val: systemID})
	}
	return n
}

// RenderDoctype serializes a DoctypeNode into its HTML string representation.
func RenderDoctype(n *html.Node) (string, error) {
	var buf bytes.Buffer
	if err := html.Render(&buf, n); err != nil {
		return "", err
	}
	return buf.String(), nil
}
go.mod
module sample

go 1.26.6

require golang.org/x/net v0.47.0
go.sum
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.DoctypeNode in pkg:golang/golang.org/x/net@v0.47.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.47.0"
  ],
  "symbols": [
    "golang.org/x/net/html.DoctypeNode"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

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

func main() {
	// Assertion 1: html.DoctypeNode is a NodeType constant
	var nodeType html.NodeType = html.DoctypeNode
	if nodeType != html.DoctypeNode {
		fmt.Fprintf(os.Stderr, "expected nodeType to match html.DoctypeNode\n")
		os.Exit(1)
	}

	// Assertion 2: html.DoctypeNode is distinct from other NodeType values
	if html.DoctypeNode == html.ErrorNode ||
		html.DoctypeNode == html.TextNode ||
		html.DoctypeNode == html.DocumentNode ||
		html.DoctypeNode == html.ElementNode ||
		html.DoctypeNode == html.CommentNode ||
		html.DoctypeNode == html.RawNode {
		fmt.Fprintf(os.Stderr, "expected html.DoctypeNode to be distinct from other NodeType values\n")
		os.Exit(1)
	}

	// Assertion 3: html.Parse parses DOCTYPE declaration as an html.DoctypeNode
	htmlDoc := "<!DOCTYPE html><html><head></head><body><p>Hello</p></body></html>"
	doc, err := html.Parse(strings.NewReader(htmlDoc))
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to parse HTML: %v\n", err)
		os.Exit(1)
	}
	if doc.Type != html.DocumentNode {
		fmt.Fprintf(os.Stderr, "expected root node to be DocumentNode, got %v\n", doc.Type)
		os.Exit(1)
	}

	dtNode := sample.FindDoctype(doc)
	if dtNode == nil {
		fmt.Fprintf(os.Stderr, "expected doctype node not found\n")
		os.Exit(1)
	}
	if dtNode.Type != html.DoctypeNode {
		fmt.Fprintf(os.Stderr, "expected doctype node to have Type html.DoctypeNode, got %v\n", dtNode.Type)
		os.Exit(1)
	}
	if dtNode.Data != "html" {
		fmt.Fprintf(os.Stderr, "expected doctype node data to be 'html', got %q\n", dtNode.Data)
		os.Exit(1)
	}
	if !sample.IsDoctype(dtNode) {
		fmt.Fprintf(os.Stderr, "expected sample.IsDoctype to return true\n")
		os.Exit(1)
	}

	// Assertion 4: html.Parse extracts system and public attributes on html.DoctypeNode
	htmlWithSystem := `<!DOCTYPE html SYSTEM "about:legacy-compat"><html><body></body></html>`
	docWithSystem, err := html.Parse(strings.NewReader(htmlWithSystem))
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to parse HTML with system doctype: %v\n", err)
		os.Exit(1)
	}
	dtSystem := sample.FindDoctype(docWithSystem)
	if dtSystem == nil || dtSystem.Type != html.DoctypeNode {
		fmt.Fprintf(os.Stderr, "expected DoctypeNode in docWithSystem\n")
		os.Exit(1)
	}
	foundSystem := false
	for _, attr := range dtSystem.Attr {
		if attr.Key == "system" && attr.Val == "about:legacy-compat" {
			foundSystem = true
		}
	}
	if !foundSystem {
		fmt.Fprintf(os.Stderr, "expected system attribute on DoctypeNode\n")
		os.Exit(1)
	}

	// Assertion 5: html.Render outputs valid DOCTYPE markup for an html.DoctypeNode
	manualDoctype := sample.NewDoctype("html", "", "")
	rendered, err := sample.RenderDoctype(manualDoctype)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to render DoctypeNode: %v\n", err)
		os.Exit(1)
	}
	if rendered != "<!DOCTYPE html>" {
		fmt.Fprintf(os.Stderr, "expected '<!DOCTYPE html>', got %q\n", rendered)
		os.Exit(1)
	}

	manualWithSystem := sample.NewDoctype("html", "", "about:legacy-compat")
	renderedSystem, err := sample.RenderDoctype(manualWithSystem)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to render DoctypeNode with system: %v\n", err)
		os.Exit(1)
	}
	if renderedSystem != `<!DOCTYPE html SYSTEM "about:legacy-compat">` {
		fmt.Fprintf(os.Stderr, "expected '<!DOCTYPE html SYSTEM \"about:legacy-compat\">', got %q\n", renderedSystem)
		os.Exit(1)
	}

	fmt.Println("All html.DoctypeNode contract assertions passed.")
}

Ursprungs-Seeder

anonym