CodeSampleX

Exemple

google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0: code.Code

Échantillon vérifié pour golang google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0: code.Code. Le contrat s'est exécuté sur go 1.26…

sha256:2a3e8220cc209d4e61603ad7470a695ea56516c4daebfe79ef8d9bcf8f101ef9

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-09-15

Cas

HOW
Objectif
verify google.golang.org/genproto/googleapis/rpc/code.Code in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0
Paquets
Symboles
  • google.golang.org/genproto/googleapis/rpc/code.Code
Créé
2026-09-15T21:12:45Z

Contrat

  1. code.Code defines canonical gRPC status codes with OK having value 0 and canonical constants like INVALID_ARGUMENT and NOT_FOUND
  2. code.Code instances provide string representations via String() matching Code_name and Code_value mappings
  3. code.Code satisfies protoreflect enum interfaces providing valid Descriptor, Type, and Number
  4. code.Code integrates with status.Status to represent and marshal standard RPC error codes

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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/genproto/googleapis/rpc/code.Code in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/code.Code

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:5aa4333147e0dde742690c55052851def9d42bde4c8a483589b6fa217d7a2503","contract":["code.Code defines canonical gRPC status codes with OK having value 0 and canonical constants like INVALID_ARGUMENT and NOT_FOUND","code.Code instances provide string representations via String() matching Code_name and Code_value mappings","code.Code satisfies protoreflect enum interfaces providing valid Descriptor, Type, and Number","code.Code integrates with status.Status to represent and marshal standard RPC error codes"],"goal":"verify google.golang.org/genproto/googleapis/rpc/code.Code in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/code.Code"]},"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/rpc@v0.0.0-20250728155136-f173205681a0"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0","symbols":["google.golang.org/genproto/googleapis/rpc/code.Code"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0
	google.golang.org/protobuf v1.36.12
)
go.sum
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-20250728155136-f173205681a0 h1:MAKi5q709QWfnkkpNQ0M12hYJ1+e8qYVDyowc4U1XZM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"fmt"
	"log"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
)

func main() {
	rpcStatus := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "request field 'id' must be a positive integer",
	}

	data, err := proto.Marshal(rpcStatus)
	if err != nil {
		log.Fatalf("failed to marshal status: %v", err)
	}

	var decoded status.Status
	if err := proto.Unmarshal(data, &decoded); err != nil {
		log.Fatalf("failed to unmarshal status: %v", err)
	}

	statusCode := code.Code(decoded.GetCode())
	fmt.Printf("RPC Error Code: %d (%s)\n", statusCode, statusCode.String())
	fmt.Printf("RPC Error Message: %s\n", decoded.GetMessage())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/code.Code in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/code.Code"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
)

func assert(condition bool, message string) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed: %s\n", message)
		os.Exit(1)
	}
}

func main() {
	// 1. code.Code defines canonical gRPC status codes with OK having value 0 and canonical constants like INVALID_ARGUMENT and NOT_FOUND
	assert(code.Code_OK == 0, "code.Code_OK must have value 0")
	assert(int32(code.Code_OK) == 0, "int32(code.Code_OK) must be 0")
	assert(code.Code_INVALID_ARGUMENT == 3, "code.Code_INVALID_ARGUMENT must have value 3")
	assert(code.Code_NOT_FOUND == 5, "code.Code_NOT_FOUND must have value 5")
	assert(code.Code_INTERNAL == 13, "code.Code_INTERNAL must have value 13")

	// 2. code.Code instances provide string representations via String() matching Code_name and Code_value mappings
	assert(code.Code_OK.String() == "OK", "code.Code_OK.String() must be 'OK'")
	assert(code.Code_INVALID_ARGUMENT.String() == "INVALID_ARGUMENT", "code.Code_INVALID_ARGUMENT.String() must be 'INVALID_ARGUMENT'")
	assert(code.Code_name[int32(code.Code_OK)] == "OK", "code.Code_name[0] must be 'OK'")
	assert(code.Code_name[int32(code.Code_NOT_FOUND)] == "NOT_FOUND", "code.Code_name[5] must be 'NOT_FOUND'")
	assert(code.Code_value["OK"] == int32(code.Code_OK), "code.Code_value['OK'] must match Code_OK")
	assert(code.Code_value["NOT_FOUND"] == int32(code.Code_NOT_FOUND), "code.Code_value['NOT_FOUND'] must match Code_NOT_FOUND")

	// 3. code.Code satisfies protoreflect enum interfaces providing valid Descriptor, Type, and Number
	assert(code.Code_OK.Number() == 0, "code.Code_OK.Number() must return 0")
	assert(*(code.Code_OK.Enum()) == code.Code_OK, "code.Code_OK.Enum() must return pointer to Code_OK")
	assert(code.Code_OK.Descriptor() != nil, "code.Code_OK.Descriptor() must not be nil")
	assert(code.Code_OK.Descriptor().FullName() == "google.rpc.Code", "Descriptor FullName must be 'google.rpc.Code'")
	assert(code.Code_OK.Type() != nil, "code.Code_OK.Type() must not be nil")
	assert(code.Code_OK.Type().Descriptor() == code.Code_OK.Descriptor(), "Type descriptor must match Enum descriptor")

	// 4. code.Code integrates with status.Status to represent and marshal standard RPC error codes
	st := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "request field 'id' must be a positive integer",
	}
	assert(st.GetCode() == int32(code.Code_INVALID_ARGUMENT), "status.Status Code must match Code_INVALID_ARGUMENT")
	assert(code.Code(st.GetCode()) == code.Code_INVALID_ARGUMENT, "status.Status Code must cast back to Code_INVALID_ARGUMENT")
	assert(st.GetMessage() == "request field 'id' must be a positive integer", "status.Status Message must match")

	data, err := proto.Marshal(st)
	assert(err == nil, "proto.Marshal(st) must succeed")
	assert(len(data) > 0, "marshaled payload must not be empty")

	var decoded status.Status
	err = proto.Unmarshal(data, &decoded)
	assert(err == nil, "proto.Unmarshal(data) must succeed")
	assert(decoded.GetCode() == int32(code.Code_INVALID_ARGUMENT), "decoded status Code must match Code_INVALID_ARGUMENT")
	assert(decoded.GetMessage() == "request field 'id' must be a positive integer", "decoded status Message must match")

	fmt.Println("All contract assertions for google.golang.org/genproto/googleapis/rpc/code.Code passed successfully.")
}

Seeder d'origine

anonyme