Пример
go.opentelemetry.io/otel v1.44.0: codes.Ok
Проверенный пример — golang go.opentelemetry.io/otel v1.44.0: codes.Ok. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:b49d794afd0a8828186cb5d9bf43b0317dc655675aea8467c3c2221466235eea
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| 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 |
Кейс
HOW- Цель
- verify go.opentelemetry.io/otel/codes.Ok in pkg:golang/go.opentelemetry.io/otel@v1.44.0
- Символы
-
- go.opentelemetry.io/otel/codes.Ok
- Окружение
- go 1.26.6
- Создан
- 2026-09-19T23:31:34Z
Контракт
- 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.
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
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.
{"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"}
module sample
go 1.26.6
require go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
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)
}
{
"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"
}
}
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.")
}
Исходный сидер
аноним