CodeSampleX

샘플

google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a

검증된 샘플 — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:cdf198f5757741cfb61ffe1919cc8ef14e45237591d9db643f57f6b95f9d3707

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-09-03

케이스

HOW
목표
verify pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a
패키지
생성일
2026-09-03T17:21:50Z

컨트랙트

  1. status.Status creates and serializes an RPC status message with code and message
  2. status.Status packs and unpacks errdetails.ErrorInfo into Any details
  3. status.Status packs and unpacks errdetails.BadRequest field violations into Any details
  4. status.Status packs and unpacks errdetails.RetryInfo with retry duration into Any details
  5. status.Status packs and unpacks errdetails.QuotaFailure and PreconditionFailure violations
  6. status.Status packs and unpacks errdetails.DebugInfo and LocalizedMessage into Any details
  7. status.Status packs and unpacks errdetails.Help links and ResourceInfo into Any details
  8. code.Code defines standard RPC status codes corresponding to canonical status values

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • 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/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a

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:a7d97041cf82b8fedb868dd4e9fd7954ddcbca255a640f2d07552b4b5b557b77","contract":["status.Status creates and serializes an RPC status message with code and message","status.Status packs and unpacks errdetails.ErrorInfo into Any details","status.Status packs and unpacks errdetails.BadRequest field violations into Any details","status.Status packs and unpacks errdetails.RetryInfo with retry duration into Any details","status.Status packs and unpacks errdetails.QuotaFailure and PreconditionFailure violations","status.Status packs and unpacks errdetails.DebugInfo and LocalizedMessage into Any details","status.Status packs and unpacks errdetails.Help links and ResourceInfo into Any details","code.Code defines standard RPC status codes corresponding to canonical status values"],"goal":"verify pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a"],"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/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a
	google.golang.org/protobuf v1.36.12
)
go.sum
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/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a h1:3Dnd1cDaZlB68lziofO+bJXpjOy8UfRv8Unt+yH8tQ4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260831171406-18b4a7587f8a/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"fmt"
	"log"
	"time"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func main() {
	errorInfo := &errdetails.ErrorInfo{
		Reason: "RESOURCE_USAGE_LIMIT",
		Domain: "example.com",
		Metadata: map[string]string{
			"quota_limit": "100",
			"quota_used":  "105",
		},
	}
	anyErrorInfo, err := anypb.New(errorInfo)
	if err != nil {
		log.Fatalf("failed to pack error info: %v", err)
	}

	badRequest := &errdetails.BadRequest{
		FieldViolations: []*errdetails.BadRequest_FieldViolation{
			{
				Field:       "username",
				Description: "username cannot contain special characters",
			},
		},
	}
	anyBadRequest, err := anypb.New(badRequest)
	if err != nil {
		log.Fatalf("failed to pack bad request: %v", err)
	}

	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(15 * time.Second),
	}
	anyRetryInfo, err := anypb.New(retryInfo)
	if err != nil {
		log.Fatalf("failed to pack retry info: %v", err)
	}

	st := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "invalid request payload",
		Details: []*anypb.Any{anyErrorInfo, anyBadRequest, anyRetryInfo},
	}

	data, err := proto.Marshal(st)
	if err != nil {
		log.Fatalf("failed to marshal status: %v", err)
	}

	var decoded status.Status
	if err := proto.Unmarshal(data, &decoded); err != nil {
		log.Fatalf("failed to unmarshal status: %v", err)
	}

	fmt.Printf("Status Code: %d\n", decoded.GetCode())
	fmt.Printf("Status Message: %s\n", decoded.GetMessage())
	fmt.Printf("Details Count: %d\n", len(decoded.GetDetails()))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260831171406-18b4a7587f8a"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func assert(condition bool, message string) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed: %s\n", message)
		os.Exit(1)
	}
}

func main() {
	// 1. status.Status creates and serializes an RPC status message with code and message
	st := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "invalid argument provided",
	}
	assert(st.GetCode() == int32(code.Code_INVALID_ARGUMENT), "status code should match INVALID_ARGUMENT")
	assert(st.GetMessage() == "invalid argument provided", "status message should match")

	data, err := proto.Marshal(st)
	assert(err == nil, "proto.Marshal(st) should succeed")
	assert(len(data) > 0, "marshaled status should not be empty")

	var unmarshaledStatus status.Status
	err = proto.Unmarshal(data, &unmarshaledStatus)
	assert(err == nil, "proto.Unmarshal should succeed")
	assert(unmarshaledStatus.GetCode() == int32(code.Code_INVALID_ARGUMENT), "unmarshaled status code must match")
	assert(unmarshaledStatus.GetMessage() == "invalid argument provided", "unmarshaled status message must match")

	// 2. status.Status packs and unpacks errdetails.ErrorInfo into Any details
	errorInfo := &errdetails.ErrorInfo{
		Reason: "RESOURCE_USAGE_LIMIT",
		Domain: "example.com",
		Metadata: map[string]string{
			"quota_limit": "100",
			"quota_used":  "105",
		},
	}
	anyErrorInfo, err := anypb.New(errorInfo)
	assert(err == nil, "anypb.New(errorInfo) should succeed")

	st.Details = append(st.Details, anyErrorInfo)
	assert(len(st.GetDetails()) == 1, "details count should be 1")

	unpackedErrorInfo := &errdetails.ErrorInfo{}
	err = anypb.UnmarshalTo(st.GetDetails()[0], unpackedErrorInfo, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling ErrorInfo Any detail should succeed")
	assert(unpackedErrorInfo.GetReason() == "RESOURCE_USAGE_LIMIT", "unpacked reason must match")
	assert(unpackedErrorInfo.GetDomain() == "example.com", "unpacked domain must match")
	assert(unpackedErrorInfo.GetMetadata()["quota_limit"] == "100", "metadata entry must match")

	// 3. status.Status packs and unpacks errdetails.BadRequest field violations into Any details
	badRequest := &errdetails.BadRequest{
		FieldViolations: []*errdetails.BadRequest_FieldViolation{
			{
				Field:       "username",
				Description: "username cannot contain special characters",
			},
			{
				Field:       "email",
				Description: "email format is invalid",
			},
		},
	}
	anyBadRequest, err := anypb.New(badRequest)
	assert(err == nil, "anypb.New(badRequest) should succeed")

	unpackedBadRequest := &errdetails.BadRequest{}
	err = anypb.UnmarshalTo(anyBadRequest, unpackedBadRequest, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling BadRequest Any detail should succeed")
	assert(len(unpackedBadRequest.GetFieldViolations()) == 2, "field violations length should be 2")
	assert(unpackedBadRequest.GetFieldViolations()[0].GetField() == "username", "field name should match")
	assert(unpackedBadRequest.GetFieldViolations()[1].GetDescription() == "email format is invalid", "description should match")

	// 4. status.Status packs and unpacks errdetails.RetryInfo with retry duration into Any details
	retryDelay := 15 * time.Second
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(retryDelay),
	}
	anyRetryInfo, err := anypb.New(retryInfo)
	assert(err == nil, "anypb.New(retryInfo) should succeed")

	unpackedRetryInfo := &errdetails.RetryInfo{}
	err = anypb.UnmarshalTo(anyRetryInfo, unpackedRetryInfo, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling RetryInfo Any detail should succeed")
	assert(unpackedRetryInfo.GetRetryDelay().AsDuration() == 15*time.Second, "retry delay duration should match")

	// 5. status.Status packs and unpacks errdetails.QuotaFailure and PreconditionFailure violations
	quotaFailure := &errdetails.QuotaFailure{
		Violations: []*errdetails.QuotaFailure_Violation{
			{
				Subject:     "project:12345",
				Description: "daily read request quota exhausted",
			},
		},
	}
	anyQuotaFailure, err := anypb.New(quotaFailure)
	assert(err == nil, "anypb.New(quotaFailure) should succeed")
	unpackedQuotaFailure := &errdetails.QuotaFailure{}
	err = anypb.UnmarshalTo(anyQuotaFailure, unpackedQuotaFailure, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling QuotaFailure should succeed")
	assert(unpackedQuotaFailure.GetViolations()[0].GetSubject() == "project:12345", "violation subject should match")

	precondFailure := &errdetails.PreconditionFailure{
		Violations: []*errdetails.PreconditionFailure_Violation{
			{
				Type:        "TOS",
				Subject:     "terms-of-service",
				Description: "Terms of service not accepted",
			},
		},
	}
	anyPrecondFailure, err := anypb.New(precondFailure)
	assert(err == nil, "anypb.New(precondFailure) should succeed")
	unpackedPrecondFailure := &errdetails.PreconditionFailure{}
	err = anypb.UnmarshalTo(anyPrecondFailure, unpackedPrecondFailure, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling PreconditionFailure should succeed")
	assert(unpackedPrecondFailure.GetViolations()[0].GetType() == "TOS", "violation type should match")

	// 6. status.Status packs and unpacks errdetails.DebugInfo and LocalizedMessage into Any details
	debugInfo := &errdetails.DebugInfo{
		StackEntries: []string{
			"handler.go:42 (ServeRPC)",
			"service.go:108 (ProcessRequest)",
		},
		Detail: "database lock timeout exceeded after 5000ms",
	}
	anyDebugInfo, err := anypb.New(debugInfo)
	assert(err == nil, "anypb.New(debugInfo) should succeed")
	unpackedDebugInfo := &errdetails.DebugInfo{}
	err = anypb.UnmarshalTo(anyDebugInfo, unpackedDebugInfo, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling DebugInfo should succeed")
	assert(len(unpackedDebugInfo.GetStackEntries()) == 2, "stack entries length should be 2")
	assert(unpackedDebugInfo.GetDetail() == "database lock timeout exceeded after 5000ms", "debug detail should match")

	localizedMsg := &errdetails.LocalizedMessage{
		Locale:  "en-US",
		Message: "The requested resource could not be found.",
	}
	anyLocalizedMsg, err := anypb.New(localizedMsg)
	assert(err == nil, "anypb.New(localizedMsg) should succeed")
	unpackedLocalizedMsg := &errdetails.LocalizedMessage{}
	err = anypb.UnmarshalTo(anyLocalizedMsg, unpackedLocalizedMsg, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling LocalizedMessage should succeed")
	assert(unpackedLocalizedMsg.GetLocale() == "en-US", "locale should match")
	assert(unpackedLocalizedMsg.GetMessage() == "The requested resource could not be found.", "message should match")

	// 7. status.Status packs and unpacks errdetails.Help links and ResourceInfo into Any details
	help := &errdetails.Help{
		Links: []*errdetails.Help_Link{
			{
				Description: "API Documentation",
				Url:         "https://example.com/docs/errors",
			},
		},
	}
	anyHelp, err := anypb.New(help)
	assert(err == nil, "anypb.New(help) should succeed")
	unpackedHelp := &errdetails.Help{}
	err = anypb.UnmarshalTo(anyHelp, unpackedHelp, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling Help should succeed")
	assert(unpackedHelp.GetLinks()[0].GetUrl() == "https://example.com/docs/errors", "help url should match")

	resourceInfo := &errdetails.ResourceInfo{
		ResourceType: "database/instance",
		ResourceName: "projects/example-p/instances/inst-1",
		Owner:        "service-admin",
		Description:  "Production database instance",
	}
	anyResourceInfo, err := anypb.New(resourceInfo)
	assert(err == nil, "anypb.New(resourceInfo) should succeed")
	unpackedResourceInfo := &errdetails.ResourceInfo{}
	err = anypb.UnmarshalTo(anyResourceInfo, unpackedResourceInfo, proto.UnmarshalOptions{})
	assert(err == nil, "unmarshaling ResourceInfo should succeed")
	assert(unpackedResourceInfo.GetResourceType() == "database/instance", "resource type should match")
	assert(unpackedResourceInfo.GetResourceName() == "projects/example-p/instances/inst-1", "resource name should match")

	// 8. code.Code defines standard RPC status codes corresponding to canonical status values
	assert(int32(code.Code_OK) == 0, "code.Code_OK must be 0")
	assert(int32(code.Code_CANCELLED) == 1, "code.Code_CANCELLED must be 1")
	assert(int32(code.Code_UNKNOWN) == 2, "code.Code_UNKNOWN must be 2")
	assert(int32(code.Code_INVALID_ARGUMENT) == 3, "code.Code_INVALID_ARGUMENT must be 3")
	assert(int32(code.Code_DEADLINE_EXCEEDED) == 4, "code.Code_DEADLINE_EXCEEDED must be 4")
	assert(int32(code.Code_NOT_FOUND) == 5, "code.Code_NOT_FOUND must be 5")
	assert(int32(code.Code_ALREADY_EXISTS) == 6, "code.Code_ALREADY_EXISTS must be 6")
	assert(int32(code.Code_PERMISSION_DENIED) == 7, "code.Code_PERMISSION_DENIED must be 7")
	assert(int32(code.Code_RESOURCE_EXHAUSTED) == 8, "code.Code_RESOURCE_EXHAUSTED must be 8")
	assert(int32(code.Code_FAILED_PRECONDITION) == 9, "code.Code_FAILED_PRECONDITION must be 9")
	assert(int32(code.Code_ABORTED) == 10, "code.Code_ABORTED must be 10")
	assert(int32(code.Code_OUT_OF_RANGE) == 11, "code.Code_OUT_OF_RANGE must be 11")
	assert(int32(code.Code_UNIMPLEMENTED) == 12, "code.Code_UNIMPLEMENTED must be 12")
	assert(int32(code.Code_INTERNAL) == 13, "code.Code_INTERNAL must be 13")
	assert(int32(code.Code_UNAVAILABLE) == 14, "code.Code_UNAVAILABLE must be 14")
	assert(int32(code.Code_DATA_LOSS) == 15, "code.Code_DATA_LOSS must be 15")
	assert(int32(code.Code_UNAUTHENTICATED) == 16, "code.Code_UNAUTHENTICATED must be 16")

	fmt.Println("All contract assertions passed successfully.")
}

오리진 시더

익명