Exemple
google.golang.org/protobuf v1.35.1: anypb.New
Échantillon vérifié pour golang google.golang.org/protobuf v1.35.1: anypb.New. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a réussi.
sha256:d2fa92af10719d962dca0d397c6e438ec222fc879ff080b0bfc9f5b539a2834e
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é
go linux 24 · ubuntu · glibc 2.39 x64 go go go
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-27 |
Cas
HOW- Objectif
- verify google.golang.org/protobuf/types/known/anypb.New in pkg:golang/google.golang.org/protobuf@v1.35.1
- Symboles
-
- google.golang.org/protobuf/types/known/anypb.New
- Environnement
- go
- Créé
- 2026-08-27T10:33:35Z
Contrat
- anypb.New packs a proto.Message into an Any message with canonical type URL and marshaled wire format payload.
- anypb.New returns an error when passed a nil proto.Message.
- Any.UnmarshalTo unmarshals the Any payload into a destination proto.Message.
- Any.UnmarshalNew dynamically resolves and unmarshals the Any payload into a new proto.Message instance.
- Any.MessageIs and Any.MessageName correctly identify the encapsulated message type.
Fichiers
- PROMPT.md
- anypb_test.go
- csx.json
- go.mod
- go.sum
- spec.json
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/protobuf/types/known/anypb.New in pkg:golang/google.golang.org/protobuf@v1.35.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/protobuf@v1.35.1
Demonstrate these symbols/APIs:
- google.golang.org/protobuf/types/known/anypb.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.
package anypbdemo_test
import (
"strings"
"testing"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func TestAnyNewWithNil(t *testing.T) {
anyMsg, err := anypb.New(nil)
if err == nil {
t.Fatal("expected error when packing nil message, got nil")
}
if !strings.Contains(err.Error(), "invalid nil source message") {
t.Errorf("expected 'invalid nil source message' error, got: %v", err)
}
if anyMsg != nil {
t.Fatalf("expected nil Any when packing nil message, got: %v", anyMsg)
}
}
func TestAnyNewAndUnmarshal(t *testing.T) {
orig := wrapperspb.String("csx-verified-payload")
anyMsg, err := anypb.New(orig)
if err != nil {
t.Fatalf("anypb.New failed: %v", err)
}
if anyMsg == nil {
t.Fatal("expected non-nil Any message")
}
expectedTypeURL := "type.googleapis.com/google.protobuf.StringValue"
if anyMsg.GetTypeUrl() != expectedTypeURL {
t.Errorf("expected TypeUrl %q, got %q", expectedTypeURL, anyMsg.GetTypeUrl())
}
if !anyMsg.MessageIs(&wrapperspb.StringValue{}) {
t.Errorf("MessageIs(&wrapperspb.StringValue{}) should be true")
}
if anyMsg.MessageIs(×tamppb.Timestamp{}) {
t.Errorf("MessageIs(×tamppb.Timestamp{}) should be false")
}
var dst wrapperspb.StringValue
if err := anyMsg.UnmarshalTo(&dst); err != nil {
t.Fatalf("UnmarshalTo failed: %v", err)
}
if !proto.Equal(orig, &dst) {
t.Errorf("expected %v, got %v", orig, &dst)
}
if dst.GetValue() != "csx-verified-payload" {
t.Errorf("expected unmarshaled value %q, got %q", "csx-verified-payload", dst.GetValue())
}
unmarshaledNew, err := anyMsg.UnmarshalNew()
if err != nil {
t.Fatalf("UnmarshalNew failed: %v", err)
}
strVal, ok := unmarshaledNew.(*wrapperspb.StringValue)
if !ok {
t.Fatalf("expected *wrapperspb.StringValue, got %T", unmarshaledNew)
}
if !proto.Equal(orig, strVal) {
t.Errorf("expected %v, got %v", orig, strVal)
}
}
func TestAnyMarshalFrom(t *testing.T) {
orig := wrapperspb.Int32(12345)
var anyMsg anypb.Any
opts := proto.MarshalOptions{
Deterministic: true,
}
if err := anypb.MarshalFrom(&anyMsg, orig, opts); err != nil {
t.Fatalf("MarshalFrom failed: %v", err)
}
var dst wrapperspb.Int32Value
if err := anyMsg.UnmarshalTo(&dst); err != nil {
t.Fatalf("UnmarshalTo failed: %v", err)
}
if dst.GetValue() != 12345 {
t.Errorf("expected 12345, got %d", dst.GetValue())
}
}
func TestAnyMessageName(t *testing.T) {
orig := timestamppb.Now()
anyMsg, err := anypb.New(orig)
if err != nil {
t.Fatalf("anypb.New failed: %v", err)
}
name := anyMsg.MessageName()
if name != "google.protobuf.Timestamp" {
t.Errorf("expected MessageName 'google.protobuf.Timestamp', got %q", name)
}
}
{"case":{"caseId":"case:sha256:00cde054eb1038a623f5f8352444276546fef04d83d5d66baa098a3391412ebb","contract":["anypb.New packs a proto.Message into an Any message with canonical type URL and marshaled wire format payload.","anypb.New returns an error when passed a nil proto.Message.","Any.UnmarshalTo unmarshals the Any payload into a destination proto.Message.","Any.UnmarshalNew dynamically resolves and unmarshals the Any payload into a new proto.Message instance.","Any.MessageIs and Any.MessageName correctly identify the encapsulated message type."],"goal":"verify google.golang.org/protobuf/types/known/anypb.New in pkg:golang/google.golang.org/protobuf@v1.35.1","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.35.1"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/types/known/anypb.New"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/protobuf@v1.35.1"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.35.1","symbols":["google.golang.org/protobuf/types/known/anypb.New"],"verifierAdapter":"golang@1"}
module example.com/anypbdemo
go 1.22
require google.golang.org/protobuf v1.35.1
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
{
"schemaVersion": 1,
"goal": "verify google.golang.org/protobuf/types/known/anypb.New in pkg:golang/google.golang.org/protobuf@v1.35.1",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/protobuf@v1.35.1"
],
"symbols": [
"google.golang.org/protobuf/types/known/anypb.New"
]
}
Seeder d'origine
anonyme