示例
github.com/envoyproxy/protoc-gen-validate v1.0.4
已验证示例 — golang github.com/envoyproxy/protoc-gen-validate v1.0.4. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: FieldRules configures string…
sha256:dce75d48432599f2733591aed03895da944a960eab1a63339e3b5b00fd86aad8
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
源代码
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.
{"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"}
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
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=
{
"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"
}
}
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: >e,
Lte: <e,
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")
}
原始种子者
匿名