CodeSampleX

Exemple

github.com/envoyproxy/go-control-plane v0.14.0: v3.ClusterType

Échantillon vérifié pour golang github.com/envoyproxy/go-control-plane v0.14.0: v3.ClusterType. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 …

sha256:29b3b8977b1c65d33ad1c02593d2c01373c0cad130f4b46d0ffda7d93287b981

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 github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType in pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0
Paquets
Symboles
  • github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType
Créé
2026-09-15T22:02:53Z

Contrat

  1. resource.ClusterType matches expected xDS v3 cluster type URL
  2. anypb.New cluster message generates TypeUrl matching resource.ClusterType
  3. cache.NewSnapshot successfully indexes cluster resources under resource.ClusterType
  4. snapshot.GetResources returns cluster resource map for resource.ClusterType
  5. snapshot.GetVersion retrieves snapshot version associated with resource.ClusterType
  6. discovery.DiscoveryResponse encapsulates cluster resources matching resource.ClusterType

Fichiers

  • PROMPT.md
  • csx.json
  • 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 github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType in pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0
Demonstrate these symbols/APIs:
  - github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType

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:e8aef06c6ba177d43b75d8a4023e42aa4fbd3353e44c2b00e1075e73c3266f1c","contract":["resource.ClusterType matches expected xDS v3 cluster type URL","anypb.New cluster message generates TypeUrl matching resource.ClusterType","cache.NewSnapshot successfully indexes cluster resources under resource.ClusterType","snapshot.GetResources returns cluster resource map for resource.ClusterType","snapshot.GetVersion retrieves snapshot version associated with resource.ClusterType","discovery.DiscoveryResponse encapsulates cluster resources matching resource.ClusterType"],"goal":"verify github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType in pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0","kind":"HOW","packages":["pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0"],"schemaVersion":1,"symbols":["github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType"]},"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.14.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0","symbols":["github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/envoyproxy/go-control-plane v0.14.0
	github.com/envoyproxy/go-control-plane/envoy v1.36.0
	google.golang.org/protobuf v1.36.10
)

require (
	cel.dev/expr v0.24.0 // indirect
	github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
	github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
	github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
	golang.org/x/net v0.42.0 // indirect
	golang.org/x/sys v0.34.0 // indirect
	golang.org/x/text v0.27.0 // indirect
	google.golang.org/genproto/googleapis/api v0.0.0-20250728155136-f173205681a0 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0 // indirect
	google.golang.org/grpc v1.75.1 // indirect
)
go.sum
cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 h1:aQ3y1lwWyqYPiWZThqv1aFbZMiM9vblcSArJRf2Irls=
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.14.0 h1:hbG2kr4RuFj222B6+7T83thSPqLjwBIfQawTkC++2HA=
github.com/envoyproxy/go-control-plane v0.14.0/go.mod h1:NcS5X47pLl/hfqxU70yPwL9ZMkUlwlKxtAohpi2wBEU=
github.com/envoyproxy/go-control-plane/envoy v1.36.0 h1:yg/JjO5E7ubRyKX3m07GF3reDNEnfOboJ0QySbH736g=
github.com/envoyproxy/go-control-plane/envoy v1.36.0/go.mod h1:ty89S1YCCVruQAm9OtKeEkQLTb+Lkz0k8v9W0Oxsv98=
github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8=
github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
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.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/api v0.0.0-20250728155136-f173205681a0 h1:0UOBWO4dC+e51ui0NFKSPbkHHiQ4TmrEfEZMLDyRmY8=
google.golang.org/genproto/googleapis/api v0.0.0-20250728155136-f173205681a0/go.mod h1:8ytArBbtOy2xfht+y2fqKd5DRDJRUQhqbyEnQ4bDChs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0 h1:MAKi5q709QWfnkkpNQ0M12hYJ1+e8qYVDyowc4U1XZM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType in pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/envoyproxy/go-control-plane@v0.14.0"
  ],
  "symbols": [
    "github.com/envoyproxy/go-control-plane/pkg/resource/v3.ClusterType"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
	discoveryv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
	"github.com/envoyproxy/go-control-plane/pkg/cache/types"
	cachev3 "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
	resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/durationpb"
)

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/pkg/resource/v3.ClusterType contract verified")
}

func runContract() error {
	// 1. Verify resource.ClusterType constant string and prefix
	expectedTypeURL := "type.googleapis.com/envoy.config.cluster.v3.Cluster"
	if resourcev3.ClusterType != expectedTypeURL {
		return fmt.Errorf("unexpected ClusterType: got %q, want %q", resourcev3.ClusterType, expectedTypeURL)
	}
	if resourcev3.ClusterType != resourcev3.APITypePrefix+"envoy.config.cluster.v3.Cluster" {
		return fmt.Errorf("ClusterType does not start with APITypePrefix")
	}

	// Build a valid cluster resource
	clusterName := "backend-service"
	cluster := &clusterv3.Cluster{
		Name:                 clusterName,
		ConnectTimeout:       durationpb.New(2 * time.Second),
		ClusterDiscoveryType: &clusterv3.Cluster_Type{Type: clusterv3.Cluster_LOGICAL_DNS},
		LbPolicy:             clusterv3.Cluster_ROUND_ROBIN,
	}

	// 2. anypb.New cluster message generates TypeUrl matching resource.ClusterType
	anyCluster, err := anypb.New(cluster)
	if err != nil {
		return fmt.Errorf("failed to marshal cluster to anypb: %w", err)
	}
	if anyCluster.GetTypeUrl() != resourcev3.ClusterType {
		return fmt.Errorf("anypb TypeUrl mismatch: got %q, want %q", anyCluster.GetTypeUrl(), resourcev3.ClusterType)
	}
	if !anyCluster.MessageIs(cluster) {
		return fmt.Errorf("anyCluster.MessageIs(&clusterv3.Cluster{}) returned false")
	}

	// 3. cache.NewSnapshot successfully indexes cluster resources under resource.ClusterType
	version := "v1.0"
	resources := map[resourcev3.Type][]types.Resource{
		resourcev3.ClusterType: {cluster},
	}
	snapshot, err := cachev3.NewSnapshot(version, resources)
	if err != nil {
		return fmt.Errorf("cache.NewSnapshot failed: %w", err)
	}
	if snapshot == nil {
		return fmt.Errorf("cache.NewSnapshot returned nil snapshot")
	}
	if err := snapshot.Consistent(); err != nil {
		return fmt.Errorf("snapshot is inconsistent: %w", err)
	}

	// 4. snapshot.GetResources returns cluster resource map for resource.ClusterType
	clusterMap := snapshot.GetResources(resourcev3.ClusterType)
	if len(clusterMap) != 1 {
		return fmt.Errorf("expected 1 cluster resource, got %d", len(clusterMap))
	}
	res, ok := clusterMap[clusterName]
	if !ok {
		return fmt.Errorf("cluster %q not found in snapshot resources for ClusterType", clusterName)
	}
	recoveredCluster, ok := res.(*clusterv3.Cluster)
	if !ok {
		return fmt.Errorf("resource is not *clusterv3.Cluster")
	}
	if recoveredCluster.GetName() != clusterName {
		return fmt.Errorf("recovered cluster name mismatch: got %q, want %q", recoveredCluster.GetName(), clusterName)
	}

	// 5. snapshot.GetVersion retrieves snapshot version associated with resource.ClusterType
	clusterVersion := snapshot.GetVersion(resourcev3.ClusterType)
	if clusterVersion != version {
		return fmt.Errorf("unexpected version for ClusterType: got %q, want %q", clusterVersion, version)
	}

	// 6. discovery.DiscoveryResponse encapsulates cluster resources matching resource.ClusterType
	resp := &discoveryv3.DiscoveryResponse{
		VersionInfo: version,
		TypeUrl:     resourcev3.ClusterType,
		Resources:   []*anypb.Any{anyCluster},
	}
	if resp.GetTypeUrl() != resourcev3.ClusterType {
		return fmt.Errorf("discovery response TypeUrl mismatch: got %q, want %q", resp.GetTypeUrl(), resourcev3.ClusterType)
	}
	if len(resp.GetResources()) != 1 {
		return fmt.Errorf("expected 1 resource in discovery response, got %d", len(resp.GetResources()))
	}
	unpackedMsg, err := resp.GetResources()[0].UnmarshalNew()
	if err != nil {
		return fmt.Errorf("failed to unmarshal discovery response resource: %w", err)
	}
	unpackedCluster, ok := unpackedMsg.(*clusterv3.Cluster)
	if !ok {
		return fmt.Errorf("unmarshaled message is not *clusterv3.Cluster")
	}
	if !proto.Equal(unpackedCluster, cluster) {
		return fmt.Errorf("unpacked cluster does not equal original cluster")
	}

	return nil
}

Seeder d'origine

anonyme