CodeSampleX

샘플

google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5: monitoredres.MonitoredResourceDescriptor

검증된 샘플 — golang google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5: monitoredres.MonitoredResourceDescriptor. go 1.26 · linux…

sha256:76aa15884396b459b1191d77bb6550a3ef64384aac11e81b6b0476333e1e8dda

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

케이스

HOW
목표
verify monitoredres.MonitoredResourceDescriptor in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5
패키지
심벌
  • monitoredres.MonitoredResourceDescriptor
생성일
2026-09-05T12:27:58Z

컨트랙트

  1. MonitoredResourceDescriptor struct fields and getter methods return configured attributes including Name, Type, DisplayName, Description, LaunchStage, and Labels
  2. Nil safety — GetName, GetType, GetDisplayName, GetDescription, GetLaunchStage, and GetLabels on nil *MonitoredResourceDescriptor return zero values without panicking
  3. Protobuf binary serialization and deserialization preserves MonitoredResourceDescriptor fields exactly
  4. Protobuf JSON serialization and deserialization preserves MonitoredResourceDescriptor structure and values
  5. Nested LabelDescriptor within MonitoredResourceDescriptor correctly specifies label schema
  6. Reset clears MonitoredResourceDescriptor fields back to zero default 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 monitoredres.MonitoredResourceDescriptor in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5
Demonstrate these symbols/APIs:
  - monitoredres.MonitoredResourceDescriptor

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:2fdccd3211a1e33f19e85fbf0576083dc708c8eba78457d09d37891beaa9f30c","contract":["MonitoredResourceDescriptor struct fields and getter methods return configured attributes including Name, Type, DisplayName, Description, LaunchStage, and Labels","Nil safety — GetName, GetType, GetDisplayName, GetDescription, GetLaunchStage, and GetLabels on nil *MonitoredResourceDescriptor return zero values without panicking","Protobuf binary serialization and deserialization preserves MonitoredResourceDescriptor fields exactly","Protobuf JSON serialization and deserialization preserves MonitoredResourceDescriptor structure and values","Nested LabelDescriptor within MonitoredResourceDescriptor correctly specifies label schema","Reset clears MonitoredResourceDescriptor fields back to zero default values"],"goal":"verify monitoredres.MonitoredResourceDescriptor in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"symbols":["monitoredres.MonitoredResourceDescriptor"]},"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/api@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5","symbols":["monitoredres.MonitoredResourceDescriptor"],"verifierAdapter":"golang@1"}
go.mod
module example.com/monitoredres

go 1.25.0

require (
	google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5
	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/api v0.0.0-20260825221802-da73d73af1c5 h1:izFU9hz7aeLI/Mi1J0991ae+xcwRLr7hTqWnB/9aIIU=
google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5/go.mod h1:3LhxRw4YYkf+ylAfgaY9JlVLFKhokkCV8duhLLe7+t0=
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/api"
	"google.golang.org/genproto/googleapis/api/label"
	"google.golang.org/genproto/googleapis/api/monitoredres"
	"google.golang.org/protobuf/encoding/protojson"
	"google.golang.org/protobuf/proto"
)

func main() {
	descriptor := &monitoredres.MonitoredResourceDescriptor{
		Name:        "projects/example-project/monitoredResourceDescriptors/custom_gateway",
		Type:        "custom_gateway",
		DisplayName: "Custom API Gateway",
		Description: "A custom monitored resource representing an API gateway instance",
		LaunchStage: api.LaunchStage_GA,
		Labels: []*label.LabelDescriptor{
			{
				Key:         "gateway_id",
				ValueType:   label.LabelDescriptor_STRING,
				Description: "Identifier for the gateway instance",
			},
			{
				Key:         "region",
				ValueType:   label.LabelDescriptor_STRING,
				Description: "Deployment region of the gateway",
			},
		},
	}

	fmt.Printf("Resource Type: %s\n", descriptor.GetType())
	fmt.Printf("Display Name: %s\n", descriptor.GetDisplayName())
	fmt.Printf("Launch Stage: %s\n", descriptor.GetLaunchStage().String())
	fmt.Printf("Configured Labels: %d\n", len(descriptor.GetLabels()))

	jsonBytes, err := protojson.Marshal(descriptor)
	if err != nil {
		fmt.Printf("JSON marshal error: %v\n", err)
		return
	}
	fmt.Printf("Serialized JSON: %s\n", string(jsonBytes))

	wireBytes, err := proto.Marshal(descriptor)
	if err != nil {
		fmt.Printf("Binary marshal error: %v\n", err)
		return
	}
	fmt.Printf("Serialized binary size: %d bytes\n", len(wireBytes))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify monitoredres.MonitoredResourceDescriptor in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260825221802-da73d73af1c5"
  ],
  "symbols": [
    "monitoredres.MonitoredResourceDescriptor"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/api"
	"google.golang.org/genproto/googleapis/api/label"
	"google.golang.org/genproto/googleapis/api/monitoredres"
	"google.golang.org/protobuf/encoding/protojson"
	"google.golang.org/protobuf/proto"
)

func main() {
	// Assertion 1: MonitoredResourceDescriptor struct fields and getter methods return configured attributes including Name, Type, DisplayName, Description, LaunchStage, and Labels
	{
		desc := &monitoredres.MonitoredResourceDescriptor{
			Name:        "projects/example-project/monitoredResourceDescriptors/custom_server",
			Type:        "custom_server",
			DisplayName: "Custom Server Instance",
			Description: "Monitored resource for custom server instances",
			LaunchStage: api.LaunchStage_GA,
			Labels: []*label.LabelDescriptor{
				{
					Key:         "server_id",
					ValueType:   label.LabelDescriptor_STRING,
					Description: "Unique server instance ID",
				},
			},
		}

		if desc.GetName() != "projects/example-project/monitoredResourceDescriptors/custom_server" {
			fmt.Fprintf(os.Stderr, "FAIL: GetName() mismatch: got %q\n", desc.GetName())
			os.Exit(1)
		}
		if desc.GetType() != "custom_server" {
			fmt.Fprintf(os.Stderr, "FAIL: GetType() mismatch: got %q\n", desc.GetType())
			os.Exit(1)
		}
		if desc.GetDisplayName() != "Custom Server Instance" {
			fmt.Fprintf(os.Stderr, "FAIL: GetDisplayName() mismatch: got %q\n", desc.GetDisplayName())
			os.Exit(1)
		}
		if desc.GetDescription() != "Monitored resource for custom server instances" {
			fmt.Fprintf(os.Stderr, "FAIL: GetDescription() mismatch: got %q\n", desc.GetDescription())
			os.Exit(1)
		}
		if desc.GetLaunchStage() != api.LaunchStage_GA {
			fmt.Fprintf(os.Stderr, "FAIL: GetLaunchStage() mismatch: got %v\n", desc.GetLaunchStage())
			os.Exit(1)
		}
		if len(desc.GetLabels()) != 1 || desc.GetLabels()[0].GetKey() != "server_id" {
			fmt.Fprintf(os.Stderr, "FAIL: GetLabels() mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 2: Nil safety — GetName, GetType, GetDisplayName, GetDescription, GetLaunchStage, and GetLabels on nil *MonitoredResourceDescriptor return zero values without panicking
	{
		var nilDesc *monitoredres.MonitoredResourceDescriptor
		if nilDesc.GetName() != "" {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetName() expected empty string, got %q\n", nilDesc.GetName())
			os.Exit(1)
		}
		if nilDesc.GetType() != "" {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetType() expected empty string, got %q\n", nilDesc.GetType())
			os.Exit(1)
		}
		if nilDesc.GetDisplayName() != "" {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetDisplayName() expected empty string, got %q\n", nilDesc.GetDisplayName())
			os.Exit(1)
		}
		if nilDesc.GetDescription() != "" {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetDescription() expected empty string, got %q\n", nilDesc.GetDescription())
			os.Exit(1)
		}
		if nilDesc.GetLaunchStage() != api.LaunchStage_LAUNCH_STAGE_UNSPECIFIED {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetLaunchStage() expected LAUNCH_STAGE_UNSPECIFIED, got %v\n", nilDesc.GetLaunchStage())
			os.Exit(1)
		}
		if nilDesc.GetLabels() != nil {
			fmt.Fprintf(os.Stderr, "FAIL: nil GetLabels() expected nil, got %v\n", nilDesc.GetLabels())
			os.Exit(1)
		}
	}

	// Assertion 3: Protobuf binary serialization and deserialization preserves MonitoredResourceDescriptor fields exactly
	{
		orig := &monitoredres.MonitoredResourceDescriptor{
			Name:        "projects/example-project/monitoredResourceDescriptors/database_cluster",
			Type:        "database_cluster",
			DisplayName: "Database Cluster",
			Description: "High-availability database cluster",
			LaunchStage: api.LaunchStage_BETA,
			Labels: []*label.LabelDescriptor{
				{
					Key:         "cluster_name",
					ValueType:   label.LabelDescriptor_STRING,
					Description: "Database cluster identifier",
				},
			},
		}

		wire, err := proto.Marshal(orig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: proto.Marshal failed: %v\n", err)
			os.Exit(1)
		}

		decoded := &monitoredres.MonitoredResourceDescriptor{}
		if err := proto.Unmarshal(wire, decoded); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: proto.Unmarshal failed: %v\n", err)
			os.Exit(1)
		}

		if !proto.Equal(orig, decoded) {
			fmt.Fprintf(os.Stderr, "FAIL: decoded proto message does not equal original\n")
			os.Exit(1)
		}
		if decoded.GetType() != orig.GetType() || decoded.GetDisplayName() != orig.GetDisplayName() || decoded.GetLaunchStage() != orig.GetLaunchStage() {
			fmt.Fprintf(os.Stderr, "FAIL: decoded fields mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 4: Protobuf JSON serialization and deserialization preserves MonitoredResourceDescriptor structure and values
	{
		orig := &monitoredres.MonitoredResourceDescriptor{
			Name:        "projects/example-project/monitoredResourceDescriptors/queue_worker",
			Type:        "queue_worker",
			DisplayName: "Queue Worker",
			Description: "Background job queue worker instance",
			LaunchStage: api.LaunchStage_GA,
		}

		jsonBytes, err := protojson.Marshal(orig)
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: protojson.Marshal failed: %v\n", err)
			os.Exit(1)
		}

		unmarshaled := &monitoredres.MonitoredResourceDescriptor{}
		if err := protojson.Unmarshal(jsonBytes, unmarshaled); err != nil {
			fmt.Fprintf(os.Stderr, "FAIL: protojson.Unmarshal failed: %v\n", err)
			os.Exit(1)
		}

		if unmarshaled.GetType() != "queue_worker" ||
			unmarshaled.GetName() != "projects/example-project/monitoredResourceDescriptors/queue_worker" ||
			unmarshaled.GetDisplayName() != "Queue Worker" ||
			unmarshaled.GetLaunchStage() != api.LaunchStage_GA {
			fmt.Fprintf(os.Stderr, "FAIL: protojson unmarshaled content mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 5: Nested LabelDescriptor within MonitoredResourceDescriptor correctly specifies label schema
	{
		desc := &monitoredres.MonitoredResourceDescriptor{
			Type: "storage_bucket",
			Labels: []*label.LabelDescriptor{
				{
					Key:         "bucket_id",
					ValueType:   label.LabelDescriptor_STRING,
					Description: "The bucket name or ID",
				},
				{
					Key:         "retention_days",
					ValueType:   label.LabelDescriptor_INT64,
					Description: "Retention period in days",
				},
			},
		}

		if len(desc.GetLabels()) != 2 {
			fmt.Fprintf(os.Stderr, "FAIL: expected 2 labels, got %d\n", len(desc.GetLabels()))
			os.Exit(1)
		}
		if desc.GetLabels()[0].GetKey() != "bucket_id" || desc.GetLabels()[0].GetValueType() != label.LabelDescriptor_STRING {
			fmt.Fprintf(os.Stderr, "FAIL: label 0 mismatch\n")
			os.Exit(1)
		}
		if desc.GetLabels()[1].GetKey() != "retention_days" || desc.GetLabels()[1].GetValueType() != label.LabelDescriptor_INT64 {
			fmt.Fprintf(os.Stderr, "FAIL: label 1 mismatch\n")
			os.Exit(1)
		}
	}

	// Assertion 6: Reset clears MonitoredResourceDescriptor fields back to zero default values
	{
		desc := &monitoredres.MonitoredResourceDescriptor{
			Name:        "projects/example-project/monitoredResourceDescriptors/test_resource",
			Type:        "test_resource",
			DisplayName: "Test Resource",
			Description: "Resource description",
			LaunchStage: api.LaunchStage_GA,
		}

		desc.Reset()
		if desc.GetName() != "" || desc.GetType() != "" || desc.GetDisplayName() != "" || desc.GetDescription() != "" {
			fmt.Fprintf(os.Stderr, "FAIL: expected empty string fields after Reset()\n")
			os.Exit(1)
		}
		if desc.GetLaunchStage() != api.LaunchStage_LAUNCH_STAGE_UNSPECIFIED {
			fmt.Fprintf(os.Stderr, "FAIL: expected LAUNCH_STAGE_UNSPECIFIED after Reset(), got %v\n", desc.GetLaunchStage())
			os.Exit(1)
		}
	}

	fmt.Println("PASS: monitoredres.MonitoredResourceDescriptor contract passed")
}

오리진 시더

익명