サンプル
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4: attribute_context.AttributeContext
検証済みサンプル — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4: attribute_context.AttributeContext. go 1.26 · linux…
sha256:80c3847c259f5cdf075a620ec042a4788fe276edcbdfa13fd83742e316b52a71
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
go linux 24 · ubuntu · glibc 2.39 x64 go go 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-01 |
ケース
HOW- ゴール
- verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
- シンボル
-
- google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext
- 環境
- go
- 作成日
- 2026-09-01T10:34:34Z
コントラクト
- AttributeContext fields Request, Response, Origin, Source, Destination, and Resource store structured RPC metadata accessible via getters.
- AttributeContext and its nested fields return safe nil or empty values when called on nil receivers.
- AttributeContext serializes to and deserializes from protocol buffer binary format preserving nested Request, Response, and Peer details.
- AttributeContext.Reset clears all fields and resets the message back to zero state.
- AttributeContext_Request stores Method, Path, Host, Headers, and Auth metadata accurately.
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract_test.go
ソース
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 in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4
Demonstrate these symbols/APIs:
- google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext
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.
{"case":{"caseId":"case:sha256:4ddaed5377c7895fd95329d32c7c309f3cfcf97fb7b45ed294097a4f00f820fa","contract":["AttributeContext fields Request, Response, Origin, Source, Destination, and Resource store structured RPC metadata accessible via getters.","AttributeContext and its nested fields return safe nil or empty values when called on nil receivers.","AttributeContext serializes to and deserializes from protocol buffer binary format preserving nested Request, Response, and Peer details.","AttributeContext.Reset clears all fields and resets the message back to zero state.","AttributeContext_Request stores Method, Path, Host, Headers, and Auth metadata accurately."],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4","symbols":["google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"],"verifierAdapter":"golang@1"}
module example.com/attributecontext
go 1.25.0
require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4
google.golang.org/protobuf v1.36.12
)
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-20260427160629-7cedc36a6bc4 h1:tEkOQcXgF6dH1G+MVKZrfpYvozGrzb91k6ha7jireSM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package main
import (
"fmt"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
"google.golang.org/protobuf/proto"
)
func main() {
attr := &attribute_context.AttributeContext{
Origin: &attribute_context.AttributeContext_Peer{
Ip: "192.0.2.1",
Port: 8080,
},
Request: &attribute_context.AttributeContext_Request{
Id: "req-12345",
Method: "POST",
Path: "/v1/resources",
Host: "example.com",
Scheme: "https",
Headers: map[string]string{
"content-type": "application/json",
},
Auth: &attribute_context.AttributeContext_Auth{
Principal: "user-service@example.com",
},
},
Response: &attribute_context.AttributeContext_Response{
Code: 200,
Size: 512,
},
Resource: &attribute_context.AttributeContext_Resource{
Service: "resource-service",
Name: "items",
Type: "type.googleapis.com/example.Item",
},
}
data, err := proto.Marshal(attr)
if err != nil {
panic(err)
}
var decoded attribute_context.AttributeContext
if err := proto.Unmarshal(data, &decoded); err != nil {
panic(err)
}
fmt.Printf("Request Method: %s\n", decoded.GetRequest().GetMethod())
fmt.Printf("Request Path: %s\n", decoded.GetRequest().GetPath())
fmt.Printf("Origin IP: %s\n", decoded.GetOrigin().GetIp())
fmt.Printf("Response Code: %d\n", decoded.GetResponse().GetCode())
}
{
"schemaVersion": 1,
"goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260427160629-7cedc36a6bc4"
],
"symbols": [
"google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext"
]
}
package test
import (
"testing"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
"google.golang.org/protobuf/proto"
)
func TestAttributeContextFieldsAndGetters(t *testing.T) {
req := &attribute_context.AttributeContext_Request{
Id: "req-101",
Method: "GET",
Path: "/api/items",
Host: "example.com",
Scheme: "https",
}
resp := &attribute_context.AttributeContext_Response{
Code: 200,
Size: 1024,
}
origin := &attribute_context.AttributeContext_Peer{
Ip: "192.0.2.1",
Port: 8080,
}
source := &attribute_context.AttributeContext_Peer{
Ip: "10.0.0.1",
Port: 443,
}
dest := &attribute_context.AttributeContext_Peer{
Ip: "10.0.0.2",
Port: 8443,
}
resource := &attribute_context.AttributeContext_Resource{
Service: "catalog-service",
Name: "catalog-item-1",
Type: "type.googleapis.com/example.CatalogItem",
}
ctx := &attribute_context.AttributeContext{
Origin: origin,
Source: source,
Destination: dest,
Request: req,
Response: resp,
Resource: resource,
}
if got := ctx.GetOrigin().GetIp(); got != "192.0.2.1" {
t.Errorf("GetOrigin().GetIp() = %q, want %q", got, "192.0.2.1")
}
if got := ctx.GetSource().GetIp(); got != "10.0.0.1" {
t.Errorf("GetSource().GetIp() = %q, want %q", got, "10.0.0.1")
}
if got := ctx.GetDestination().GetPort(); got != 8443 {
t.Errorf("GetDestination().GetPort() = %d, want 8443", got)
}
if got := ctx.GetRequest().GetMethod(); got != "GET" {
t.Errorf("GetRequest().GetMethod() = %q, want %q", got, "GET")
}
if got := ctx.GetResponse().GetCode(); got != 200 {
t.Errorf("GetResponse().GetCode() = %d, want 200", got)
}
if got := ctx.GetResource().GetService(); got != "catalog-service" {
t.Errorf("GetResource().GetService() = %q, want %q", got, "catalog-service")
}
}
func TestAttributeContextNilSafeGetters(t *testing.T) {
var nilCtx *attribute_context.AttributeContext
if nilCtx.GetOrigin() != nil {
t.Errorf("nilCtx.GetOrigin() expected nil, got %v", nilCtx.GetOrigin())
}
if nilCtx.GetSource() != nil {
t.Errorf("nilCtx.GetSource() expected nil, got %v", nilCtx.GetSource())
}
if nilCtx.GetDestination() != nil {
t.Errorf("nilCtx.GetDestination() expected nil, got %v", nilCtx.GetDestination())
}
if nilCtx.GetRequest() != nil {
t.Errorf("nilCtx.GetRequest() expected nil, got %v", nilCtx.GetRequest())
}
if nilCtx.GetResponse() != nil {
t.Errorf("nilCtx.GetResponse() expected nil, got %v", nilCtx.GetResponse())
}
if nilCtx.GetResource() != nil {
t.Errorf("nilCtx.GetResource() expected nil, got %v", nilCtx.GetResource())
}
if nilCtx.GetApi() != nil {
t.Errorf("nilCtx.GetApi() expected nil, got %v", nilCtx.GetApi())
}
var nilReq *attribute_context.AttributeContext_Request
if got := nilReq.GetId(); got != "" {
t.Errorf("nilReq.GetId() = %q, want empty string", got)
}
if got := nilReq.GetMethod(); got != "" {
t.Errorf("nilReq.GetMethod() = %q, want empty string", got)
}
if nilReq.GetHeaders() != nil {
t.Errorf("nilReq.GetHeaders() expected nil, got %v", nilReq.GetHeaders())
}
if nilReq.GetAuth() != nil {
t.Errorf("nilReq.GetAuth() expected nil, got %v", nilReq.GetAuth())
}
}
func TestAttributeContextProtoSerialization(t *testing.T) {
original := &attribute_context.AttributeContext{
Origin: &attribute_context.AttributeContext_Peer{
Ip: "198.51.100.1",
Port: 9000,
},
Request: &attribute_context.AttributeContext_Request{
Id: "req-roundtrip",
Method: "PUT",
Path: "/v1/records/42",
Host: "example.com",
Scheme: "https",
},
Response: &attribute_context.AttributeContext_Response{
Code: 204,
},
}
data, err := proto.Marshal(original)
if err != nil {
t.Fatalf("proto.Marshal failed: %v", err)
}
var decoded attribute_context.AttributeContext
if err := proto.Unmarshal(data, &decoded); err != nil {
t.Fatalf("proto.Unmarshal failed: %v", err)
}
if decoded.GetRequest().GetId() != original.GetRequest().GetId() {
t.Errorf("decoded Request.Id = %q, want %q", decoded.GetRequest().GetId(), original.GetRequest().GetId())
}
if decoded.GetRequest().GetMethod() != original.GetRequest().GetMethod() {
t.Errorf("decoded Request.Method = %q, want %q", decoded.GetRequest().GetMethod(), original.GetRequest().GetMethod())
}
if decoded.GetOrigin().GetIp() != original.GetOrigin().GetIp() {
t.Errorf("decoded Origin.Ip = %q, want %q", decoded.GetOrigin().GetIp(), original.GetOrigin().GetIp())
}
if decoded.GetResponse().GetCode() != original.GetResponse().GetCode() {
t.Errorf("decoded Response.Code = %d, want %d", decoded.GetResponse().GetCode(), original.GetResponse().GetCode())
}
}
func TestAttributeContextReset(t *testing.T) {
ctx := &attribute_context.AttributeContext{
Request: &attribute_context.AttributeContext_Request{
Id: "req-to-reset",
Method: "DELETE",
},
Response: &attribute_context.AttributeContext_Response{
Code: 200,
},
}
ctx.Reset()
if ctx.GetRequest() != nil {
t.Errorf("Reset() did not clear Request: got %v", ctx.GetRequest())
}
if ctx.GetResponse() != nil {
t.Errorf("Reset() did not clear Response: got %v", ctx.GetResponse())
}
}
func TestAttributeContextRequestMetadata(t *testing.T) {
req := &attribute_context.AttributeContext_Request{
Id: "req-meta",
Method: "POST",
Path: "/api/v2/orders",
Host: "order.example.com",
Headers: map[string]string{
"content-type": "application/json",
"x-api-key": "test-key",
},
Auth: &attribute_context.AttributeContext_Auth{
Principal: "service-account@example.com",
Audiences: []string{"order.example.com"},
},
}
if got := req.GetMethod(); got != "POST" {
t.Errorf("GetMethod() = %q, want %q", got, "POST")
}
if got := req.GetPath(); got != "/api/v2/orders" {
t.Errorf("GetPath() = %q, want %q", got, "/api/v2/orders")
}
if got := req.GetHost(); got != "order.example.com" {
t.Errorf("GetHost() = %q, want %q", got, "order.example.com")
}
if got := req.GetHeaders()["content-type"]; got != "application/json" {
t.Errorf("Headers[content-type] = %q, want application/json", got)
}
if got := req.GetAuth().GetPrincipal(); got != "service-account@example.com" {
t.Errorf("GetAuth().GetPrincipal() = %q, want service-account@example.com", got)
}
}
オリジンシーダー
匿名