CodeSampleX

Sample

golang.org/x/time v0.11.0: rate.Limit

Verified sample for golang golang.org/x/time v0.11.0: rate.Limit. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:4b0d4a1715f0a5cecada9e89acfb7c878c114ec0a819334e92649339c680a4e5

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
2
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-26
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

Case

HOW
Goal
verify golang.org/x/time/rate.Limit in pkg:golang/golang.org/x/time@v0.11.0
Packages
Symbols
  • golang.org/x/time/rate.Limit
Created
2026-08-26T12:17:01Z

Contract

  1. limit := rate.Every(100 * time.Millisecond)
  2. limit == rate.Limit(10)
  3. rate.Every(0) == rate.Inf
  4. limiter := rate.NewLimiter(rate.Limit(5), 2)
  5. limiter.Limit() == rate.Limit(5)
  6. limiter.SetLimit(rate.Limit(20))
  7. limiter.Limit() == rate.Limit(20)
  8. unlimited := rate.NewLimiter(rate.Inf, 0)
  9. unlimited.Limit() == rate.Inf
  10. unlimited.Allow() == true

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • ratelimit.go
  • spec.json
  • test/contract_test.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 golang.org/x/time/rate.Limit in pkg:golang/golang.org/x/time@v0.11.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/time@v0.11.0
Demonstrate these symbols/APIs:
  - golang.org/x/time/rate.Limit

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:39bc2c8993b2916622fb3b26a2232134e1d7fcf34f7f339dd987909eca5f90e3","contract":["limit := rate.Every(100 * time.Millisecond)","limit == rate.Limit(10)","rate.Every(0) == rate.Inf","limiter := rate.NewLimiter(rate.Limit(5), 2)","limiter.Limit() == rate.Limit(5)","limiter.SetLimit(rate.Limit(20))","limiter.Limit() == rate.Limit(20)","unlimited := rate.NewLimiter(rate.Inf, 0)","unlimited.Limit() == rate.Inf","unlimited.Allow() == true"],"goal":"verify golang.org/x/time/rate.Limit in pkg:golang/golang.org/x/time@v0.11.0","kind":"HOW","packages":["pkg:golang/golang.org/x/time@v0.11.0"],"schemaVersion":1,"symbols":["golang.org/x/time/rate.Limit"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/time@v0.11.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/time@v0.11.0","symbols":["golang.org/x/time/rate.Limit"],"verifierAdapter":"golang@1"}
go.mod
module example.com/ratelimit

go 1.23.0

require golang.org/x/time v0.11.0
go.sum
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
ratelimit.go
package ratelimit

import (
	"time"

	"golang.org/x/time/rate"
)

// LimitManager manages rate limiting configurations with rate.Limit.
type LimitManager struct {
	limiter *rate.Limiter
}

// NewLimitManager creates a manager with a specified rate limit and burst size.
func NewLimitManager(r rate.Limit, burst int) *LimitManager {
	return &LimitManager{
		limiter: rate.NewLimiter(r, burst),
	}
}

// NewLimitFromInterval creates a manager using an interval duration converted to rate.Limit.
func NewLimitFromInterval(interval time.Duration, burst int) *LimitManager {
	limit := rate.Every(interval)
	return &LimitManager{
		limiter: rate.NewLimiter(limit, burst),
	}
}

// CurrentLimit returns the current rate.Limit of the limiter.
func (m *LimitManager) CurrentLimit() rate.Limit {
	return m.limiter.Limit()
}

// SetLimit updates the rate.Limit of the limiter.
func (m *LimitManager) SetLimit(r rate.Limit) {
	m.limiter.SetLimit(r)
}

// Allow reports whether an event may happen now.
func (m *LimitManager) Allow() bool {
	return m.limiter.Allow()
}

// IsInfinite returns true if the limit is rate.Inf.
func (m *LimitManager) IsInfinite() bool {
	return m.limiter.Limit() == rate.Inf
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/time/rate.Limit in pkg:golang/golang.org/x/time@v0.11.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/time@v0.11.0"
  ],
  "symbols": [
    "golang.org/x/time/rate.Limit"
  ]
}
test/contract_test.go
package test

import (
	"testing"
	"time"

	"golang.org/x/time/rate"
)

func TestLimitContract(t *testing.T) {
	// 1. rate.Every converts an interval into a rate.Limit
	limit := rate.Every(100 * time.Millisecond)
	if limit != rate.Limit(10) {
		t.Fatalf("expected rate.Every(100ms) to be 10 events/sec, got %v", limit)
	}

	// 2. rate.Every with non-positive duration returns rate.Inf
	infLimit := rate.Every(0)
	if infLimit != rate.Inf {
		t.Fatalf("expected rate.Every(0) to be rate.Inf, got %v", infLimit)
	}

	// 3. NewLimiter accepts rate.Limit and returns configured limit
	limiter := rate.NewLimiter(rate.Limit(5), 2)
	if limiter.Limit() != rate.Limit(5) {
		t.Fatalf("expected limit to be 5, got %v", limiter.Limit())
	}

	// 4. SetLimit updates the active rate.Limit
	limiter.SetLimit(rate.Limit(20))
	if limiter.Limit() != rate.Limit(20) {
		t.Fatalf("expected updated limit to be 20, got %v", limiter.Limit())
	}

	// 5. rate.Inf allows unbounded operations
	unlimited := rate.NewLimiter(rate.Inf, 0)
	if unlimited.Limit() != rate.Inf {
		t.Fatalf("expected limit to be rate.Inf, got %v", unlimited.Limit())
	}
	if !unlimited.Allow() {
		t.Fatal("expected unlimited limiter to allow event")
	}
}

Origin Seeder

anonymous