CodeSampleX

Exemple

github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5: v3.ResourceLocator

Échantillon vérifié pour golang github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5: v3.ResourceLocator. Le contrat s'est exécuté sur go 1.26 · linux…

sha256:9fde4f31cf98f9549e178e1603f698684f784a61892aa00b6cd89f2960bedf00

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

Cas

HOW
Objectif
verify github.com/cncf/xds/go/xds/core/v3.ResourceLocator in pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5
Paquets
Symboles
  • github.com/cncf/xds/go/xds/core/v3.ResourceLocator
Créé
2026-10-15T01:36:14Z

Contrat

  1. ResourceLocator initializes with scheme, id, authority, resource type, exact context, and directives
  2. ResourceLocator getters safely return default values on nil and empty receivers without panic
  3. ResourceLocator validation passes for valid XDSTP, HTTP, and FILE schemes with non-empty resource type and nested alt directives
  4. ResourceLocator validation returns an error when resource type is empty or scheme is out of range
  5. ResourceLocator round-trips through Protobuf binary wire format preserving equality
  6. proto.Clone creates an independent deep copy of ResourceLocator

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/main.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/cncf/xds/go/xds/core/v3.ResourceLocator in pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5
Demonstrate these symbols/APIs:
  - github.com/cncf/xds/go/xds/core/v3.ResourceLocator

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:5dc9dd00707e3d49b55da02a65b6a553e012b6a322b31000aac408f7680718a1","contract":["ResourceLocator initializes with scheme, id, authority, resource type, exact context, and directives","ResourceLocator getters safely return default values on nil and empty receivers without panic","ResourceLocator validation passes for valid XDSTP, HTTP, and FILE schemes with non-empty resource type and nested alt directives","ResourceLocator validation returns an error when resource type is empty or scheme is out of range","ResourceLocator round-trips through Protobuf binary wire format preserving equality","proto.Clone creates an independent deep copy of ResourceLocator"],"goal":"verify github.com/cncf/xds/go/xds/core/v3.ResourceLocator in pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5","kind":"HOW","packages":["pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5"],"schemaVersion":1,"symbols":["github.com/cncf/xds/go/xds/core/v3.ResourceLocator"]},"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/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5"],"schemaVersion":1,"subject":"pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5","symbols":["github.com/cncf/xds/go/xds/core/v3.ResourceLocator"],"verifierAdapter":"golang@1"}
go.mod
module example.com/resourcelocator

go 1.24

require (
	github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5
	google.golang.org/protobuf v1.36.10
)

require github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
go.sum
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 h1:6xNmx7iTtyBRev0+D/Tv1FZd4SCg8axKApyNyRsAt/w=
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI=
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/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/cncf/xds/go/xds/core/v3.ResourceLocator in pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/cncf/xds/go@v0.0.0-20251210132809-ee656c7534f5"
  ],
  "symbols": [
    "github.com/cncf/xds/go/xds/core/v3.ResourceLocator"
  ]
}
test/main.go
package main

import (
	"fmt"
	"os"

	corev3 "github.com/cncf/xds/go/xds/core/v3"
	"google.golang.org/protobuf/proto"
)

func check(ok bool, msg string) {
	if !ok {
		fmt.Fprintf(os.Stderr, "contract failed: %s\n", msg)
		os.Exit(1)
	}
}

func main() {
	// 1. ResourceLocator initializes with scheme, id, authority, resource type, exact context, and directives
	{
		loc := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_XDSTP,
			Id:           "route-primary",
			Authority:    "example.com",
			ResourceType: "envoy.config.route.v3.RouteConfiguration",
			ContextParamSpecifier: &corev3.ResourceLocator_ExactContext{
				ExactContext: &corev3.ContextParams{
					Params: map[string]string{
						"region": "us-east",
					},
				},
			},
			Directives: []*corev3.ResourceLocator_Directive{
				{
					Directive: &corev3.ResourceLocator_Directive_Entry{
						Entry: "main-entry",
					},
				},
			},
		}
		check(loc.GetScheme() == corev3.ResourceLocator_XDSTP, "GetScheme mismatch")
		check(loc.GetId() == "route-primary", "GetId mismatch")
		check(loc.GetAuthority() == "example.com", "GetAuthority mismatch")
		check(loc.GetResourceType() == "envoy.config.route.v3.RouteConfiguration", "GetResourceType mismatch")
		check(loc.GetExactContext() != nil, "GetExactContext nil")
		check(loc.GetExactContext().GetParams()["region"] == "us-east", "ExactContext param mismatch")
		check(len(loc.GetDirectives()) == 1, "GetDirectives length mismatch")
		check(loc.GetDirectives()[0].GetEntry() == "main-entry", "Directive entry mismatch")
	}

	// 2. ResourceLocator getters safely return default values on nil and empty receivers without panic
	{
		var nilLoc *corev3.ResourceLocator
		check(nilLoc.GetScheme() == corev3.ResourceLocator_XDSTP, "nil GetScheme should be XDSTP")
		check(nilLoc.GetId() == "", "nil GetId should be empty")
		check(nilLoc.GetAuthority() == "", "nil GetAuthority should be empty")
		check(nilLoc.GetResourceType() == "", "nil GetResourceType should be empty")
		check(nilLoc.GetContextParamSpecifier() == nil, "nil GetContextParamSpecifier should be nil")
		check(nilLoc.GetExactContext() == nil, "nil GetExactContext should be nil")
		check(nilLoc.GetDirectives() == nil, "nil GetDirectives should be nil")
		check(nilLoc.Validate() == nil, "nil Validate should return nil")
		check(nilLoc.ValidateAll() == nil, "nil ValidateAll should return nil")

		emptyLoc := &corev3.ResourceLocator{}
		check(emptyLoc.GetScheme() == corev3.ResourceLocator_XDSTP, "empty GetScheme should be XDSTP")
		check(emptyLoc.GetId() == "", "empty GetId should be empty")
		check(emptyLoc.GetAuthority() == "", "empty GetAuthority should be empty")
		check(emptyLoc.GetResourceType() == "", "empty GetResourceType should be empty")
		check(emptyLoc.GetExactContext() == nil, "empty GetExactContext should be nil")
		check(emptyLoc.GetDirectives() == nil, "empty GetDirectives should be nil")
	}

	// 3. ResourceLocator validation passes for valid XDSTP, HTTP, and FILE schemes with non-empty resource type and nested alt directives
	{
		validXdstp := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_XDSTP,
			ResourceType: "envoy.config.listener.v3.Listener",
		}
		check(validXdstp.Validate() == nil, "validXdstp Validate failed")
		check(validXdstp.ValidateAll() == nil, "validXdstp ValidateAll failed")

		validWithAlt := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_HTTP,
			Authority:    "example.com",
			ResourceType: "envoy.config.cluster.v3.Cluster",
			Directives: []*corev3.ResourceLocator_Directive{
				{
					Directive: &corev3.ResourceLocator_Directive_Alt{
						Alt: &corev3.ResourceLocator{
							Scheme:       corev3.ResourceLocator_FILE,
							ResourceType: "envoy.config.cluster.v3.Cluster",
						},
					},
				},
			},
		}
		check(validWithAlt.Validate() == nil, "validWithAlt Validate failed")
		check(validWithAlt.ValidateAll() == nil, "validWithAlt ValidateAll failed")
	}

	// 4. ResourceLocator validation returns an error when resource type is empty or scheme is out of range
	{
		missingType := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_XDSTP,
			ResourceType: "",
		}
		check(missingType.Validate() != nil, "expected error for empty ResourceType")

		badScheme := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_Scheme(42),
			ResourceType: "envoy.config.listener.v3.Listener",
		}
		check(badScheme.Validate() != nil, "expected error for invalid Scheme")
		check(badScheme.ValidateAll() != nil, "expected ValidateAll error for invalid Scheme")
	}

	// 5. ResourceLocator round-trips through Protobuf binary wire format preserving equality
	{
		original := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_XDSTP,
			Id:           "listener-01",
			Authority:    "example.com",
			ResourceType: "envoy.config.listener.v3.Listener",
			ContextParamSpecifier: &corev3.ResourceLocator_ExactContext{
				ExactContext: &corev3.ContextParams{
					Params: map[string]string{"zone": "az1"},
				},
			},
		}
		data, err := proto.Marshal(original)
		check(err == nil && len(data) > 0, "proto.Marshal failed")

		decoded := &corev3.ResourceLocator{}
		err = proto.Unmarshal(data, decoded)
		check(err == nil, "proto.Unmarshal failed")
		check(proto.Equal(original, decoded), "proto.Equal failed after round-trip")
	}

	// 6. proto.Clone creates an independent deep copy of ResourceLocator
	{
		src := &corev3.ResourceLocator{
			Scheme:       corev3.ResourceLocator_XDSTP,
			Id:           "src-id",
			Authority:    "example.com",
			ResourceType: "envoy.config.listener.v3.Listener",
			ContextParamSpecifier: &corev3.ResourceLocator_ExactContext{
				ExactContext: &corev3.ContextParams{
					Params: map[string]string{"tier": "frontend"},
				},
			},
		}
		dst := proto.Clone(src).(*corev3.ResourceLocator)
		check(proto.Equal(src, dst), "cloned message not equal to source")

		dst.Id = "modified-id"
		dst.GetExactContext().GetParams()["tier"] = "backend"
		check(src.GetId() == "src-id", "mutating clone affected source Id")
		check(src.GetExactContext().GetParams()["tier"] == "frontend", "mutating clone affected source ExactContext")
	}

	fmt.Println("PASS")
}

Seeder d'origine

anonyme