CodeSampleX

Beispiel

google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: code.Code_CANCELLED

Verifiziertes Beispiel für golang google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5: code.Code_CANCELLED. Der Vertrag lief auf go…

sha256:c3e797ea7cfc49af08b8ad57c90aed4eeea6da35d02ae9cf7663ea41b2d8f1dc

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-07

Fall

HOW
Ziel
verify google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Pakete
Symbole
  • google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED
Umgebung
go 1.26.6
Erstellt
2026-09-07T00:17:54Z

Contract

  1. code.Code_CANCELLED equals numerical value 1
  2. code.Code_CANCELLED is a code.Code enum value
  3. code.Code_CANCELLED String() returns "CANCELLED"
  4. code.Code_CANCELLED Number() returns protoreflect.EnumNumber 1
  5. code.Code_CANCELLED Enum() returns a pointer to Code_CANCELLED
  6. code.Code_name maps 1 to "CANCELLED"
  7. code.Code_value maps "CANCELLED" to 1
  8. IsCancelled returns true for Code_CANCELLED and false for Code_OK
  9. GetCancelledCode returns Code_CANCELLED

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/code.Code_CANCELLED in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED

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

import (
	"google.golang.org/genproto/googleapis/rpc/code"
)

// IsCancelled returns true if the given code is Code_CANCELLED.
func IsCancelled(c code.Code) bool {
	return c == code.Code_CANCELLED
}

// GetCancelledCode returns the Code_CANCELLED enum value.
func GetCancelledCode() code.Code {
	return code.Code_CANCELLED
}

// GetCancelledName returns the string representation of Code_CANCELLED.
func GetCancelledName() string {
	return code.Code_CANCELLED.String()
}

// GetCancelledNumber returns the integer value of Code_CANCELLED.
func GetCancelledNumber() int32 {
	return int32(code.Code_CANCELLED)
}
csx.json
{"case":{"caseId":"case:sha256:c68562f6ca17cfddbe1090d833027e02362e3cc4c24263830e22920aae5e07b4","contract":["code.Code_CANCELLED equals numerical value 1","code.Code_CANCELLED is a code.Code enum value","code.Code_CANCELLED String() returns \"CANCELLED\"","code.Code_CANCELLED Number() returns protoreflect.EnumNumber 1","code.Code_CANCELLED Enum() returns a pointer to Code_CANCELLED","code.Code_name maps 1 to \"CANCELLED\"","code.Code_value maps \"CANCELLED\" to 1","IsCancelled returns true for Code_CANCELLED and false for Code_OK","GetCancelledCode returns Code_CANCELLED"],"goal":"verify google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED"]},"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/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5","symbols":["google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5

require google.golang.org/protobuf v1.36.12 // indirect
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=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED in pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/rpc@v0.0.0-20260825221802-da73d73af1c5"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/rpc/code.Code_CANCELLED"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/rpc/code"
	"sample"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: all contract assertions satisfied")
}

func runContract() error {
	// Assertion 1: code.Code_CANCELLED equals numerical value 1
	if code.Code_CANCELLED != 1 {
		return fmt.Errorf("expected code.Code_CANCELLED to equal 1, got %d", int32(code.Code_CANCELLED))
	}
	if int32(code.Code_CANCELLED) != 1 {
		return fmt.Errorf("expected int32(code.Code_CANCELLED) to equal 1, got %d", int32(code.Code_CANCELLED))
	}

	// Assertion 2: code.Code_CANCELLED is a code.Code enum value
	var c code.Code = code.Code_CANCELLED
	if c != 1 {
		return fmt.Errorf("expected c to equal 1, got %v", c)
	}

	// Assertion 3: code.Code_CANCELLED String() returns "CANCELLED"
	if s := code.Code_CANCELLED.String(); s != "CANCELLED" {
		return fmt.Errorf("expected String() to return \"CANCELLED\", got %q", s)
	}

	// Assertion 4: code.Code_CANCELLED Number() returns protoreflect.EnumNumber 1
	if num := code.Code_CANCELLED.Number(); int32(num) != 1 {
		return fmt.Errorf("expected Number() to return 1, got %d", num)
	}

	// Assertion 5: code.Code_CANCELLED Enum() returns a pointer to Code_CANCELLED
	enumPtr := code.Code_CANCELLED.Enum()
	if enumPtr == nil || *enumPtr != code.Code_CANCELLED {
		return fmt.Errorf("expected Enum() to return pointer to Code_CANCELLED, got %v", enumPtr)
	}

	// Assertion 6: code.Code_name maps 1 to "CANCELLED"
	if name, ok := code.Code_name[int32(code.Code_CANCELLED)]; !ok || name != "CANCELLED" {
		return fmt.Errorf("expected Code_name[1] to be \"CANCELLED\", got %q (ok=%v)", name, ok)
	}

	// Assertion 7: code.Code_value maps "CANCELLED" to 1
	if val, ok := code.Code_value["CANCELLED"]; !ok || val != int32(code.Code_CANCELLED) {
		return fmt.Errorf("expected Code_value[\"CANCELLED\"] to be 1, got %d (ok=%v)", val, ok)
	}

	// Assertion 8: IsCancelled returns true for Code_CANCELLED and false for Code_OK
	if !sample.IsCancelled(code.Code_CANCELLED) {
		return fmt.Errorf("expected IsCancelled(Code_CANCELLED) to be true")
	}
	if sample.IsCancelled(code.Code_OK) {
		return fmt.Errorf("expected IsCancelled(Code_OK) to be false")
	}

	// Assertion 9: GetCancelledCode returns Code_CANCELLED
	if sample.GetCancelledCode() != code.Code_CANCELLED {
		return fmt.Errorf("expected GetCancelledCode() to return Code_CANCELLED")
	}

	return nil
}

Ursprungs-Seeder

anonym