샘플
google.golang.org/protobuf v1.36.11
검증된 샘플 — golang google.golang.org/protobuf v1.36.11. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: proto.Marshal and proto.Unmarshal correctly…
sha256:b0be09da07a3a049c710fdb290e38652329a37c42c55cc8fbdd4bd611a449fcf
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify pkg:golang/google.golang.org/protobuf@v1.36.11
- 생성일
- 2026-08-27T20:11:04Z
컨트랙트
- proto.Marshal and proto.Unmarshal correctly round-trip protobuf messages
- proto.Equal and proto.Clone maintain message equality and deep-copy semantics
- proto.Merge merges populated fields from source message into destination
- protojson.Marshal and protojson.Unmarshal convert messages to and from valid JSON
- anypb.New and UnmarshalTo pack and unpack arbitrary protobuf messages
- structpb.NewStruct and AsMap convert between Go map structures and dynamic protobuf structs
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- 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/google.golang.org/protobuf@v1.36.11
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/protobuf@v1.36.11
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:3c502179395e6ebb652d903e3fc4731d85b324204ab0f82de48bb8c9d7a3d207","contract":["proto.Marshal and proto.Unmarshal correctly round-trip protobuf messages","proto.Equal and proto.Clone maintain message equality and deep-copy semantics","proto.Merge merges populated fields from source message into destination","protojson.Marshal and protojson.Unmarshal convert messages to and from valid JSON","anypb.New and UnmarshalTo pack and unpack arbitrary protobuf messages","structpb.NewStruct and AsMap convert between Go map structures and dynamic protobuf structs"],"goal":"verify pkg:golang/google.golang.org/protobuf@v1.36.11","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.36.11"],"schemaVersion":1},"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.11"],"schemaVersion":1,"verifierAdapter":"golang@1"}
module example.com/sample
go 1.23
require google.golang.org/protobuf v1.36.11
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.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package main
import (
"fmt"
"time"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// MetricRecord represents a structured telemetry event.
type MetricRecord struct {
Timestamp *timestamppb.Timestamp
Payload *structpb.Struct
Detail *anypb.Any
}
// NewMetricRecord creates a new MetricRecord from standard Go types.
func NewMetricRecord(t time.Time, metadata map[string]any, detail proto.Message) (*MetricRecord, error) {
st, err := structpb.NewStruct(metadata)
if err != nil {
return nil, fmt.Errorf("failed to create structpb: %w", err)
}
var anyDetail *anypb.Any
if detail != nil {
anyDetail, err = anypb.New(detail)
if err != nil {
return nil, fmt.Errorf("failed to create anypb: %w", err)
}
}
return &MetricRecord{
Timestamp: timestamppb.New(t),
Payload: st,
Detail: anyDetail,
}, nil
}
// ToJSON serializes the metric payload into a JSON string using protojson.
func (m *MetricRecord) ToJSON() (string, error) {
if m.Payload == nil {
return "{}", nil
}
data, err := protojson.Marshal(m.Payload)
if err != nil {
return "", fmt.Errorf("protojson marshal failed: %w", err)
}
return string(data), nil
}
// CloneTimestamp creates a deep copy of the Timestamp message using proto.Clone.
func (m *MetricRecord) CloneTimestamp() *timestamppb.Timestamp {
if m.Timestamp == nil {
return nil
}
cloned := proto.Clone(m.Timestamp)
return cloned.(*timestamppb.Timestamp)
}
func main() {
now := time.Now()
meta := map[string]any{
"metric_name": "cpu_usage",
"value": float64(45.2),
"active": true,
}
record, err := NewMetricRecord(now, meta, timestamppb.New(now))
if err != nil {
fmt.Printf("Error creating metric record: %v\n", err)
return
}
jsonStr, err := record.ToJSON()
if err != nil {
fmt.Printf("Error encoding to JSON: %v\n", err)
return
}
fmt.Printf("Record created at %v with JSON payload: %s\n", record.Timestamp.AsTime(), jsonStr)
clonedTs := record.CloneTimestamp()
if proto.Equal(record.Timestamp, clonedTs) {
fmt.Println("Timestamp successfully cloned and verified equal.")
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/google.golang.org/protobuf@v1.36.11",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/protobuf@v1.36.11"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"bytes"
"fmt"
"os"
"reflect"
"time"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"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.Marshal and proto.Unmarshal correctly round-trip protobuf messages
{
orig := timestamppb.New(time.Date(2026, 8, 19, 12, 30, 0, 500, time.UTC))
data, err := proto.Marshal(orig)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal error: %v\n", err)
os.Exit(1)
}
if len(data) == 0 {
fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal produced empty byte slice\n")
os.Exit(1)
}
var decoded timestamppb.Timestamp
if err := proto.Unmarshal(data, &decoded); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal error: %v\n", err)
os.Exit(1)
}
if !proto.Equal(orig, &decoded) {
fmt.Fprintf(os.Stderr, "FAIL: unmarshaled message does not equal original\n")
os.Exit(1)
}
if !decoded.AsTime().Equal(orig.AsTime()) {
fmt.Fprintf(os.Stderr, "FAIL: decoded time %v does not match original %v\n", decoded.AsTime(), orig.AsTime())
os.Exit(1)
}
}
// Assertion 2: proto.Equal and proto.Clone maintain message equality and deep-copy semantics
{
orig := &durationpb.Duration{
Seconds: 3600,
Nanos: 500000,
}
cloned := proto.Clone(orig).(*durationpb.Duration)
if !proto.Equal(orig, cloned) {
fmt.Fprintf(os.Stderr, "FAIL: proto.Clone result is not equal to original\n")
os.Exit(1)
}
// Mutating clone must not affect original
cloned.Seconds = 7200
if proto.Equal(orig, cloned) {
fmt.Fprintf(os.Stderr, "FAIL: mutated clone should not be equal to original\n")
os.Exit(1)
}
if orig.Seconds != 3600 {
fmt.Fprintf(os.Stderr, "FAIL: modifying clone altered original message\n")
os.Exit(1)
}
}
// Assertion 3: proto.Merge merges populated fields from source message into destination
{
dst := &durationpb.Duration{
Seconds: 100,
Nanos: 0,
}
src := &durationpb.Duration{
Seconds: 0,
Nanos: 500,
}
proto.Merge(dst, src)
if dst.Nanos != 500 {
fmt.Fprintf(os.Stderr, "FAIL: proto.Merge did not update destination field\n")
os.Exit(1)
}
}
// Assertion 4: protojson.Marshal and protojson.Unmarshal convert messages to and from valid JSON
{
orig := timestamppb.New(time.Date(2026, 1, 15, 8, 0, 0, 0, time.UTC))
jsonBytes, err := protojson.Marshal(orig)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Marshal error: %v\n", err)
os.Exit(1)
}
if !bytes.Contains(jsonBytes, []byte("2026-01-15T08:00:00Z")) {
fmt.Fprintf(os.Stderr, "FAIL: JSON output %s does not contain expected RFC3339 timestamp\n", string(jsonBytes))
os.Exit(1)
}
var decoded timestamppb.Timestamp
if err := protojson.Unmarshal(jsonBytes, &decoded); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: protojson.Unmarshal error: %v\n", err)
os.Exit(1)
}
if !proto.Equal(orig, &decoded) {
fmt.Fprintf(os.Stderr, "FAIL: protojson unmarshaled message does not equal original\n")
os.Exit(1)
}
}
// Assertion 5: anypb.New and UnmarshalTo pack and unpack arbitrary protobuf messages
{
inner := &durationpb.Duration{
Seconds: 120,
Nanos: 0,
}
anyMsg, err := anypb.New(inner)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: anypb.New error: %v\n", err)
os.Exit(1)
}
if !anyMsg.MessageIs(&durationpb.Duration{}) {
fmt.Fprintf(os.Stderr, "FAIL: anyMsg.MessageIs returned false for Duration\n")
os.Exit(1)
}
var unpacked durationpb.Duration
if err := anyMsg.UnmarshalTo(&unpacked); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: anyMsg.UnmarshalTo error: %v\n", err)
os.Exit(1)
}
if !proto.Equal(inner, &unpacked) {
fmt.Fprintf(os.Stderr, "FAIL: unpacked any message does not match original\n")
os.Exit(1)
}
}
// Assertion 6: structpb.NewStruct and AsMap convert between Go map structures and dynamic protobuf structs
{
inputMap := map[string]any{
"string_key": "sample_value",
"number_key": float64(42),
"bool_key": true,
}
st, err := structpb.NewStruct(inputMap)
if err != nil {
fmt.Fprintf(os.Stderr, "FAIL: structpb.NewStruct error: %v\n", err)
os.Exit(1)
}
outMap := st.AsMap()
if !reflect.DeepEqual(inputMap, outMap) {
fmt.Fprintf(os.Stderr, "FAIL: AsMap result %v does not match input %v\n", outMap, inputMap)
os.Exit(1)
}
}
fmt.Println("PASS: google.golang.org/protobuf contract passed")
}
오리진 시더
익명