CodeSampleX

Exemplo

google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Request

Amostra verificada para golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Request. O…

sha256:d3d3205f7ed8c14bf8cdf4531446c75b0250a6c1ae741795011e6d44c5df717f

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-03

Caso

HOW
Objetivo
verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Pacotes
Símbolos
  • google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request
Criado
2026-09-03T03:22:17Z

Contrato

  1. NewHTTPRequest initializes AttributeContext_Request with provided fields
  2. Getters return expected values for populated fields
  3. GetHeaders returns populated header map and reflects entries
  4. Timestamp, Reason, Auth, and Origin fields can be set and accessed
  5. Getters on nil *AttributeContext_Request return safe default zero values without panicking
  6. ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation
  7. Reset clears all fields of AttributeContext_Request to zero values
  8. Helper functions GetHeaderValue and FullURL work accurately

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • request.go
  • spec.json
  • test/contract.go

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/context/attribute_context.AttributeContext_Request in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request

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:6a5e04e7156c3864d45af2b2c45550cf685736f832e51fc65cc61b24bea5886c","contract":["NewHTTPRequest initializes AttributeContext_Request with provided fields","Getters return expected values for populated fields","GetHeaders returns populated header map and reflects entries","Timestamp, Reason, Auth, and Origin fields can be set and accessed","Getters on nil *AttributeContext_Request return safe default zero values without panicking","ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation","Reset clears all fields of AttributeContext_Request to zero values","Helper functions GetHeaderValue and FullURL work accurately"],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request"]},"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-20260825221802-da73d73af1c5"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5

require 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-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
request.go
package sample

import (
	"strings"

	"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
	"google.golang.org/protobuf/types/known/timestamppb"
)

// NewHTTPRequest constructs an AttributeContext_Request message with common HTTP attributes.
func NewHTTPRequest(id, method, scheme, host, path, query, protocol string, headers map[string]string, size int64) *attribute_context.AttributeContext_Request {
	return &attribute_context.AttributeContext_Request{
		Id:       id,
		Method:   method,
		Scheme:   scheme,
		Host:     host,
		Path:     path,
		Query:    query,
		Protocol: protocol,
		Headers:  headers,
		Size:     size,
	}
}

// GetHeaderValue retrieves a header value from AttributeContext_Request case-insensitively.
func GetHeaderValue(req *attribute_context.AttributeContext_Request, key string) (string, bool) {
	if req == nil || req.GetHeaders() == nil {
		return "", false
	}
	target := strings.ToLower(key)
	for k, v := range req.GetHeaders() {
		if strings.ToLower(k) == target {
			return v, true
		}
	}
	return "", false
}

// FullURL builds the complete URL string from Scheme, Host, Path, and Query.
func FullURL(req *attribute_context.AttributeContext_Request) string {
	if req == nil {
		return ""
	}
	var sb strings.Builder
	if req.GetScheme() != "" {
		sb.WriteString(req.GetScheme())
		sb.WriteString("://")
	}
	sb.WriteString(req.GetHost())
	sb.WriteString(req.GetPath())
	if req.GetQuery() != "" {
		sb.WriteString("?")
		sb.WriteString(req.GetQuery())
	}
	return sb.String()
}

// WithAuth attaches authentication attributes to an existing AttributeContext_Request.
func WithAuth(req *attribute_context.AttributeContext_Request, principal, presenter string) *attribute_context.AttributeContext_Request {
	if req == nil {
		return nil
	}
	req.Auth = &attribute_context.AttributeContext_Auth{
		Principal: principal,
		Presenter: presenter,
	}
	return req
}

// WithTimestamp attaches a timestamp to an existing AttributeContext_Request.
func WithTimestamp(req *attribute_context.AttributeContext_Request, ts *timestamppb.Timestamp) *attribute_context.AttributeContext_Request {
	if req == nil {
		return nil
	}
	req.Time = ts
	return req
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
	"google.golang.org/protobuf/types/known/timestamppb"
	"sample"
)

func main() {
	// Assertion 1: NewHTTPRequest initializes AttributeContext_Request with provided fields
	headers := map[string]string{
		"content-type": "application/json",
		"accept":       "application/json",
	}
	req := sample.NewHTTPRequest(
		"req-12345",
		"GET",
		"https",
		"example.com",
		"/api/v1/resource",
		"filter=active&limit=10",
		"HTTP/2.0",
		headers,
		1024,
	)
	if req == nil {
		fmt.Fprintf(os.Stderr, "expected non-nil AttributeContext_Request\n")
		os.Exit(1)
	}

	// Assertion 2: Getters return expected values for populated fields
	if req.GetId() != "req-12345" {
		fmt.Fprintf(os.Stderr, "expected Id 'req-12345', got %q\n", req.GetId())
		os.Exit(1)
	}
	if req.GetMethod() != "GET" {
		fmt.Fprintf(os.Stderr, "expected Method 'GET', got %q\n", req.GetMethod())
		os.Exit(1)
	}
	if req.GetScheme() != "https" {
		fmt.Fprintf(os.Stderr, "expected Scheme 'https', got %q\n", req.GetScheme())
		os.Exit(1)
	}
	if req.GetHost() != "example.com" {
		fmt.Fprintf(os.Stderr, "expected Host 'example.com', got %q\n", req.GetHost())
		os.Exit(1)
	}
	if req.GetPath() != "/api/v1/resource" {
		fmt.Fprintf(os.Stderr, "expected Path '/api/v1/resource', got %q\n", req.GetPath())
		os.Exit(1)
	}
	if req.GetQuery() != "filter=active&limit=10" {
		fmt.Fprintf(os.Stderr, "expected Query 'filter=active&limit=10', got %q\n", req.GetQuery())
		os.Exit(1)
	}
	if req.GetProtocol() != "HTTP/2.0" {
		fmt.Fprintf(os.Stderr, "expected Protocol 'HTTP/2.0', got %q\n", req.GetProtocol())
		os.Exit(1)
	}
	if req.GetSize() != 1024 {
		fmt.Fprintf(os.Stderr, "expected Size 1024, got %d\n", req.GetSize())
		os.Exit(1)
	}

	// Assertion 3: GetHeaders returns populated header map and reflects entries
	gotHeaders := req.GetHeaders()
	if len(gotHeaders) != 2 || gotHeaders["content-type"] != "application/json" || gotHeaders["accept"] != "application/json" {
		fmt.Fprintf(os.Stderr, "unexpected headers: %v\n", gotHeaders)
		os.Exit(1)
	}

	// Assertion 4: Timestamp, Reason, Auth, and Origin fields can be set and accessed
	ts := timestamppb.Now()
	sample.WithTimestamp(req, ts)
	sample.WithAuth(req, "test-principal", "test-presenter")
	req.Reason = "audit-check"
	req.Origin = "https://example.com"

	if req.GetTime() != ts {
		fmt.Fprintf(os.Stderr, "expected Time to match, got %v\n", req.GetTime())
		os.Exit(1)
	}
	if req.GetReason() != "audit-check" {
		fmt.Fprintf(os.Stderr, "expected Reason 'audit-check', got %q\n", req.GetReason())
		os.Exit(1)
	}
	if req.GetAuth() == nil || req.GetAuth().GetPrincipal() != "test-principal" || req.GetAuth().GetPresenter() != "test-presenter" {
		fmt.Fprintf(os.Stderr, "unexpected Auth value\n")
		os.Exit(1)
	}
	if req.GetOrigin() != "https://example.com" {
		fmt.Fprintf(os.Stderr, "expected Origin 'https://example.com', got %q\n", req.GetOrigin())
		os.Exit(1)
	}

	// Assertion 5: Getters on nil *AttributeContext_Request return safe default zero values without panicking
	var nilReq *attribute_context.AttributeContext_Request
	if nilReq.GetId() != "" || nilReq.GetMethod() != "" || nilReq.GetHeaders() != nil ||
		nilReq.GetPath() != "" || nilReq.GetHost() != "" || nilReq.GetScheme() != "" ||
		nilReq.GetQuery() != "" || nilReq.GetTime() != nil || nilReq.GetSize() != 0 ||
		nilReq.GetProtocol() != "" || nilReq.GetReason() != "" || nilReq.GetAuth() != nil ||
		nilReq.GetOrigin() != "" {
		fmt.Fprintf(os.Stderr, "nil receiver getters returned non-zero value\n")
		os.Exit(1)
	}

	// Assertion 6: ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation
	if req.ProtoReflect() == nil {
		fmt.Fprintf(os.Stderr, "expected non-nil ProtoReflect\n")
		os.Exit(1)
	}
	req.ProtoMessage()
	if req.String() == "" {
		fmt.Fprintf(os.Stderr, "expected non-empty String()\n")
		os.Exit(1)
	}

	// Assertion 7: Reset clears all fields of AttributeContext_Request to zero values
	req.Reset()
	if req.GetId() != "" || req.GetMethod() != "" || req.GetHeaders() != nil ||
		req.GetPath() != "" || req.GetHost() != "" || req.GetScheme() != "" ||
		req.GetQuery() != "" || req.GetTime() != nil || req.GetSize() != 0 ||
		req.GetProtocol() != "" || req.GetReason() != "" || req.GetAuth() != nil ||
		req.GetOrigin() != "" {
		fmt.Fprintf(os.Stderr, "Reset did not clear all fields\n")
		os.Exit(1)
	}

	// Assertion 8: Helper functions GetHeaderValue and FullURL work accurately
	testReq := sample.NewHTTPRequest("1", "POST", "http", "localhost", "/submit", "id=42", "HTTP/1.1", map[string]string{"X-Custom-Header": "custom-val"}, 512)
	val, ok := sample.GetHeaderValue(testReq, "x-custom-header")
	if !ok || val != "custom-val" {
		fmt.Fprintf(os.Stderr, "GetHeaderValue failed: val=%q ok=%v\n", val, ok)
		os.Exit(1)
	}
	_, notFound := sample.GetHeaderValue(testReq, "non-existent")
	if notFound {
		fmt.Fprintf(os.Stderr, "GetHeaderValue expected false for missing key\n")
		os.Exit(1)
	}
	fullURL := sample.FullURL(testReq)
	if fullURL != "http://localhost/submit?id=42" {
		fmt.Fprintf(os.Stderr, "FullURL expected 'http://localhost/submit?id=42', got %q\n", fullURL)
		os.Exit(1)
	}

	fmt.Println("All google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Request contract assertions passed.")
}

Seeder de origem

anônimo