CodeSampleX

Exemple

go.opentelemetry.io/proto/otlp v1.9.0: v1.AnyValue_DoubleValue

Échantillon vérifié pour golang go.opentelemetry.io/proto/otlp v1.9.0: v1.AnyValue_DoubleValue. Le contrat s'est exécuté sur go 1.26 · linux debian/x64 …

sha256:a758bad674bece3a4775289748446a94506dd7eabb37b54773b6972676b13db9

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

Cas

HOW
Objectif
verify go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Paquets
Symboles
  • go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue
Créé
2026-09-05T14:03:39Z

Contrat

  1. AnyValue_DoubleValue wraps a 64-bit float value implementing the isAnyValue_Value interface for AnyValue.Value.
  2. AnyValue.GetDoubleValue returns the wrapped float64 value when AnyValue_DoubleValue is set, and returns 0.0 when unset or nil.
  3. Type assertion on AnyValue.GetValue matches *commonpb.AnyValue_DoubleValue and provides direct access to DoubleValue field.
  4. AnyValue_DoubleValue correctly preserves positive, negative, fractional, zero, and special floating-point values.
  5. AnyValue containing AnyValue_DoubleValue serializes and deserializes accurately via binary protobuf wire format and proto.Equal.
  6. AnyValue containing AnyValue_DoubleValue marshals to and unmarshals from protojson format, representing the field as 'doubleValue'.

Fichiers

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/main.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 go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Demonstrate these symbols/APIs:
  - go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue

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:cc35a2c48cd633987411af22e370955c82b7d6e3c975b6931f4c8bd58034985e","contract":["AnyValue_DoubleValue wraps a 64-bit float value implementing the isAnyValue_Value interface for AnyValue.Value.","AnyValue.GetDoubleValue returns the wrapped float64 value when AnyValue_DoubleValue is set, and returns 0.0 when unset or nil.","Type assertion on AnyValue.GetValue matches *commonpb.AnyValue_DoubleValue and provides direct access to DoubleValue field.","AnyValue_DoubleValue correctly preserves positive, negative, fractional, zero, and special floating-point values.","AnyValue containing AnyValue_DoubleValue serializes and deserializes accurately via binary protobuf wire format and proto.Equal.","AnyValue containing AnyValue_DoubleValue marshals to and unmarshals from protojson format, representing the field as 'doubleValue'."],"goal":"verify go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue"]},"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/go.opentelemetry.io/proto/otlp@v1.9.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","symbols":["go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue"],"verifierAdapter":"golang@1"}
go.mod
module example.com/otlpanyvaluedouble

go 1.26.6

require (
	go.opentelemetry.io/proto/otlp v1.9.0
	google.golang.org/protobuf v1.36.10
)
go.sum
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"
  ],
  "symbols": [
    "go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue"
  ]
}
test/main.go
package main

import (
	"bytes"
	"fmt"
	"math"
	"os"

	commonpb "go.opentelemetry.io/proto/otlp/common/v1"
	"google.golang.org/protobuf/encoding/protojson"
	"google.golang.org/protobuf/proto"
)

func assert(condition bool, message string) {
	if !condition {
		fmt.Fprintf(os.Stderr, "assertion failed: %s\n", message)
		os.Exit(1)
	}
}

func main() {
	// Assertion 1: AnyValue_DoubleValue wraps a 64-bit float value implementing the isAnyValue_Value interface for AnyValue.Value.
	{
		dv := &commonpb.AnyValue_DoubleValue{
			DoubleValue: 3.141592653589793,
		}
		anyVal := &commonpb.AnyValue{
			Value: dv,
		}
		assert(anyVal.GetValue() != nil, "expected non-nil Value")
		assert(dv.DoubleValue == 3.141592653589793, "expected matching DoubleValue field")
	}

	// Assertion 2: AnyValue.GetDoubleValue returns the wrapped float64 value when AnyValue_DoubleValue is set, and returns 0.0 when unset or nil.
	{
		anyVal := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 42.5},
		}
		assert(anyVal.GetDoubleValue() == 42.5, "expected GetDoubleValue to return 42.5")

		emptyVal := &commonpb.AnyValue{}
		assert(emptyVal.GetDoubleValue() == 0.0, "expected default 0.0 on empty AnyValue")

		var nilVal *commonpb.AnyValue
		assert(nilVal.GetDoubleValue() == 0.0, "expected default 0.0 on nil AnyValue")

		strVal := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_StringValue{StringValue: "not a float"},
		}
		assert(strVal.GetDoubleValue() == 0.0, "expected default 0.0 on mismatched StringValue variant")
	}

	// Assertion 3: Type assertion on AnyValue.GetValue matches *commonpb.AnyValue_DoubleValue and provides direct access to DoubleValue field.
	{
		anyVal := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 123.456},
		}
		dv, ok := anyVal.GetValue().(*commonpb.AnyValue_DoubleValue)
		assert(ok, "expected type assertion to *commonpb.AnyValue_DoubleValue to succeed")
		assert(dv != nil && dv.DoubleValue == 123.456, "expected dv.DoubleValue to be 123.456")

		otherVal := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_IntValue{IntValue: 100},
		}
		_, okOther := otherVal.GetValue().(*commonpb.AnyValue_DoubleValue)
		assert(!okOther, "expected type assertion to fail on IntValue variant")
	}

	// Assertion 4: AnyValue_DoubleValue correctly preserves positive, negative, fractional, zero, and special floating-point values.
	{
		testCases := []float64{
			0.0,
			-0.0,
			1.0,
			-1.0,
			0.00000000001,
			-9876543210.12345,
			math.MaxFloat64,
			math.SmallestNonzeroFloat64,
			math.Inf(1),
			math.Inf(-1),
		}

		for _, tc := range testCases {
			val := &commonpb.AnyValue{
				Value: &commonpb.AnyValue_DoubleValue{DoubleValue: tc},
			}
			assert(val.GetDoubleValue() == tc, fmt.Sprintf("expected %v, got %v", tc, val.GetDoubleValue()))
		}

		nanVal := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_DoubleValue{DoubleValue: math.NaN()},
		}
		assert(math.IsNaN(nanVal.GetDoubleValue()), "expected NaN value to be preserved")
	}

	// Assertion 5: AnyValue containing AnyValue_DoubleValue serializes and deserializes accurately via binary protobuf wire format and proto.Equal.
	{
		orig := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 271.8281828},
		}
		wire, err := proto.Marshal(orig)
		assert(err == nil, "proto.Marshal failed")
		assert(len(wire) > 0, "marshaled wire length is 0")

		unmarshaled := &commonpb.AnyValue{}
		err = proto.Unmarshal(wire, unmarshaled)
		assert(err == nil, "proto.Unmarshal failed")
		assert(proto.Equal(orig, unmarshaled), "proto.Equal returned false for protobuf round-trip")
		assert(unmarshaled.GetDoubleValue() == 271.8281828, "unmarshaled GetDoubleValue mismatched")
	}

	// Assertion 6: AnyValue containing AnyValue_DoubleValue marshals to and unmarshals from protojson format, representing the field as 'doubleValue'.
	{
		orig := &commonpb.AnyValue{
			Value: &commonpb.AnyValue_DoubleValue{DoubleValue: 6.022e23},
		}
		jsonBytes, err := protojson.Marshal(orig)
		assert(err == nil, "protojson.Marshal failed")
		assert(bytes.Contains(jsonBytes, []byte(`"doubleValue"`)), "json must contain 'doubleValue'")

		jsonUnmarshaled := &commonpb.AnyValue{}
		err = protojson.Unmarshal(jsonBytes, jsonUnmarshaled)
		assert(err == nil, "protojson.Unmarshal failed")
		assert(proto.Equal(orig, jsonUnmarshaled), "proto.Equal returned false for protojson round-trip")
		assert(jsonUnmarshaled.GetDoubleValue() == 6.022e23, "json unmarshaled GetDoubleValue mismatched")
	}

	fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/common/v1.AnyValue_DoubleValue contract assertions verified")
}

Seeder d'origine

anonyme