CodeSampleX

Exemple

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

Échantillon vérifié pour golang golang.org/x/net v0.42.0: html.DoctypeNode. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.

sha256:0073bfb199e8bac01abc776f6b6168d642ddeda079f7597b0868c46eb8580798

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-15

Cas

HOW
Objectif
verify golang.org/x/net/html.DoctypeNode in pkg:golang/golang.org/x/net@v0.42.0
Paquets
Symboles
  • golang.org/x/net/html.DoctypeNode
Créé
2026-09-15T04:23:37Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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.DoctypeNode in pkg:golang/golang.org/x/net@v0.42.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.42.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:08aa626428d58cd9c2f58b7a7f4a7605b9a1340ccf2bfe7bd68438940f859b32","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.42.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.42.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.42.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.42.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.42.0
go.sum
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.DoctypeNode in pkg:golang/golang.org/x/net@v0.42.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.42.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.")
}

Seeder d'origine

anonyme