CodeSampleX

サンプル

google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: code.Code_UNAVAILABLE

検証済みサンプル — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: code.Code_UNAVAILABLE. go 1.26 · linux alpine/x64 · docker で…

sha256:555989af129d5d70a0d346ce2a9e029e3f0cfda28def3e464167a2063415b1ea

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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 google.golang.org/genproto/googleapis/rpc/code.Code_UNAVAILABLE in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
パッケージ
シンボル
  • google.golang.org/genproto/googleapis/rpc/code.Code_UNAVAILABLE
作成日
2026-08-27T11:15:42Z

コントラクト

  1. code.Code_UNAVAILABLE represents temporary service unavailability with enum value 14
  2. code.Code_UNAVAILABLE enum converts to string representation UNAVAILABLE and maps in Code_name and Code_value
  3. status.Status represents an RPC error status with code.Code_UNAVAILABLE and unmarshals successfully
  4. status.Status with code.Code_UNAVAILABLE encapsulates retry and error details describing service unavailability

ファイル

  • 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 google.golang.org/genproto/googleapis/rpc/code.Code_UNAVAILABLE 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/code.Code_UNAVAILABLE

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:655ce6991c788f18b14969d6956e1230ad2c83abc3fb1faa0b5967105b737f29","contract":["code.Code_UNAVAILABLE represents temporary service unavailability with enum value 14","code.Code_UNAVAILABLE enum converts to string representation UNAVAILABLE and maps in Code_name and Code_value","status.Status represents an RPC error status with code.Code_UNAVAILABLE and unmarshals successfully","status.Status with code.Code_UNAVAILABLE encapsulates retry and error details describing service unavailability"],"goal":"verify google.golang.org/genproto/googleapis/rpc/code.Code_UNAVAILABLE 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/code.Code_UNAVAILABLE"]},"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/code.Code_UNAVAILABLE"],"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() {
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(5 * 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_UNAVAILABLE),
		Message: "service temporarily unavailable, retry after backoff",
		Details: []*anypb.Any{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 (%s)\n", decoded.GetCode(), code.Code_name[decoded.GetCode()])
	fmt.Printf("Status Message: %s\n", decoded.GetMessage())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/code.Code_UNAVAILABLE 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/code.Code_UNAVAILABLE"
  ]
}
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. code.Code_UNAVAILABLE represents temporary service unavailability with enum value 14
	assert(code.Code_UNAVAILABLE == 14, "code.Code_UNAVAILABLE must have value 14")
	assert(int32(code.Code_UNAVAILABLE) == 14, "int32(code.Code_UNAVAILABLE) must be 14")

	// 2. code.Code_UNAVAILABLE enum converts to string representation UNAVAILABLE and maps in Code_name and Code_value
	assert(code.Code_UNAVAILABLE.String() == "UNAVAILABLE", "code.Code_UNAVAILABLE.String() must be UNAVAILABLE")
	assert(code.Code_name[int32(code.Code_UNAVAILABLE)] == "UNAVAILABLE", "code.Code_name[14] must be UNAVAILABLE")
	assert(code.Code_value["UNAVAILABLE"] == int32(code.Code_UNAVAILABLE), "code.Code_value[UNAVAILABLE] must match Code_UNAVAILABLE")

	// 3. status.Status represents an RPC error status with code.Code_UNAVAILABLE and unmarshals successfully
	st := &status.Status{
		Code:    int32(code.Code_UNAVAILABLE),
		Message: "service temporarily unavailable, please retry later",
	}
	assert(st.GetCode() == int32(code.Code_UNAVAILABLE), "status code must match Code_UNAVAILABLE")
	assert(st.GetMessage() == "service temporarily unavailable, please retry later", "status message must match")

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

	var decoded status.Status
	err = proto.Unmarshal(data, &decoded)
	assert(err == nil, "proto.Unmarshal(data) must succeed")
	assert(decoded.GetCode() == int32(code.Code_UNAVAILABLE), "decoded status code must match Code_UNAVAILABLE")
	assert(decoded.GetMessage() == "service temporarily unavailable, please retry later", "decoded message must match")

	// 4. status.Status with code.Code_UNAVAILABLE encapsulates retry and error details describing service unavailability
	retryInfo := &errdetails.RetryInfo{
		RetryDelay: durationpb.New(10 * time.Second),
	}
	anyRetry, err := anypb.New(retryInfo)
	assert(err == nil, "anypb.New(retryInfo) must succeed")

	errorInfo := &errdetails.ErrorInfo{
		Reason: "RATE_LIMIT_EXCEEDED",
		Domain: "api.example.com",
		Metadata: map[string]string{
			"retry_after": "10s",
		},
	}
	anyErrorInfo, err := anypb.New(errorInfo)
	assert(err == nil, "anypb.New(errorInfo) must succeed")

	st.Details = append(st.Details, anyRetry, anyErrorInfo)
	assert(len(st.GetDetails()) == 2, "details count must be 2")

	unpackedRetry := &errdetails.RetryInfo{}
	err = anypb.UnmarshalTo(st.GetDetails()[0], unpackedRetry, proto.UnmarshalOptions{})
	assert(err == nil, "anypb.UnmarshalTo retryInfo must succeed")
	assert(unpackedRetry.GetRetryDelay().GetSeconds() == 10, "retry delay seconds must match 10")

	unpackedInfo := &errdetails.ErrorInfo{}
	err = anypb.UnmarshalTo(st.GetDetails()[1], unpackedInfo, proto.UnmarshalOptions{})
	assert(err == nil, "anypb.UnmarshalTo errorInfo must succeed")
	assert(unpackedInfo.GetReason() == "RATE_LIMIT_EXCEEDED", "unpacked reason must match")
	assert(unpackedInfo.GetDomain() == "api.example.com", "unpacked domain must match")
	assert(unpackedInfo.GetMetadata()["retry_after"] == "10s", "metadata retry_after must match")

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

オリジンシーダー

匿名