CodeSampleX

Exemplo

golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e

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

sha256:59e052fbf46af2ee888ec8e96f4d20453eb9490cdd69ddc97975d559963beacb

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
2
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 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-21
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 pkg:golang/golang.org/x/net@v0.0.0-20200324143707-d3edc9973b7e
Pacotes
Criado
2026-10-21T06:59:31Z

Contrato

  1. html.Parse and html.Render round-trip HTML document trees and decode entity text into atom.P element nodes
  2. html.EscapeString and html.UnescapeString round-trip special HTML characters accurately
  3. publicsuffix.EffectiveTLDPlusOne and publicsuffix.PublicSuffix resolve ICANN effective TLD+1 and public suffix offline
  4. ctxhttp.Get with an already-canceled context returns context.Canceled immediately without network activity

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • 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 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

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:626d3010095616b96b22061fe62ce2f9d75c623a0f2735a23a0bf2f474a253d5","contract":["html.Parse and html.Render round-trip HTML document trees and decode entity text into atom.P element nodes","html.EscapeString and html.UnescapeString round-trip special HTML characters accurately","publicsuffix.EffectiveTLDPlusOne and publicsuffix.PublicSuffix resolve ICANN effective TLD+1 and public suffix offline","ctxhttp.Get with an already-canceled context returns context.Canceled immediately without network activity"],"goal":"verify 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},"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","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

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=
main.go
package main

import (
	"fmt"
	"log"
	"strings"

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

func main() {
	doc, err := html.Parse(strings.NewReader(`<!DOCTYPE html><html><body><p id="greeting">Hello &amp; Welcome</p></body></html>`))
	if err != nil {
		log.Fatalf("html.Parse failed: %v", err)
	}
	_ = doc

	domain, err := publicsuffix.EffectiveTLDPlusOne("www.sub.example.co.uk")
	if err != nil {
		log.Fatalf("publicsuffix.EffectiveTLDPlusOne failed: %v", err)
	}
	fmt.Printf("EffectiveTLDPlusOne: %s\n", domain)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify 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"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"context"
	"fmt"
	"os"
	"strings"

	"golang.org/x/net/context/ctxhttp"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
	"golang.org/x/net/publicsuffix"
)

func main() {
	// 1. html.Parse and html.Render round-trip HTML document trees and decode entity text into atom.P element nodes
	markup := `<!DOCTYPE html><html><head><title>Sample</title></head><body><p id="lead">Alpha &amp; Beta</p></body></html>`
	doc, err := html.Parse(strings.NewReader(markup))
	if err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: html.Parse error: %v\n", err)
		os.Exit(1)
	}
	if doc == nil || doc.Type != html.DocumentNode {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected DocumentNode root\n")
		os.Exit(1)
	}

	var pNode *html.Node
	var walk func(*html.Node)
	walk = func(n *html.Node) {
		if n.Type == html.ElementNode && n.DataAtom == atom.P {
			pNode = n
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			walk(c)
		}
	}
	walk(doc)

	if pNode == nil || pNode.FirstChild == nil || pNode.FirstChild.Type != html.TextNode || pNode.FirstChild.Data != "Alpha & Beta" {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected parsed <p> node content\n")
		os.Exit(1)
	}

	var rendered bytes.Buffer
	if err := html.Render(&rendered, doc); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: html.Render error: %v\n", err)
		os.Exit(1)
	}
	if !strings.Contains(rendered.String(), `<p id="lead">Alpha &amp; Beta</p>`) {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected rendered HTML: %s\n", rendered.String())
		os.Exit(1)
	}

	// 2. html.EscapeString and html.UnescapeString round-trip special HTML characters accurately
	raw := `<span class="tag">One & "Two" 'Three'</span>`
	escaped := html.EscapeString(raw)
	if escaped != `&lt;span class=&#34;tag&#34;&gt;One &amp; &#34;Two&#34; &#39;Three&#39;&lt;/span&gt;` {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected EscapeString output: %s\n", escaped)
		os.Exit(1)
	}
	if html.UnescapeString(escaped) != raw {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: unexpected UnescapeString output\n")
		os.Exit(1)
	}

	// 3. publicsuffix.EffectiveTLDPlusOne and publicsuffix.PublicSuffix resolve ICANN effective TLD+1 and public suffix offline
	etld1, err := publicsuffix.EffectiveTLDPlusOne("www.sub.example.co.uk")
	if err != nil || etld1 != "example.co.uk" {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected example.co.uk, got %q (err=%v)\n", etld1, err)
		os.Exit(1)
	}
	suffix, icann := publicsuffix.PublicSuffix("www.sub.example.co.uk")
	if suffix != "co.uk" || !icann {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected co.uk (icann=true), got %q (icann=%v)\n", suffix, icann)
		os.Exit(1)
	}

	// 4. ctxhttp.Get with an already-canceled context returns context.Canceled immediately without network activity
	ctx, cancel := context.WithCancel(context.Background())
	cancel()
	_, err = ctxhttp.Get(ctx, nil, "http://localhost:0/")
	if err != context.Canceled {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: expected context.Canceled, got %v\n", err)
		os.Exit(1)
	}
}

Seeder de origem

anônimo