CodeSampleX

サンプル

github.com/envoyproxy/protoc-gen-validate v1.0.4

検証済みサンプル — golang github.com/envoyproxy/protoc-gen-validate v1.0.4. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:dce75d48432599f2733591aed03895da944a960eab1a63339e3b5b00fd86aad8

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

検証実行環境

環境 コントラクト ステージ 実行日
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-19

ケース

HOW
ゴール
verify pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4
パッケージ
環境
go 1.26.6
作成日
2026-09-18T18:56:23Z

コントラクト

  1. FieldRules configures string constraints with min and max length, prefix, suffix, and email well-known regex
  2. FieldRules configures int32 constraints with range bounds and value sets
  3. FieldRules attaches to and retrieves from descriptorpb.FieldOptions using E_Rules extension
  4. FieldRules serializes to protobuf binary and unmarshals with identical rule constraints

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:3de2d904360d8d6805939cb031189ad61a5fd20a39baf6aedbcefbb6b51af8de","contract":["FieldRules configures string constraints with min and max length, prefix, suffix, and email well-known regex","FieldRules configures int32 constraints with range bounds and value sets","FieldRules attaches to and retrieves from descriptorpb.FieldOptions using E_Rules extension","FieldRules serializes to protobuf binary and unmarshals with identical rule constraints"],"goal":"verify pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4","kind":"HOW","packages":["pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4"],"schemaVersion":1,"subject":"pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/envoyproxy/protoc-gen-validate v1.0.4
	google.golang.org/protobuf v1.32.0
)

require golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
go.sum
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
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=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/envoyproxy/protoc-gen-validate@v1.0.4"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
test/contract.go
package main

import (
	"fmt"

	"github.com/envoyproxy/protoc-gen-validate/validate"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/descriptorpb"
)

func main() {
	// 1. FieldRules configures string constraints with min/max length, prefix, suffix, and email well-known regex
	minLen := uint64(5)
	maxLen := uint64(100)
	prefix := "user_"
	suffix := "@example.com"
	contains := "domain"
	stringRules := &validate.FieldRules{
		Type: &validate.FieldRules_String_{
			String_: &validate.StringRules{
				MinLen:   &minLen,
				MaxLen:   &maxLen,
				Prefix:   &prefix,
				Suffix:   &suffix,
				Contains: &contains,
				WellKnown: &validate.StringRules_Email{
					Email: true,
				},
			},
		},
	}

	str := stringRules.GetString_()
	if str.GetMinLen() != 5 {
		panic(fmt.Sprintf("expected MinLen 5, got %d", str.GetMinLen()))
	}
	if str.GetMaxLen() != 100 {
		panic(fmt.Sprintf("expected MaxLen 100, got %d", str.GetMaxLen()))
	}
	if str.GetPrefix() != "user_" {
		panic(fmt.Sprintf("expected Prefix 'user_', got %s", str.GetPrefix()))
	}
	if str.GetSuffix() != "@example.com" {
		panic(fmt.Sprintf("expected Suffix '@example.com', got %s", str.GetSuffix()))
	}
	if str.GetContains() != "domain" {
		panic(fmt.Sprintf("expected Contains 'domain', got %s", str.GetContains()))
	}
	if !str.GetEmail() {
		panic("expected Email well-known rule to be true")
	}

	// 2. FieldRules configures int32 constraints with range bounds and value sets
	gte := int32(1)
	lte := int32(65535)
	intRules := &validate.FieldRules{
		Type: &validate.FieldRules_Int32{
			Int32: &validate.Int32Rules{
				Gte:   &gte,
				Lte:   &lte,
				In:    []int32{80, 443, 8080},
				NotIn: []int32{22, 25},
			},
		},
	}

	i32 := intRules.GetInt32()
	if i32.GetGte() != 1 || i32.GetLte() != 65535 {
		panic("expected Gte 1 and Lte 65535")
	}
	if len(i32.GetIn()) != 3 || i32.GetIn()[1] != 443 {
		panic("expected In list [80, 443, 8080]")
	}
	if len(i32.GetNotIn()) != 2 || i32.GetNotIn()[0] != 22 {
		panic("expected NotIn list [22, 25]")
	}

	// 3. FieldRules attaches to and retrieves from descriptorpb.FieldOptions using E_Rules extension
	fieldOpts := &descriptorpb.FieldOptions{}
	proto.SetExtension(fieldOpts, validate.E_Rules, stringRules)
	if !proto.HasExtension(fieldOpts, validate.E_Rules) {
		panic("expected E_Rules extension to be present on fieldOpts")
	}

	extractedExt := proto.GetExtension(fieldOpts, validate.E_Rules)
	retrievedRules, ok := extractedExt.(*validate.FieldRules)
	if !ok || retrievedRules == nil {
		panic("expected extension to cast to *validate.FieldRules")
	}
	if retrievedRules.GetString_().GetPrefix() != "user_" {
		panic("retrieved rules prefix mismatch")
	}

	// 4. FieldRules serializes to protobuf binary and unmarshals with identical rule constraints
	data, err := proto.Marshal(intRules)
	if err != nil {
		panic(fmt.Sprintf("proto.Marshal failed: %v", err))
	}
	if len(data) == 0 {
		panic("marshaled protobuf bytes should not be empty")
	}

	unmarshaledRules := &validate.FieldRules{}
	if err := proto.Unmarshal(data, unmarshaledRules); err != nil {
		panic(fmt.Sprintf("proto.Unmarshal failed: %v", err))
	}
	unmarshaledI32 := unmarshaledRules.GetInt32()
	if unmarshaledI32.GetGte() != 1 || unmarshaledI32.GetLte() != 65535 {
		panic("unmarshaled int32 rules bounds mismatch")
	}
	if len(unmarshaledI32.GetIn()) != 3 || unmarshaledI32.GetIn()[2] != 8080 {
		panic("unmarshaled int32 rules In slice mismatch")
	}

	fmt.Println("PASS: protoc-gen-validate verification successful")
}

オリジンシーダー

匿名