CodeSampleX

Exemple

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

Échantillon vérifié pour golang google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0: code.Code_INVALID_ARGUMENT. Le contrat s'est…

sha256:7493866d8159b77297bc5826d444b2a614211b68db1204bb04b65a3728ac8159

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_INVALID_ARGUMENT in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20250728155136-f173205681a0
Paquets
Symboles
  • google.golang.org/genproto/googleapis/rpc/code.Code_INVALID_ARGUMENT
Créé
2026-09-15T21:40:28Z

Contrat

  1. code.Code_INVALID_ARGUMENT represents client-specified invalid argument with enum value 3
  2. code.Code_INVALID_ARGUMENT enum converts to string representation INVALID_ARGUMENT and maps in Code_name and Code_value
  3. status.Status represents an RPC error status with code.Code_INVALID_ARGUMENT and unmarshals successfully
  4. status.Status with code.Code_INVALID_ARGUMENT encapsulates BadRequest error details describing invalid field arguments

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_INVALID_ARGUMENT 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_INVALID_ARGUMENT

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:4004ab04cc10d23ec59f81a29e9f04ccd45e6834ffb6c0b0cb04e013c2ec9070","contract":["code.Code_INVALID_ARGUMENT represents client-specified invalid argument with enum value 3","code.Code_INVALID_ARGUMENT enum converts to string representation INVALID_ARGUMENT and maps in Code_name and Code_value","status.Status represents an RPC error status with code.Code_INVALID_ARGUMENT and unmarshals successfully","status.Status with code.Code_INVALID_ARGUMENT encapsulates BadRequest error details describing invalid field arguments"],"goal":"verify google.golang.org/genproto/googleapis/rpc/code.Code_INVALID_ARGUMENT 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_INVALID_ARGUMENT"]},"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_INVALID_ARGUMENT"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20250728155136-f173205681a0
	google.golang.org/protobuf v1.36.6
)
go.sum
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
main.go
package main

import (
	"fmt"
	"log"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
)

func main() {
	badRequest := &errdetails.BadRequest{
		FieldViolations: []*errdetails.BadRequest_FieldViolation{
			{
				Field:       "user_id",
				Description: "user ID cannot be empty",
			},
		},
	}
	anyDetail, err := anypb.New(badRequest)
	if err != nil {
		log.Fatalf("failed to pack error detail: %v", err)
	}

	st := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "invalid argument provided in request",
		Details: []*anypb.Any{anyDetail},
	}

	data, err := proto.Marshal(st)
	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)
	}

	fmt.Printf("Status Code: %d (%s)\n", decoded.GetCode(), code.Code_name[decoded.GetCode()])
	fmt.Printf("Status Message: %s\n", decoded.GetMessage())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/code.Code_INVALID_ARGUMENT 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_INVALID_ARGUMENT"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/code"
	"google.golang.org/genproto/googleapis/rpc/errdetails"
	"google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
)

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_INVALID_ARGUMENT represents client-specified invalid argument with enum value 3
	assert(code.Code_INVALID_ARGUMENT == 3, "code.Code_INVALID_ARGUMENT must have value 3")
	assert(int32(code.Code_INVALID_ARGUMENT) == 3, "int32(code.Code_INVALID_ARGUMENT) must be 3")

	// 2. code.Code_INVALID_ARGUMENT enum converts to string representation INVALID_ARGUMENT and maps in Code_name and Code_value
	assert(code.Code_INVALID_ARGUMENT.String() == "INVALID_ARGUMENT", "code.Code_INVALID_ARGUMENT.String() must be INVALID_ARGUMENT")
	assert(code.Code_name[int32(code.Code_INVALID_ARGUMENT)] == "INVALID_ARGUMENT", "code.Code_name[3] must be INVALID_ARGUMENT")
	assert(code.Code_value["INVALID_ARGUMENT"] == int32(code.Code_INVALID_ARGUMENT), "code.Code_value[INVALID_ARGUMENT] must match Code_INVALID_ARGUMENT")

	// 3. status.Status represents an RPC error status with code.Code_INVALID_ARGUMENT and unmarshals successfully
	st := &status.Status{
		Code:    int32(code.Code_INVALID_ARGUMENT),
		Message: "invalid argument: user ID cannot be empty",
	}
	assert(st.GetCode() == int32(code.Code_INVALID_ARGUMENT), "status code must match Code_INVALID_ARGUMENT")
	assert(st.GetMessage() == "invalid argument: user ID cannot be empty", "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() == "invalid argument: user ID cannot be empty", "decoded message must match")

	// 4. status.Status with code.Code_INVALID_ARGUMENT encapsulates BadRequest error details describing invalid field arguments
	badRequest := &errdetails.BadRequest{
		FieldViolations: []*errdetails.BadRequest_FieldViolation{
			{
				Field:       "user_id",
				Description: "user ID cannot be empty",
			},
		},
	}
	anyDetail, err := anypb.New(badRequest)
	assert(err == nil, "anypb.New(badRequest) must succeed")

	st.Details = append(st.Details, anyDetail)
	assert(len(st.GetDetails()) == 1, "details count must be 1")

	unpackedBadReq := &errdetails.BadRequest{}
	err = anypb.UnmarshalTo(st.GetDetails()[0], unpackedBadReq, proto.UnmarshalOptions{})
	assert(err == nil, "anypb.UnmarshalTo must succeed")
	assert(len(unpackedBadReq.GetFieldViolations()) == 1, "field violations count must be 1")
	assert(unpackedBadReq.GetFieldViolations()[0].GetField() == "user_id", "violation field must match")
	assert(unpackedBadReq.GetFieldViolations()[0].GetDescription() == "user ID cannot be empty", "violation description must match")

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

Seeder d'origine

anonyme