CodeSampleX

Ejemplo

github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473: v2.Cluster

Muestra verificada para golang github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473: v2.Cluster. El contrato se ejecutó en go 1.26 …

sha256:1b866a22cac24de2c3595775c90196e9a4d79fa5383ec0c227c255c786e16d0d

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

Caso

HOW
Objetivo
verify github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster in pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473
Paquetes
Símbolos
  • github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster
Creado
2026-10-17T08:30:07Z

Contrato

  1. v2.Cluster initializes and passes validation with logical DNS discovery and round-robin load balancing
  2. v2.Cluster validation rejects invalid configuration with missing required fields
  3. v2.Cluster serializes to and deserializes from protobuf wire format without data loss
  4. ptypes.MarshalAny packs v2.Cluster with type URL matching type.googleapis.com/envoy.api.v2.Cluster
  5. cache.ClusterType matches v2.Cluster type URL
  6. cache.NewSnapshot successfully indexes v2.Cluster under cache.ClusterType and validates consistency

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • 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 github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster in pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473
Demonstrate these symbols/APIs:
  - github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster

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:d2912cfa38f2f5fb80352858d9752b68b4f6aa974cce643fc3e749fd86877766","contract":["v2.Cluster initializes and passes validation with logical DNS discovery and round-robin load balancing","v2.Cluster validation rejects invalid configuration with missing required fields","v2.Cluster serializes to and deserializes from protobuf wire format without data loss","ptypes.MarshalAny packs v2.Cluster with type URL matching type.googleapis.com/envoy.api.v2.Cluster","cache.ClusterType matches v2.Cluster type URL","cache.NewSnapshot successfully indexes v2.Cluster under cache.ClusterType and validates consistency"],"goal":"verify github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster in pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473","kind":"HOW","packages":["pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473"],"schemaVersion":1,"symbols":["github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster"]},"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/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473"],"schemaVersion":1,"subject":"pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473","symbols":["github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

require (
	github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473
	github.com/golang/protobuf v1.5.4
)

require (
	github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
	golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
	golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a // indirect
	golang.org/x/text v0.3.0 // indirect
	google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
	google.golang.org/grpc v1.23.0 // indirect
	google.golang.org/protobuf v1.33.0 // indirect
)
go.sum
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473 h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster in pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/envoyproxy/go-control-plane@v0.9.1-0.20191026205805-5f8ba28d4473"
  ],
  "symbols": [
    "github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
	core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
	"github.com/envoyproxy/go-control-plane/pkg/cache"
	"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/ptypes"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: github.com/envoyproxy/go-control-plane/envoy/api/v2.Cluster contract verified")
}

func runContract() error {
	clusterName := "service_cluster_v2"
	timeout := 5 * time.Second

	// 1. Construct and populate Cluster
	cluster := &v2.Cluster{
		Name:           clusterName,
		ConnectTimeout: ptypes.DurationProto(timeout),
		ClusterDiscoveryType: &v2.Cluster_Type{
			Type: v2.Cluster_LOGICAL_DNS,
		},
		LbPolicy:        v2.Cluster_ROUND_ROBIN,
		DnsLookupFamily: v2.Cluster_V4_ONLY,
		DnsResolvers: []*core.Address{
			{
				Address: &core.Address_SocketAddress{
					SocketAddress: &core.SocketAddress{
						Address: "127.0.0.1",
						PortSpecifier: &core.SocketAddress_PortValue{
							PortValue: 8080,
						},
					},
				},
			},
		},
	}

	// 2. Validate valid cluster
	if err := cluster.Validate(); err != nil {
		return fmt.Errorf("valid cluster failed validation: %w", err)
	}

	// 3. Validation failure check (empty cluster name)
	invalidCluster := &v2.Cluster{}
	if err := invalidCluster.Validate(); err == nil {
		return fmt.Errorf("expected validation error for empty cluster, but got nil")
	}

	// 4. Protobuf wire serialization and deserialization
	data, err := proto.Marshal(cluster)
	if err != nil {
		return fmt.Errorf("proto.Marshal failed: %w", err)
	}
	unmarshaled := &v2.Cluster{}
	if err := proto.Unmarshal(data, unmarshaled); err != nil {
		return fmt.Errorf("proto.Unmarshal failed: %w", err)
	}
	if unmarshaled.GetName() != clusterName {
		return fmt.Errorf("unmarshaled cluster name mismatch: got %q, want %q", unmarshaled.GetName(), clusterName)
	}
	if unmarshaled.GetLbPolicy() != v2.Cluster_ROUND_ROBIN {
		return fmt.Errorf("unmarshaled cluster lbPolicy mismatch: got %v, want %v", unmarshaled.GetLbPolicy(), v2.Cluster_ROUND_ROBIN)
	}
	if !proto.Equal(cluster, unmarshaled) {
		return fmt.Errorf("unmarshaled cluster does not equal original cluster")
	}

	// 5. Any packing and type URL verification
	anyMsg, err := ptypes.MarshalAny(cluster)
	if err != nil {
		return fmt.Errorf("ptypes.MarshalAny failed: %w", err)
	}
	expectedTypeURL := "type.googleapis.com/envoy.api.v2.Cluster"
	if anyMsg.GetTypeUrl() != expectedTypeURL {
		return fmt.Errorf("type URL mismatch: got %q, want %q", anyMsg.GetTypeUrl(), expectedTypeURL)
	}
	if !ptypes.Is(anyMsg, cluster) {
		return fmt.Errorf("ptypes.Is returned false for cluster message")
	}
	var unpackedCluster v2.Cluster
	if err := ptypes.UnmarshalAny(anyMsg, &unpackedCluster); err != nil {
		return fmt.Errorf("ptypes.UnmarshalAny failed: %w", err)
	}
	if !proto.Equal(cluster, &unpackedCluster) {
		return fmt.Errorf("unpacked cluster does not equal original cluster")
	}

	// 6. Integration with pkg/cache
	if cache.ClusterType != expectedTypeURL {
		return fmt.Errorf("cache.ClusterType mismatch: got %q, want %q", cache.ClusterType, expectedTypeURL)
	}
	snapshot := cache.NewSnapshot("v1", nil, []cache.Resource{cluster}, nil, nil, nil)
	if err := snapshot.Consistent(); err != nil {
		return fmt.Errorf("snapshot is inconsistent: %w", err)
	}
	clusters := snapshot.GetResources(cache.ClusterType)
	if len(clusters) != 1 {
		return fmt.Errorf("expected 1 cluster in snapshot, got %d", len(clusters))
	}
	retrievedResource, ok := clusters[clusterName]
	if !ok {
		return fmt.Errorf("cluster %q not found in snapshot", clusterName)
	}
	retrievedCluster, ok := retrievedResource.(*v2.Cluster)
	if !ok {
		return fmt.Errorf("retrieved resource is not *v2.Cluster")
	}
	if retrievedCluster.GetName() != clusterName {
		return fmt.Errorf("retrieved cluster name mismatch: got %q, want %q", retrievedCluster.GetName(), clusterName)
	}
	if snapshot.GetVersion(cache.ClusterType) != "v1" {
		return fmt.Errorf("snapshot version mismatch: got %q, want %q", snapshot.GetVersion(cache.ClusterType), "v1")
	}

	return nil
}

Seeder de origen

anónimo