Exemple
google.golang.org/grpc v1.82.0: status.Status
Échantillon vérifié pour golang google.golang.org/grpc v1.82.0: status.Status. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 · docker et a réussi.
sha256:e07d68e6d59f27b002df3668abc7c6a0d0ff13a90194604d5331cedb54142832
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-10-12 |
Cas
HOW- Objectif
- verify google.golang.org/grpc/status.Status in pkg:golang/google.golang.org/grpc@v1.82.0
- Paquets
- Symboles
-
- google.golang.org/grpc/status.Status
- Créé
- 2026-10-12T13:35:31Z
Contrat
- status.New constructs a Status object with the given code and message
- status.Newf constructs a formatted Status object with formatting arguments
- Status.Err returns an error representing the Status and status.FromError retrieves the original Status
- status.Code extracts the status code from error or returns OK for nil error
- status.Convert converts errors into Status instances returning nil for nil error
Fichiers
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- status.go
- test/contract.go
Code source
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/grpc/status.Status in pkg:golang/google.golang.org/grpc@v1.82.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/grpc@v1.82.0
Demonstrate these symbols/APIs:
- google.golang.org/grpc/status.Status
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:4b464a8cde2a90f02f979f0ad1272ee849381b72edb20b1a128c96159aba1230","contract":["status.New constructs a Status object with the given code and message","status.Newf constructs a formatted Status object with formatting arguments","Status.Err returns an error representing the Status and status.FromError retrieves the original Status","status.Code extracts the status code from error or returns OK for nil error","status.Convert converts errors into Status instances returning nil for nil error"],"goal":"verify google.golang.org/grpc/status.Status in pkg:golang/google.golang.org/grpc@v1.82.0","kind":"HOW","packages":["pkg:golang/google.golang.org/grpc@v1.82.0"],"schemaVersion":1,"symbols":["google.golang.org/grpc/status.Status"]},"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.82.0"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/grpc@v1.82.0","symbols":["google.golang.org/grpc/status.Status"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require google.golang.org/grpc v1.82.0
require (
golang.org/x/sys v0.47.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
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=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 h1:qEHAMpSaUhtD0p3NbEEI83HwNGFxEwaSJ1G9PLnCBZE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.82.0 h1:vguDnZUPjE26w09A63VoxZPnvPjB5Riyc0mkXPFmAIU=
google.golang.org/grpc v1.82.0/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
{
"schemaVersion": 1,
"goal": "verify google.golang.org/grpc/status.Status in pkg:golang/google.golang.org/grpc@v1.82.0",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/grpc@v1.82.0"
],
"symbols": [
"google.golang.org/grpc/status.Status"
]
}
package sample
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// NewStatus creates a new Status pointer with the given code and message.
func NewStatus(code codes.Code, msg string) *status.Status {
return status.New(code, msg)
}
// NewStatusf creates a formatted Status pointer with the given code and format string.
func NewStatusf(code codes.Code, format string, args ...any) *status.Status {
return status.Newf(code, format, args...)
}
// StatusToError converts a Status to an error interface.
func StatusToError(s *status.Status) error {
if s == nil {
return nil
}
return s.Err()
}
// ErrorToStatus extracts a Status from an error if possible.
func ErrorToStatus(err error) (*status.Status, bool) {
return status.FromError(err)
}
// ConvertError converts any error into a Status pointer.
func ConvertError(err error) *status.Status {
return status.Convert(err)
}
// GetCode extracts the status code from an error.
func GetCode(err error) codes.Code {
return status.Code(err)
}
package main
import (
"errors"
"fmt"
"os"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"sample"
)
func main() {
fmt.Println("Running contract tests for google.golang.org/grpc/status.Status...")
// Assertion 1: status.New constructs a Status object with the given code and message
{
var st *status.Status = sample.NewStatus(codes.NotFound, "entity not found")
if st == nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: status is nil\n")
os.Exit(1)
}
if st.Code() != codes.NotFound {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected code NotFound, got %v\n", st.Code())
os.Exit(1)
}
if st.Message() != "entity not found" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected message 'entity not found', got '%s'\n", st.Message())
os.Exit(1)
}
if st.Proto().GetCode() != int32(codes.NotFound) {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: proto code mismatch: %d\n", st.Proto().GetCode())
os.Exit(1)
}
if st.Proto().GetMessage() != "entity not found" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: proto message mismatch: '%s'\n", st.Proto().GetMessage())
os.Exit(1)
}
fmt.Println(" ✓ Assertion 1 passed: status.New constructs Status with code and message")
}
// Assertion 2: status.Newf constructs a formatted Status object with formatting arguments
{
st := sample.NewStatusf(codes.InvalidArgument, "invalid item id: %d", 42)
if st == nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: status is nil\n")
os.Exit(1)
}
if st.Code() != codes.InvalidArgument {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected code InvalidArgument, got %v\n", st.Code())
os.Exit(1)
}
if st.Message() != "invalid item id: 42" {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected message 'invalid item id: 42', got '%s'\n", st.Message())
os.Exit(1)
}
fmt.Println(" ✓ Assertion 2 passed: status.Newf constructs formatted Status")
}
// Assertion 3: Status.Err returns an error representing the Status and status.FromError retrieves the original Status
{
st := sample.NewStatus(codes.PermissionDenied, "access denied")
err := sample.StatusToError(st)
if err == nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected non-nil error from non-OK status\n")
os.Exit(1)
}
expectedErrStr := "rpc error: code = PermissionDenied desc = access denied"
if err.Error() != expectedErrStr {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected '%s', got '%s'\n", expectedErrStr, err.Error())
os.Exit(1)
}
extracted, ok := sample.ErrorToStatus(err)
if !ok || extracted == nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: status.FromError failed to extract status\n")
os.Exit(1)
}
if extracted.Code() != codes.PermissionDenied {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: extracted code mismatch: %v\n", extracted.Code())
os.Exit(1)
}
if extracted.Message() != "access denied" {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: extracted message mismatch: '%s'\n", extracted.Message())
os.Exit(1)
}
// Also verify that OK status returns nil error
okStatus := sample.NewStatus(codes.OK, "")
if okErr := sample.StatusToError(okStatus); okErr != nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: OK status should produce nil error, got %v\n", okErr)
os.Exit(1)
}
fmt.Println(" ✓ Assertion 3 passed: Status.Err and status.FromError bidirectional conversion")
}
// Assertion 4: status.Code extracts the status code from error or returns OK for nil error
{
if c := sample.GetCode(nil); c != codes.OK {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: nil error should return OK, got %v\n", c)
os.Exit(1)
}
st := sample.NewStatus(codes.ResourceExhausted, "quota exceeded")
if c := sample.GetCode(sample.StatusToError(st)); c != codes.ResourceExhausted {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected ResourceExhausted, got %v\n", c)
os.Exit(1)
}
plainErr := errors.New("arbitrary standard error")
if c := sample.GetCode(plainErr); c != codes.Unknown {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: plain error should return Unknown, got %v\n", c)
os.Exit(1)
}
fmt.Println(" ✓ Assertion 4 passed: status.Code extracts code from errors")
}
// Assertion 5: status.Convert converts errors into Status instances returning nil for nil error
{
convNil := sample.ConvertError(nil)
if convNil != nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: Convert(nil) should yield nil, got %v\n", convNil)
os.Exit(1)
}
st := sample.NewStatus(codes.Unauthenticated, "missing bearer token")
convGrpc := sample.ConvertError(sample.StatusToError(st))
if convGrpc == nil || convGrpc.Code() != codes.Unauthenticated || convGrpc.Message() != "missing bearer token" {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: Convert(grpcErr) mismatch\n")
os.Exit(1)
}
plainErr := errors.New("database timeout")
convPlain := sample.ConvertError(plainErr)
if convPlain == nil || convPlain.Code() != codes.Unknown || convPlain.Message() != "database timeout" {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: Convert(plainErr) mismatch\n")
os.Exit(1)
}
fmt.Println(" ✓ Assertion 5 passed: status.Convert converts errors returning nil for nil error")
}
fmt.Println("All contract tests passed successfully!")
}
Seeder d'origine
anonyme