CodeSampleX

示例

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

已验证示例 — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.ResourceInfo. contract 在 go 1.26 · linux alpine/x64 …

sha256:177cf900f143e9336b8adf199d3539df476e050512ad96f6198abedbdd9546a3

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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/errdetails.ResourceInfo in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
包
符号
  • google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo
创建时间
2026-08-27T11:54:47Z

契约

  1. ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields
  2. Getters return safe empty string defaults when called on a nil ResourceInfo pointer
  3. ResourceInfo correctly serializes to and deserializes from protocol buffer binary format
  4. Reset clears all fields of a ResourceInfo instance to their zero values
  5. ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name

文件

  • 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/errdetails.ResourceInfo 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.ResourceInfo

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:0203997b94c29258593a12ddd9b006871087ad1e6e499b01aaf4612f65515d4d","contract":["ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields","Getters return safe empty string defaults when called on a nil ResourceInfo pointer","ResourceInfo correctly serializes to and deserializes from protocol buffer binary format","Reset clears all fields of a ResourceInfo instance to their zero values","ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name"],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo 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.ResourceInfo"]},"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.ResourceInfo"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	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-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.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"fmt"

	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/protobuf/proto"
)

// CreateResourceInfo creates a ResourceInfo instance with the given details.
func CreateResourceInfo(resourceType, resourceName, owner, description string) *errdetails.ResourceInfo {
	return &errdetails.ResourceInfo{
		ResourceType: resourceType,
		ResourceName: resourceName,
		Owner:        owner,
		Description:  description,
	}
}

// MarshalResourceInfo serializes a ResourceInfo proto message to binary.
func MarshalResourceInfo(info *errdetails.ResourceInfo) ([]byte, error) {
	return proto.Marshal(info)
}

// UnmarshalResourceInfo deserializes binary data into a ResourceInfo proto message.
func UnmarshalResourceInfo(data []byte) (*errdetails.ResourceInfo, error) {
	var info errdetails.ResourceInfo
	if err := proto.Unmarshal(data, &info); err != nil {
		return nil, err
	}
	return &info, nil
}

func main() {
	info := CreateResourceInfo(
		"type.googleapis.com/example.Database",
		"projects/example-project/databases/db-1",
		"admin@example.com",
		"Database resource quota exceeded",
	)

	fmt.Printf("Resource Type: %s\n", info.GetResourceType())
	fmt.Printf("Resource Name: %s\n", info.GetResourceName())
	fmt.Printf("Owner: %s\n", info.GetOwner())
	fmt.Printf("Description: %s\n", info.GetDescription())

	data, err := MarshalResourceInfo(info)
	if err != nil {
		panic(err)
	}

	decoded, err := UnmarshalResourceInfo(data)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Decoded Resource: %s\n", decoded.GetResourceName())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo 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.ResourceInfo"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
	// Assertion 1: ResourceInfo correctly stores and returns ResourceType, ResourceName, Owner, and Description fields
	res := &errdetails.ResourceInfo{
		ResourceType: "storage.googleapis.com/Bucket",
		ResourceName: "projects/sample-project/buckets/data-store",
		Owner:        "service-admin",
		Description:  "Sample bucket resource",
	}

	if got := res.GetResourceType(); got != "storage.googleapis.com/Bucket" {
		fmt.Fprintf(os.Stderr, "FAIL: GetResourceType mismatch: got %q, want %q\n", got, "storage.googleapis.com/Bucket")
		os.Exit(1)
	}
	if got := res.GetResourceName(); got != "projects/sample-project/buckets/data-store" {
		fmt.Fprintf(os.Stderr, "FAIL: GetResourceName mismatch: got %q, want %q\n", got, "projects/sample-project/buckets/data-store")
		os.Exit(1)
	}
	if got := res.GetOwner(); got != "service-admin" {
		fmt.Fprintf(os.Stderr, "FAIL: GetOwner mismatch: got %q, want %q\n", got, "service-admin")
		os.Exit(1)
	}
	if got := res.GetDescription(); got != "Sample bucket resource" {
		fmt.Fprintf(os.Stderr, "FAIL: GetDescription mismatch: got %q, want %q\n", got, "Sample bucket resource")
		os.Exit(1)
	}

	// Assertion 2: Getters return safe empty string defaults when called on a nil ResourceInfo pointer
	var nilRes *errdetails.ResourceInfo
	if got := nilRes.GetResourceType(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetResourceType expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetResourceName(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetResourceName expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetOwner(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetOwner expected empty string, got %q\n", got)
		os.Exit(1)
	}
	if got := nilRes.GetDescription(); got != "" {
		fmt.Fprintf(os.Stderr, "FAIL: nil GetDescription expected empty string, got %q\n", got)
		os.Exit(1)
	}

	// Assertion 3: ResourceInfo correctly serializes to and deserializes from protocol buffer binary format
	data, err := proto.Marshal(res)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal failed: %v\n", err)
		os.Exit(1)
	}
	if len(data) == 0 {
		fmt.Fprintf(os.Stderr, "FAIL: marshaled proto data is empty\n")
		os.Exit(1)
	}

	var unmarshaled errdetails.ResourceInfo
	if err := proto.Unmarshal(data, &unmarshaled); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal failed: %v\n", err)
		os.Exit(1)
	}
	if !proto.Equal(res, &unmarshaled) {
		fmt.Fprintf(os.Stderr, "FAIL: unmarshaled proto does not equal original\n")
		os.Exit(1)
	}

	// Assertion 4: Reset clears all fields of a ResourceInfo instance to their zero values
	copyRes := &errdetails.ResourceInfo{
		ResourceType: "compute.googleapis.com/Instance",
		ResourceName: "projects/sample-project/zones/us-central1-a/instances/worker-1",
		Owner:        "ops-team",
		Description:  "Compute engine instance",
	}
	copyRes.Reset()
	if copyRes.GetResourceType() != "" || copyRes.GetResourceName() != "" || copyRes.GetOwner() != "" || copyRes.GetDescription() != "" {
		fmt.Fprintf(os.Stderr, "FAIL: Reset failed to clear all fields\n")
		os.Exit(1)
	}

	// Assertion 5: ProtoReflect returns a valid Message descriptor matching google.rpc.ResourceInfo full name
	msg := res.ProtoReflect()
	descriptor := msg.Descriptor()
	if string(descriptor.FullName()) != "google.rpc.ResourceInfo" {
		fmt.Fprintf(os.Stderr, "FAIL: Descriptor FullName mismatch: got %q, want %q\n", descriptor.FullName(), "google.rpc.ResourceInfo")
		os.Exit(1)
	}
	resTypeField := descriptor.Fields().ByName(protoreflect.Name("resource_type"))
	if resTypeField == nil {
		fmt.Fprintf(os.Stderr, "FAIL: field descriptor for resource_type not found\n")
		os.Exit(1)
	}

	fmt.Println("PASS: google.golang.org/genproto/googleapis/rpc/errdetails.ResourceInfo contract verified")
}

原始种子者

匿名