CodeSampleX

Sample

cloud.google.com/go/auth v0.18.2: Token

Verified sample for golang cloud.google.com/go/auth v0.18.2: Token. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:2f3cd2b05f26e6f9517363906bed67c5def6a8a555ddc02068d78ee8b04e1513

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 linux 24 · ubuntu · glibc 2.39 x64 go

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

Case

HOW
Goal
verify cloud.google.com/go/auth.Token in pkg:golang/cloud.google.com/go/auth@v0.18.2
Packages
Symbols
  • cloud.google.com/go/auth.Token
Created
2026-10-10T14:56:05Z

Contract

  1. Token with non-empty value and zero expiry is reported as valid
  2. Token with empty value, nil pointer, or past expiry timestamp is reported as invalid
  3. Token with future expiry timestamp beyond the expiry delta is reported as valid
  4. Token MetadataString retrieves string values and returns empty string for missing keys, nil metadata, or non-string values
  5. CachedTokenProvider returns the Token provided by the underlying TokenProvider and caches valid tokens across repeated calls

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 cloud.google.com/go/auth.Token in pkg:golang/cloud.google.com/go/auth@v0.18.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/cloud.google.com/go/auth@v0.18.2
Demonstrate these symbols/APIs:
  - cloud.google.com/go/auth.Token

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:692a09f6d83238a7661753eeef2dce3e8c2d9846ef47fb11dd5007dd993ca560","contract":["Token with non-empty value and zero expiry is reported as valid","Token with empty value, nil pointer, or past expiry timestamp is reported as invalid","Token with future expiry timestamp beyond the expiry delta is reported as valid","Token MetadataString retrieves string values and returns empty string for missing keys, nil metadata, or non-string values","CachedTokenProvider returns the Token provided by the underlying TokenProvider and caches valid tokens across repeated calls"],"goal":"verify cloud.google.com/go/auth.Token in pkg:golang/cloud.google.com/go/auth@v0.18.2","kind":"HOW","packages":["pkg:golang/cloud.google.com/go/auth@v0.18.2"],"schemaVersion":1,"symbols":["cloud.google.com/go/auth.Token"]},"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/cloud.google.com/go/auth@v0.18.2"],"schemaVersion":1,"subject":"pkg:golang/cloud.google.com/go/auth@v0.18.2","symbols":["cloud.google.com/go/auth.Token"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.24.0

require cloud.google.com/go/auth v0.18.2

require (
	cloud.google.com/go/compute/metadata v0.9.0 // indirect
	github.com/googleapis/gax-go/v2 v2.17.0 // indirect
	golang.org/x/sys v0.40.0 // indirect
)
go.sum
cloud.google.com/go/auth v0.18.2 h1:+Nbt5Ev0xEqxlNjd6c+yYUeosQ5TtEUaNcN/3FozlaM=
cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M=
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
github.com/googleapis/enterprise-certificate-proxy v0.3.11 h1:vAe81Msw+8tKUxi2Dqh/NZMz7475yUvmRIkXr4oN2ao=
github.com/googleapis/enterprise-certificate-proxy v0.3.11/go.mod h1:RFV7MUdlb7AgEq2v7FmMCfeSMCllAzWxFgRdusoGks8=
github.com/googleapis/gax-go/v2 v2.17.0 h1:RksgfBpxqff0EZkDWYuz9q/uWsTVz+kf43LsZ1J6SMc=
github.com/googleapis/gax-go/v2 v2.17.0/go.mod h1:mzaqghpQp4JDh3HvADwrat+6M3MOIDp5YKHhb9PAgDY=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO785nis48=
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
google.golang.org/genproto v0.0.0-20260128011058-8636f8732409 h1:VQZ/yAbAtjkHgH80teYd2em3xtIkkHd7ZhqfH2N9CsM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"context"
	"fmt"
	"time"

	"cloud.google.com/go/auth"
)

type staticTokenProvider struct {
	token *auth.Token
}

func (s *staticTokenProvider) Token(ctx context.Context) (*auth.Token, error) {
	return s.token, nil
}

func main() {
	tok := &auth.Token{
		Value:  "sample-access-token-xyz",
		Type:   "Bearer",
		Expiry: time.Now().Add(1 * time.Hour),
		Metadata: map[string]interface{}{
			"scope":      "https://example.com/auth/read",
			"token_type": "Bearer",
		},
	}

	fmt.Printf("Token valid: %t\n", tok.IsValid())
	fmt.Printf("Token type: %s\n", tok.Type)
	fmt.Printf("Token scope: %s\n", tok.MetadataString("scope"))

	provider := &staticTokenProvider{token: tok}
	cachedProvider := auth.NewCachedTokenProvider(provider, nil)

	ctx := context.Background()
	retrievedTok, err := cachedProvider.Token(ctx)
	if err != nil {
		fmt.Printf("Failed to get token: %v\n", err)
		return
	}
	fmt.Printf("Retrieved token value: %s\n", retrievedTok.Value)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cloud.google.com/go/auth.Token in pkg:golang/cloud.google.com/go/auth@v0.18.2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/cloud.google.com/go/auth@v0.18.2"
  ],
  "symbols": [
    "cloud.google.com/go/auth.Token"
  ]
}
test/contract.go
package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"cloud.google.com/go/auth"
)

type countingTokenProvider struct {
	token *auth.Token
	calls int
}

func (p *countingTokenProvider) Token(ctx context.Context) (*auth.Token, error) {
	p.calls++
	return p.token, nil
}

func main() {
	// Assertion 1: Token with non-empty value and zero expiry is reported as valid
	{
		tok := &auth.Token{Value: "sample-token-value"}
		if !tok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected token with value and zero expiry to be valid\n")
			os.Exit(1)
		}
	}

	// Assertion 2: Token with empty value, nil pointer, or past expiry timestamp is reported as invalid
	{
		emptyTok := &auth.Token{}
		if emptyTok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected empty token to be invalid\n")
			os.Exit(1)
		}

		var nilTok *auth.Token
		if nilTok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected nil token to be invalid\n")
			os.Exit(1)
		}

		pastTok := &auth.Token{Value: "token-val", Expiry: time.Now().Add(-10 * time.Minute)}
		if pastTok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected past expired token to be invalid\n")
			os.Exit(1)
		}

		nearExpiryTok := &auth.Token{Value: "token-val", Expiry: time.Now().Add(60 * time.Second)}
		if nearExpiryTok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected token expiring within delta to be invalid\n")
			os.Exit(1)
		}
	}

	// Assertion 3: Token with future expiry timestamp beyond the expiry delta is reported as valid
	{
		futureTok := &auth.Token{Value: "token-val", Expiry: time.Now().Add(1 * time.Hour)}
		if !futureTok.IsValid() {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected future token to be valid\n")
			os.Exit(1)
		}
	}

	// Assertion 4: Token MetadataString retrieves string values and returns empty string for missing keys, nil metadata, or non-string values
	{
		nilMetaTok := &auth.Token{Value: "val"}
		if nilMetaTok.MetadataString("key") != "" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected empty string for nil metadata\n")
			os.Exit(1)
		}

		tokWithMeta := &auth.Token{
			Value: "val",
			Metadata: map[string]interface{}{
				"string_key": "sample-string",
				"int_key":    42,
			},
		}
		if got := tokWithMeta.MetadataString("string_key"); got != "sample-string" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected 'sample-string', got %q\n", got)
			os.Exit(1)
		}
		if got := tokWithMeta.MetadataString("int_key"); got != "" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected empty string for non-string key, got %q\n", got)
			os.Exit(1)
		}
		if got := tokWithMeta.MetadataString("missing_key"); got != "" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected empty string for missing key, got %q\n", got)
			os.Exit(1)
		}
	}

	// Assertion 5: CachedTokenProvider returns the Token provided by the underlying TokenProvider and caches valid tokens across repeated calls
	{
		provider := &countingTokenProvider{
			token: &auth.Token{Value: "cached-token-xyz", Expiry: time.Now().Add(1 * time.Hour)},
		}
		cached := auth.NewCachedTokenProvider(provider, nil)
		ctx := context.Background()

		tok1, err := cached.Token(ctx)
		if err != nil || tok1 == nil || tok1.Value != "cached-token-xyz" {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: first call failed: tok=%v, err=%v\n", tok1, err)
			os.Exit(1)
		}

		tok2, err := cached.Token(ctx)
		if err != nil || tok2 == nil || tok2.Value != "cached-token-xyz" {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: second call failed: tok=%v, err=%v\n", tok2, err)
			os.Exit(1)
		}

		if provider.calls != 1 {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected exactly 1 underlying call, got %d\n", provider.calls)
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all auth.Token contract assertions passed successfully")
}

Origin Seeder

anonymous