CodeSampleX

Exemplo

google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.Help_Link

Amostra verificada para golang google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9: errdetails.Help_Link. O contrato rodou em go…

sha256:054931e26d7d0331511e02409f27d1e9e368d93a708e14c3f5a72cc9ed2a142c

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 go linux 24 · ubuntu · glibc 2.39 x64 go go go

Ambientes das execuções de verificação

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

Caso

HOW
Objetivo
verify google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Pacotes
Símbolos
  • google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link
Ambiente
go
Criado
2026-08-27T11:38:49Z

Contrato

  1. errdetails.Help_Link fields Description and Url are directly accessible and populated via struct literals.
  2. Help_Link.GetDescription and Help_Link.GetUrl return the configured strings on non-nil instances and empty string on nil receiver.
  3. Help_Link.Reset clears Description and Url back to default empty strings.
  4. Help_Link can be serialized and deserialized accurately using proto.Marshal and proto.Unmarshal.
  5. errdetails.Help embeds a slice of Help_Link pointers, accessible via GetLinks and serializable with protobuf.

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract_test.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/genproto/googleapis/rpc/errdetails.Help_Link in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link

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:23467e41c24e2ce3f54e3dce2c6fe2b959c1569e828c04a10ad19b22be34a5ff","contract":["errdetails.Help_Link fields Description and Url are directly accessible and populated via struct literals.","Help_Link.GetDescription and Help_Link.GetUrl return the configured strings on non-nil instances and empty string on nil receiver.","Help_Link.Reset clears Description and Url back to default empty strings.","Help_Link can be serialized and deserialized accurately using proto.Marshal and proto.Unmarshal.","errdetails.Help embeds a slice of Help_Link pointers, accessible via GetLinks and serializable with protobuf."],"goal":"verify google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link"]},"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/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9","symbols":["google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link"],"verifierAdapter":"golang@1"}
go.mod
module example.com/errdetails

go 1.26.6

require (
	google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
	google.golang.org/protobuf v1.35.1
)
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-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
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=
main.go
package main

import (
	"fmt"

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

func main() {
	link := &errdetails.Help_Link{
		Description: "Documentation link",
		Url:         "https://example.com/docs/troubleshooting",
	}

	fmt.Printf("Link Description: %s\n", link.GetDescription())
	fmt.Printf("Link URL: %s\n", link.GetUrl())

	help := &errdetails.Help{
		Links: []*errdetails.Help_Link{link},
	}

	data, err := proto.Marshal(help)
	if err != nil {
		panic(err)
	}

	var unmarshaledHelp errdetails.Help
	if err := proto.Unmarshal(data, &unmarshaledHelp); err != nil {
		panic(err)
	}

	for _, l := range unmarshaledHelp.GetLinks() {
		fmt.Printf("Unmarshaled Link: %s -> %s\n", l.GetDescription(), l.GetUrl())
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20241007155032-5fefd90f89a9"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/errdetails.Help_Link"
  ]
}
test/contract_test.go
package test

import (
	"testing"

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

func TestHelpLinkFieldsAndGetters(t *testing.T) {
	link := &errdetails.Help_Link{
		Description: "API Reference",
		Url:         "https://example.com/docs/api",
	}

	if got := link.GetDescription(); got != "API Reference" {
		t.Errorf("GetDescription() = %q, want %q", got, "API Reference")
	}
	if got := link.GetUrl(); got != "https://example.com/docs/api" {
		t.Errorf("GetUrl() = %q, want %q", got, "https://example.com/docs/api")
	}
	if got := link.Description; got != "API Reference" {
		t.Errorf("Description field = %q, want %q", got, "API Reference")
	}
	if got := link.Url; got != "https://example.com/docs/api" {
		t.Errorf("Url field = %q, want %q", got, "https://example.com/docs/api")
	}
}

func TestHelpLinkNilSafeGetters(t *testing.T) {
	var nilLink *errdetails.Help_Link

	if got := nilLink.GetDescription(); got != "" {
		t.Errorf("nil.GetDescription() = %q, want empty string", got)
	}
	if got := nilLink.GetUrl(); got != "" {
		t.Errorf("nil.GetUrl() = %q, want empty string", got)
	}
}

func TestHelpLinkReset(t *testing.T) {
	link := &errdetails.Help_Link{
		Description: "Temporary Link",
		Url:         "https://example.com/temp",
	}

	link.Reset()

	if link.GetDescription() != "" || link.GetUrl() != "" {
		t.Errorf("Reset() did not clear fields: desc=%q, url=%q", link.GetDescription(), link.GetUrl())
	}
}

func TestHelpLinkProtoSerialization(t *testing.T) {
	original := &errdetails.Help_Link{
		Description: "Error guide",
		Url:         "https://example.com/guide/101",
	}

	data, err := proto.Marshal(original)
	if err != nil {
		t.Fatalf("proto.Marshal failed: %v", err)
	}

	var decoded errdetails.Help_Link
	if err := proto.Unmarshal(data, &decoded); err != nil {
		t.Fatalf("proto.Unmarshal failed: %v", err)
	}

	if decoded.GetDescription() != original.GetDescription() {
		t.Errorf("decoded Description = %q, want %q", decoded.GetDescription(), original.GetDescription())
	}
	if decoded.GetUrl() != original.GetUrl() {
		t.Errorf("decoded Url = %q, want %q", decoded.GetUrl(), original.GetUrl())
	}
}

func TestHelpWithHelpLinks(t *testing.T) {
	link1 := &errdetails.Help_Link{
		Description: "Overview",
		Url:         "https://example.com/overview",
	}
	link2 := &errdetails.Help_Link{
		Description: "Support",
		Url:         "https://example.com/support",
	}

	help := &errdetails.Help{
		Links: []*errdetails.Help_Link{link1, link2},
	}

	links := help.GetLinks()
	if len(links) != 2 {
		t.Fatalf("help.GetLinks() len = %d, want 2", len(links))
	}
	if links[0].GetDescription() != "Overview" || links[0].GetUrl() != "https://example.com/overview" {
		t.Errorf("link[0] mismatch: %v", links[0])
	}
	if links[1].GetDescription() != "Support" || links[1].GetUrl() != "https://example.com/support" {
		t.Errorf("link[1] mismatch: %v", links[1])
	}

	data, err := proto.Marshal(help)
	if err != nil {
		t.Fatalf("proto.Marshal(help) failed: %v", err)
	}

	var decodedHelp errdetails.Help
	if err := proto.Unmarshal(data, &decodedHelp); err != nil {
		t.Fatalf("proto.Unmarshal(help) failed: %v", err)
	}

	decodedLinks := decodedHelp.GetLinks()
	if len(decodedLinks) != 2 {
		t.Fatalf("decodedHelp.GetLinks() len = %d, want 2", len(decodedLinks))
	}
	if decodedLinks[0].GetDescription() != link1.GetDescription() || decodedLinks[0].GetUrl() != link1.GetUrl() {
		t.Errorf("decoded link[0] mismatch: %v", decodedLinks[0])
	}
}

Seeder de origem

anônimo