CodeSampleX

Sample

go.opentelemetry.io/otel v1.44.0: codes.Ok

Verified sample for golang go.opentelemetry.io/otel v1.44.0: codes.Ok. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:b49d794afd0a8828186cb5d9bf43b0317dc655675aea8467c3c2221466235eea

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Verification-run environments

Environment Contract Stages Run
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-19

Case

HOW
Goal
verify go.opentelemetry.io/otel/codes.Ok in pkg:golang/go.opentelemetry.io/otel@v1.44.0
Packages
Symbols
  • go.opentelemetry.io/otel/codes.Ok
Environment
go 1.26.6
Created
2026-09-19T23:31:34Z

Contract

  1. codes.Ok is a typed codes.Code constant with underlying uint32 value 2, strictly distinct from Unset (0) and Error (1).
  2. codes.Ok.String() returns "Ok", matching its canonical identifier name.
  3. (*codes.Code).MarshalJSON() encodes codes.Ok as string "\"Ok\"", whereas value json.Marshal(codes.Ok) falls back to underlying numeric representation 2 due to pointer receiver.
  4. (*codes.Code).UnmarshalJSON() successfully decodes both string "\"Ok\"" and numeric 2 into codes.Ok.
  5. (*codes.Code).UnmarshalJSON() rejects case-mismatched or malformed inputs such as "OK", "ok", "STATUS_CODE_OK", returning an error without corrupting the target code.

Files

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

Download the source artifact (tar.gz)

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/otel/codes.Ok in pkg:golang/go.opentelemetry.io/otel@v1.44.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/go.opentelemetry.io/otel@v1.44.0
Demonstrate these symbols/APIs:
  - go.opentelemetry.io/otel/codes.Ok
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:32f968a16a7a140df7a9bd79be5aa3e15e5349f199130d83cf72cb5953fff12e","contract":["codes.Ok is a typed codes.Code constant with underlying uint32 value 2, strictly distinct from Unset (0) and Error (1).","codes.Ok.String() returns \"Ok\", matching its canonical identifier name.","(*codes.Code).MarshalJSON() encodes codes.Ok as string \"\\\"Ok\\\"\", whereas value json.Marshal(codes.Ok) falls back to underlying numeric representation 2 due to pointer receiver.","(*codes.Code).UnmarshalJSON() successfully decodes both string \"\\\"Ok\\\"\" and numeric 2 into codes.Ok.","(*codes.Code).UnmarshalJSON() rejects case-mismatched or malformed inputs such as \"OK\", \"ok\", \"STATUS_CODE_OK\", returning an error without corrupting the target code."],"goal":"verify go.opentelemetry.io/otel/codes.Ok in pkg:golang/go.opentelemetry.io/otel@v1.44.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/otel@v1.44.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/otel/codes.Ok"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/go.opentelemetry.io/otel@v1.44.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/otel@v1.44.0","symbols":["go.opentelemetry.io/otel/codes.Ok"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require go.opentelemetry.io/otel v1.44.0
go.sum
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
main.go
package main

import (
	"encoding/json"
	"fmt"

	"go.opentelemetry.io/otel/codes"
)

func main() {
	// Demonstrate codes.Ok usage and properties
	status := codes.Ok
	fmt.Printf("Status: %s (value %d)\n", status, uint32(status))

	// Demonstrate JSON representation difference between pointer and value
	okPtr := &status
	ptrJSON, _ := okPtr.MarshalJSON()
	valJSON, _ := json.Marshal(status)
	fmt.Printf("Pointer JSON: %s, Value JSON: %s\n", string(ptrJSON), string(valJSON))

	// Demonstrate unmarshaling string "Ok"
	var decoded codes.Code
	_ = json.Unmarshal([]byte(`"Ok"`), &decoded)
	fmt.Printf("Decoded status from string: %s (is Ok: %v)\n", decoded, decoded == codes.Ok)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify go.opentelemetry.io/otel/codes.Ok in pkg:golang/go.opentelemetry.io/otel@v1.44.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/go.opentelemetry.io/otel@v1.44.0"
  ],
  "symbols": [
    "go.opentelemetry.io/otel/codes.Ok"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
test/contract.go
package main

import (
	"encoding/json"
	"fmt"
	"os"

	"go.opentelemetry.io/otel/codes"
)

func main() {
	// Assertion 1: codes.Ok is a typed codes.Code constant with underlying uint32 value 2, strictly distinct from Unset (0) and Error (1).
	if codes.Ok != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: expected codes.Ok to equal 2, got %d\n", uint32(codes.Ok))
		os.Exit(1)
	}
	if codes.Ok == codes.Unset {
		fmt.Fprintf(os.Stderr, "FAIL: codes.Ok unexpectedly equals codes.Unset\n")
		os.Exit(1)
	}
	if codes.Ok == codes.Error {
		fmt.Fprintf(os.Stderr, "FAIL: codes.Ok unexpectedly equals codes.Error\n")
		os.Exit(1)
	}

	// Assertion 2: codes.Ok.String() returns "Ok", matching its canonical identifier name.
	if str := codes.Ok.String(); str != "Ok" {
		fmt.Fprintf(os.Stderr, "FAIL: expected codes.Ok.String() to be 'Ok', got %q\n", str)
		os.Exit(1)
	}

	// Assertion 3: (*codes.Code).MarshalJSON() encodes codes.Ok as string "\"Ok\"", whereas value json.Marshal(codes.Ok) falls back to underlying numeric representation 2 due to pointer receiver.
	okVal := codes.Ok
	ptrJSON, err := (&okVal).MarshalJSON()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: (&okVal).MarshalJSON() failed: %v\n", err)
		os.Exit(1)
	}
	if string(ptrJSON) != `"Ok"` {
		fmt.Fprintf(os.Stderr, "FAIL: expected ptrJSON to be '\"Ok\"', got %s\n", string(ptrJSON))
		os.Exit(1)
	}

	valJSON, err := json.Marshal(codes.Ok)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: json.Marshal(codes.Ok) failed: %v\n", err)
		os.Exit(1)
	}
	if string(valJSON) != "2" {
		fmt.Fprintf(os.Stderr, "FAIL: expected valJSON to be '2', got %s\n", string(valJSON))
		os.Exit(1)
	}

	// Assertion 4: (*codes.Code).UnmarshalJSON() successfully decodes both string "\"Ok\"" and numeric 2 into codes.Ok.
	var c1 codes.Code
	if err := json.Unmarshal([]byte(`"Ok"`), &c1); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: json.Unmarshal string '\"Ok\"' failed: %v\n", err)
		os.Exit(1)
	}
	if c1 != codes.Ok {
		fmt.Fprintf(os.Stderr, "FAIL: expected unmarshaled string '\"Ok\"' to equal codes.Ok, got %v\n", c1)
		os.Exit(1)
	}

	var c2 codes.Code
	if err := json.Unmarshal([]byte("2"), &c2); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: json.Unmarshal numeric 2 failed: %v\n", err)
		os.Exit(1)
	}
	if c2 != codes.Ok {
		fmt.Fprintf(os.Stderr, "FAIL: expected unmarshaled numeric 2 to equal codes.Ok, got %v\n", c2)
		os.Exit(1)
	}

	// Assertion 5: (*codes.Code).UnmarshalJSON() rejects case-mismatched or malformed inputs such as "OK", "ok", "STATUS_CODE_OK", returning an error without corrupting the target code.
	invalidInputs := []string{`"OK"`, `"ok"`, `"STATUS_CODE_OK"`, `"invalid"`}
	for _, input := range invalidInputs {
		target := codes.Ok
		if err := json.Unmarshal([]byte(input), &target); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error unmarshaling %s, but got nil\n", input)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all codes.Ok contract assertions passed.")
}

Origin Seeder

anonymous