CodeSampleX

샘플

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

검증된 샘플 — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.QuotaFailure_Violation. go 1.26 · linux alpine/x64 …

sha256:bc0f630b22058cd45c82fec8dbda1058e64cdd23af7235cfb9fe6ab7c8896355

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

검증 실행 환경

환경 컨트랙트 단계 실행일
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.QuotaFailure_Violation in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
패키지
심벌
  • google.golang.org/genproto/googleapis/rpc/errdetails.QuotaFailure_Violation
환경
go 1.26.6
생성일
2026-08-27T11:51:37Z

컨트랙트

  1. QuotaFailure_Violation struct initialized with Subject and Description retains field values
  2. GetSubject returns the configured subject string on valid instance and empty string on nil
  3. GetDescription returns the configured description string on valid instance and empty string on nil
  4. QuotaFailure aggregates QuotaFailure_Violation instances in its Violations slice
  5. QuotaFailure containing QuotaFailure_Violation instances roundtrips through protobuf wire format

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • quotafailure.go
  • spec.json
  • test/contract_test.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.QuotaFailure_Violation 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.QuotaFailure_Violation
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: esm
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:b247889a762175df77e0d60b8ab729a7bdca20fbffc61e729067e12f0b3fdbb0","contract":["QuotaFailure_Violation struct initialized with Subject and Description retains field values","GetSubject returns the configured subject string on valid instance and empty string on nil","GetDescription returns the configured description string on valid instance and empty string on nil","QuotaFailure aggregates QuotaFailure_Violation instances in its Violations slice","QuotaFailure containing QuotaFailure_Violation instances roundtrips through protobuf wire format"],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.QuotaFailure_Violation 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.QuotaFailure_Violation"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","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.QuotaFailure_Violation"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.36.5
)
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.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
quotafailure.go
package sample

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

// NewQuotaViolation creates a new QuotaFailure_Violation with the given subject and description.
func NewQuotaViolation(subject, description string) *errdetails.QuotaFailure_Violation {
	return &errdetails.QuotaFailure_Violation{
		Subject:     subject,
		Description: description,
	}
}

// NewQuotaFailure wraps multiple violations into a QuotaFailure error detail.
func NewQuotaFailure(violations ...*errdetails.QuotaFailure_Violation) *errdetails.QuotaFailure {
	return &errdetails.QuotaFailure{
		Violations: violations,
	}
}

// SerializeQuotaFailure marshals a QuotaFailure into protobuf wire bytes.
func SerializeQuotaFailure(qf *errdetails.QuotaFailure) ([]byte, error) {
	return proto.Marshal(qf)
}

// DeserializeQuotaFailure unmarshals protobuf wire bytes into a QuotaFailure.
func DeserializeQuotaFailure(data []byte) (*errdetails.QuotaFailure, error) {
	var qf errdetails.QuotaFailure
	if err := proto.Unmarshal(data, &qf); err != nil {
		return nil, err
	}
	return &qf, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.QuotaFailure_Violation 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.QuotaFailure_Violation"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "esm",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract_test.go
package test

import (
	"testing"

	"example.com/sample"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
)

func TestQuotaFailureViolationContract(t *testing.T) {
	// Direct struct initialization
	v := &errdetails.QuotaFailure_Violation{
		Subject:     "project:test-project-123",
		Description: "Daily API call quota exceeded for standard tier",
	}

	// Field access and getters
	if got := v.GetSubject(); got != "project:test-project-123" {
		t.Fatalf("unexpected Subject: got %q, want %q", got, "project:test-project-123")
	}
	if got := v.GetDescription(); got != "Daily API call quota exceeded for standard tier" {
		t.Fatalf("unexpected Description: got %q, want %q", got, "Daily API call quota exceeded for standard tier")
	}

	// Nil-safe getters
	var nilViolation *errdetails.QuotaFailure_Violation
	if nilViolation.GetSubject() != "" {
		t.Fatalf("nil violation GetSubject should return empty string")
	}
	if nilViolation.GetDescription() != "" {
		t.Fatalf("nil violation GetDescription should return empty string")
	}

	// Helper constructors
	helperViolation := sample.NewQuotaViolation("clientip:127.0.0.1", "Rate limit exceeded")
	if helperViolation.GetSubject() != "clientip:127.0.0.1" {
		t.Fatalf("unexpected helper Subject: got %q", helperViolation.GetSubject())
	}
	if helperViolation.GetDescription() != "Rate limit exceeded" {
		t.Fatalf("unexpected helper Description: got %q", helperViolation.GetDescription())
	}

	// Envelope aggregation
	qf := sample.NewQuotaFailure(v, helperViolation)
	if len(qf.GetViolations()) != 2 {
		t.Fatalf("expected 2 violations, got %d", len(qf.GetViolations()))
	}
	if qf.GetViolations()[0].GetSubject() != "project:test-project-123" {
		t.Fatalf("unexpected violation 0 subject: %s", qf.GetViolations()[0].GetSubject())
	}
	if qf.GetViolations()[1].GetSubject() != "clientip:127.0.0.1" {
		t.Fatalf("unexpected violation 1 subject: %s", qf.GetViolations()[1].GetSubject())
	}

	// Protobuf serialization round-trip
	bytes, err := sample.SerializeQuotaFailure(qf)
	if err != nil {
		t.Fatalf("SerializeQuotaFailure failed: %v", err)
	}

	restored, err := sample.DeserializeQuotaFailure(bytes)
	if err != nil {
		t.Fatalf("DeserializeQuotaFailure failed: %v", err)
	}

	if len(restored.GetViolations()) != 2 {
		t.Fatalf("expected 2 restored violations, got %d", len(restored.GetViolations()))
	}
	if restored.GetViolations()[0].GetDescription() != "Daily API call quota exceeded for standard tier" {
		t.Fatalf("unexpected restored violation 0 description: %s", restored.GetViolations()[0].GetDescription())
	}
	if restored.GetViolations()[1].GetDescription() != "Rate limit exceeded" {
		t.Fatalf("unexpected restored violation 1 description: %s", restored.GetViolations()[1].GetDescription())
	}
}

오리진 시더

익명