CodeSampleX

Exemplo

google.golang.org/protobuf v1.26.0-rc.1: proto.Clone

Amostra verificada para golang google.golang.org/protobuf v1.26.0-rc.1: proto.Clone. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:c0ca0bd99ff9184a87445efaf659c49cee7e040bd4d39959aa4f5b81e80af83f

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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-04

Caso

HOW
Objetivo
verify pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1
Pacotes
Símbolos
  • google.golang.org/protobuf/proto.Clone
Ambiente
go
Criado
2026-09-04T23:10:59Z

Contrato

  1. proto.Clone returns nil when given a nil proto.Message or typed nil message pointer
  2. proto.Clone creates a value duplicate of a message that satisfies proto.Equal with distinct pointer identity
  3. proto.Clone performs a deep copy of nested messages, ensuring mutations on cloned fields do not affect the source
  4. proto.Clone duplicates an empty message into a distinct empty instance satisfying proto.Equal
  5. proto.Clone preserves the concrete message type and permits direct type assertion to the original pointer type

Arquivos

  • NOTES.md
  • PROMPT.md
  • contract_test.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json

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

Código-fonte

NOTES.md
# Verification of `proto.Clone` in `google.golang.org/protobuf@v1.26.0-rc.1`

## Search Results
A search via `search_known_solution` for `proto.Clone` in `pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1` returned `NO_SAFE_MATCH`.

## Verified Behaviors and Contract
1. **Nil Message Safety**:
   - `proto.Clone(nil)` safely returns `nil` without panic.
   - Passing a typed nil pointer to `proto.Clone` returns `nil`, satisfying `proto.Equal`.

2. **Value Equality & Separate Allocation**:
   - `proto.Clone(msg)` produces an exact replica such that `proto.Equal(msg, cloned)` is `true`.
   - The memory address of the cloned message is distinct from the source.

3. **Deep Copy & Mutation Isolation**:
   - `proto.Clone` recursively copies nested message and map structures (e.g. `structpb.Struct`).
   - Mutating fields or map entries on the cloned instance does not affect the source instance.

4. **Empty Message Duplication**:
   - Cloning an empty message (e.g. `emptypb.Empty`) results in a distinct, equal instance.

5. **Type Preservation**:
   - `proto.Clone` preserves the underlying dynamic/static type, enabling safe type assertions back to the concrete pointer type.
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 pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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.
contract_test.go
package sample

import (
	"testing"

	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/emptypb"
	"google.golang.org/protobuf/types/known/structpb"
	"google.golang.org/protobuf/types/known/wrapperspb"
)

// TestClone_NilMessage verifies that proto.Clone returns nil when passed nil.
func TestClone_NilMessage(t *testing.T) {
	if got := proto.Clone(nil); got != nil {
		t.Fatalf("expected proto.Clone(nil) to be nil, got %v", got)
	}

	var typedNil *wrapperspb.StringValue
	if got := proto.Clone(typedNil); got != nil {
		if !proto.Equal(typedNil, got) {
			t.Fatalf("expected proto.Clone(typedNil) to equal typedNil, got %v", got)
		}
	}
}

// TestClone_ValueEquality verifies that proto.Clone creates a duplicate that satisfies proto.Equal.
func TestClone_ValueEquality(t *testing.T) {
	src := wrapperspb.String("hello CodeSampleX")
	cloned := proto.Clone(src)

	if cloned == nil {
		t.Fatal("expected non-nil clone for non-nil message")
	}

	if !proto.Equal(src, cloned) {
		t.Fatalf("expected cloned message to equal source: src=%v, cloned=%v", src, cloned)
	}

	if src == cloned {
		t.Fatal("expected clone to be a separate allocated instance, but pointers were identical")
	}
}

// TestClone_DeepCopyMutationIsolation verifies that mutating a nested field on a cloned message
// does not modify the source message.
func TestClone_DeepCopyMutationIsolation(t *testing.T) {
	src, err := structpb.NewStruct(map[string]any{
		"nested": map[string]any{
			"key": "original-value",
		},
		"count": 100,
	})
	if err != nil {
		t.Fatalf("failed to create initial structpb: %v", err)
	}

	cloned, ok := proto.Clone(src).(*structpb.Struct)
	if !ok {
		t.Fatalf("expected cloned message to be *structpb.Struct, got %T", proto.Clone(src))
	}

	// Mutate nested field in the clone
	nestedStruct := cloned.Fields["nested"].GetStructValue()
	nestedStruct.Fields["key"] = structpb.NewStringValue("modified-in-clone")
	cloned.Fields["count"] = structpb.NewNumberValue(999)

	// Verify original is untouched
	origNested := src.Fields["nested"].GetStructValue()
	if origVal := origNested.Fields["key"].GetStringValue(); origVal != "original-value" {
		t.Fatalf("source mutated after modifying clone: expected 'original-value', got '%s'", origVal)
	}
	if origCount := src.Fields["count"].GetNumberValue(); origCount != 100 {
		t.Fatalf("source count mutated after modifying clone: expected 100, got %f", origCount)
	}

	// Verify cloned has the updated values
	if clonedVal := nestedStruct.Fields["key"].GetStringValue(); clonedVal != "modified-in-clone" {
		t.Fatalf("clone does not have mutated value: expected 'modified-in-clone', got '%s'", clonedVal)
	}
}

// TestClone_EmptyMessage verifies that proto.Clone copies empty messages into distinct empty instances.
func TestClone_EmptyMessage(t *testing.T) {
	src := &emptypb.Empty{}
	cloned := proto.Clone(src)

	if cloned == nil {
		t.Fatal("expected non-nil clone for Empty message")
	}
	if !proto.Equal(src, cloned) {
		t.Fatalf("expected clone of Empty to equal source")
	}
	if src == cloned {
		t.Fatal("expected clone of Empty to have a distinct pointer address")
	}
}

// TestClone_TypePreservation verifies that proto.Clone preserves the concrete message type
// and supports type assertion back to the concrete pointer.
func TestClone_TypePreservation(t *testing.T) {
	src := wrapperspb.Int64(42)
	cloned := proto.Clone(src)

	typedVal, ok := cloned.(*wrapperspb.Int64Value)
	if !ok {
		t.Fatalf("type assertion to *wrapperspb.Int64Value failed, got %T", cloned)
	}
	if typedVal.GetValue() != 42 {
		t.Fatalf("expected value 42, got %d", typedVal.GetValue())
	}
}
csx.json
{"case":{"caseId":"case:sha256:fb65213c88530ab4ac430b69726d7c6ee77a4fff88e7e8846ab611265c01dc83","contract":["proto.Clone returns nil when given a nil proto.Message or typed nil message pointer","proto.Clone creates a value duplicate of a message that satisfies proto.Equal with distinct pointer identity","proto.Clone performs a deep copy of nested messages, ensuring mutations on cloned fields do not affect the source","proto.Clone duplicates an empty message into a distinct empty instance satisfying proto.Equal","proto.Clone preserves the concrete message type and permits direct type assertion to the original pointer type"],"goal":"verify pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/proto.Clone"]},"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.26.0-rc.1"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1","symbols":["google.golang.org/protobuf/proto.Clone"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require google.golang.org/protobuf v1.26.0-rc.1
go.sum
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.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/protobuf@v1.26.0-rc.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}

Seeder de origem

anônimo