CodeSampleX

Exemplo

google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.RetryInfo

Amostra verificada para golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.RetryInfo. O contrato rodou em go…

sha256:d43d71899d406ff6170b741f3ccd4cb3ff0b900221e87667c30a1e0d34b0d25b

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Pacotes
Símbolos
  • google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo
Criado
2026-08-27T11:57:22Z

Contrato

  1. RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately
  2. RetryInfo packs into anypb.Any and unpacks back successfully
  3. RetryInfo integrates into status.Status details and roundtrips through proto serialization
  4. RetryInfo handles nil RetryDelay safely returning nil
  5. RetryInfo message matches anypb.MessageIs type check

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo

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:8e2350702b52e0b6768d46e683a56bd82424abb19c113991a3a0cf6af0b4f4ab","contract":["RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately","RetryInfo packs into anypb.Any and unpacks back successfully","RetryInfo integrates into status.Status details and roundtrips through proto serialization","RetryInfo handles nil RetryDelay safely returning nil","RetryInfo message matches anypb.MessageIs type check"],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"]},"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-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.35.1
)
go.sum
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
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=
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() {
	// 1. Create a RetryInfo detail indicating a retry backoff duration
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(15 * time.Second),
	}

	// 2. Pack RetryInfo into Any protobuf message
	anyRetryInfo, err := anypb.New(retryInfo)
	if err != nil {
		log.Fatalf("failed to pack retry info: %v", err)
	}

	// 3. Attach RetryInfo Any message into standard RPC status
	rpcStatus := &status.Status{
		Code:    int32(code.Code_UNAVAILABLE),
		Message: "service temporarily unavailable, please retry later",
		Details: []*anypb.Any{anyRetryInfo},
	}

	// 4. Serialize Status to binary protobuf
	data, err := proto.Marshal(rpcStatus)
	if err != nil {
		log.Fatalf("failed to marshal status: %v", err)
	}

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

	for _, detail := range decoded.GetDetails() {
		if detail.MessageIs(&errdetails.RetryInfo{}) {
			unpacked := &errdetails.RetryInfo{}
			if err := detail.UnmarshalTo(unpacked); err != nil {
				log.Fatalf("failed to unpack detail: %v", err)
			}
			fmt.Printf("Retry delay: %v\n", unpacked.GetRetryDelay().AsDuration())
		}
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/errdetails.RetryInfo"
  ]
}
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. RetryInfo initializes with durationpb RetryDelay and retrieves duration accurately
	expectedDuration := 10 * time.Second
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(expectedDuration),
	}
	assert(retryInfo.GetRetryDelay() != nil, "RetryDelay should not be nil")
	assert(retryInfo.GetRetryDelay().GetSeconds() == 10, "RetryDelay seconds should be 10")
	assert(retryInfo.GetRetryDelay().GetNanos() == 0, "RetryDelay nanos should be 0")
	assert(retryInfo.GetRetryDelay().AsDuration() == expectedDuration, "RetryDelay AsDuration should match expectedDuration")

	// 2. RetryInfo packs into anypb.Any and unpacks back successfully
	anyMsg, err := anypb.New(retryInfo)
	assert(err == nil, "anypb.New(retryInfo) should succeed")
	assert(anyMsg != nil, "anyMsg should not be nil")

	unpacked := &errdetails.RetryInfo{}
	err = anypb.UnmarshalTo(anyMsg, unpacked, proto.UnmarshalOptions{})
	assert(err == nil, "UnmarshalTo should succeed")
	assert(unpacked.GetRetryDelay().AsDuration() == expectedDuration, "unpacked retry duration should match")

	// 3. RetryInfo integrates into status.Status details and roundtrips through proto serialization
	rpcStatus := &status.Status{
		Code:    int32(code.Code_UNAVAILABLE),
		Message: "service overloaded, please back off",
		Details: []*anypb.Any{anyMsg},
	}
	data, err := proto.Marshal(rpcStatus)
	assert(err == nil, "proto.Marshal should succeed")
	assert(len(data) > 0, "marshaled bytes should not be empty")

	var decodedStatus status.Status
	err = proto.Unmarshal(data, &decodedStatus)
	assert(err == nil, "proto.Unmarshal should succeed")
	assert(decodedStatus.GetCode() == int32(code.Code_UNAVAILABLE), "status code should match UNAVAILABLE")
	assert(len(decodedStatus.GetDetails()) == 1, "details count should be 1")

	// 4. RetryInfo handles nil RetryDelay safely returning nil
	nilRetryInfo := &errdetails.RetryInfo{}
	assert(nilRetryInfo.GetRetryDelay() == nil, "GetRetryDelay on empty RetryInfo should return nil")
	var typedNil *errdetails.RetryInfo
	assert(typedNil.GetRetryDelay() == nil, "GetRetryDelay on typed nil should return nil")

	// 5. RetryInfo message matches anypb.MessageIs type check
	assert(anyMsg.MessageIs(&errdetails.RetryInfo{}), "MessageIs should return true for RetryInfo")
	assert(!anyMsg.MessageIs(&errdetails.BadRequest{}), "MessageIs should return false for BadRequest")

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

Seeder de origem

anônimo