Ejemplo
google.golang.org/protobuf v1.35.1: proto.UnmarshalOptions
Muestra verificada para golang google.golang.org/protobuf v1.35.1: proto.UnmarshalOptions. El contrato se ejecutó en go 1.26 · linux alpine/x64 · docker y…
sha256:d8bea7fcd1de723bf7fb6adfba5c5fb5fc32d5c9ddadb0fa11ba21b1cfc374b7
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-27 |
Caso
HOW- Objetivo
- verify google.golang.org/protobuf/proto.UnmarshalOptions in pkg:golang/google.golang.org/protobuf@v1.35.1
- Paquetes
- Símbolos
-
- google.golang.org/protobuf/proto.UnmarshalOptions
- Creado
- 2026-08-27T10:26:00Z
Contrato
- proto.UnmarshalOptions.Unmarshal parses wire-format protobuf data into target messages
- proto.UnmarshalOptions with Merge=true preserves existing fields not overwritten by input while Merge=false resets destination
- proto.UnmarshalOptions with DiscardUnknown=true strips unknown wire fields while DiscardUnknown=false retains them
- proto.UnmarshalOptions with AllowPartial=true permits unmarshaling partial protobuf messages
- proto.UnmarshalOptions with custom RecursionLimit enforces recursion depth constraints during unmarshaling
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código fuente
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 google.golang.org/protobuf/proto.UnmarshalOptions in pkg:golang/google.golang.org/protobuf@v1.35.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/protobuf@v1.35.1
Demonstrate these symbols/APIs:
- google.golang.org/protobuf/proto.UnmarshalOptions
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:f4daff629485d459752b7c2dd4008d069e4fedc3417f565088bc7835d7967b29","contract":["proto.UnmarshalOptions.Unmarshal parses wire-format protobuf data into target messages","proto.UnmarshalOptions with Merge=true preserves existing fields not overwritten by input while Merge=false resets destination","proto.UnmarshalOptions with DiscardUnknown=true strips unknown wire fields while DiscardUnknown=false retains them","proto.UnmarshalOptions with AllowPartial=true permits unmarshaling partial protobuf messages","proto.UnmarshalOptions with custom RecursionLimit enforces recursion depth constraints during unmarshaling"],"goal":"verify google.golang.org/protobuf/proto.UnmarshalOptions in pkg:golang/google.golang.org/protobuf@v1.35.1","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.35.1"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/proto.UnmarshalOptions"]},"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/google.golang.org/protobuf@v1.35.1"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.35.1","symbols":["google.golang.org/protobuf/proto.UnmarshalOptions"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.22
require google.golang.org/protobuf v1.35.1
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-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
package main
import (
"fmt"
"os"
"time"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// UnmarshalWithDiscardUnknown unmarshals wire-format protobuf bytes into dst,
// discarding any unknown fields.
func UnmarshalWithDiscardUnknown(data []byte, dst proto.Message) error {
opts := proto.UnmarshalOptions{
DiscardUnknown: true,
}
return opts.Unmarshal(data, dst)
}
// UnmarshalWithMerge unmarshals wire-format protobuf bytes into dst without
// clearing dst first, merging incoming fields into existing message content.
func UnmarshalWithMerge(data []byte, dst proto.Message) error {
opts := proto.UnmarshalOptions{
Merge: true,
}
return opts.Unmarshal(data, dst)
}
// UnmarshalWithPartial unmarshals wire-format protobuf bytes with AllowPartial enabled.
func UnmarshalWithPartial(data []byte, dst proto.Message) error {
opts := proto.UnmarshalOptions{
AllowPartial: true,
}
return opts.Unmarshal(data, dst)
}
// UnmarshalWithRecursionLimit unmarshals wire-format protobuf bytes with a custom recursion depth limit.
func UnmarshalWithRecursionLimit(data []byte, dst proto.Message, limit int) error {
opts := proto.UnmarshalOptions{
RecursionLimit: limit,
}
return opts.Unmarshal(data, dst)
}
func main() {
now := time.Now().UTC()
ts := timestamppb.New(now)
data, err := proto.Marshal(ts)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to marshal timestamp: %v\n", err)
os.Exit(1)
}
var decoded timestamppb.Timestamp
if err := UnmarshalWithDiscardUnknown(data, &decoded); err != nil {
fmt.Fprintf(os.Stderr, "failed to unmarshal timestamp: %v\n", err)
os.Exit(1)
}
dur := &durationpb.Duration{Seconds: 300, Nanos: 0}
durData, err := proto.Marshal(&durationpb.Duration{Nanos: 500})
if err != nil {
fmt.Fprintf(os.Stderr, "failed to marshal duration: %v\n", err)
os.Exit(1)
}
if err := UnmarshalWithMerge(durData, dur); err != nil {
fmt.Fprintf(os.Stderr, "failed to merge duration: %v\n", err)
os.Exit(1)
}
fmt.Printf("Unmarshaled timestamp: %v, Merged duration: %vs %dns\n", decoded.AsTime(), dur.Seconds, dur.Nanos)
}
{
"schemaVersion": 1,
"goal": "verify google.golang.org/protobuf/proto.UnmarshalOptions in pkg:golang/google.golang.org/protobuf@v1.35.1",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/protobuf@v1.35.1"
],
"symbols": [
"google.golang.org/protobuf/proto.UnmarshalOptions"
]
}
package main
import (
"bytes"
"fmt"
"os"
"time"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
func main() {
// Assertion 1: proto.UnmarshalOptions.Unmarshal parses wire-format protobuf data into target messages
{
orig := timestamppb.New(time.Date(2026, 8, 27, 10, 0, 0, 0, time.UTC))
data, err := proto.Marshal(orig)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [1]: proto.Marshal failed: %v\n", err)
os.Exit(1)
}
opts := proto.UnmarshalOptions{}
var decoded timestamppb.Timestamp
if err := opts.Unmarshal(data, &decoded); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [1]: opts.Unmarshal failed: %v\n", err)
os.Exit(1)
}
if !proto.Equal(orig, &decoded) {
fmt.Fprintf(os.Stderr, "FAIL [1]: unmarshaled message does not match original\n")
os.Exit(1)
}
}
// Assertion 2: proto.UnmarshalOptions with Merge=true preserves existing fields not overwritten by input while Merge=false resets destination
{
// Destination message has Seconds=100, Nanos=200
dstMerge := &durationpb.Duration{Seconds: 100, Nanos: 200}
// Input only contains Nanos=999 (Seconds is unset / default)
input := &durationpb.Duration{Nanos: 999}
data, err := proto.Marshal(input)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [2]: proto.Marshal failed: %v\n", err)
os.Exit(1)
}
// With Merge: true, Seconds=100 is preserved, Nanos is updated to 999
optsMerge := proto.UnmarshalOptions{Merge: true}
if err := optsMerge.Unmarshal(data, dstMerge); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [2]: Unmarshal with Merge=true failed: %v\n", err)
os.Exit(1)
}
if dstMerge.Seconds != 100 || dstMerge.Nanos != 999 {
fmt.Fprintf(os.Stderr, "FAIL [2]: Merge=true expected Seconds=100, Nanos=999, got Seconds=%d, Nanos=%d\n", dstMerge.Seconds, dstMerge.Nanos)
os.Exit(1)
}
// With Merge: false (default), dst is reset before unmarshaling; Seconds becomes 0
dstNoMerge := &durationpb.Duration{Seconds: 100, Nanos: 200}
optsNoMerge := proto.UnmarshalOptions{Merge: false}
if err := optsNoMerge.Unmarshal(data, dstNoMerge); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [2]: Unmarshal with Merge=false failed: %v\n", err)
os.Exit(1)
}
if dstNoMerge.Seconds != 0 || dstNoMerge.Nanos != 999 {
fmt.Fprintf(os.Stderr, "FAIL [2]: Merge=false expected Seconds=0, Nanos=999, got Seconds=%d, Nanos=%d\n", dstNoMerge.Seconds, dstNoMerge.Nanos)
os.Exit(1)
}
}
// Assertion 3: proto.UnmarshalOptions with DiscardUnknown=true strips unknown wire fields while DiscardUnknown=false retains them
{
orig := &durationpb.Duration{Seconds: 50, Nanos: 100}
data, err := proto.Marshal(orig)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [3]: proto.Marshal failed: %v\n", err)
os.Exit(1)
}
// Append unknown wire field: field number 99, wire type 0 (varint), value 42
// Tag: (99 << 3) | 0 = 792 = 0x318 -> varint: 0x98, 0x06
unknownTagValue := []byte{0x98, 0x06, 42}
dataWithUnknown := append(data, unknownTagValue...)
// With DiscardUnknown: false (default), unknown fields must be preserved
var dstRetain durationpb.Duration
optsRetain := proto.UnmarshalOptions{DiscardUnknown: false}
if err := optsRetain.Unmarshal(dataWithUnknown, &dstRetain); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [3]: Unmarshal with DiscardUnknown=false failed: %v\n", err)
os.Exit(1)
}
unknownBytes := dstRetain.ProtoReflect().GetUnknown()
if !bytes.Equal(unknownBytes, unknownTagValue) {
fmt.Fprintf(os.Stderr, "FAIL [3]: expected unknown bytes %v, got %v\n", unknownTagValue, unknownBytes)
os.Exit(1)
}
// With DiscardUnknown: true, unknown fields must be discarded
var dstDiscard durationpb.Duration
optsDiscard := proto.UnmarshalOptions{DiscardUnknown: true}
if err := optsDiscard.Unmarshal(dataWithUnknown, &dstDiscard); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [3]: Unmarshal with DiscardUnknown=true failed: %v\n", err)
os.Exit(1)
}
if len(dstDiscard.ProtoReflect().GetUnknown()) != 0 {
fmt.Fprintf(os.Stderr, "FAIL [3]: expected empty unknown fields with DiscardUnknown=true, got %v\n", dstDiscard.ProtoReflect().GetUnknown())
os.Exit(1)
}
}
// Assertion 4: proto.UnmarshalOptions with AllowPartial=true permits unmarshaling partial protobuf messages
{
orig := timestamppb.New(time.Date(2026, 8, 27, 0, 0, 0, 0, time.UTC))
data, err := proto.Marshal(orig)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [4]: proto.Marshal failed: %v\n", err)
os.Exit(1)
}
optsPartial := proto.UnmarshalOptions{AllowPartial: true}
var dst timestamppb.Timestamp
if err := optsPartial.Unmarshal(data, &dst); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [4]: Unmarshal with AllowPartial=true failed: %v\n", err)
os.Exit(1)
}
if !proto.Equal(orig, &dst) {
fmt.Fprintf(os.Stderr, "FAIL [4]: AllowPartial unmarshaled value mismatch\n")
os.Exit(1)
}
}
// Assertion 5: proto.UnmarshalOptions with custom RecursionLimit enforces recursion depth constraints during unmarshaling
{
// Construct nested structpb values: {"level1": {"level2": {"level3": 123}}}
innerMap := map[string]any{
"level1": map[string]any{
"level2": map[string]any{
"level3": float64(123),
},
},
}
st, err := structpb.NewStruct(innerMap)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [5]: structpb.NewStruct failed: %v\n", err)
os.Exit(1)
}
data, err := proto.Marshal(st)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL [5]: proto.Marshal failed: %v\n", err)
os.Exit(1)
}
// With default/sufficient RecursionLimit (e.g. 10), unmarshaling succeeds
var okDst structpb.Struct
optsOK := proto.UnmarshalOptions{RecursionLimit: 10}
if err := optsOK.Unmarshal(data, &okDst); err != nil {
fmt.Fprintf(os.Stderr, "FAIL [5]: Unmarshal with RecursionLimit=10 failed: %v\n", err)
os.Exit(1)
}
// With strict RecursionLimit: 2, deeply nested payload exceeds limit and returns error
var failDst structpb.Struct
optsLimit := proto.UnmarshalOptions{RecursionLimit: 2}
if err := optsLimit.Unmarshal(data, &failDst); err == nil {
fmt.Fprintf(os.Stderr, "FAIL [5]: expected error for RecursionLimit=2 with deeply nested structure, got nil\n")
os.Exit(1)
}
}
fmt.Println("PASS: all proto.UnmarshalOptions contract assertions passed")
}
Seeder de origen
anónimo