Exemplo
google.golang.org/grpc v1.75.1: NewServer
Amostra verificada para golang google.golang.org/grpc v1.75.1: NewServer. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.
sha256:c93f5be3a25c8159066b29bedfdf762f88edc44b26e9634af641244c7e0ae223
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-14 |
Caso
HOW- Objetivo
- verify grpc.NewServer in pkg:golang/google.golang.org/grpc@v1.75.1
- Pacotes
- Símbolos
-
- grpc.NewServer
- Criado
- 2026-09-14T21:52:54Z
Contrato
- grpc.NewServer creates a non-nil gRPC server instance with default options
- grpc.NewServer creates a server configured with custom ServerOption values including message size limits and connection timeout
- grpc.Server registers services and exposes their metadata through GetServiceInfo
- grpc.Server serves requests on a listener and terminates cleanly on GracefulStop
Arquivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.go
Código-fonte
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 grpc.NewServer in pkg:golang/google.golang.org/grpc@v1.75.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/grpc@v1.75.1
Demonstrate these symbols/APIs:
- grpc.NewServer
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:bbefdcd95f9df16ef75ec27ba0705f4063ef32ebca2417136df529ac3cd794b9","contract":["grpc.NewServer creates a non-nil gRPC server instance with default options","grpc.NewServer creates a server configured with custom ServerOption values including message size limits and connection timeout","grpc.Server registers services and exposes their metadata through GetServiceInfo","grpc.Server serves requests on a listener and terminates cleanly on GracefulStop"],"goal":"verify grpc.NewServer in pkg:golang/google.golang.org/grpc@v1.75.1","kind":"HOW","packages":["pkg:golang/google.golang.org/grpc@v1.75.1"],"schemaVersion":1,"symbols":["grpc.NewServer"]},"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/grpc@v1.75.1"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/grpc@v1.75.1","symbols":["grpc.NewServer"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require google.golang.org/grpc v1.75.1
require (
golang.org/x/net v0.41.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.26.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/protobuf v1.36.6 // indirect
)
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 h1:pFyd6EwwL2TqFf8emdthzeX+gZE1ElRq3iM8pui4KBY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
package sample
import (
"context"
"net"
"time"
"google.golang.org/grpc"
)
// CreateServer creates a gRPC server with the given options.
func CreateServer(opts ...grpc.ServerOption) *grpc.Server {
return grpc.NewServer(opts...)
}
// ServerConfig holds configuration parameters for constructing a gRPC server.
type ServerConfig struct {
MaxRecvMsgSize int
MaxSendMsgSize int
ConnectionTimeout time.Duration
}
// CreateConfiguredServer creates a gRPC server configured with the specified buffer and timeout options.
func CreateConfiguredServer(cfg ServerConfig) *grpc.Server {
opts := []grpc.ServerOption{
grpc.MaxRecvMsgSize(cfg.MaxRecvMsgSize),
grpc.MaxSendMsgSize(cfg.MaxSendMsgSize),
grpc.ConnectionTimeout(cfg.ConnectionTimeout),
}
return grpc.NewServer(opts...)
}
// RegisterDummyService registers a mock service description onto the server.
func RegisterDummyService(s *grpc.Server, serviceName string) {
sd := &grpc.ServiceDesc{
ServiceName: serviceName,
HandlerType: (*any)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
return "pong", nil
},
},
},
Streams: []grpc.StreamDesc{},
}
s.RegisterService(sd, struct{}{})
}
// StartAndStopServer starts the server on the given listener and cleanly stops it.
func StartAndStopServer(s *grpc.Server, lis net.Listener) error {
errCh := make(chan error, 1)
go func() {
errCh <- s.Serve(lis)
}()
s.GracefulStop()
return <-errCh
}
{
"schemaVersion": 1,
"goal": "verify grpc.NewServer in pkg:golang/google.golang.org/grpc@v1.75.1",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/grpc@v1.75.1"
],
"symbols": [
"grpc.NewServer"
]
}
package main
import (
"fmt"
"net"
"os"
"time"
"google.golang.org/grpc"
"sample"
)
func main() {
// Assertion 1: grpc.NewServer creates a non-nil gRPC server instance with default options
serverDefault := sample.CreateServer()
if serverDefault == nil {
fmt.Fprintf(os.Stderr, "expected non-nil server with default options\n")
os.Exit(1)
}
serverDefault.Stop()
// Assertion 2: grpc.NewServer creates a server configured with custom ServerOption values
cfg := sample.ServerConfig{
MaxRecvMsgSize: 1024 * 1024,
MaxSendMsgSize: 1024 * 1024,
ConnectionTimeout: 5 * time.Second,
}
serverCustom := sample.CreateConfiguredServer(cfg)
if serverCustom == nil {
fmt.Fprintf(os.Stderr, "expected non-nil server with custom options\n")
os.Exit(1)
}
defer serverCustom.Stop()
// Assertion 3: grpc.Server registers services and exposes their metadata through GetServiceInfo
serviceName := "sample.v1.EchoService"
sample.RegisterDummyService(serverCustom, serviceName)
info := serverCustom.GetServiceInfo()
svcInfo, ok := info[serviceName]
if !ok {
fmt.Fprintf(os.Stderr, "service %q not found in GetServiceInfo\n", serviceName)
os.Exit(1)
}
if len(svcInfo.Methods) != 1 || svcInfo.Methods[0].Name != "Ping" {
fmt.Fprintf(os.Stderr, "expected method Ping in service info, got %+v\n", svcInfo.Methods)
os.Exit(1)
}
// Assertion 4: grpc.Server serves requests on a listener and terminates cleanly on GracefulStop
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create local listener: %v\n", err)
os.Exit(1)
}
serverToServe := sample.CreateServer()
sample.RegisterDummyService(serverToServe, serviceName)
serveErrCh := make(chan error, 1)
go func() {
serveErrCh <- serverToServe.Serve(lis)
}()
time.Sleep(50 * time.Millisecond)
serverToServe.GracefulStop()
select {
case serveErr := <-serveErrCh:
if serveErr != nil {
fmt.Fprintf(os.Stderr, "server Serve returned unexpected error: %v\n", serveErr)
os.Exit(1)
}
case <-time.After(3 * time.Second):
fmt.Fprintf(os.Stderr, "server failed to stop within timeout\n")
serverToServe.Stop()
os.Exit(1)
}
var _ *grpc.Server = serverDefault
fmt.Println("All grpc.NewServer contract assertions passed.")
}
Seeder de origem
anônimo