Пример
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Response
Проверенный пример — golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: attribute_context.AttributeContext_Response.…
sha256:c1bef6ce2549ea7f37f6de3d42f244b32a19f7771198d8013d4c87f9ae9969a9
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 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-03 |
Кейс
HOW- Цель
- verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Response in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
- Символы
-
- google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Response
- Создан
- 2026-09-03T05:03:07Z
Контракт
- NewHTTPResponse initializes AttributeContext_Response with code, size, headers, time, and latency
- AttributeContext_Response getters return expected values for code, size, and headers
- GetTime returns timestamp and GetBackendLatency returns duration
- Getters on nil *AttributeContext_Response return safe default zero values without panicking
- AttributeContext_Response ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation
- AttributeContext_Response Reset clears all fields to zero values
- Helper functions GetHeaderValue, LatencyMilliseconds, and IsSuccess operate correctly
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.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_Response 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_Response
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:3ab8643087cb6bfd1244606a1999b146833a27c2655eab2af2c594962f7125fa","contract":["NewHTTPResponse initializes AttributeContext_Response with code, size, headers, time, and latency","AttributeContext_Response getters return expected values for code, size, and headers","GetTime returns timestamp and GetBackendLatency returns duration","Getters on nil *AttributeContext_Response return safe default zero values without panicking","AttributeContext_Response ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation","AttributeContext_Response Reset clears all fields to zero values","Helper functions GetHeaderValue, LatencyMilliseconds, and IsSuccess operate correctly"],"goal":"verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Response 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_Response"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","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_Response"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5
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-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=
package sample
import (
"strings"
"time"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// NewHTTPResponse constructs an AttributeContext_Response message.
func NewHTTPResponse(code, size int64, headers map[string]string, respTime time.Time, latency time.Duration) *attribute_context.AttributeContext_Response {
resp := &attribute_context.AttributeContext_Response{
Code: code,
Size: size,
Headers: headers,
}
if !respTime.IsZero() {
resp.Time = timestamppb.New(respTime)
}
if latency > 0 {
resp.BackendLatency = durationpb.New(latency)
}
return resp
}
// GetHeaderValue retrieves a header value from AttributeContext_Response case-insensitively.
func GetHeaderValue(resp *attribute_context.AttributeContext_Response, key string) (string, bool) {
if resp == nil || resp.GetHeaders() == nil {
return "", false
}
for k, v := range resp.GetHeaders() {
if strings.EqualFold(k, key) {
return v, true
}
}
return "", false
}
// LatencyMilliseconds returns the backend latency in milliseconds, or 0 if unset or invalid.
func LatencyMilliseconds(resp *attribute_context.AttributeContext_Response) int64 {
if resp == nil || resp.GetBackendLatency() == nil {
return 0
}
return resp.GetBackendLatency().AsDuration().Milliseconds()
}
// IsSuccess returns true if the response code is in the 2xx range.
func IsSuccess(resp *attribute_context.AttributeContext_Response) bool {
if resp == nil {
return false
}
return resp.GetCode() >= 200 && resp.GetCode() < 300
}
{
"schemaVersion": 1,
"goal": "verify google.golang.org/genproto/googleapis/rpc/context/attribute_context.AttributeContext_Response 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_Response"
]
}
package main
import (
"fmt"
"os"
"strings"
"time"
"google.golang.org/genproto/googleapis/rpc/context/attribute_context"
"sample"
)
func main() {
if err := runTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All AttributeContext_Response contract tests passed successfully.")
}
func runTests() error {
now := time.Date(2026, 9, 3, 12, 0, 0, 0, time.UTC)
latency := 150 * time.Millisecond
headers := map[string]string{
"content-type": "application/json",
"server": "envoy",
}
// 1. NewHTTPResponse initializes AttributeContext_Response with code, size, headers, time, and latency
resp := sample.NewHTTPResponse(200, 1024, headers, now, latency)
if resp == nil {
return fmt.Errorf("expected non-nil AttributeContext_Response")
}
// 2. AttributeContext_Response getters return expected values for code, size, and headers
if got := resp.GetCode(); got != 200 {
return fmt.Errorf("expected code 200, got %d", got)
}
if got := resp.GetSize(); got != 1024 {
return fmt.Errorf("expected size 1024, got %d", got)
}
h := resp.GetHeaders()
if len(h) != 2 || h["content-type"] != "application/json" || h["server"] != "envoy" {
return fmt.Errorf("unexpected headers: %v", h)
}
// 3. GetTime returns timestamp and GetBackendLatency returns duration
if resp.GetTime() == nil || !resp.GetTime().AsTime().Equal(now) {
return fmt.Errorf("expected time %v, got %v", now, resp.GetTime())
}
if resp.GetBackendLatency() == nil || resp.GetBackendLatency().AsDuration() != latency {
return fmt.Errorf("expected latency %v, got %v", latency, resp.GetBackendLatency())
}
// 4. Getters on nil *AttributeContext_Response return safe default zero values without panicking
var nilResp *attribute_context.AttributeContext_Response
if nilResp.GetCode() != 0 {
return fmt.Errorf("expected 0 code on nil response")
}
if nilResp.GetSize() != 0 {
return fmt.Errorf("expected 0 size on nil response")
}
if nilResp.GetHeaders() != nil {
return fmt.Errorf("expected nil headers on nil response")
}
if nilResp.GetTime() != nil {
return fmt.Errorf("expected nil time on nil response")
}
if nilResp.GetBackendLatency() != nil {
return fmt.Errorf("expected nil latency on nil response")
}
// 5. AttributeContext_Response ProtoReflect and ProtoMessage methods succeed and String returns non-empty representation
if resp.ProtoReflect() == nil {
return fmt.Errorf("expected non-nil proto reflect")
}
resp.ProtoMessage()
str := resp.String()
if !strings.Contains(str, "200") || !strings.Contains(str, "1024") {
return fmt.Errorf("expected string representation to contain code and size: %s", str)
}
// 6. AttributeContext_Response Reset clears all fields to zero values
respCopy := sample.NewHTTPResponse(200, 1024, headers, now, latency)
respCopy.Reset()
if respCopy.GetCode() != 0 || respCopy.GetSize() != 0 || len(respCopy.GetHeaders()) != 0 || respCopy.GetTime() != nil || respCopy.GetBackendLatency() != nil {
return fmt.Errorf("expected all fields cleared after Reset")
}
// 7. Helper functions GetHeaderValue, LatencyMilliseconds, and IsSuccess operate correctly
val, ok := sample.GetHeaderValue(resp, "Content-Type")
if !ok || val != "application/json" {
return fmt.Errorf("expected Content-Type header 'application/json', got %q, %v", val, ok)
}
_, okMissing := sample.GetHeaderValue(resp, "x-unknown")
if okMissing {
return fmt.Errorf("expected x-unknown to be absent")
}
if ms := sample.LatencyMilliseconds(resp); ms != 150 {
return fmt.Errorf("expected 150ms latency, got %d", ms)
}
if !sample.IsSuccess(resp) {
return fmt.Errorf("expected 200 response to be success")
}
badResp := sample.NewHTTPResponse(500, 0, nil, time.Time{}, 0)
if sample.IsSuccess(badResp) {
return fmt.Errorf("expected 500 response not to be success")
}
return nil
}
Исходный сидер
аноним