CodeSampleX

Ejemplo

google.golang.org/grpc v1.82.0: status.New

Muestra verificada para golang google.golang.org/grpc v1.82.0: status.New. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:a16d29d74337e835093020327dc47f695b14c09701223c4e5441e273533b3ebe

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify google.golang.org/grpc/status.New in pkg:golang/google.golang.org/grpc@v1.82.0
Paquetes
Símbolos
  • google.golang.org/grpc/status.New
Creado
2026-10-12T12:13:34Z

Contrato

  1. status.New returns a Status instance with the specified Code and Message
  2. status.New with codes.OK returns a Status whose Err() is nil
  3. status.New with a non-OK code returns a Status whose Err() produces a gRPC error containing the code and message
  4. status.New returns a Status whose Proto() message contains the expected code number and message string
  5. status.FromError recovers the original Status created by status.New

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json
  • test/contract.go

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
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.New 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.New

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.
csx.json
{"case":{"caseId":"case:sha256:b182406821ffd2561d6c90983c33432b7c533261afe6f6d07be5e5988e771a61","contract":["status.New returns a Status instance with the specified Code and Message","status.New with codes.OK returns a Status whose Err() is nil","status.New with a non-OK code returns a Status whose Err() produces a gRPC error containing the code and message","status.New returns a Status whose Proto() message contains the expected code number and message string","status.FromError recovers the original Status created by status.New"],"goal":"verify google.golang.org/grpc/status.New 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.New"]},"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.New"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require google.golang.org/grpc v1.82.0

require (
	golang.org/x/sys v0.43.0 // indirect
	google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
	google.golang.org/protobuf v1.36.11 // indirect
)
go.sum
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.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.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-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/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=
sample.go
package sample

import (
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

// New creates a new Status instance with the provided code and message using status.New.
func New(c codes.Code, msg string) *status.Status {
	return status.New(c, msg)
}

// NewError creates a new error representing the status using status.New(c, msg).Err().
func NewError(c codes.Code, msg string) error {
	return status.New(c, msg).Err()
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/grpc/status.New 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.New"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	"sample"

	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func main() {
	// 1. status.New returns a Status instance with the specified Code and Message
	st1 := status.New(codes.NotFound, "resource not found")
	if st1 == nil {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: status.New returned nil\n")
		os.Exit(1)
	}
	if st1.Code() != codes.NotFound {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected Code %v, got %v\n", codes.NotFound, st1.Code())
		os.Exit(1)
	}
	if st1.Message() != "resource not found" {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: expected Message 'resource not found', got %q\n", st1.Message())
		os.Exit(1)
	}
	wrappedSt1 := sample.New(codes.NotFound, "resource not found")
	if wrappedSt1.Code() != codes.NotFound || wrappedSt1.Message() != "resource not found" {
		fmt.Fprintf(os.Stderr, "assertion 1 failed: sample.New mismatch\n")
		os.Exit(1)
	}

	// 2. status.New with codes.OK returns a Status whose Err() is nil
	st2 := status.New(codes.OK, "operation succeeded")
	if err := st2.Err(); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: expected nil error for codes.OK, got: %v\n", err)
		os.Exit(1)
	}
	if err := sample.NewError(codes.OK, "operation succeeded"); err != nil {
		fmt.Fprintf(os.Stderr, "assertion 2 failed: sample.NewError returned non-nil for codes.OK: %v\n", err)
		os.Exit(1)
	}

	// 3. status.New with a non-OK code returns a Status whose Err() produces a gRPC error containing the code and message
	st3 := status.New(codes.InvalidArgument, "invalid parameter")
	err3 := st3.Err()
	if err3 == nil {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected non-nil error for InvalidArgument\n")
		os.Exit(1)
	}
	if gotCode := status.Code(err3); gotCode != codes.InvalidArgument {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: expected status.Code(err3) == InvalidArgument, got %v\n", gotCode)
		os.Exit(1)
	}
	errMsg := err3.Error()
	if !strings.Contains(errMsg, "InvalidArgument") || !strings.Contains(errMsg, "invalid parameter") {
		fmt.Fprintf(os.Stderr, "assertion 3 failed: error message %q missing expected details\n", errMsg)
		os.Exit(1)
	}

	// 4. status.New returns a Status whose Proto() message contains the expected code number and message string
	st4 := status.New(codes.PermissionDenied, "permission denied")
	protoMsg := st4.Proto()
	if protoMsg == nil {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: Proto() returned nil\n")
		os.Exit(1)
	}
	if protoMsg.GetCode() != int32(codes.PermissionDenied) {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: expected proto code %d, got %d\n", int32(codes.PermissionDenied), protoMsg.GetCode())
		os.Exit(1)
	}
	if protoMsg.GetMessage() != "permission denied" {
		fmt.Fprintf(os.Stderr, "assertion 4 failed: expected proto message 'permission denied', got %q\n", protoMsg.GetMessage())
		os.Exit(1)
	}

	// 5. status.FromError recovers the original Status created by status.New
	st5 := status.New(codes.ResourceExhausted, "rate limit exceeded")
	err5 := st5.Err()
	recovered, ok := status.FromError(err5)
	if !ok {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: status.FromError returned ok=false\n")
		os.Exit(1)
	}
	if recovered.Code() != codes.ResourceExhausted {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: expected Code %v, got %v\n", codes.ResourceExhausted, recovered.Code())
		os.Exit(1)
	}
	if recovered.Message() != "rate limit exceeded" {
		fmt.Fprintf(os.Stderr, "assertion 5 failed: expected Message 'rate limit exceeded', got %q\n", recovered.Message())
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed successfully.")
}

Seeder de origen

anónimo