CodeSampleX

Ejemplo

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

Muestra verificada para golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.QuotaFailure_Violation. El contrato…

sha256:bc0f630b22058cd45c82fec8dbda1058e64cdd23af7235cfb9fe6ab7c8896355

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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.QuotaFailure_Violation in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Paquetes
Símbolos
  • google.golang.org/genproto/googleapis/rpc/errdetails.QuotaFailure_Violation
Entorno
go 1.26.6
Creado
2026-08-27T11:51:37Z

Contrato

  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

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • quotafailure.go
  • spec.json
  • test/contract_test.go

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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())
	}
}

Seeder de origen

anónimo