Пример
google.golang.org/protobuf v1.36.4: proto.Equal
Проверенный пример — golang google.golang.org/protobuf v1.36.4: proto.Equal. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:7fdc425068384ec073f76afc7fa20b2e533f16a934cd93f12195c2aeee4930bf
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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-24 |
Кейс
HOW- Цель
- verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4
- Символы
-
- google.golang.org/protobuf/proto.Equal
- Создан
- 2026-10-24T13:31:54Z
Контракт
- proto.Equal returns true when comparing two untyped nil values or two typed nil pointers of the same message type
- proto.Equal returns false when comparing an untyped nil interface with a typed nil message pointer
- proto.Equal returns false when comparing messages with different descriptors even when both are empty or typed nil
- proto.Equal returns true for distinct message instances with identical scalar field values and false when scalar fields differ
- proto.Equal distinguishes unset proto2 fields from explicitly set zero-value proto2 fields
- proto.Equal treats floating-point NaN values as equal while distinguishing positive and negative zero
- proto.Equal compares map entries independent of insertion order and repeated list elements in order
- proto.Equal includes unparsed unknown wire fields in equality comparisons
Файлы
- 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 google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/protobuf@v1.36.4
Demonstrate these symbols/APIs:
- google.golang.org/protobuf/proto.Equal
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:4bf0d44fb9296d185fc5c12378195c502a8f14d650061b3da0def2a69df5d3a1","contract":["proto.Equal returns true when comparing two untyped nil values or two typed nil pointers of the same message type","proto.Equal returns false when comparing an untyped nil interface with a typed nil message pointer","proto.Equal returns false when comparing messages with different descriptors even when both are empty or typed nil","proto.Equal returns true for distinct message instances with identical scalar field values and false when scalar fields differ","proto.Equal distinguishes unset proto2 fields from explicitly set zero-value proto2 fields","proto.Equal treats floating-point NaN values as equal while distinguishing positive and negative zero","proto.Equal compares map entries independent of insertion order and repeated list elements in order","proto.Equal includes unparsed unknown wire fields in equality comparisons"],"goal":"verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.36.4"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/proto.Equal"]},"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.36.4"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.36.4","symbols":["google.golang.org/protobuf/proto.Equal"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.21
require google.golang.org/protobuf v1.36.4
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.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
{
"schemaVersion": 1,
"goal": "verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/protobuf@v1.36.4"
],
"symbols": [
"google.golang.org/protobuf/proto.Equal"
]
}
package main
import (
"fmt"
"math"
"os"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func assert(cond bool, msg string) {
if !cond {
fmt.Fprintln(os.Stderr, "contract failed:", msg)
os.Exit(1)
}
}
func main() {
// 1. Untyped nil and typed nil of the same message type
var untypedA, untypedB proto.Message
assert(proto.Equal(untypedA, untypedB), "two untyped nil messages must be equal")
var typedNilStrA, typedNilStrB *wrapperspb.StringValue
assert(proto.Equal(typedNilStrA, typedNilStrB), "two typed nil pointers of the same message type must be equal")
// 2. Untyped nil vs typed nil pointer
assert(!proto.Equal(untypedA, typedNilStrA), "untyped nil and typed nil message pointer must not be equal")
// 3. Different message descriptors (empty or typed nil)
var typedNilInt *wrapperspb.Int64Value
assert(!proto.Equal(typedNilStrA, typedNilInt), "typed nil pointers of different message types must not be equal")
assert(!proto.Equal(&wrapperspb.StringValue{}, &wrapperspb.Int64Value{}), "empty messages of different descriptors must not be equal")
// 4. Scalar field equality and inequality across distinct instances
s1 := wrapperspb.String("hello")
s2 := wrapperspb.String("hello")
s3 := wrapperspb.String("world")
assert(s1 != s2 && proto.Equal(s1, s2), "distinct messages with identical scalar values must be equal")
assert(!proto.Equal(s1, s3), "messages with different scalar values must not be equal")
// 5. Explicit presence (proto2): unset field vs explicitly set zero-value field
unsetProto2 := &descriptorpb.FieldDescriptorProto{}
emptyNameProto2 := &descriptorpb.FieldDescriptorProto{Name: proto.String("")}
sameEmptyNameProto2 := &descriptorpb.FieldDescriptorProto{Name: proto.String("")}
assert(!proto.Equal(unsetProto2, emptyNameProto2), "unset proto2 field must not equal explicitly set empty proto2 field")
assert(proto.Equal(emptyNameProto2, sameEmptyNameProto2), "two proto2 messages with identical explicitly set zero values must be equal")
// 6. IEEE-754 floating-point NaN and signed zeros
nanA := wrapperspb.Double(math.NaN())
nanB := wrapperspb.Double(math.NaN())
assert(proto.Equal(nanA, nanB), "proto.Equal must treat NaN float values as equal")
posZero := wrapperspb.Double(0.0)
negZero := wrapperspb.Double(math.Copysign(0.0, -1.0))
assert(!proto.Equal(posZero, negZero), "proto.Equal must distinguish +0.0 and -0.0")
// 7. Map entries (order-independent) and repeated list elements (order-sensitive)
mapA := &structpb.Struct{
Fields: map[string]*structpb.Value{
"first": structpb.NewNumberValue(1),
"second": structpb.NewStringValue("two"),
},
}
mapB := &structpb.Struct{
Fields: map[string]*structpb.Value{
"second": structpb.NewStringValue("two"),
"first": structpb.NewNumberValue(1),
},
}
mapC := &structpb.Struct{
Fields: map[string]*structpb.Value{
"first": structpb.NewNumberValue(1),
"second": structpb.NewStringValue("different"),
},
}
assert(proto.Equal(mapA, mapB), "map fields with identical key-value pairs must be equal")
assert(!proto.Equal(mapA, mapC), "map fields with differing values must not be equal")
listA := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(1),
structpb.NewNumberValue(2),
},
}
listB := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(1),
structpb.NewNumberValue(2),
},
}
listReversed := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(2),
structpb.NewNumberValue(1),
},
}
assert(proto.Equal(listA, listB), "repeated fields with identical elements in order must be equal")
assert(!proto.Equal(listA, listReversed), "repeated fields with elements in different order must not be equal")
// 8. Unknown wire fields included in equality comparison
var rawUnknown []byte
rawUnknown = protowire.AppendTag(rawUnknown, 999, protowire.VarintType)
rawUnknown = protowire.AppendVarint(rawUnknown, 42)
u1 := wrapperspb.String("payload")
u2 := wrapperspb.String("payload")
u1.ProtoReflect().SetUnknown(rawUnknown)
assert(!proto.Equal(u1, u2), "message with unknown fields must not equal message without unknown fields")
u2.ProtoReflect().SetUnknown(rawUnknown)
assert(proto.Equal(u1, u2), "messages with identical known and unknown fields must be equal")
}
Исходный сидер
аноним