CodeSampleX

Ejemplo

golang.org/x/net v0.17.0: proxy.Direct

Muestra verificada para golang golang.org/x/net v0.17.0: proxy.Direct. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:c84e07011aaf497e269decac1790c5bfbccb6f47b547ef526fe83d42ec3fa5f5

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-01

Caso

HOW
Objetivo
verify proxy.Direct in pkg:golang/golang.org/x/net@v0.17.0
Paquetes
Símbolos
  • proxy.Direct
Creado
2026-09-01T01:37:08Z

Contrato

  1. proxy.Direct implements proxy.Dialer and proxy.ContextDialer for direct network connections
  2. proxy.Direct.Dial connects to local TCP listeners and supports full duplex communication
  3. proxy.Direct.DialContext honors context cancellation and timeout deadlines
  4. proxy.Direct.Dial returns a network error when dialing an invalid or unreachable address

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 proxy.Direct in pkg:golang/golang.org/x/net@v0.17.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.17.0
Demonstrate these symbols/APIs:
  - proxy.Direct
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:d13b9fa35ea9803d21058d0e754b31646631078dfddbca5881e1a3d0e3197aa5","contract":["proxy.Direct implements proxy.Dialer and proxy.ContextDialer for direct network connections","proxy.Direct.Dial connects to local TCP listeners and supports full duplex communication","proxy.Direct.DialContext honors context cancellation and timeout deadlines","proxy.Direct.Dial returns a network error when dialing an invalid or unreachable address"],"goal":"verify proxy.Direct in pkg:golang/golang.org/x/net@v0.17.0","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.17.0"],"schemaVersion":1,"symbols":["proxy.Direct"]},"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.17.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.17.0","symbols":["proxy.Direct"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require golang.org/x/net v0.17.0
go.sum
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
main.go
package main

import (
	"context"
	"fmt"
	"io"
	"log"
	"net"
	"time"

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

func main() {
	listener, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatalf("Failed to start listener: %v", err)
	}
	defer listener.Close()

	go func() {
		for {
			conn, err := listener.Accept()
			if err != nil {
				return
			}
			go func(c net.Conn) {
				defer c.Close()
				io.Copy(c, c)
			}(conn)
		}
	}()

	// 1. Direct dial using proxy.Direct.Dial
	conn, err := proxy.Direct.Dial("tcp", listener.Addr().String())
	if err != nil {
		log.Fatalf("proxy.Direct.Dial failed: %v", err)
	}
	defer conn.Close()

	message := "hello proxy.Direct"
	if _, err := conn.Write([]byte(message)); err != nil {
		log.Fatalf("Failed to write to connection: %v", err)
	}

	buf := make([]byte, len(message))
	if _, err := io.ReadFull(conn, buf); err != nil {
		log.Fatalf("Failed to read from connection: %v", err)
	}
	fmt.Printf("Received echo: %s\n", string(buf))

	// 2. Direct dial using proxy.ContextDialer interface
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
	defer cancel()

	if ctxDialer, ok := any(proxy.Direct).(proxy.ContextDialer); ok {
		ctxConn, err := ctxDialer.DialContext(ctx, "tcp", listener.Addr().String())
		if err != nil {
			log.Fatalf("proxy.Direct.DialContext failed: %v", err)
		}
		defer ctxConn.Close()
	}

	fmt.Println("proxy.Direct verification complete.")
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify proxy.Direct in pkg:golang/golang.org/x/net@v0.17.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.17.0"
  ],
  "symbols": [
    "proxy.Direct"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"context"
	"errors"
	"fmt"
	"io"
	"net"
	"os"
	"time"

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

func main() {
	// Assertion 1: proxy.Direct implements proxy.Dialer interface
	{
		var dialer proxy.Dialer = proxy.Direct
		if dialer == nil {
			fmt.Fprintf(os.Stderr, "Contract 1 failed: proxy.Direct does not satisfy proxy.Dialer\n")
			os.Exit(1)
		}
	}

	// Assertion 2: proxy.Direct implements proxy.ContextDialer interface
	{
		ctxDialer, ok := any(proxy.Direct).(proxy.ContextDialer)
		if !ok || ctxDialer == nil {
			fmt.Fprintf(os.Stderr, "Contract 2 failed: proxy.Direct does not satisfy proxy.ContextDialer\n")
			os.Exit(1)
		}
	}

	// Set up an offline in-process TCP listener
	listener, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Setup failed: net.Listen error: %v\n", err)
		os.Exit(1)
	}
	defer listener.Close()

	go func() {
		for {
			conn, err := listener.Accept()
			if err != nil {
				return
			}
			go func(c net.Conn) {
				defer c.Close()
				buf := make([]byte, 1024)
				n, err := c.Read(buf)
				if err == nil && n > 0 {
					c.Write(buf[:n])
				}
			}(conn)
		}
	}()

	addr := listener.Addr().String()

	// Assertion 3: proxy.Direct.Dial connects to local TCP listener and transfers data
	{
		conn, err := proxy.Direct.Dial("tcp", addr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: proxy.Direct.Dial error: %v\n", err)
			os.Exit(1)
		}
		defer conn.Close()

		payload := []byte("ping-direct-dial")
		if _, err := conn.Write(payload); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: conn.Write error: %v\n", err)
			os.Exit(1)
		}

		reply := make([]byte, len(payload))
		if _, err := io.ReadFull(conn, reply); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: io.ReadFull error: %v\n", err)
			os.Exit(1)
		}

		if !bytes.Equal(reply, payload) {
			fmt.Fprintf(os.Stderr, "Contract 3 failed: reply mismatch: expected %q, got %q\n", payload, reply)
			os.Exit(1)
		}
	}

	// Assertion 4: proxy.Direct.DialContext connects with an active context
	{
		ctxDialer := any(proxy.Direct).(proxy.ContextDialer)
		ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
		defer cancel()

		conn, err := ctxDialer.DialContext(ctx, "tcp", addr)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: DialContext error: %v\n", err)
			os.Exit(1)
		}
		defer conn.Close()

		payload := []byte("ping-context-dial")
		if _, err := conn.Write(payload); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: conn.Write error: %v\n", err)
			os.Exit(1)
		}

		reply := make([]byte, len(payload))
		if _, err := io.ReadFull(conn, reply); err != nil {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: io.ReadFull error: %v\n", err)
			os.Exit(1)
		}

		if !bytes.Equal(reply, payload) {
			fmt.Fprintf(os.Stderr, "Contract 4 failed: reply mismatch: expected %q, got %q\n", payload, reply)
			os.Exit(1)
		}
	}

	// Assertion 5: proxy.Direct.DialContext honors canceled context
	{
		ctxDialer := any(proxy.Direct).(proxy.ContextDialer)
		ctx, cancel := context.WithCancel(context.Background())
		cancel() // Cancel immediately before dial

		_, err := ctxDialer.DialContext(ctx, "tcp", addr)
		if err == nil {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: expected error with canceled context, got nil\n")
			os.Exit(1)
		}
		if !errors.Is(err, context.Canceled) && !errors.Is(ctx.Err(), context.Canceled) {
			fmt.Fprintf(os.Stderr, "Contract 5 failed: expected context.Canceled error, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 6: proxy.Direct.Dial fails when dialing an invalid network/address
	{
		_, err := proxy.Direct.Dial("invalid_network", "127.0.0.1:0")
		if err == nil {
			fmt.Fprintf(os.Stderr, "Contract 6 failed: expected error for unknown network, got nil\n")
			os.Exit(1)
		}
	}

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

Seeder de origen

anónimo