示例
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9: configure annotations.HttpRule with URL patterns, bindings, and verify proto serialization
已验证示例 — golang google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9: configure annotations.HttpRule with URL patterns, bindings, and…
sha256:b060ee723554c13319f8a382d31ae9e983de9a30549ca90f86a115f2881edd76
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-23 |
案例
HOW- 目标
- configure annotations.HttpRule with URL patterns, bindings, and verify proto serialization
- 符号
-
- annotations.HttpRule
- 创建时间
- 2026-08-23T16:23:52Z
契约
- annotations.HttpRule configures HTTP GET pattern, selector, and response body mappings with getter methods
- annotations.HttpRule supports additional HTTP bindings for secondary route patterns
- annotations.HttpRule supports custom HTTP patterns with custom verbs and paths
- annotations.HttpRule serializes to binary protobuf format and deserializes back preserving all pattern and selector fields
- annotations.HttpRule resets state correctly with Reset and implements protoreflect.Message
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- 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: configure annotations.HttpRule with URL patterns, bindings, and verify proto serialization
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9
Demonstrate these symbols/APIs:
- annotations.HttpRule
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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.
{"case":{"caseId":"case:sha256:acae5839864046404316bd4333a87269743b74c5b514278f7f6064f5ada97bca","contract":["annotations.HttpRule configures HTTP GET pattern, selector, and response body mappings with getter methods","annotations.HttpRule supports additional HTTP bindings for secondary route patterns","annotations.HttpRule supports custom HTTP patterns with custom verbs and paths","annotations.HttpRule serializes to binary protobuf format and deserializes back preserving all pattern and selector fields","annotations.HttpRule resets state correctly with Reset and implements protoreflect.Message"],"goal":"configure annotations.HttpRule with URL patterns, bindings, and verify proto serialization","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["annotations.HttpRule"]},"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/api@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9","symbols":["annotations.HttpRule"],"verifierAdapter":"golang@1"}
module sample-googleapis-api
go 1.22
require (
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9
google.golang.org/protobuf v1.35.1
)
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 h1:T6rh4haD3GVYsgEfWExoCZA2o2FmbNyKpTuAxbEFPTg=
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:wp2WsuBYj6j8wUdo3ToZsdxxixbvQNAHqVJrTgi5E5M=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
{
"schemaVersion": 1,
"goal": "configure annotations.HttpRule with URL patterns, bindings, and verify proto serialization",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20241007155032-5fefd90f89a9"
],
"symbols": [
"annotations.HttpRule"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"fmt"
"os"
"google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/proto"
)
func main() {
// 1. annotations.HttpRule configures HTTP GET pattern, selector, and response body mappings with getter methods
{
rule := &annotations.HttpRule{
Selector: "google.example.v1.Messaging.GetMessage",
Pattern: &annotations.HttpRule_Get{
Get: "/v1/messages/{message_id}",
},
Body: "",
ResponseBody: "message",
}
if rule.GetSelector() != "google.example.v1.Messaging.GetMessage" {
fmt.Fprintf(os.Stderr, "Contract 1 failed: selector mismatch: %s\n", rule.GetSelector())
os.Exit(1)
}
if rule.GetGet() != "/v1/messages/{message_id}" {
fmt.Fprintf(os.Stderr, "Contract 1 failed: get pattern mismatch: %s\n", rule.GetGet())
os.Exit(1)
}
if rule.GetResponseBody() != "message" {
fmt.Fprintf(os.Stderr, "Contract 1 failed: response body mismatch: %s\n", rule.GetResponseBody())
os.Exit(1)
}
}
// 2. annotations.HttpRule supports additional HTTP bindings for secondary route patterns
{
rule := &annotations.HttpRule{
Selector: "google.example.v1.Messaging.GetMessage",
Pattern: &annotations.HttpRule_Get{
Get: "/v1/messages/{message_id}",
},
AdditionalBindings: []*annotations.HttpRule{
{
Pattern: &annotations.HttpRule_Get{
Get: "/v1/users/{user_id}/messages/{message_id}",
},
},
{
Pattern: &annotations.HttpRule_Post{
Post: "/v1/messages:batchGet",
},
Body: "*",
},
},
}
bindings := rule.GetAdditionalBindings()
if len(bindings) != 2 {
fmt.Fprintf(os.Stderr, "Contract 2 failed: expected 2 bindings, got %d\n", len(bindings))
os.Exit(1)
}
if bindings[0].GetGet() != "/v1/users/{user_id}/messages/{message_id}" {
fmt.Fprintf(os.Stderr, "Contract 2 failed: binding 0 get mismatch: %s\n", bindings[0].GetGet())
os.Exit(1)
}
if bindings[1].GetPost() != "/v1/messages:batchGet" || bindings[1].GetBody() != "*" {
fmt.Fprintf(os.Stderr, "Contract 2 failed: binding 1 post/body mismatch\n")
os.Exit(1)
}
}
// 3. annotations.HttpRule supports custom HTTP patterns with custom verbs and paths
{
rule := &annotations.HttpRule{
Selector: "google.example.v1.Messaging.CustomAction",
Pattern: &annotations.HttpRule_Custom{
Custom: &annotations.CustomHttpPattern{
Kind: "HEAD",
Path: "/v1/messages/{message_id}:head",
},
},
}
custom := rule.GetCustom()
if custom == nil {
fmt.Fprintf(os.Stderr, "Contract 3 failed: expected non-nil Custom\n")
os.Exit(1)
}
if custom.GetKind() != "HEAD" || custom.GetPath() != "/v1/messages/{message_id}:head" {
fmt.Fprintf(os.Stderr, "Contract 3 failed: custom kind/path mismatch: %s, %s\n", custom.GetKind(), custom.GetPath())
os.Exit(1)
}
}
// 4. annotations.HttpRule serializes to binary protobuf format and deserializes back preserving all pattern and selector fields
{
original := &annotations.HttpRule{
Selector: "google.example.v1.Messaging.UpdateMessage",
Pattern: &annotations.HttpRule_Patch{
Patch: "/v1/messages/{message_id}",
},
Body: "*",
AdditionalBindings: []*annotations.HttpRule{
{
Pattern: &annotations.HttpRule_Put{
Put: "/v1/messages/{message_id}",
},
Body: "*",
},
},
}
data, err := proto.Marshal(original)
if err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed to marshal: %v\n", err)
os.Exit(1)
}
var decoded annotations.HttpRule
if err := proto.Unmarshal(data, &decoded); err != nil {
fmt.Fprintf(os.Stderr, "Contract 4 failed to unmarshal: %v\n", err)
os.Exit(1)
}
if decoded.GetSelector() != original.GetSelector() {
fmt.Fprintf(os.Stderr, "Contract 4 failed: selector mismatch: %s != %s\n", decoded.GetSelector(), original.GetSelector())
os.Exit(1)
}
if decoded.GetPatch() != original.GetPatch() {
fmt.Fprintf(os.Stderr, "Contract 4 failed: patch pattern mismatch: %s != %s\n", decoded.GetPatch(), original.GetPatch())
os.Exit(1)
}
if decoded.GetBody() != original.GetBody() {
fmt.Fprintf(os.Stderr, "Contract 4 failed: body mismatch: %s != %s\n", decoded.GetBody(), original.GetBody())
os.Exit(1)
}
if len(decoded.GetAdditionalBindings()) != 1 || decoded.GetAdditionalBindings()[0].GetPut() != "/v1/messages/{message_id}" {
fmt.Fprintf(os.Stderr, "Contract 4 failed: decoded binding mismatch\n")
os.Exit(1)
}
}
// 5. annotations.HttpRule resets state correctly with Reset and implements protoreflect.Message
{
rule := &annotations.HttpRule{
Selector: "google.example.v1.Messaging.DeleteMessage",
Pattern: &annotations.HttpRule_Delete{
Delete: "/v1/messages/{message_id}",
},
}
if rule.ProtoReflect() == nil {
fmt.Fprintf(os.Stderr, "Contract 5 failed: ProtoReflect returned nil\n")
os.Exit(1)
}
rule.Reset()
if rule.GetSelector() != "" || rule.GetDelete() != "" {
fmt.Fprintf(os.Stderr, "Contract 5 failed: Reset did not clear fields\n")
os.Exit(1)
}
}
fmt.Println("All contract assertions passed.")
}
原始种子者
匿名