CodeSampleX

Exemplo

google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc: protojson.Marshal

Amostra verificada para golang google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc: protojson.Marshal. O contrato rodou em go 1.26 · linux…

sha256:e3b01a2831f24e727c9bc6fbe1e4cdac9d81a19286a4ce6279a93d461a6c77b1

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-21

Caso

HOW
Objetivo
verify google.golang.org/protobuf/encoding/protojson.Marshal in pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc
Pacotes
Símbolos
  • google.golang.org/protobuf/encoding/protojson.Marshal
Criado
2026-10-21T22:03:54Z

Contrato

  1. protojson.Marshal encodes wrapperspb.StringValue{Value: "hello world"} into the JSON string literal "hello world"
  2. protojson.Marshal encodes durationpb.Duration{Seconds: 3, Nanos: 500000000} into the canonical JSON string "3.500s"
  3. protojson.Marshal encodes structpb.Struct containing boolean and numeric fields into a JSON object with those fields

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/protobuf/encoding/protojson.Marshal in pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc
Demonstrate these symbols/APIs:
  - google.golang.org/protobuf/encoding/protojson.Marshal

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:b786214c91fc2056e2d0800f9fa644dfa022aa03d152eb9fa8b0a8719440e382","contract":["protojson.Marshal encodes wrapperspb.StringValue{Value: \"hello world\"} into the JSON string literal \"hello world\"","protojson.Marshal encodes durationpb.Duration{Seconds: 3, Nanos: 500000000} into the canonical JSON string \"3.500s\"","protojson.Marshal encodes structpb.Struct containing boolean and numeric fields into a JSON object with those fields"],"goal":"verify google.golang.org/protobuf/encoding/protojson.Marshal in pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/encoding/protojson.Marshal"]},"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/protobuf@v1.23.1-0.20200526195155-81db48ad09cc"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc","symbols":["google.golang.org/protobuf/encoding/protojson.Marshal"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.21

require google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc
go.sum
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/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 v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc h1:TnonUr8u3himcMY0vSh23jFOXA+cnucl1gB6EQTReBI=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/protobuf/encoding/protojson.Marshal in pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/protobuf@v1.23.1-0.20200526195155-81db48ad09cc"
  ],
  "symbols": [
    "google.golang.org/protobuf/encoding/protojson.Marshal"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"strings"

	"google.golang.org/protobuf/encoding/protojson"
	"google.golang.org/protobuf/types/known/durationpb"
	"google.golang.org/protobuf/types/known/structpb"
	"google.golang.org/protobuf/types/known/wrapperspb"
)

func main() {
	strVal := &wrapperspb.StringValue{Value: "hello world"}
	strBytes, err := protojson.Marshal(strVal)
	if err != nil {
		panic(fmt.Sprintf("unexpected error marshaling StringValue: %v", err))
	}
	if string(strBytes) != `"hello world"` {
		panic(fmt.Sprintf("expected %q, got %s", `"hello world"`, string(strBytes)))
	}

	durVal := &durationpb.Duration{Seconds: 3, Nanos: 500000000}
	durBytes, err := protojson.Marshal(durVal)
	if err != nil {
		panic(fmt.Sprintf("unexpected error marshaling Duration: %v", err))
	}
	if string(durBytes) != `"3.500s"` {
		panic(fmt.Sprintf("expected %q, got %s", `"3.500s"`, string(durBytes)))
	}

	stVal := &structpb.Struct{
		Fields: map[string]*structpb.Value{
			"active": {Kind: &structpb.Value_BoolValue{BoolValue: true}},
			"count":  {Kind: &structpb.Value_NumberValue{NumberValue: 42}},
		},
	}
	stBytes, err := protojson.Marshal(stVal)
	if err != nil {
		panic(fmt.Sprintf("unexpected error marshaling Struct: %v", err))
	}
	stJSON := string(stBytes)
	if !strings.Contains(stJSON, `"active":true`) && !strings.Contains(stJSON, `"active": true`) {
		panic(fmt.Sprintf("expected JSON to contain active:true, got %s", stJSON))
	}
	if !strings.Contains(stJSON, `"count":42`) && !strings.Contains(stJSON, `"count": 42`) {
		panic(fmt.Sprintf("expected JSON to contain count:42, got %s", stJSON))
	}
}

Seeder de origem

anônimo