CodeSampleX

Exemplo

github.com/envoyproxy/go-control-plane/envoy v1.32.2: v3.DiscoveryResponse

Amostra verificada para golang github.com/envoyproxy/go-control-plane/envoy v1.32.2: v3.DiscoveryResponse. O contrato rodou em go 1.26 · linux debian/x64 …

sha256:25fd41903919be0b5b9e731a9698bfd7ade65bd2cf026b0b4d1c6939b1f5d602

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
1
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 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-15

Caso

HOW
Objetivo
verify github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse in pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2
Pacotes
Símbolos
  • github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse
Criado
2026-10-15T03:52:30Z

Contrato

  1. DiscoveryResponse constructs with VersionInfo, Resources, Canary, TypeUrl, Nonce, and ControlPlane
  2. DiscoveryResponse Validate and ValidateAll succeed on valid xDS response message
  3. DiscoveryResponse protobuf Marshal and Unmarshal preserve fields and typed Any resources

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • 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 github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse in pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2
Demonstrate these symbols/APIs:
  - github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse

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:ce13684da17c7887f96a38b29271ca2e3ded3da8c81fee6412a348b0042f31dd","contract":["DiscoveryResponse constructs with VersionInfo, Resources, Canary, TypeUrl, Nonce, and ControlPlane","DiscoveryResponse Validate and ValidateAll succeed on valid xDS response message","DiscoveryResponse protobuf Marshal and Unmarshal preserve fields and typed Any resources"],"goal":"verify github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse in pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2","kind":"HOW","packages":["pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2"],"schemaVersion":1,"symbols":["github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse"]},"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/envoy@v1.32.2"],"schemaVersion":1,"subject":"pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2","symbols":["github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/envoyproxy/go-control-plane/envoy v1.32.2
	google.golang.org/protobuf v1.35.2
)

require (
	github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20 // indirect
	github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
	github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
	golang.org/x/net v0.28.0 // indirect
	golang.org/x/sys v0.24.0 // indirect
	golang.org/x/text v0.17.0 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
	google.golang.org/grpc v1.67.1 // indirect
)
go.sum
github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20 h1:N+3sFI5GUjRKBi+i0TxYVST9h4Ie192jJWpHvthBBgg=
github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
github.com/envoyproxy/go-control-plane/envoy v1.32.2 h1:zidqwmijfcbyKqVxjQDFx042PgX+p9U+/fu/f9VtSk8=
github.com/envoyproxy/go-control-plane/envoy v1.32.2/go.mod h1:eR2SOX2IedqlPvmiKjUH7Wu//S602JKI7HPC/L3SRq8=
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse in pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/envoyproxy/go-control-plane/envoy@v1.32.2"
  ],
  "symbols": [
    "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3.DiscoveryResponse"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
	discoveryv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/wrapperspb"
)

func main() {
	resVal, err := anypb.New(wrapperspb.String("cluster-resource-1"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "anypb.New failed: %v\n", err)
		os.Exit(1)
	}

	resp := &discoveryv3.DiscoveryResponse{
		VersionInfo: "v1.0.0",
		Resources:   []*anypb.Any{resVal},
		Canary:      true,
		TypeUrl:     "type.googleapis.com/google.protobuf.StringValue",
		Nonce:       "nonce-001",
		ControlPlane: &corev3.ControlPlane{
			Identifier: "cp-main",
		},
	}

	if err := resp.Validate(); err != nil {
		fmt.Fprintf(os.Stderr, "Validate failed: %v\n", err)
		os.Exit(1)
	}
	if err := resp.ValidateAll(); err != nil {
		fmt.Fprintf(os.Stderr, "ValidateAll failed: %v\n", err)
		os.Exit(1)
	}

	raw, err := proto.Marshal(resp)
	if err != nil {
		fmt.Fprintf(os.Stderr, "proto.Marshal failed: %v\n", err)
		os.Exit(1)
	}

	var decoded discoveryv3.DiscoveryResponse
	if err := proto.Unmarshal(raw, &decoded); err != nil {
		fmt.Fprintf(os.Stderr, "proto.Unmarshal failed: %v\n", err)
		os.Exit(1)
	}

	if decoded.GetVersionInfo() != "v1.0.0" {
		fmt.Fprintf(os.Stderr, "unexpected VersionInfo: %q\n", decoded.GetVersionInfo())
		os.Exit(1)
	}
	if !decoded.GetCanary() {
		fmt.Fprintf(os.Stderr, "expected Canary=true\n")
		os.Exit(1)
	}
	if decoded.GetTypeUrl() != "type.googleapis.com/google.protobuf.StringValue" {
		fmt.Fprintf(os.Stderr, "unexpected TypeUrl: %q\n", decoded.GetTypeUrl())
		os.Exit(1)
	}
	if decoded.GetNonce() != "nonce-001" {
		fmt.Fprintf(os.Stderr, "unexpected Nonce: %q\n", decoded.GetNonce())
		os.Exit(1)
	}
	if decoded.GetControlPlane().GetIdentifier() != "cp-main" {
		fmt.Fprintf(os.Stderr, "unexpected ControlPlane Identifier: %q\n", decoded.GetControlPlane().GetIdentifier())
		os.Exit(1)
	}
	if len(decoded.GetResources()) != 1 {
		fmt.Fprintf(os.Stderr, "unexpected Resources len: %d\n", len(decoded.GetResources()))
		os.Exit(1)
	}

	var unwrapped wrapperspb.StringValue
	if err := decoded.GetResources()[0].UnmarshalTo(&unwrapped); err != nil {
		fmt.Fprintf(os.Stderr, "UnmarshalTo failed: %v\n", err)
		os.Exit(1)
	}
	if unwrapped.GetValue() != "cluster-resource-1" {
		fmt.Fprintf(os.Stderr, "unexpected resource value: %q\n", unwrapped.GetValue())
		os.Exit(1)
	}

	decoded.Reset()
	if decoded.GetVersionInfo() != "" || len(decoded.GetResources()) != 0 {
		fmt.Fprintf(os.Stderr, "Reset did not clear fields\n")
		os.Exit(1)
	}
}

Seeder de origem

anônimo